|  | @ -351,7 +351,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         if (5==orderDO.getOrderSource()){//睡眠带工单
 |  |         if (5==orderDO.getOrderSource()){//睡眠带工单
 | 
												
													
														
															|  |             try {
 |  |             try {
 | 
												
													
														
															|  |                 JSONObject monitorInfo = patientSignTopicInfo(orderDO.getPatient(),"preventOutOfBed");
 |  | 
 | 
												
													
														
															|  | 
 |  |                 JSONObject monitorInfo = patientSignTopicInfo(null,orderDO.getPatient(),"preventOutOfBed");
 | 
												
													
														
															|  |                 Map<String,Object> tmp = JSONObject.parseObject(objectMapper.writeValueAsString(monitorInfo));
 |  |                 Map<String,Object> tmp = JSONObject.parseObject(objectMapper.writeValueAsString(monitorInfo));
 | 
												
													
														
															|  |                 if ("true".equals( tmp.get("sleepStatus").toString())){
 |  |                 if ("true".equals( tmp.get("sleepStatus").toString())){
 | 
												
													
														
															|  |                     Map<String,Object> sleepInfo = (Map<String, Object>) tmp.get("sleepInfo");
 |  |                     Map<String,Object> sleepInfo = (Map<String, Object>) tmp.get("sleepInfo");
 | 
												
											
												
													
														
															|  | @ -1213,291 +1213,151 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
 | 
												
													
														
															|  |         else {
 |  |         else {
 | 
												
													
														
															|  |             result.put("fall",false);
 |  |             result.put("fall",false);
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         if ((StringUtils.isNotBlank(topicItem)&&"preventLost".equals(topicItem))){
 |  | 
 | 
												
													
														
															|  |             List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
 |  | 
 | 
												
													
														
															|  |             if (devicePatientDeviceDos.size()==0){
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             else {
 |  | 
 | 
												
													
														
															|  |                 DevicePatientDevice device = devicePatientDeviceDos.get(0);
 |  | 
 | 
												
													
														
															|  |                 result.put("deviceSn",device.getDeviceSn());
 |  | 
 | 
												
													
														
															|  |                 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);
 |  | 
 | 
												
													
														
															|  |                         }
 |  | 
 | 
												
													
														
															|  |                         //围栏信息
 |  | 
 | 
												
													
														
															|  |                         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);
 |  | 
 | 
												
													
														
															|  |                             }
 |  | 
 | 
												
													
														
															|  |                         }
 |  | 
 | 
												
													
														
															|  |                     }
 |  | 
 | 
												
													
														
															|  |                 }catch (Exception e){
 |  | 
 | 
												
													
														
															|  |                     e.printStackTrace();
 |  | 
 | 
												
													
														
															|  |                     result.put("location",null);
 |  | 
 | 
												
													
														
															|  |                 }
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  | 
 |  |         if (StringUtils.isNotBlank(topicItem)){
 | 
												
													
														
															|  | 
 |  |             result = patientSignTopicInfo(result,patient,topicItem);
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         if ((StringUtils.isNotBlank(topicItem)&&"preventFall".equals(topicItem))){
 |  | 
 | 
												
													
														
															|  |             List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
 |  | 
 | 
												
													
														
															|  |             if (devicePatientDeviceDos.size()==0){
 |  | 
 | 
												
													
														
															|  | 
 |  |         return result;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             else{
 |  | 
 | 
												
													
														
															|  |                 try {
 |  | 
 | 
												
													
														
															|  |                     DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
 |  | 
 | 
												
													
														
															|  |                     JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,deviceDo.getDeviceSn(),1,null);
 |  | 
 | 
												
													
														
															|  |                     result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
 |  | 
 | 
												
													
														
															|  |                     result.put("patientAddress",deviceDo.getSosAddress());
 |  | 
 | 
												
													
														
															|  |                     if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
 |  | 
 | 
												
													
														
															|  |                         result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
 |  | 
 | 
												
													
														
															|  |                     }
 |  | 
 | 
												
													
														
															|  |                     else {
 |  | 
 | 
												
													
														
															|  |                         result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
 |  | 
 | 
												
													
														
															|  |                     }
 |  | 
 | 
												
													
														
															|  |                 }catch (Exception e){
 |  | 
 | 
												
													
														
															|  |                     e.printStackTrace();
 |  | 
 | 
												
													
														
															|  |                 }
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  | 
 |  |     public JSONObject patientSignTopicInfo(JSONObject result,String patient,String topicItem){
 | 
												
													
														
															|  | 
 |  |         if (null==result){
 | 
												
													
														
															|  | 
 |  |             result = new JSONObject();
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |         if ((StringUtils.isNotBlank(topicItem)&&"preventOutOfBed".equals(topicItem))){
 |  | 
 | 
												
													
														
															|  |             List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"13");
 |  | 
 | 
												
													
														
															|  |             if (devicePatientDeviceDos.size()==0){
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |             }else {
 |  | 
 | 
												
													
														
															|  |                 DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
 |  | 
 | 
												
													
														
															|  |                 JSONObject deviceInfo =  patientDeviceService.getSleepDeviceInfo(deviceDo.getDeviceSn());
 |  | 
 | 
												
													
														
															|  |                 if(deviceInfo.getBooleanValue("success")){
 |  | 
 | 
												
													
														
															|  |                     result.put("patientAddress",deviceDo.getSosAddress());
 |  | 
 | 
												
													
														
															|  |                     JSONArray objInfo = deviceInfo.getJSONArray("objs");
 |  | 
 | 
												
													
														
															|  |                     if (objInfo.size()>0){
 |  | 
 | 
												
													
														
															|  |                         result.put("sleepStatus",true);
 |  | 
 | 
												
													
														
															|  |                         JSONObject tmp = objInfo.getJSONObject(0);
 |  | 
 | 
												
													
														
															|  |                         JSONObject sleepInfo = new JSONObject();
 |  | 
 | 
												
													
														
															|  |                         sleepInfo.put("online",tmp.getBooleanValue("online"));
 |  | 
 | 
												
													
														
															|  |                         sleepInfo.put("onbed",tmp.getBooleanValue("onbed"));
 |  | 
 | 
												
													
														
															|  |                         sleepInfo.put("heartrate",tmp.getString("heartrate"));
 |  | 
 | 
												
													
														
															|  |                         sleepInfo.put("breathrate",tmp.getString("breathrate"));
 |  | 
 | 
												
													
														
															|  |                         BasePatientOutBed outBed = outBedDao.findByPatientAndDeviceSnAndStatus(patient,deviceDo.getDeviceSn(),0);
 |  | 
 | 
												
													
														
															|  |                         if (null!=outBed){
 |  | 
 | 
												
													
														
															|  |                             String outBedTime = "";
 |  | 
 | 
												
													
														
															|  |                             Date date = new Date();
 |  | 
 | 
												
													
														
															|  |                             long millisecondsDiff = date.getTime() - outBed.getCreateTime().getTime();
 |  | 
 | 
												
													
														
															|  |                             long minutesDiff = millisecondsDiff / TimeUnit.MINUTES.toMillis(1L);
 |  | 
 | 
												
													
														
															|  |                             long hoursDiff = millisecondsDiff / TimeUnit.HOURS.toMillis(1L);
 |  | 
 | 
												
													
														
															|  |                             if (hoursDiff > 0L) {
 |  | 
 | 
												
													
														
															|  |                                 outBedTime += String.format("%d小时", hoursDiff);
 |  | 
 | 
												
													
														
															|  | 
 |  |         if (StringUtils.isNotBlank(topicItem)){
 | 
												
													
														
															|  | 
 |  |             if ("preventLost".equals(topicItem)){
 | 
												
													
														
															|  | 
 |  |                 List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
 | 
												
													
														
															|  | 
 |  |                 if (devicePatientDeviceDos.size()==0){}
 | 
												
													
														
															|  | 
 |  |                 else {
 | 
												
													
														
															|  | 
 |  |                     DevicePatientDevice device = devicePatientDeviceDos.get(0);
 | 
												
													
														
															|  | 
 |  |                     result.put("deviceSn",device.getDeviceSn());
 | 
												
													
														
															|  | 
 |  |                     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);
 | 
												
													
														
															|  |                             }
 |  |                             }
 | 
												
													
														
															|  |                             if (minutesDiff>0){
 |  | 
 | 
												
													
														
															|  |                                 outBedTime +=String.format("%d分钟", minutesDiff);
 |  | 
 | 
												
													
														
															|  | 
 |  |                             //围栏信息
 | 
												
													
														
															|  | 
 |  |                             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);
 | 
												
													
														
															|  | 
 |  |                                 }
 | 
												
													
														
															|  |                             }
 |  |                             }
 | 
												
													
														
															|  |                             sleepInfo.put("outBedTime",outBedTime);
 |  | 
 | 
												
													
														
															|  |                         }else {
 |  | 
 | 
												
													
														
															|  |                             sleepInfo.put("outBedTime","无");
 |  | 
 | 
												
													
														
															|  |                         }
 |  |                         }
 | 
												
													
														
															|  |                         result.put("sleepInfo",sleepInfo);
 |  | 
 | 
												
													
														
															|  | 
 |  |                     }catch (Exception e){
 | 
												
													
														
															|  | 
 |  |                         e.printStackTrace();
 | 
												
													
														
															|  | 
 |  |                         result.put("location",null);
 | 
												
													
														
															|  |                     }
 |  |                     }
 | 
												
													
														
															|  |                 }else {
 |  | 
 | 
												
													
														
															|  |                     result.put("sleepStatus",false);
 |  | 
 | 
												
													
														
															|  |                     result.put("sleepInfo","获取睡眠带数据失败");
 |  | 
 | 
												
													
														
															|  |                 }
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             //监控
 |  | 
 | 
												
													
														
															|  |             devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
 |  | 
 | 
												
													
														
															|  |             if (devicePatientDeviceDos.size()==0){
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             else{
 |  | 
 | 
												
													
														
															|  |                 try {
 |  | 
 | 
												
													
														
															|  |                     DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
 |  | 
 | 
												
													
														
															|  |                     JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,deviceDo.getDeviceSn(),1,null);
 |  | 
 | 
												
													
														
															|  |                     result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
 |  | 
 | 
												
													
														
															|  |                     result.put("patientAddress",deviceDo.getSosAddress());
 |  | 
 | 
												
													
														
															|  |                     if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
 |  | 
 | 
												
													
														
															|  |                         result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
 |  | 
 | 
												
													
														
															|  |                     }
 |  | 
 | 
												
													
														
															|  |                     else {
 |  | 
 | 
												
													
														
															|  |                         result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
 |  | 
 | 
												
													
														
															|  |                     }
 |  | 
 | 
												
													
														
															|  |                 }catch (Exception e){
 |  | 
 | 
												
													
														
															|  |                     e.printStackTrace();
 |  | 
 | 
												
													
														
															|  |                 }
 |  |                 }
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |         }
 |  | 
 | 
												
													
														
															|  |         return result;
 |  | 
 | 
												
													
														
															|  |     }
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     public JSONObject patientSignTopicInfo(String patient,String topicItem){
 |  | 
 | 
												
													
														
															|  |         JSONObject result = new JSONObject();
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         if ((StringUtils.isNotBlank(topicItem)&&"preventLost".equals(topicItem))){
 |  | 
 | 
												
													
														
															|  |             List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4");
 |  | 
 | 
												
													
														
															|  |             if (devicePatientDeviceDos.size()==0){
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             else {
 |  | 
 | 
												
													
														
															|  |                 DevicePatientDevice device = devicePatientDeviceDos.get(0);
 |  | 
 | 
												
													
														
															|  |                 result.put("deviceSn",device.getDeviceSn());
 |  | 
 | 
												
													
														
															|  |                 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);
 |  | 
 | 
												
													
														
															|  | 
 |  |             if ("preventFall".equals(topicItem)){
 | 
												
													
														
															|  | 
 |  |                 List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
 | 
												
													
														
															|  | 
 |  |                 if (devicePatientDeviceDos.size()==0){}
 | 
												
													
														
															|  | 
 |  |                 else{
 | 
												
													
														
															|  | 
 |  |                     try {
 | 
												
													
														
															|  | 
 |  |                         DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
 | 
												
													
														
															|  | 
 |  |                         JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,deviceDo.getDeviceSn(),1,null);
 | 
												
													
														
															|  | 
 |  |                         result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
 | 
												
													
														
															|  | 
 |  |                         result.put("patientAddress",deviceDo.getSosAddress());
 | 
												
													
														
															|  | 
 |  |                         if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
 | 
												
													
														
															|  | 
 |  |                             result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
 | 
												
													
														
															|  |                         }
 |  |                         }
 | 
												
													
														
															|  |                         //围栏信息
 |  | 
 | 
												
													
														
															|  |                         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);
 |  | 
 | 
												
													
														
															|  |                             }
 |  | 
 | 
												
													
														
															|  | 
 |  |                         else {
 | 
												
													
														
															|  | 
 |  |                             result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
 | 
												
													
														
															|  |                         }
 |  |                         }
 | 
												
													
														
															|  | 
 |  |                     }catch (Exception e){
 | 
												
													
														
															|  | 
 |  |                         e.printStackTrace();
 | 
												
													
														
															|  |                     }
 |  |                     }
 | 
												
													
														
															|  |                 }catch (Exception e){
 |  | 
 | 
												
													
														
															|  |                     e.printStackTrace();
 |  | 
 | 
												
													
														
															|  |                     result.put("location",null);
 |  | 
 | 
												
													
														
															|  |                 }
 |  |                 }
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |         }
 |  | 
 | 
												
													
														
															|  |         if ((StringUtils.isNotBlank(topicItem)&&"preventFall".equals(topicItem))){
 |  | 
 | 
												
													
														
															|  |             List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
 |  | 
 | 
												
													
														
															|  |             if (devicePatientDeviceDos.size()==0){
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             else{
 |  | 
 | 
												
													
														
															|  |                 try {
 |  | 
 | 
												
													
														
															|  | 
 |  |             if ("preventOutOfBed".equals(topicItem)){
 | 
												
													
														
															|  | 
 |  |                 List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"13");
 | 
												
													
														
															|  | 
 |  |                 if (devicePatientDeviceDos.size()==0){}
 | 
												
													
														
															|  | 
 |  |                 else {
 | 
												
													
														
															|  |                     DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
 |  |                     DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
 | 
												
													
														
															|  |                     JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,deviceDo.getDeviceSn(),1,null);
 |  | 
 | 
												
													
														
															|  |                     result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
 |  | 
 | 
												
													
														
															|  |                     result.put("patientAddress",deviceDo.getSosAddress());
 |  | 
 | 
												
													
														
															|  |                     if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
 |  | 
 | 
												
													
														
															|  |                         result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
 |  | 
 | 
												
													
														
															|  |                     }
 |  | 
 | 
												
													
														
															|  |                     else {
 |  | 
 | 
												
													
														
															|  |                         result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
 |  | 
 | 
												
													
														
															|  |                     }
 |  | 
 | 
												
													
														
															|  |                 }catch (Exception e){
 |  | 
 | 
												
													
														
															|  |                     e.printStackTrace();
 |  | 
 | 
												
													
														
															|  |                 }
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |         }
 |  | 
 | 
												
													
														
															|  |         if ((StringUtils.isNotBlank(topicItem)&&"preventOutOfBed".equals(topicItem))){
 |  | 
 | 
												
													
														
															|  |             List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"13");
 |  | 
 | 
												
													
														
															|  |             if (devicePatientDeviceDos.size()==0){
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |             }else {
 |  | 
 | 
												
													
														
															|  |                 DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
 |  | 
 | 
												
													
														
															|  |                 JSONObject deviceInfo =  patientDeviceService.getSleepDeviceInfo(deviceDo.getDeviceSn());
 |  | 
 | 
												
													
														
															|  |                 if(deviceInfo.getBooleanValue("success")){
 |  | 
 | 
												
													
														
															|  |                     result.put("patientAddress",deviceDo.getSosAddress());
 |  | 
 | 
												
													
														
															|  |                     JSONArray objInfo = deviceInfo.getJSONArray("objs");
 |  | 
 | 
												
													
														
															|  |                     if (objInfo.size()>0){
 |  | 
 | 
												
													
														
															|  |                         result.put("sleepStatus",true);
 |  | 
 | 
												
													
														
															|  |                         JSONObject tmp = objInfo.getJSONObject(0);
 |  | 
 | 
												
													
														
															|  |                         JSONObject sleepInfo = new JSONObject();
 |  | 
 | 
												
													
														
															|  |                         sleepInfo.put("online",tmp.getBooleanValue("online"));
 |  | 
 | 
												
													
														
															|  |                         sleepInfo.put("onbed",tmp.getBooleanValue("onbed"));
 |  | 
 | 
												
													
														
															|  |                         sleepInfo.put("heartrate",tmp.getString("heartrate"));
 |  | 
 | 
												
													
														
															|  |                         sleepInfo.put("breathrate",tmp.getString("breathrate"));
 |  | 
 | 
												
													
														
															|  |                         BasePatientOutBed outBed = outBedDao.findByPatientAndDeviceSnAndStatus(patient,deviceDo.getDeviceSn(),0);
 |  | 
 | 
												
													
														
															|  |                         if (null!=outBed){
 |  | 
 | 
												
													
														
															|  |                             String outBedTime = "";
 |  | 
 | 
												
													
														
															|  |                             Date date = new Date();
 |  | 
 | 
												
													
														
															|  |                             long millisecondsDiff = date.getTime() - outBed.getCreateTime().getTime();
 |  | 
 | 
												
													
														
															|  |                             long minutesDiff = millisecondsDiff / TimeUnit.MINUTES.toMillis(1L);
 |  | 
 | 
												
													
														
															|  |                             long hoursDiff = millisecondsDiff / TimeUnit.HOURS.toMillis(1L);
 |  | 
 | 
												
													
														
															|  |                             if (hoursDiff > 0L) {
 |  | 
 | 
												
													
														
															|  |                                 outBedTime += String.format("%d小时", hoursDiff);
 |  | 
 | 
												
													
														
															|  |                             }
 |  | 
 | 
												
													
														
															|  |                             if (minutesDiff>0){
 |  | 
 | 
												
													
														
															|  |                                 outBedTime +=String.format("%d分钟", minutesDiff);
 |  | 
 | 
												
													
														
															|  | 
 |  |                     JSONObject deviceInfo =  patientDeviceService.getSleepDeviceInfo(deviceDo.getDeviceSn());
 | 
												
													
														
															|  | 
 |  |                     if(deviceInfo.getBooleanValue("success")){
 | 
												
													
														
															|  | 
 |  |                         result.put("patientAddress",deviceDo.getSosAddress());
 | 
												
													
														
															|  | 
 |  |                         JSONArray objInfo = deviceInfo.getJSONArray("objs");
 | 
												
													
														
															|  | 
 |  |                         if (objInfo.size()>0){
 | 
												
													
														
															|  | 
 |  |                             result.put("sleepStatus",true);
 | 
												
													
														
															|  | 
 |  |                             JSONObject tmp = objInfo.getJSONObject(0);
 | 
												
													
														
															|  | 
 |  |                             JSONObject sleepInfo = new JSONObject();
 | 
												
													
														
															|  | 
 |  |                             sleepInfo.put("online",tmp.getBooleanValue("online"));
 | 
												
													
														
															|  | 
 |  |                             sleepInfo.put("onbed",tmp.getBooleanValue("onbed"));
 | 
												
													
														
															|  | 
 |  |                             sleepInfo.put("heartrate",tmp.getString("heartrate"));
 | 
												
													
														
															|  | 
 |  |                             sleepInfo.put("breathrate",tmp.getString("breathrate"));
 | 
												
													
														
															|  | 
 |  |                             BasePatientOutBed outBed = outBedDao.findByPatientAndDeviceSnAndStatus(patient,deviceDo.getDeviceSn(),0);
 | 
												
													
														
															|  | 
 |  |                             if (null!=outBed){
 | 
												
													
														
															|  | 
 |  |                                 String outBedTime = "";
 | 
												
													
														
															|  | 
 |  |                                 Date date = new Date();
 | 
												
													
														
															|  | 
 |  |                                 long millisecondsDiff = date.getTime() - outBed.getCreateTime().getTime();
 | 
												
													
														
															|  | 
 |  |                                 long minutesDiff = millisecondsDiff / TimeUnit.MINUTES.toMillis(1L);
 | 
												
													
														
															|  | 
 |  |                                 long hoursDiff = millisecondsDiff / TimeUnit.HOURS.toMillis(1L);
 | 
												
													
														
															|  | 
 |  |                                 long minuteFieldDiff = minutesDiff - TimeUnit.HOURS.toMinutes(hoursDiff);
 | 
												
													
														
															|  | 
 |  |                                 if (hoursDiff > 0L) {
 | 
												
													
														
															|  | 
 |  |                                     outBedTime += String.format("%d小时", hoursDiff);
 | 
												
													
														
															|  | 
 |  |                                 }
 | 
												
													
														
															|  | 
 |  |                                 if (minuteFieldDiff>0){
 | 
												
													
														
															|  | 
 |  |                                     outBedTime +=String.format("%d分钟", minuteFieldDiff);
 | 
												
													
														
															|  | 
 |  |                                 }
 | 
												
													
														
															|  | 
 |  |                                 sleepInfo.put("outBedTime",outBedTime);
 | 
												
													
														
															|  | 
 |  |                             }else {
 | 
												
													
														
															|  | 
 |  |                                 sleepInfo.put("outBedTime","无");
 | 
												
													
														
															|  |                             }
 |  |                             }
 | 
												
													
														
															|  |                             sleepInfo.put("outBedTime",outBedTime);
 |  | 
 | 
												
													
														
															|  |                         }else {
 |  | 
 | 
												
													
														
															|  |                             sleepInfo.put("outBedTime","无");
 |  | 
 | 
												
													
														
															|  | 
 |  |                             result.put("sleepInfo",sleepInfo);
 | 
												
													
														
															|  |                         }
 |  |                         }
 | 
												
													
														
															|  |                         result.put("sleepInfo",sleepInfo);
 |  | 
 | 
												
													
														
															|  | 
 |  |                     }else {
 | 
												
													
														
															|  | 
 |  |                         result.put("sleepStatus",false);
 | 
												
													
														
															|  | 
 |  |                         result.put("sleepInfo","获取睡眠带数据失败");
 | 
												
													
														
															|  |                     }
 |  |                     }
 | 
												
													
														
															|  |                 }else {
 |  | 
 | 
												
													
														
															|  |                     result.put("sleepStatus",false);
 |  | 
 | 
												
													
														
															|  |                     result.put("sleepInfo","获取睡眠带数据失败");
 |  | 
 | 
												
													
														
															|  |                 }
 |  |                 }
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             //监控
 |  | 
 | 
												
													
														
															|  |             devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
 |  | 
 | 
												
													
														
															|  |             if (devicePatientDeviceDos.size()==0){
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             else{
 |  | 
 | 
												
													
														
															|  |                 try {
 |  | 
 | 
												
													
														
															|  |                     DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
 |  | 
 | 
												
													
														
															|  |                     JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,deviceDo.getDeviceSn(),1,null);
 |  | 
 | 
												
													
														
															|  |                     result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
 |  | 
 | 
												
													
														
															|  |                     result.put("patientAddress",deviceDo.getSosAddress());
 |  | 
 | 
												
													
														
															|  |                     if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
 |  | 
 | 
												
													
														
															|  |                         result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
 |  | 
 | 
												
													
														
															|  |                     }
 |  | 
 | 
												
													
														
															|  |                     else {
 |  | 
 | 
												
													
														
															|  |                         result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
 |  | 
 | 
												
													
														
															|  | 
 |  |                 //监控
 | 
												
													
														
															|  | 
 |  |                 devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
 | 
												
													
														
															|  | 
 |  |                 if (devicePatientDeviceDos.size()==0){}
 | 
												
													
														
															|  | 
 |  |                 else{
 | 
												
													
														
															|  | 
 |  |                     try {
 | 
												
													
														
															|  | 
 |  |                         DevicePatientDevice deviceDo = devicePatientDeviceDos.get(0);
 | 
												
													
														
															|  | 
 |  |                         JSONObject monitorUrl = ysDeviceServicel.getDeviceLiveAddress(patient,deviceDo.getDeviceSn(),1,null);
 | 
												
													
														
															|  | 
 |  |                         result.put("monitorInfoStatus",monitorUrl.getIntValue(ResponseContant.resultFlag));
 | 
												
													
														
															|  | 
 |  |                         result.put("patientAddress",deviceDo.getSosAddress());
 | 
												
													
														
															|  | 
 |  |                         if (monitorUrl.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
 | 
												
													
														
															|  | 
 |  |                             result.put("monitorInfo",monitorUrl.getString(ResponseContant.resultMsg));
 | 
												
													
														
															|  | 
 |  |                         }
 | 
												
													
														
															|  | 
 |  |                         else {
 | 
												
													
														
															|  | 
 |  |                             result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg));
 | 
												
													
														
															|  | 
 |  |                         }
 | 
												
													
														
															|  | 
 |  |                     }catch (Exception e){
 | 
												
													
														
															|  | 
 |  |                         e.printStackTrace();
 | 
												
													
														
															|  |                     }
 |  |                     }
 | 
												
													
														
															|  |                 }catch (Exception e){
 |  | 
 | 
												
													
														
															|  |                     e.printStackTrace();
 |  | 
 | 
												
													
														
															|  |                 }
 |  |                 }
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |         }
 |  |         }
 |