|  | @ -30,6 +30,7 @@ import com.yihu.jw.util.healthIndex.HealthIndexUtil;
 | 
												
													
														
															|  | import com.yihu.mysql.query.BaseJpaService;
 |  | import com.yihu.mysql.query.BaseJpaService;
 | 
												
													
														
															|  | import org.apache.commons.collections.map.HashedMap;
 |  | import org.apache.commons.collections.map.HashedMap;
 | 
												
													
														
															|  | import org.apache.commons.lang3.StringUtils;
 |  | import org.apache.commons.lang3.StringUtils;
 | 
												
													
														
															|  | 
 |  | import org.hibernate.annotations.Synchronize;
 | 
												
													
														
															|  | import org.json.JSONArray;
 |  | import org.json.JSONArray;
 | 
												
													
														
															|  | import org.json.JSONObject;
 |  | import org.json.JSONObject;
 | 
												
													
														
															|  | import org.slf4j.Logger;
 |  | import org.slf4j.Logger;
 | 
												
											
												
													
														
															|  | @ -48,6 +49,7 @@ import org.springframework.http.HttpMethod;
 | 
												
													
														
															|  | import org.springframework.http.MediaType;
 |  | import org.springframework.http.MediaType;
 | 
												
													
														
															|  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 |  | import org.springframework.jdbc.core.BeanPropertyRowMapper;
 | 
												
													
														
															|  | import org.springframework.jdbc.core.JdbcTemplate;
 |  | import org.springframework.jdbc.core.JdbcTemplate;
 | 
												
													
														
															|  | 
 |  | import org.springframework.scheduling.annotation.Async;
 | 
												
													
														
															|  | import org.springframework.stereotype.Component;
 |  | import org.springframework.stereotype.Component;
 | 
												
													
														
															|  | import org.springframework.transaction.annotation.Transactional;
 |  | import org.springframework.transaction.annotation.Transactional;
 | 
												
													
														
															|  | import org.springframework.util.LinkedMultiValueMap;
 |  | import org.springframework.util.LinkedMultiValueMap;
 | 
												
											
												
													
														
															|  | @ -125,6 +127,11 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
												
													
														
															|  |     private PatientSafeAreaDao safeAreaDao;
 |  |     private PatientSafeAreaDao safeAreaDao;
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private SecurityMonitoringOrderDao securityMonitoringOrderDao;
 |  |     private SecurityMonitoringOrderDao securityMonitoringOrderDao;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private MessageUtil messageUtil;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private PatientSafeAreaConfirmDao patientSafeAreaConfirmDao;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     @PostConstruct
 |  |     @PostConstruct
 | 
												
													
														
															|  |     public void init() {
 |  |     public void init() {
 | 
												
											
												
													
														
															|  | @ -1774,7 +1781,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      *
 |  | 
 | 
												
													
														
															|  | 
 |  |      *      修改电子围栏信息
 | 
												
													
														
															|  |      *    | enable       |  否  | Int          |  0,1 是否启用                        |
 |  |      *    | enable       |  否  | Int          |  0,1 是否启用                        |
 | 
												
													
														
															|  |      *    | name         |  否  | String       |   安全区名称                           |
 |  |      *    | name         |  否  | String       |   安全区名称                           |
 | 
												
													
														
															|  |      *    | freq         |  否  | Boolean      |  0,触发一天;1,每日触发        |
 |  |      *    | freq         |  否  | Boolean      |  0,触发一天;1,每日触发        |
 | 
												
											
												
													
														
															|  | @ -1816,6 +1823,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
												
													
														
															|  |                 safeAreaDao.deleteByPatient(patient);
 |  |                 safeAreaDao.deleteByPatient(patient);
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |             else{//新增或修改
 |  |             else{//新增或修改
 | 
												
													
														
															|  | 
 |  |                 safeAreaDO.setDel("1");
 | 
												
													
														
															|  |                 safeAreaDO.setSafeAreaGz(safe_area);
 |  |                 safeAreaDO.setSafeAreaGz(safe_area);
 | 
												
													
														
															|  |                 safeAreaDO.setUpdateTime(new Date());
 |  |                 safeAreaDO.setUpdateTime(new Date());
 | 
												
													
														
															|  |                 safeAreaDO.setSuccessFlag(-1);
 |  |                 safeAreaDO.setSuccessFlag(-1);
 | 
												
											
												
													
														
															|  | @ -1870,6 +1878,75 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
												
													
														
															|  |         return "success";
 |  |         return "success";
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 助老员新增电子围栏记录
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     public com.alibaba.fastjson.JSONObject doctorNewSafeArea(String doctor,String patient,String safe_area) throws Exception{
 | 
												
													
														
															|  | 
 |  |         com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         List<PatientSafeAreaConfirm> SafeAreaConfirms = patientSafeAreaConfirmDao.findByDoctorCodeAndPatient(doctor,patient);
 | 
												
													
														
															|  | 
 |  |         if (SafeAreaConfirms.size()>0){
 | 
												
													
														
															|  | 
 |  |             result.put(ResponseContant.resultFlag,ResponseContant.fail);
 | 
												
													
														
															|  | 
 |  |             result.put(ResponseContant.resultMsg,"你已为改居民新增过电子围栏!");
 | 
												
													
														
															|  | 
 |  |             return result;
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         BaseDoctorDO doctorDO = doctorDao.findById(doctor);
 | 
												
													
														
															|  | 
 |  |         PatientSafeAreaDO safeAreaDO = new PatientSafeAreaDO();
 | 
												
													
														
															|  | 
 |  |         boolean firstAdd=false;
 | 
												
													
														
															|  | 
 |  |         List<Map<String,Object>> relatives = new ArrayList<>();
 | 
												
													
														
															|  | 
 |  |         if (StringUtils.isNotBlank(patient)){
 | 
												
													
														
															|  | 
 |  |             List<PatientSafeAreaDO> safeAreaDOS = safeAreaDao.findByPatient2(patient);
 | 
												
													
														
															|  | 
 |  |             if (safeAreaDOS.size()>0){
 | 
												
													
														
															|  | 
 |  |                 safeAreaDO = safeAreaDOS.get(0);
 | 
												
													
														
															|  | 
 |  |             }else {//首次新增
 | 
												
													
														
															|  | 
 |  |                 safeAreaDO.setPatient(patient);
 | 
												
													
														
															|  | 
 |  |                 safeAreaDO.setCreateTime(new Date());
 | 
												
													
														
															|  | 
 |  |                 safeAreaDO.setUpdateTime(new Date());
 | 
												
													
														
															|  | 
 |  |                 safeAreaDO.setSuccessFlag(-1);
 | 
												
													
														
															|  | 
 |  |                 safeAreaDO.setDel("1");
 | 
												
													
														
															|  | 
 |  |                 // 发送确认消息给家属 有家属直接确认
 | 
												
													
														
															|  | 
 |  |                 String sql = " select  t2.id,t2.name from  base_patient_family_member t1,  base_patient t2 where  " +
 | 
												
													
														
															|  | 
 |  |                         "t2.id in (select family_member from base_patient_family_member where patient = '"+patient+"' )  " +
 | 
												
													
														
															|  | 
 |  |                         " and t1.patient = '"+patient+"'  and t1.family_member = t2.id  " +
 | 
												
													
														
															|  | 
 |  |                         " and t2.archive_type=3 GROUP BY t2.id " ;
 | 
												
													
														
															|  | 
 |  |                 relatives = jdbcTemplate.queryForList(sql);
 | 
												
													
														
															|  | 
 |  |                 safeAreaDO.setManageStatus(relatives.size()>0?0:1);
 | 
												
													
														
															|  | 
 |  |                 firstAdd=true;
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             safeAreaDO.setSafeAreaGz(safe_area);
 | 
												
													
														
															|  | 
 |  |             safeAreaDO.setUpdateTime(new Date());
 | 
												
													
														
															|  | 
 |  |             safeAreaDO.setSuccessFlag(-1);
 | 
												
													
														
															|  | 
 |  |             safeAreaDO = safeAreaDao.save(safeAreaDO);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |             PatientSafeAreaConfirm patientSafeAreaConfirm = new PatientSafeAreaConfirm();
 | 
												
													
														
															|  | 
 |  |             patientSafeAreaConfirm.setPatient(patient);
 | 
												
													
														
															|  | 
 |  |             patientSafeAreaConfirm.setDoctorCode(doctor);
 | 
												
													
														
															|  | 
 |  |             patientSafeAreaConfirm.setDel("1");
 | 
												
													
														
															|  | 
 |  |             patientSafeAreaConfirm.setCreateTime(new Date());
 | 
												
													
														
															|  | 
 |  |             patientSafeAreaConfirm.setSafeId(safeAreaDO.getId()+"");
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |             if(firstAdd&&(null == safeAreaDO.getManageStatus()||0 == safeAreaDO.getManageStatus())){//首次添加给家属发送待确认消息
 | 
												
													
														
															|  | 
 |  |                 patientSafeAreaConfirm.setManageStatus(0);
 | 
												
													
														
															|  | 
 |  |                 for (Map<String,Object> tmp:relatives){
 | 
												
													
														
															|  | 
 |  |                     messageUtil.saveSystemMessage("",patient,"监护确认","44",doctorDO.getId(),doctorDO.getName(),tmp.get("id").toString(),
 | 
												
													
														
															|  | 
 |  |                             tmp.get("name").toString(),null,null,"0" );
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |             }else {//无家属 直接确认
 | 
												
													
														
															|  | 
 |  |                 patientSafeAreaConfirm.setManageStatus(1);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |                Integer successFlag =  updatePatientSafeArea(patient,safe_area);
 | 
												
													
														
															|  | 
 |  |                safeAreaDO.setSuccessFlag(successFlag);
 | 
												
													
														
															|  | 
 |  |                 safeAreaDao.save(safeAreaDO);
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             patientSafeAreaConfirmDao.save(patientSafeAreaConfirm);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         result.put(ResponseContant.resultFlag,ResponseContant.success);
 | 
												
													
														
															|  | 
 |  |         result.put(ResponseContant.resultMsg,"添加成功");
 | 
												
													
														
															|  | 
 |  |         return result;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      *获取设备轨迹
 |  |      *获取设备轨迹
 | 
												
													
														
															|  |      * @param deviceSn
 |  |      * @param deviceSn
 | 
												
											
												
													
														
															|  | @ -1977,4 +2054,50 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /******************************************* 爱牵挂设备end *****************************************************/
 |  |     /******************************************* 爱牵挂设备end *****************************************************/
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     public Integer updatePatientSafeArea(String patient,String safe_area){
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         List<DevicePatientDevice> devices = patientDeviceDao.findAllByUserAndCategoryCode(patient,"4");
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         if (devices.size()>0){
 | 
												
													
														
															|  | 
 |  |             DevicePatientDevice patientDevice = devices.get(0);
 | 
												
													
														
															|  | 
 |  |             String deviceSnTmp = patientDevice.getDeviceSn();
 | 
												
													
														
															|  | 
 |  |             String url ="";
 | 
												
													
														
															|  | 
 |  |             if ("4".equals(devices.get(0).getCategoryCode())){//手表
 | 
												
													
														
															|  | 
 |  |                 Device device = deviceDao.findOne(devices.get(0).getDeviceId());
 | 
												
													
														
															|  | 
 |  |                 if (device!=null){
 | 
												
													
														
															|  | 
 |  |                     if ("X1".equals(device.getModel())){
 | 
												
													
														
															|  | 
 |  |                         url = MessageFormat.format(AqgConfig.X1fence_area, deviceSnTmp,1);
 | 
												
													
														
															|  | 
 |  |                     }
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |             }else {
 | 
												
													
														
															|  | 
 |  |                 url = MessageFormat.format(AqgConfig.S3fence_area, deviceSnTmp,1);
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
 | 
												
													
														
															|  | 
 |  |             if (StringUtils.isNotBlank(safe_area)){
 | 
												
													
														
															|  | 
 |  |                     String[] position = safe_area.split(";");
 | 
												
													
														
															|  | 
 |  |                     safe_area = "";
 | 
												
													
														
															|  | 
 |  |                     for (String tmp:position){
 | 
												
													
														
															|  | 
 |  |                         String[] point = tmp.split(",");
 | 
												
													
														
															|  | 
 |  |                         safe_area+= gpsUtil.bd09_To_Gcj02_str(Double.parseDouble(point[1]),Double.parseDouble(point[0]))+";";
 | 
												
													
														
															|  | 
 |  |                     }
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             param.add("name", "安全区域1");
 | 
												
													
														
															|  | 
 |  |             param.add("freq", "1");
 | 
												
													
														
															|  | 
 |  |             param.add("enable","1");
 | 
												
													
														
															|  | 
 |  |             param.add("time_begin", "0");
 | 
												
													
														
															|  | 
 |  |             param.add("time_end", "86400");
 | 
												
													
														
															|  | 
 |  |             param.add("safe_area", safe_area);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |             HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.aqgCookieHttp(url, param, HttpMethod.POST, getCookie());
 | 
												
													
														
															|  | 
 |  |             com.alibaba.fastjson.JSONObject responseObj = response.getBody();
 | 
												
													
														
															|  | 
 |  |             if (responseObj.getBoolean("success")){
 | 
												
													
														
															|  | 
 |  |                 return 1;
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             else {
 | 
												
													
														
															|  | 
 |  |                 return -1;
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         return -1;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | }
 |  | }
 |