| 
					
				 | 
			
			
				@ -18,32 +18,31 @@ import com.yihu.jw.care.service.family.PatientFamilyMemberService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.service.sign.ServicePackageService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.util.ConstantUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.util.CountDistance; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.util.MessageUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.doctor.BaseDoctorDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.im.ConsultDo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.im.ConsultTeamDo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.patient.BasePatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.contacts.PatientSosContactsDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.BasePatientOutBed; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DevicePatientDevice; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.securitymonitoring.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.hospital.message.SystemMessageDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.message.dao.SystemMessageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.im.dao.ConsultDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.im.dao.ConsultTeamDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.im.util.ImUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.patient.dao.BasePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.ResponseContant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.care.util.MessageUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.doctor.BaseDoctorDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.patient.BasePatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DevicePatientDevice; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.securitymonitoring.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.message.dao.SystemMessageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.patient.dao.BasePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.ResponseContant; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.common.IdCardUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.entity.EntityUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.mysql.query.BaseJpaService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import jdk.management.resource.internal.inst.FileOutputStreamRMHooks; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -351,19 +350,31 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (5==orderDO.getOrderSource()){//睡眠带工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject monitorInfo = patientSignTopicInfo(null,orderDO.getPatient(),"preventOutOfBed"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Map<String,Object> tmp = JSONObject.parseObject(objectMapper.writeValueAsString(monitorInfo)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if ("true".equals( tmp.get("sleepStatus").toString())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Map<String,Object> sleepInfo = (Map<String, Object>) tmp.get("sleepInfo"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    sleepInfo.put("outBedTime","30分钟"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                emergencyOrderVO.setInformation(tmp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject monitorInfo = JSONObject.parseObject(orderDO.getWarnInfo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                emergencyOrderVO.setInformation(monitorInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (6==orderDO.getOrderSource()){//气感工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject monitorInfo = JSONObject.parseObject(orderDO.getWarnInfo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                emergencyOrderVO.setInformation(monitorInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (7==orderDO.getOrderSource()){//烟感工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject monitorInfo = JSONObject.parseObject(orderDO.getWarnInfo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                emergencyOrderVO.setInformation(monitorInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //TODO 火灾、燃气、离床专题返回值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // http://192.168.1.103:85/%E5%8C%BB%E5%85%BB%E7%BB%93%E5%90%88/V0.7.0/#g=1&p=%E6%96%B0%E5%AE%89%E9%98%B2%E5%8C%85 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //通知对象 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> noticePersons = new ArrayList<>(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -1217,145 +1228,186 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject patientSignTopicInfo(JSONObject result,String patient,String topicItem){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (null==result){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void preventLost(JSONObject result,String patient){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"4"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (devicePatientDeviceDos.size()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("preventLost".equals(topicItem)||StringUtils.isBlank(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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    result.put("location",null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("preventFall".equals(topicItem)||StringUtils.isBlank(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)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        result.put("monitorInfo",monitorUrl.getJSONObject(ResponseContant.resultMsg)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (fencesEnables.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        result.put("fences",fencesEnables); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("location",null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("preventOutOfBed".equals(topicItem)||StringUtils.isBlank(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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            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","无"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void preventOutOfBed(JSONObject result,String patient){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        long minuteFieldDiff = minutesDiff - TimeUnit.HOURS.toMinutes(hoursDiff); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (hoursDiff > 0L) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            outBedTime += String.format("%d小时", hoursDiff); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (minuteFieldDiff>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            outBedTime +=String.format("%d分钟", minuteFieldDiff); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        result.put("sleepInfo",sleepInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        sleepInfo.put("outBedTime",outBedTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        sleepInfo.put("outBedTime","无"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    result.put("sleepStatus",false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    result.put("sleepInfo","获取睡眠带数据失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    result.put("sleepInfo",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)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        monitorInfo(result, patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void preventFire(JSONObject result,String patient){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT r.value from wlyy_patient_device pd,base_device_health_index r " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "WHERE pd.device_sn = r.device_sn and pd.`user` = '"+patient+"' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql += " and pd.category_code='15' ORDER BY r.create_time desc LIMIT 1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> list1 = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(list1.size()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("smoke","-1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("smoke",list1.get(0).get("value")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("smokeOrderNum",getOrder(patient,"preventFire")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        monitorInfo(result, patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Integer getOrder(String patient,String topicItem){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select count(1) from base_security_monitoring_order " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "WHERE patient = '"+patient+"' and `status` = 1 and topic_item = '"+topicItem+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer num = jdbcTemplate.queryForObject(sql,Integer.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return num; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void preventGasLeakage(JSONObject result,String patient){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT r.value from wlyy_patient_device pd,base_device_health_index r " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "WHERE pd.device_sn = r.device_sn and pd.`user` = '"+patient+"' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        sql += " and pd.category_code='14' ORDER BY r.create_time desc LIMIT 1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> list1 = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(list1.size()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("methane","-1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("methane",list1.get(0).get("value")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("methaneOrderNum",getOrder(patient,"preventGasLeakage")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        monitorInfo(result, patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void monitorInfo(JSONObject result,String patient){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //监控 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"12"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (devicePatientDeviceDos.size()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        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 ("preventLost".equals(topicItem)||StringUtils.isBlank(topicItem)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            preventLost(result, patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("preventFall".equals(topicItem)||StringUtils.isBlank(topicItem)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            monitorInfo(result, patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("preventOutOfBed".equals(topicItem)||StringUtils.isBlank(topicItem)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            preventOutOfBed(result, patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("preventFire".equals(topicItem)||StringUtils.isBlank(topicItem)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            preventFire(result, patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("preventGasLeakage".equals(topicItem)||StringUtils.isBlank(topicItem)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            preventGasLeakage(result, patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 |