| 
					
				 | 
			
			
				@ -5,15 +5,9 @@ import com.alibaba.fastjson.JSONArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.serializer.SerializerFeature; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.config.AqgConfig; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.BaseSleepDeviceReportDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.DevicePatientHealthIndexDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.DeviceSosLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.PatientDeviceDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.dao.device.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.patient.BasePatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.BaseSleepDeviceReport; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DevicePatientHealthIndex; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DevicePatientDevice; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.DeviceSosLogDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.care.device.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.hospital.message.SystemMessageDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.util.AesEncryptUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.message.dao.SystemMessageDao; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -80,6 +74,10 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private ImUtil imUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseSleepDeviceReportDao sleepDeviceReportDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseSleepNightRecordDao nightRecord; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientOutBedDao outBedDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取爱牵挂管理员cookie 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -121,12 +119,12 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 柏颐sos 接收 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param imei  15位设备唯一序号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param time_begin  发生时间YYYY-MM-DD HH:mm:SS 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param heartrate   心率 int 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param city  城市 String 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param address  地址 String 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param lon  经度 double 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param lat  纬度 double 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type  类型   0:Gps定位; 1:基站定位 String 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param //heartrate   心率 int 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param //city  城市 String 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param //address  地址 String 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param //lon  经度 double 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param //lat  纬度 double 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param //type  类型   0:Gps定位; 1:基站定位 String 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Async 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void aqgsos(String imei,String label_mac,String time_begin, HttpServletRequest request) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -241,8 +239,8 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type  type=1 SOS,type=2 fall,type=3 new 新成员加入 ,type=4 电子围栏触发, type=5 设备低电,type=6 环境音 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param deviceid 15位设备唯一序号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param communityid 机构ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param url  String 环境音下载地址 只有环境音(type=6)为必填,其他type都为非必填 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param name String 设备名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param //url  String 环境音下载地址 只有环境音(type=6)为必填,其他type都为非必填 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param //name String 设备名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Async 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -552,67 +550,178 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param is_warn 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Async 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void bySleep(String device,String time_begin,String heartrate,String breath,String turn_over,String is_warn) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String bySleep(String device,String time_begin,String heartrate,String breath,String bed_status,String turn_over,String is_warn) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(StringUtils.isNotBlank(device)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (devicePatientDeviceDos.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ("1".equals(is_warn)){//触发安防工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        BasePatientDO patientDO = patientDao.findById(devicePatientDeviceDos.get(0).getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if(null!=patientDO){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            String sql ="select DISTINCT pack.org_code,pack.org_name\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    " from base_service_package_sign_record sr,base_service_package_record pr,base_service_package_item item ,base_service_package pack\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    "where pr.patient = '"+patientDO.getId()+"' and sr.id = pr.sign_id and pr.service_package_id = item.service_package_id \tand  item.`code`='preventOutOfBed'  and item.service_package_id = pack.id \n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    "  and pack.del=1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if (sqlResult.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                Map<String, String> json = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                String address= devicePatientDeviceDos.get(0).getSosAddress(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (StringUtils.isNotBlank(devicePatientDeviceDos.get(0).getSosAddress())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    json = LatitudeUtils.getGeocoderLatitude(address.replace("G.", "").replace("(糖友网)", "").replace("(高友网)", "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String patient = devicePatientDeviceDos.get(0).getUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //更新患者在床状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //12点以后 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Date bedIn = DateUtil.getDateStart();//入睡时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Calendar today = Calendar.getInstance(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    today.set(Calendar.HOUR_OF_DAY, 5); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    today.set(Calendar.MINUTE, 59); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    today.set(Calendar.SECOND, 59); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    today.set(Calendar.MILLISECOND, 999); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Date bedUp = today.getTime();//起床时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Date timeDate = DateUtil.strToDate(time_begin); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Long timeDiffer = timeDate.getTime() - bedIn.getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (timeDiffer>0&&timeDate.before(bedUp)){ //起夜记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        BaseSleepNightRecord record = new BaseSleepNightRecord(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if ("0".equals(bed_status)){//离床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            List<BaseSleepNightRecord> records = nightRecord.findBySnStaPaTime(device,patient,0,bedIn); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if (records.size()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                record.setPatient(devicePatientDeviceDos.get(0).getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                record.setDeviceSn(device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                record.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                record.setCreateTime(timeDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                nightRecord.save(record); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            }else {//是否触发工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                record = records.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                timeDiffer = timeDate.getTime()-record.getCreateTime().getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (timeDiffer>1800*1000){//超过半小时 触发工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    outBedOrder(records.get(0),devicePatientDeviceDos.get(0),patient,device,"起夜超时未回床"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                String lat=null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                String lng=null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (json != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    lat= json.get("lat".toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    lng = json.get("lng".toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if ("1".equals(bed_status)){//在床记录起夜时长 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            timeDiffer = bedUp.getTime()-timeDate.getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if (timeDiffer>0){//6点之前入睡时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             List<BaseSleepNightRecord> records = nightRecord.findBySnStaPaTime(device,patient,0,bedIn); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (records.size()>0){// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    record = records.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    record.setStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    record.setUpdateTime(timeDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    Date outDate = record.getCreateTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    timeDiffer = (timeDate.getTime() - outDate.getTime())/1000; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    record.setOutTime(timeDiffer+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    nightRecord.save(record); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                Map<String,Object> map = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                String url = cloudCareUrl+"/cloudCare/noLogin/security/createOrder"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                jsonObject.put("patient",patientDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                jsonObject.put("patientName",patientDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                jsonObject.put("patientPhone",patientDO.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                jsonObject.put("serveDesc","疑似发生意外"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                jsonObject.put("hospital",sqlResult.get(0).get("org_code")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                jsonObject.put("serveAddress",address.replace(" ","")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                jsonObject.put("serveLat",lat); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                jsonObject.put("serveLon",lng); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                jsonObject.put("topicItem","preventOutOfBed"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                jsonObject.put("deviceSn",device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                JSONObject jsonObjectParam = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                jsonObjectParam.put("order", jsonObject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                map.put("jsonData", jsonObjectParam.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                map.put("orderSource", 5); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                map.put("warnStr", "疑似发生意外"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                String content = com.alibaba.fastjson.JSONObject.toJSONString(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                String postParams = AesEncryptUtils.agEncrypt(content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                String response = httpClientUtil.postBodyRawForm(url,postParams); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                JSONObject result = com.alibaba.fastjson.JSONObject.parseObject(response); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                JSONObject jsonObjectData =JSONObject.parseObject(AesEncryptUtils.agDecrypt(result.getString("data"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                System.out.println(jsonObjectData.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if ("1".equals(bed_status)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            timeDiffer = timeDate.getTime() - bedUp.getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if (1800*1000<timeDiffer&&timeDiffer<3600*1000){//超过半小时未起床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                outBedOrder(null,devicePatientDeviceDos.get(0),patient,device,"超时未起床"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ("1".equals(bed_status)){//呼吸 心率检测 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Integer theshold_breath_h = 100; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Integer theshold_breath_l = 50; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Integer theshold_heartrate_h = 25; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Integer theshold_heartrate_l = 8; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (StringUtils.isNotBlank(breath)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                          Integer breath1 = Integer.parseInt(breath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                          if (breath1>theshold_breath_h||breath1<theshold_breath_l){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                              outBedOrder(null,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                              return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                          } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (StringUtils.isNotBlank(heartrate)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            Integer heartrate1 = Integer.parseInt(heartrate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if (heartrate1>theshold_heartrate_h||theshold_heartrate_h<theshold_heartrate_l){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                outBedOrder(null,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void outBedOrder(BaseSleepNightRecord record,DevicePatientDevice patientDevice,String patient ,String device,String serverName)throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // //夜间十二点 起床半小时后未回床 触发安防工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BasePatientDO patientDO = patientDao.findById(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(null!=patientDO){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String sql ="select DISTINCT pack.org_code,pack.org_name\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        " from base_service_package_sign_record sr,base_service_package_record pr,base_service_package_item item ,base_service_package pack\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "where pr.patient = '"+patientDO.getId()+"' and sr.id = pr.sign_id and pr.service_package_id = item.service_package_id \tand  item.`code`='preventOutOfBed'  and item.service_package_id = pack.id \n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "  and pack.del=1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (sqlResult.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Map<String, String> json = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String address= patientDevice.getSosAddress(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (StringUtils.isNotBlank(patientDevice.getSosAddress())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        json = LatitudeUtils.getGeocoderLatitude(address.replace("G.", "").replace("(糖友网)", "").replace("(高友网)", "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String lat=null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String lng=null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (json != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        lat= json.get("lat".toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        lng = json.get("lng".toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Map<String,Object> map = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String url = cloudCareUrl+"/cloudCare/noLogin/security/createOrder"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("patient",patientDO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("patientName",patientDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("patientPhone",patientDO.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("serveDesc",serverName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("hospital",sqlResult.get(0).get("org_code")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("serveAddress",address.replace(" ","")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("serveLat",lat); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("serveLon",lng); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("topicItem","preventOutOfBed"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("deviceSn",device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONObject jsonObjectParam = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObjectParam.put("order", jsonObject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    map.put("jsonData", jsonObjectParam.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    map.put("orderSource", 5); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    map.put("warnStr", serverName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String content = com.alibaba.fastjson.JSONObject.toJSONString(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String postParams = AesEncryptUtils.agEncrypt(content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String response = httpClientUtil.postBodyRawForm(url,postParams); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONObject result = com.alibaba.fastjson.JSONObject.parseObject(response); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONObject jsonObjectData =JSONObject.parseObject(AesEncryptUtils.agDecrypt(result.getString("data"))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    System.out.println(jsonObjectData.toJSONString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (null!=record){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                record.setStatus(-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                nightRecord.save(record); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void updatePatientSleepStatus(String device,String patient,String time_begin,String bed_status){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Integer status = Integer.parseInt(bed_status); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BasePatientOutBed outBed = outBedDao.findByPatientAndDeviceSnAndStatus(patient,device,0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        switch (status){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case 0://离床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (null==outBed){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    outBed = new BasePatientOutBed(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    outBed.setPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    outBed.setDeviceSn(device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    outBed.setStatus(status); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    outBed.setCreateTime(DateUtil.strToDate(time_begin,DateUtil.YYYY_MM_DD_HH_MM_SS)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    outBedDao.save(outBed); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case 1://在床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (null!=outBed){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                   outBed.setStatus(status); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                   outBed.setCreateTime(DateUtil.strToDate(time_begin,DateUtil.YYYY_MM_DD_HH_MM_SS)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                   outBedDao.save(outBed); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Async 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void bySleepReport(String device,String dateStr,String fallasleep,String sleepTime,String restTime,String awakeTime,String lightTime, 
			 |