|
@ -41,110 +41,114 @@ public class PatientSosContactsJob implements Job {
|
|
|
@Override
|
|
|
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
|
|
logger.info("PATIENT_SOS_CONTACTS_JOB start");
|
|
|
try {
|
|
|
String sql = " UPDATE base_patient_sos_contacts set success_flag=0,update_info = null,error_info=null where \n" +
|
|
|
" `success_flag` <> '1' AND `del` = '1' ";
|
|
|
jdbcTemplate.execute(sql);
|
|
|
|
|
|
String sql = " UPDATE base_patient_sos_contacts set success_flag=0,update_info = null,error_info=null where \n" +
|
|
|
" `success_flag` <> '1' AND `del` = '1' ";
|
|
|
jdbcTemplate.execute(sql);
|
|
|
|
|
|
sql = " select pd.device_sn,pd.category_code,wd.iccid as sim,sc.* from wlyy_patient_device pd inner join wlyy_devices wd " +
|
|
|
" on pd.device_sn = wd.device_code and pd.del=0 " +
|
|
|
"INNER JOIN base_patient_sos_contacts sc on sc.patient = pd.user and sc.del=1 " +
|
|
|
"where sc.success_flag=0 and pd.category_code in('7','4','16') group by wd.device_code ";
|
|
|
List<Map<String,Object>> sims = jdbcTemplate.queryForList(sql);
|
|
|
List<PatientSosContactsDO> modify = new ArrayList<>();
|
|
|
for(Map<String,Object> tmp:sims){//添加白名单,添加设备联系人
|
|
|
String sim = tmp.get("sim")==null?null:tmp.get("sim").toString() ;
|
|
|
String patient = tmp.get("patient").toString() ;
|
|
|
String device_sn = tmp.get("device_sn").toString() ;
|
|
|
String category_code = tmp.get("category_code").toString() ;
|
|
|
String id = tmp.get("id").toString() ;
|
|
|
String sos_name = tmp.get("sos_name").toString() ;
|
|
|
String sos_phone = tmp.get("sos_phone").toString() ;
|
|
|
String phone_seqid = tmp.get("phone_seqid").toString() ;
|
|
|
try {
|
|
|
PatientSosContactsDO sosContactsDO = sosContactsDao.findOne(Long.parseLong(id));
|
|
|
if (StringUtils.isBlank(sosContactsDO.getUpdateInfo())){
|
|
|
sosContactsDO.setUpdateInfo(" ");
|
|
|
}
|
|
|
if(null!=sosContactsDO){
|
|
|
if (StringUtils.isNotBlank(sim)){
|
|
|
JSONObject response = cardService.setPatientContacts(null, sim, null, "1", sos_phone);//移动白名单
|
|
|
//0成功 12102名单重复
|
|
|
if (response.getInteger("status")==0||response.getInteger("status")==12108){
|
|
|
if (1==sosContactsDO.getSuccessFlag()||0==sosContactsDO.getSuccessFlag()){
|
|
|
sosContactsDO.setSuccessFlag(1);
|
|
|
}else {
|
|
|
sosContactsDO.setSuccessFlag(-1);
|
|
|
}
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+1+"}");
|
|
|
}else {
|
|
|
sosContactsDO.setSuccessFlag(-1);
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+-1+"}");
|
|
|
sosContactsDO.setErrorInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+response.getString("message")+"}");
|
|
|
}
|
|
|
sql = " select pd.device_sn,pd.category_code,wd.iccid as sim,sc.* from wlyy_patient_device pd inner join wlyy_devices wd " +
|
|
|
" on pd.device_sn = wd.device_code and pd.del=0 " +
|
|
|
"INNER JOIN base_patient_sos_contacts sc on sc.patient = pd.user and sc.del=1 " +
|
|
|
"where sc.success_flag=0 and pd.category_code in('7','4','16') group by wd.device_code ";
|
|
|
List<Map<String,Object>> sims = jdbcTemplate.queryForList(sql);
|
|
|
List<PatientSosContactsDO> modify = new ArrayList<>();
|
|
|
for(Map<String,Object> tmp:sims){//添加白名单,添加设备联系人
|
|
|
String sim = tmp.get("sim")==null?null:tmp.get("sim").toString() ;
|
|
|
String patient = tmp.get("patient").toString() ;
|
|
|
String device_sn = tmp.get("device_sn").toString() ;
|
|
|
String category_code = tmp.get("category_code").toString() ;
|
|
|
String id = tmp.get("id").toString() ;
|
|
|
String sos_name = tmp.get("sos_name").toString() ;
|
|
|
String sos_phone = tmp.get("sos_phone").toString() ;
|
|
|
String phone_seqid = tmp.get("phone_seqid").toString() ;
|
|
|
try {
|
|
|
PatientSosContactsDO sosContactsDO = sosContactsDao.findOne(Long.parseLong(id));
|
|
|
if (StringUtils.isBlank(sosContactsDO.getUpdateInfo())){
|
|
|
sosContactsDO.setUpdateInfo(" ");
|
|
|
}
|
|
|
//设备修改
|
|
|
if ("4".equals(category_code)||"7".equals(category_code)){
|
|
|
JSONObject response2 = deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
|
|
|
if (response2.getBoolean("success")){
|
|
|
if (1==sosContactsDO.getSuccessFlag()||0==sosContactsDO.getSuccessFlag()){
|
|
|
sosContactsDO.setSuccessFlag(1);
|
|
|
if(null!=sosContactsDO){
|
|
|
if (StringUtils.isNotBlank(sim)){
|
|
|
JSONObject response = cardService.setPatientContacts(null, sim, null, "1", sos_phone);//移动白名单
|
|
|
logger.info("setPatientContacts:"+response);
|
|
|
//0成功 12102名单重复
|
|
|
if (response.getInteger("status")==0||response.getInteger("status")==12108){
|
|
|
if (1==sosContactsDO.getSuccessFlag()||0==sosContactsDO.getSuccessFlag()){
|
|
|
sosContactsDO.setSuccessFlag(1);
|
|
|
}else {
|
|
|
sosContactsDO.setSuccessFlag(-1);
|
|
|
}
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+1+"}");
|
|
|
}else {
|
|
|
sosContactsDO.setSuccessFlag(-1);
|
|
|
}
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+1+"}");
|
|
|
}else {
|
|
|
sosContactsDO.setSuccessFlag(-1);
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+-1+"}");
|
|
|
sosContactsDO.setErrorInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+response2.getString("message")+"}");
|
|
|
}
|
|
|
}else if ("16".equals(category_code)){
|
|
|
sql =" select sos_phone from base_patient_sos_contacts where patient='"+patient+"' and del=1 order by phone_seqid asc ";
|
|
|
List<String> nums = jdbcTemplate.queryForList(sql,String.class);
|
|
|
String phone1 = null;
|
|
|
String phone2 = null;
|
|
|
String phone3 = null;
|
|
|
for (int i=0;i<nums.size();i++){
|
|
|
if(i==0){
|
|
|
phone1 = nums.get(i);
|
|
|
}
|
|
|
if(i==2){
|
|
|
phone2 = nums.get(i);
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+-1+"}");
|
|
|
sosContactsDO.setErrorInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+response.getString("message")+"}");
|
|
|
}
|
|
|
}
|
|
|
String yxResponse = yunXunDeviceService.setSos(device_sn,phone1,phone2,phone3);
|
|
|
if (StringUtils.isBlank(yxResponse)){//请求失败或超时
|
|
|
if (!sosContactsDO.getUpdateInfo().contains(device_sn)){
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":error}");
|
|
|
}
|
|
|
sosContactsDO.setSuccessFlag(-1);
|
|
|
}else {
|
|
|
JSONObject yxResponseObj = JSONObject.parseObject(yxResponse);
|
|
|
if (200==yxResponseObj.getInteger("status")){//返回成功
|
|
|
if (!sosContactsDO.getUpdateInfo().contains(device_sn)){
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":success}");
|
|
|
}
|
|
|
//设备修改
|
|
|
if ("4".equals(category_code)||"7".equals(category_code)){
|
|
|
JSONObject response2 = deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
|
|
|
logger.info("updAqgDeviceSosInfo:"+response2);
|
|
|
if (response2.getBoolean("success")){
|
|
|
if (1==sosContactsDO.getSuccessFlag()||0==sosContactsDO.getSuccessFlag()){
|
|
|
sosContactsDO.setSuccessFlag(1);
|
|
|
}else {
|
|
|
sosContactsDO.setSuccessFlag(-1);
|
|
|
}
|
|
|
} else { //返回失败
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+1+"}");
|
|
|
}else {
|
|
|
sosContactsDO.setSuccessFlag(-1);
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+-1+"}");
|
|
|
sosContactsDO.setErrorInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+response2.getString("message")+"}");
|
|
|
}
|
|
|
}else if ("16".equals(category_code)){
|
|
|
sql =" select sos_phone from base_patient_sos_contacts where patient='"+patient+"' and del=1 order by phone_seqid asc ";
|
|
|
List<String> nums = jdbcTemplate.queryForList(sql,String.class);
|
|
|
String phone1 = null;
|
|
|
String phone2 = null;
|
|
|
String phone3 = null;
|
|
|
for (int i=0;i<nums.size();i++){
|
|
|
if(i==0){
|
|
|
phone1 = nums.get(i);
|
|
|
}
|
|
|
if(i==2){
|
|
|
phone2 = nums.get(i);
|
|
|
}
|
|
|
}
|
|
|
String yxResponse = yunXunDeviceService.setSos(device_sn,phone1,phone2,phone3);
|
|
|
if (StringUtils.isBlank(yxResponse)){//请求失败或超时
|
|
|
if (!sosContactsDO.getUpdateInfo().contains(device_sn)){
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+yxResponseObj.getString("message")+"}");
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":error}");
|
|
|
}
|
|
|
sosContactsDO.setSuccessFlag(-1);
|
|
|
}else {
|
|
|
JSONObject yxResponseObj = JSONObject.parseObject(yxResponse);
|
|
|
if (200==yxResponseObj.getInteger("status")){//返回成功
|
|
|
if (!sosContactsDO.getUpdateInfo().contains(device_sn)){
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":success}");
|
|
|
}
|
|
|
if (1==sosContactsDO.getSuccessFlag()||0==sosContactsDO.getSuccessFlag()){
|
|
|
sosContactsDO.setSuccessFlag(1);
|
|
|
}else {
|
|
|
sosContactsDO.setSuccessFlag(-1);
|
|
|
}
|
|
|
} else { //返回失败
|
|
|
if (!sosContactsDO.getUpdateInfo().contains(device_sn)){
|
|
|
sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+yxResponseObj.getString("message")+"}");
|
|
|
}
|
|
|
sosContactsDO.setSuccessFlag(-1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
sosContactsDao.save(sosContactsDO);
|
|
|
}
|
|
|
sosContactsDao.save(sosContactsDO);
|
|
|
}catch (Exception e){
|
|
|
logger.info(sim+"--同步失败--"+sos_phone);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.info(sim+"--同步失败--"+sos_phone);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
// sosContactsDao.save(modify);
|
|
|
logger.info("PATIENT_SOS_CONTACTS_JOB end");
|
|
|
}
|
|
|
}
|