|  | @ -38,6 +38,7 @@ import com.yihu.jw.restmodel.emergency.EmergencyOrderVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.PageEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.GpsUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.LatitudeUtils;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.entity.EntityUtils;
 | 
	
		
			
				|  |  | import com.yihu.mysql.query.BaseJpaService;
 | 
	
	
		
			
				|  | @ -123,6 +124,8 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |     private BaseSleepPlanDetailDao sleepPlanDetailDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseSleepNightRecordDao nightRecordDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientSafeAreaDao safeAreaDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -237,6 +240,9 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         message.put("content_type",40);
 | 
	
		
			
				|  |  |         for (BaseDoctorDO doctorDO:doctorDOS){
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 if (StringUtils.isNotBlank(doctorDO.getMobile())){
 | 
	
		
			
				|  |  |                     messageUtil.sendTXYSJson("1099807",doctorDO.getMobile(),orderDO.getPatientName(),orderDO.getServeDesc());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 imUtil.sendMDTSocketMessageToDoctor(doctorDO.getId(),message.toString());
 | 
	
		
			
				|  |  |             }catch (Exception e){
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
	
		
			
				|  | @ -250,13 +256,26 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String , Object>> getElectronicFence(String deviceSn){
 | 
	
		
			
				|  |  |         String sql = " select safe_area_gz safeAreaGz from wlyy_patient_device where device_sn = '"+deviceSn+"' and del = 0 order by id desc limit 1";
 | 
	
		
			
				|  |  |     public List<Map<String , Object>> getElectronicFence(String patient){
 | 
	
		
			
				|  |  |         String sql = " select safe_area_gz safeAreaGz from wlyy_patient_safe_area where patient = '"+patient+"' ";
 | 
	
		
			
				|  |  |         return jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String , Object>> getActionTrack(String deviceSn,String day){
 | 
	
		
			
				|  |  |         String sql = "SELECT * FROM base_yxdevice_index WHERE sn = '"+deviceSn+"' AND lon != 0 AND lat != 0  and create_time like '"+day+"%' ORDER BY create_time DESC LIMIT 0,20";
 | 
	
		
			
				|  |  |         return jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String,Object>>getNewList(String deviceSn,String day){
 | 
	
		
			
				|  |  |         if (StringUtils.isBlank(day)){
 | 
	
		
			
				|  |  |             day = DateUtil.getStringDateShort();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String sql = "SELECT * FROM base_yxdevice_index WHERE sn = '"+deviceSn+"' AND create_time LIKE '"+day+"%' AND lon != 0 AND lat != 0 ORDER BY create_time DESC limit 1";
 | 
	
		
			
				|  |  |         return jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Map<String , Object>> getActionTrack(String deviceSn){
 | 
	
		
			
				|  |  |         String sql = "SELECT * FROM base_yxdevice_index WHERE sn = '"+deviceSn+"' AND lon != 0 AND lat != 0 ORDER BY create_time DESC LIMIT 0,20";
 | 
	
		
			
				|  |  |     public List<Map<String , Object>> getPatientLatLon(String deviceSn){
 | 
	
		
			
				|  |  |         String sql = "SELECT p.lat_lon FROM base_patient p,wlyy_patient_device pd WHERE pd.del = 0 AND pd.device_sn = '"+deviceSn+"' AND pd.`user` = p.id AND p.del = 1 limit 1";
 | 
	
		
			
				|  |  |         return jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -338,13 +357,13 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //附加信息 电子围栏状态
 | 
	
		
			
				|  |  |         if (orderDO.getOrderSource()==2){
 | 
	
		
			
				|  |  |         if (2==orderDO.getOrderSource()||8==orderDO.getOrderSource()){//手表/拐杖
 | 
	
		
			
				|  |  |             Map<String,Object> map = new HashMap<>();
 | 
	
		
			
				|  |  |             map.put("inFenceStatus",false);
 | 
	
		
			
				|  |  |             map.put("inFenceName","疑似超出安全区域");
 | 
	
		
			
				|  |  |             emergencyOrderVO.setInformation(map);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if(4==orderDO.getOrderSource()){
 | 
	
		
			
				|  |  |         if(4==orderDO.getOrderSource()){//报警器
 | 
	
		
			
				|  |  |             List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(orderDO.getPatient(),"12");
 | 
	
		
			
				|  |  |             if (devicePatientDeviceDos.size()==0){
 | 
	
		
			
				|  |  |             }
 | 
	
	
		
			
				|  | @ -380,7 +399,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     monitorInfo.put("sleepPlan",false);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall");
 | 
	
		
			
				|  |  |                 monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall",null);
 | 
	
		
			
				|  |  |                 emergencyOrderVO.setInformation(monitorInfo);
 | 
	
		
			
				|  |  |             }catch (Exception e){
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
	
		
			
				|  | @ -389,7 +408,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         if (6==orderDO.getOrderSource()){//气感工单
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 JSONObject monitorInfo = JSONObject.parseObject(orderDO.getWarnInfo());
 | 
	
		
			
				|  |  |                 monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall");
 | 
	
		
			
				|  |  |                 monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall",null);
 | 
	
		
			
				|  |  |                 emergencyOrderVO.setInformation(monitorInfo);
 | 
	
		
			
				|  |  |             }catch (Exception e){
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
	
		
			
				|  | @ -398,7 +417,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |         if (7==orderDO.getOrderSource()){//烟感工单
 | 
	
		
			
				|  |  |             try {
 | 
	
		
			
				|  |  |                 JSONObject monitorInfo = JSONObject.parseObject(orderDO.getWarnInfo());
 | 
	
		
			
				|  |  |                 monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall");
 | 
	
		
			
				|  |  |                 monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall",null);
 | 
	
		
			
				|  |  |                 emergencyOrderVO.setInformation(monitorInfo);
 | 
	
		
			
				|  |  |             }catch (Exception e){
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
	
		
			
				|  | @ -1286,57 +1305,156 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |                     break;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         result = patientSignTopicInfo(result,patient,topicItem);
 | 
	
		
			
				|  |  |         result = patientSignTopicInfo(result,patient,topicItem,null);
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void preventLost(JSONObject result,String patient){
 | 
	
		
			
				|  |  |         List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
 | 
	
		
			
				|  |  |         if (devicePatientDeviceDos.size()==0){
 | 
	
		
			
				|  |  |             return;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         DevicePatientDevice device = devicePatientDeviceDos.get(0);
 | 
	
		
			
				|  |  |         result.put("deviceSn",device.getDeviceSn());
 | 
	
		
			
				|  |  |     public void preventLost(JSONObject result,String patient,String deviceSn){
 | 
	
		
			
				|  |  |         //手表与拐杖同时绑定时优先手表,围栏状态其中一个超出围栏即为超出围栏
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             JSONObject response= patientDeviceService.getAqgDeviceInfo(device.getDeviceSn());
 | 
	
		
			
				|  |  |             if (response!=null){
 | 
	
		
			
				|  |  |                 //定位信息
 | 
	
		
			
				|  |  |                 if (response.containsKey("last_location")&&response.get("last_location")!=null){
 | 
	
		
			
				|  |  |                     JSONObject locationTmp = response.getJSONObject("last_location");
 | 
	
		
			
				|  |  |                     Double lon = locationTmp.getJSONArray("coordinates").getDouble(0);
 | 
	
		
			
				|  |  |                     Double lat = locationTmp.getJSONArray("coordinates").getDouble(1);
 | 
	
		
			
				|  |  |                     JSONObject tmp = gpsUtil.gcj02_To_Bd09(lat,lon);
 | 
	
		
			
				|  |  |                     tmp.put("city",response.getString("last_city"));
 | 
	
		
			
				|  |  |                     tmp.put("province",response.getString("last_province"));
 | 
	
		
			
				|  |  |                     tmp.put("address",response.getString("last_address"));
 | 
	
		
			
				|  |  |                     result.put("location",tmp);
 | 
	
		
			
				|  |  |             Integer categoryCode=0;
 | 
	
		
			
				|  |  |             List<DevicePatientDevice> devicePatientDeviceDos = new ArrayList<>();
 | 
	
		
			
				|  |  |             List<DevicePatientDevice> devicePatientDeviceDos2 = new ArrayList<>();
 | 
	
		
			
				|  |  |             if (StringUtils.isNotBlank(deviceSn)){//查看指定设备详情
 | 
	
		
			
				|  |  |                 List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSn(deviceSn);
 | 
	
		
			
				|  |  |                 if (devices.size()>0){
 | 
	
		
			
				|  |  |                    String categoryCodeTmp = devices.get(0).getCategoryCode();
 | 
	
		
			
				|  |  |                     categoryCode = StringUtils.isBlank(categoryCodeTmp)?-1:Integer.parseInt(categoryCodeTmp);
 | 
	
		
			
				|  |  |                     if (4==categoryCode){
 | 
	
		
			
				|  |  |                         devicePatientDeviceDos = devices;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     if (16==categoryCode){
 | 
	
		
			
				|  |  |                         devicePatientDeviceDos2 = devices;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
 | 
	
		
			
				|  |  |                 devicePatientDeviceDos2 = patientDeviceDao.findByUserAndCategoryCode(patient,"16");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (devicePatientDeviceDos.size()>0&&(4==categoryCode||0==categoryCode)){
 | 
	
		
			
				|  |  |                 DevicePatientDevice device = devicePatientDeviceDos.get(0);
 | 
	
		
			
				|  |  |                 result.put("deviceSn",device.getDeviceSn());
 | 
	
		
			
				|  |  |                 JSONObject response= patientDeviceService.getAqgDeviceInfo(device.getDeviceSn());
 | 
	
		
			
				|  |  |                 if (response!=null){
 | 
	
		
			
				|  |  |                     //定位信息
 | 
	
		
			
				|  |  |                     if (response.containsKey("last_location")&&response.get("last_location")!=null){
 | 
	
		
			
				|  |  |                         JSONObject locationTmp = response.getJSONObject("last_location");
 | 
	
		
			
				|  |  |                         Double lon = locationTmp.getJSONArray("coordinates").getDouble(0);
 | 
	
		
			
				|  |  |                         Double lat = locationTmp.getJSONArray("coordinates").getDouble(1);
 | 
	
		
			
				|  |  |                         JSONObject tmp = gpsUtil.gcj02_To_Bd09(lat,lon);
 | 
	
		
			
				|  |  |                         tmp.put("city",response.getString("last_city"));
 | 
	
		
			
				|  |  |                         tmp.put("province",response.getString("last_province"));
 | 
	
		
			
				|  |  |                         tmp.put("address",response.getString("last_address"));
 | 
	
		
			
				|  |  |                         result.put("location",tmp);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     //围栏信息
 | 
	
		
			
				|  |  |                     if (response.containsKey("fences")&&response.get("fences")!=null){
 | 
	
		
			
				|  |  |                         JSONArray fencesArr = response.getJSONArray("fences");
 | 
	
		
			
				|  |  |                         JSONArray fencesEnables = new JSONArray();
 | 
	
		
			
				|  |  |                         for (int i=0;i<fencesArr.size();i++){
 | 
	
		
			
				|  |  |                             JSONObject tmp = fencesArr.getJSONObject(i);
 | 
	
		
			
				|  |  |                             if (tmp.getBooleanValue("enable")){//围栏生效
 | 
	
		
			
				|  |  |                                 JSONObject fenceTmp = new JSONObject();
 | 
	
		
			
				|  |  |                                 fenceTmp.put("fenceNO",tmp.getInteger("seqid").toString());
 | 
	
		
			
				|  |  |                                 fenceTmp.put("name",tmp.getString("name"));
 | 
	
		
			
				|  |  |                                 JSONArray fenceLocationTmp = tmp.getJSONObject("safe_area").getJSONArray("coordinates").getJSONArray(0);
 | 
	
		
			
				|  |  |                                 JSONArray fenceLocation = new JSONArray();
 | 
	
		
			
				|  |  |                                 for (int j=0;j<fenceLocationTmp.size();j++){
 | 
	
		
			
				|  |  |                                     Double lon = fenceLocationTmp.getJSONArray(j).getDouble(0);
 | 
	
		
			
				|  |  |                                     Double lat = fenceLocationTmp.getJSONArray(j).getDouble(1);
 | 
	
		
			
				|  |  |                                     JSONObject positionTmp = gpsUtil.gcj02_To_Bd09(lat,lon);
 | 
	
		
			
				|  |  |                                     fenceLocation.add(positionTmp);
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                                 fenceTmp.put("location",fenceLocation);
 | 
	
		
			
				|  |  |                                 fenceTmp.put("inFenceStatus",countDistance.isInPolygon(result.getJSONObject("location").getDouble("lon"),result.getJSONObject("location").getDouble("lat"),fenceLocation));
 | 
	
		
			
				|  |  |                                 fencesEnables.add(fenceTmp);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         if (fencesEnables.size()>0){
 | 
	
		
			
				|  |  |                             result.put("fences",fencesEnables);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (devicePatientDeviceDos2.size()>0&&(16==categoryCode||0==categoryCode)) {
 | 
	
		
			
				|  |  |                 DevicePatientDevice deviceDO = devicePatientDeviceDos2.get(0);
 | 
	
		
			
				|  |  |                 double dulat = 0l;
 | 
	
		
			
				|  |  |                 double dulon = 0l;
 | 
	
		
			
				|  |  |                 //获取当前定位
 | 
	
		
			
				|  |  |                 String sql = " SELECT * FROM base_yxdevice_index WHERE sn = '" + deviceDO.getDeviceSn() + "' " +
 | 
	
		
			
				|  |  |                         "AND create_time LIKE '" + DateUtil.getStringDateShort() + "%' AND lon != 0 AND lat != 0 ORDER BY create_time DESC  ";
 | 
	
		
			
				|  |  |                 List<Map<String, Object>> pointTmp = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (pointTmp.size() > 0) {
 | 
	
		
			
				|  |  |                     dulat = Double.parseDouble(pointTmp.get(0).get("lat").toString());
 | 
	
		
			
				|  |  |                     dulon = Double.parseDouble(pointTmp.get(0).get("lon").toString());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 //围栏信息
 | 
	
		
			
				|  |  |                 if (response.containsKey("fences")&&response.get("fences")!=null){
 | 
	
		
			
				|  |  |                     JSONArray fencesArr = response.getJSONArray("fences");
 | 
	
		
			
				|  |  |                     JSONArray fencesEnables = new JSONArray();
 | 
	
		
			
				|  |  |                     for (int i=0;i<fencesArr.size();i++){
 | 
	
		
			
				|  |  |                         JSONObject tmp = fencesArr.getJSONObject(i);
 | 
	
		
			
				|  |  |                         if (tmp.getBooleanValue("enable")){//围栏生效
 | 
	
		
			
				|  |  |                             JSONObject fenceTmp = new JSONObject();
 | 
	
		
			
				|  |  |                             fenceTmp.put("fenceNO",tmp.getInteger("seqid").toString());
 | 
	
		
			
				|  |  |                             fenceTmp.put("name",tmp.getString("name"));
 | 
	
		
			
				|  |  |                             JSONArray fenceLocationTmp = tmp.getJSONObject("safe_area").getJSONArray("coordinates").getJSONArray(0);
 | 
	
		
			
				|  |  |                             JSONArray fenceLocation = new JSONArray();
 | 
	
		
			
				|  |  |                             for (int j=0;j<fenceLocationTmp.size();j++){
 | 
	
		
			
				|  |  |                                 Double lon = fenceLocationTmp.getJSONArray(j).getDouble(0);
 | 
	
		
			
				|  |  |                                 Double lat = fenceLocationTmp.getJSONArray(j).getDouble(1);
 | 
	
		
			
				|  |  |                                 JSONObject positionTmp = gpsUtil.gcj02_To_Bd09(lat,lon);
 | 
	
		
			
				|  |  |                                 fenceLocation.add(positionTmp);
 | 
	
		
			
				|  |  |                 if ((dulat == 0.0 && dulon == 0.0)) {
 | 
	
		
			
				|  |  |                     BasePatientDO patientDO = basePatientDao.findById(deviceDO.getUser());
 | 
	
		
			
				|  |  |                     String points = patientDO.getLatLon();
 | 
	
		
			
				|  |  |                     if (StringUtils.isNotBlank(points)) {
 | 
	
		
			
				|  |  |                         String[] pointss = points.split(",");
 | 
	
		
			
				|  |  |                         if (2 == pointss.length) {
 | 
	
		
			
				|  |  |                             if (StringUtils.isNotBlank(pointss[0])) {
 | 
	
		
			
				|  |  |                                 dulat = Double.parseDouble(pointss[0]);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                             if (StringUtils.isNotBlank(pointss[1])) {
 | 
	
		
			
				|  |  |                                 dulat = Double.parseDouble(pointss[1]);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                             fenceTmp.put("location",fenceLocation);
 | 
	
		
			
				|  |  |                             fenceTmp.put("inFenceStatus",countDistance.isInPolygon(result.getJSONObject("location").getDouble("lon"),result.getJSONObject("location").getDouble("lat"),fenceLocation));
 | 
	
		
			
				|  |  |                             fencesEnables.add(fenceTmp);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     if (fencesEnables.size()>0){
 | 
	
		
			
				|  |  |                         result.put("fences",fencesEnables);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if (!(dulat == 0.0 && dulon == 0.0)) {
 | 
	
		
			
				|  |  |                     List<PatientSafeAreaDO> safeAreaDOS = safeAreaDao.findByPatient(deviceDO.getUser());
 | 
	
		
			
				|  |  |                     String safeArea=null;
 | 
	
		
			
				|  |  |                     if (safeAreaDOS.size()>0){
 | 
	
		
			
				|  |  |                         safeArea = safeAreaDOS.get(0).getSafeAreaGz();
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     JSONArray fenceLocation = new JSONArray();
 | 
	
		
			
				|  |  |                     String address = LatitudeUtils.getLocationAddress(dulat + "", dulon + "");
 | 
	
		
			
				|  |  |                     if (StringUtils.isNotBlank(safeArea)) {
 | 
	
		
			
				|  |  |                         String[] safeAreas = safeArea.split(";");
 | 
	
		
			
				|  |  |                         for (String area : safeAreas) {
 | 
	
		
			
				|  |  |                             String[] areaPoint = area.split(",");
 | 
	
		
			
				|  |  |                             JSONObject positionTmp = new JSONObject();
 | 
	
		
			
				|  |  |                             Double areaLon = Double.parseDouble(areaPoint[0]);
 | 
	
		
			
				|  |  |                             Double areaLat = Double.parseDouble(areaPoint[1]);
 | 
	
		
			
				|  |  |                             positionTmp.put("lat", areaLat);
 | 
	
		
			
				|  |  |                             positionTmp.put("lon", areaLon);
 | 
	
		
			
				|  |  |                             fenceLocation.add(positionTmp);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         if (devicePatientDeviceDos2.size() > 0 && 0 == categoryCode) {
 | 
	
		
			
				|  |  |                             JSONObject obj = result.getJSONArray("fences").getJSONObject(0);
 | 
	
		
			
				|  |  |                             if (!obj.getBooleanValue("inFenceStatus")) {
 | 
	
		
			
				|  |  |                                 if (!countDistance.isInPolygon(dulon, dulat, fenceLocation)) {
 | 
	
		
			
				|  |  |                                     obj.put("inFenceStatus", false);
 | 
	
		
			
				|  |  |                                     obj = result.getJSONObject("location");
 | 
	
		
			
				|  |  |                                     obj.put("address", address);
 | 
	
		
			
				|  |  |                                     obj.put("lon", dulon);
 | 
	
		
			
				|  |  |                                     obj.put("lat", dulat);
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                         if (devicePatientDeviceDos2.size() > 0 && 16 == categoryCode) {
 | 
	
		
			
				|  |  |                             if (StringUtils.isNotBlank(safeArea)) {
 | 
	
		
			
				|  |  |                                 result.put("deviceSn", deviceDO.getDeviceSn());
 | 
	
		
			
				|  |  |                                 JSONObject location = new JSONObject();
 | 
	
		
			
				|  |  |                                 location.put("address",address);
 | 
	
		
			
				|  |  |                                 location.put("province","");
 | 
	
		
			
				|  |  |                                 location.put("city","");
 | 
	
		
			
				|  |  |                                 location.put("lon",dulon);
 | 
	
		
			
				|  |  |                                 location.put("lat",dulat);
 | 
	
		
			
				|  |  |                                 result.put("location",location);
 | 
	
		
			
				|  |  |                                 JSONArray fences = new JSONArray();
 | 
	
		
			
				|  |  |                                 JSONObject fence = new JSONObject();
 | 
	
		
			
				|  |  |                                 fence.put("fenceNO","1");
 | 
	
		
			
				|  |  |                                 fence.put("name","安全区域1");
 | 
	
		
			
				|  |  |                                 fence.put("inFenceStatus", countDistance.isInPolygon(dulon, dulat, fenceLocation));
 | 
	
		
			
				|  |  |                                 fence.put("location", fenceLocation);
 | 
	
		
			
				|  |  |                                 fences.add(fence);
 | 
	
		
			
				|  |  |                                 result.put("fences",fences);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
	
		
			
				|  | @ -1363,14 +1481,15 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  |                         dayTime = getSleepMonitoringDay(new Date(),patient);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     List<BaseSleepPlanDetail> planDetails = sleepPlanDetailDao.findByPatientAndDay(patient,dayTime);
 | 
	
		
			
				|  |  |                     BaseSleepPlanDetail planDetail = new BaseSleepPlanDetail();
 | 
	
		
			
				|  |  |                     if (planDetails.size()>0){
 | 
	
		
			
				|  |  |                         BaseSleepPlanDetail planDetail =  planDetails.get(0);
 | 
	
		
			
				|  |  |                         planDetail =  planDetails.get(0);
 | 
	
		
			
				|  |  |                         List<BaseSleepNightRecord> sleepNightRecordList = nightRecordDao.findByPatientAndDayOrderByCreateTimeDesc(patient,dayTime);
 | 
	
		
			
				|  |  |                         planDetail.setSleepNightRecordList(sleepNightRecordList);
 | 
	
		
			
				|  |  |                         String jsonStr = JSON.toJSONStringWithDateFormat(planDetail, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue);
 | 
	
		
			
				|  |  |                         sleepInfo = JSONObject.parseObject(jsonStr);
 | 
	
		
			
				|  |  |                         sleepInfo.put("day",dayTime);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     String jsonStr = JSON.toJSONStringWithDateFormat(planDetail, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue);
 | 
	
		
			
				|  |  |                     sleepInfo = JSONObject.parseObject(jsonStr);
 | 
	
		
			
				|  |  |                     sleepInfo.put("day",dayTime);
 | 
	
		
			
				|  |  |                     List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatient(patient);
 | 
	
		
			
				|  |  |                     if (sleepPlans.size()>0){
 | 
	
		
			
				|  |  |                         BaseSleepPlan sleepPlan = sleepPlans.get(0);
 | 
	
	
		
			
				|  | @ -1496,12 +1615,12 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject patientSignTopicInfo(JSONObject result,String patient,String topicItem){
 | 
	
		
			
				|  |  |     public JSONObject patientSignTopicInfo(JSONObject result,String patient,String topicItem,String deviceSn){
 | 
	
		
			
				|  |  |         if (null==result){
 | 
	
		
			
				|  |  |             result = new JSONObject();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if ("preventLost".equals(topicItem)||StringUtils.isBlank(topicItem)){
 | 
	
		
			
				|  |  |             preventLost(result, patient);
 | 
	
		
			
				|  |  |             preventLost(result, patient,deviceSn);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if ("preventFall".equals(topicItem)||StringUtils.isBlank(topicItem)){
 | 
	
		
			
				|  |  |             monitorInfo(result, patient);
 |