|  | @ -35,54 +35,83 @@ public class PatientSosContactsJob implements Job {
 | 
	
		
			
				|  |  |     private NetworkCardService cardService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientDeviceService deviceService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private YunXunDeviceService yunXunDeviceService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Override
 | 
	
		
			
				|  |  |     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
 | 
	
		
			
				|  |  |         logger.info("PATIENT_SOS_CONTACTS_JOB start");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String sql = " select pd.device_sn,wd.sim,sc.* from  wlyy_patient_device pd inner join wlyy_devices wd " +
 | 
	
		
			
				|  |  |                 " on pd.device_sn = wd.device_code and pd.del=0 and wd.sim is not null and pd.category_code in('7','4') " +
 | 
	
		
			
				|  |  |                 "INNER JOIN base_patient_sos_contacts sc on sc.patient = pd.user and sc.del=1 and sc.success_flag=0 group by wd.sim";
 | 
	
		
			
				|  |  |         String sql = " select pd.device_sn,pd.category_code,wd.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").toString() ;
 | 
	
		
			
				|  |  |             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){
 | 
	
		
			
				|  |  |                     JSONObject response = cardService.setPatientContacts(sim, null, null, "1", sos_phone, null);//移动白名单
 | 
	
		
			
				|  |  |                     //0成功 12102名单重复
 | 
	
		
			
				|  |  |                     if (response.getInteger("status")==0||response.getInteger("status")==12108){
 | 
	
		
			
				|  |  |                         sosContactsDO.setSuccessFlag(1);
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         sosContactsDO.setSuccessFlag(-1);
 | 
	
		
			
				|  |  |                         modify.add(sosContactsDO);
 | 
	
		
			
				|  |  |                     if (StringUtils.isNotBlank(sim)){
 | 
	
		
			
				|  |  |                         JSONObject response = cardService.setPatientContacts(sim, null, null, "1", sos_phone, null);//移动白名单
 | 
	
		
			
				|  |  |                         //0成功 12102名单重复
 | 
	
		
			
				|  |  |                         if (response.getInteger("status")==0||response.getInteger("status")==12108){
 | 
	
		
			
				|  |  |                             sosContactsDO.setSuccessFlag(1);
 | 
	
		
			
				|  |  |                             sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+1+"}");
 | 
	
		
			
				|  |  |                         }else {
 | 
	
		
			
				|  |  |                             sosContactsDO.setSuccessFlag(-1);
 | 
	
		
			
				|  |  |                             sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{sim:"+sim+":"+-1+"}");
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     //设备修改
 | 
	
		
			
				|  |  |                     JSONObject response2 =  deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
 | 
	
		
			
				|  |  |                     System.out.println(response2.toString());
 | 
	
		
			
				|  |  |                     if (response2.getBoolean("success")){
 | 
	
		
			
				|  |  |                         if (1==sosContactsDO.getSuccessFlag()){
 | 
	
		
			
				|  |  |                             sosContactsDO.setSuccessFlag(1);
 | 
	
		
			
				|  |  |                     if ("4".equals(category_code)||"7".equals(category_code)){
 | 
	
		
			
				|  |  |                         JSONObject response2 =  deviceService.updAqgDeviceSosInfo(device_sn,phone_seqid,sos_name,sos_phone,"1",null);
 | 
	
		
			
				|  |  |                         System.out.println(response2.toString());
 | 
	
		
			
				|  |  |                         if (response2.getBoolean("success")){
 | 
	
		
			
				|  |  |                             if (1==sosContactsDO.getSuccessFlag()){
 | 
	
		
			
				|  |  |                                 sosContactsDO.setSuccessFlag(1);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                             sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+1+"}");
 | 
	
		
			
				|  |  |                         }else {
 | 
	
		
			
				|  |  |                             sosContactsDO.setSuccessFlag(-1);
 | 
	
		
			
				|  |  |                             sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":"+-1+"}");
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }else if ("16".equals(category_code)){
 | 
	
		
			
				|  |  |                         sql =" select sos_phone from base_patient_sos_contacts where patient='"+patient+"' ";
 | 
	
		
			
				|  |  |                         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.setSuccessFlag(-1);
 | 
	
		
			
				|  |  |                     }else {
 | 
	
		
			
				|  |  |                         sosContactsDO.setSuccessFlag(-1);
 | 
	
		
			
				|  |  |                         yunXunDeviceService.setSos(device_sn,phone1,phone2,phone3);
 | 
	
		
			
				|  |  |                         sosContactsDO.setUpdateInfo(sosContactsDO.getUpdateInfo()+",{deviceSn:"+device_sn+":unknow}");
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     modify.add(sosContactsDO);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     sosContactsDao.save(sosContactsDO);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }catch (Exception e){
 | 
	
		
			
				|  |  |                 logger.info(sim+"--同步失败--"+sos_phone);
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         sosContactsDao.save(modify);
 | 
	
		
			
				|  |  | //        sosContactsDao.save(modify);
 | 
	
		
			
				|  |  |         logger.info("PATIENT_SOS_CONTACTS_JOB end");
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |