|  | @ -139,63 +139,65 @@ public class DeviceService {
 | 
	
		
			
				|  |  |             Double lat= Double.parseDouble(request.getParameter("lat"));
 | 
	
		
			
				|  |  |             Double lon= Double.parseDouble(request.getParameter("lon"));
 | 
	
		
			
				|  |  |             List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(imei);
 | 
	
		
			
				|  |  |             DevicePatientDevice deviceDO = devicePatientDeviceDos.get(0);
 | 
	
		
			
				|  |  |             BasePatientDO patientDO = patientDao.findById(deviceDO.getUser());
 | 
	
		
			
				|  |  |             DeviceSosLogDO logDO = new DeviceSosLogDO();
 | 
	
		
			
				|  |  |             logDO.setPatient(patientDO.getId());
 | 
	
		
			
				|  |  |             logDO.setPatientName(patientDO.getName());
 | 
	
		
			
				|  |  |             logDO.setIdcard(patientDO.getIdcard());
 | 
	
		
			
				|  |  |             logDO.setCategoryCode(deviceDO.getCategoryCode());
 | 
	
		
			
				|  |  |             logDO.setDeviceSn(deviceDO.getDeviceSn());
 | 
	
		
			
				|  |  |             logDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |             if (deviceDO.getCategoryCode().equals("4")) {
 | 
	
		
			
				|  |  |                 JSONObject position = gpsUtil.gcj02_To_Bd09(lat,lon);
 | 
	
		
			
				|  |  |                 logDO.setSosAddress(address);
 | 
	
		
			
				|  |  |                 logDO.setSosLat(position.getDouble("lat")+"");
 | 
	
		
			
				|  |  |                 logDO.setSosLon(position.getDouble("lon")+"");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             if (deviceDO.getCategoryCode().equals("7")) {
 | 
	
		
			
				|  |  |                 logDO.setSosAddress(deviceDO.getSosAddress());
 | 
	
		
			
				|  |  |                 Map<String, String> json = null;
 | 
	
		
			
				|  |  |                 if (StringUtils.isNotBlank(deviceDO.getSosAddress())) {
 | 
	
		
			
				|  |  |                     json = LatitudeUtils.getGeocoderLatitude(deviceDO.getSosAddress().replace("G.", "").replace("(糖友网)", "").replace("(高友网)", ""));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if (json != null) {
 | 
	
		
			
				|  |  |                     logDO.setSosLat(json.get("lat").toString());
 | 
	
		
			
				|  |  |                     logDO.setSosLon(json.get("lng").toString());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //发送紧急救助
 | 
	
		
			
				|  |  |             String sql =" select Distinct pack.org_code,pack.org_name\n" +
 | 
	
		
			
				|  |  |                     "from base_service_package_sign_record sr INNER JOIN base_service_package_record pr\n" +
 | 
	
		
			
				|  |  |                     "on sr.id = pr.sign_id and sr.status=1 INNER JOIN base_service_package_item item on pr.service_package_id = item.service_package_id and item.del=1 \n" +
 | 
	
		
			
				|  |  |                     "INNER JOIN base_service_package pack pack on pr.service_package_id = pack.id where item.code='emergencyAssistance' and sr.patient='"+patientDO.getId()+"'";
 | 
	
		
			
				|  |  |             List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |             if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                 JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |                 jsonObject.put("serveAddress",logDO.getSosAddress());
 | 
	
		
			
				|  |  |                 jsonObject.put("serveLon",logDO.getSosLon());
 | 
	
		
			
				|  |  |                 jsonObject.put("serveLat",logDO.getSosLat());
 | 
	
		
			
				|  |  |                 jsonObject.put("orgCode",sqlResult.get(0).get("org_code").toString());
 | 
	
		
			
				|  |  |                 jsonObject.put("orgName",sqlResult.get(0).get("org_name").toString());
 | 
	
		
			
				|  |  |                 jsonObject.put("patient",logDO.getPatient());
 | 
	
		
			
				|  |  |                 jsonObject.put("patientName",logDO.getPatientName());
 | 
	
		
			
				|  |  |                 jsonObject.put("deviceSn",logDO.getDeviceSn());
 | 
	
		
			
				|  |  |                 String url = cloudCareUrl+"cloudCare/noLogin/emergency_assistance/newOrder";
 | 
	
		
			
				|  |  |                 List<NameValuePair> params = new ArrayList<>();
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("jsonData", jsonObject.toJSONString()));
 | 
	
		
			
				|  |  |                 params.add(new BasicNameValuePair("patientId", logDO.getPatient()));
 | 
	
		
			
				|  |  |             if (devicePatientDeviceDos.size()>0){
 | 
	
		
			
				|  |  |                 DevicePatientDevice deviceDO = devicePatientDeviceDos.get(0);
 | 
	
		
			
				|  |  |                 BasePatientDO patientDO = patientDao.findById(deviceDO.getUser());
 | 
	
		
			
				|  |  |                 DeviceSosLogDO logDO = new DeviceSosLogDO();
 | 
	
		
			
				|  |  |                 logDO.setPatient(patientDO.getId());
 | 
	
		
			
				|  |  |                 logDO.setPatientName(patientDO.getName());
 | 
	
		
			
				|  |  |                 logDO.setIdcard(patientDO.getIdcard());
 | 
	
		
			
				|  |  |                 logDO.setCategoryCode(deviceDO.getCategoryCode());
 | 
	
		
			
				|  |  |                 logDO.setDeviceSn(deviceDO.getDeviceSn());
 | 
	
		
			
				|  |  |                 logDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                 if (deviceDO.getCategoryCode().equals("4")) {
 | 
	
		
			
				|  |  |                     params.add(new BasicNameValuePair("orderSource", "2"));//工单来源工单发起来源状态 1APP 2手环 3居家报警
 | 
	
		
			
				|  |  |                     JSONObject position = gpsUtil.gcj02_To_Bd09(lat,lon);
 | 
	
		
			
				|  |  |                     logDO.setSosAddress(address);
 | 
	
		
			
				|  |  |                     logDO.setSosLat(position.getDouble("lat")+"");
 | 
	
		
			
				|  |  |                     logDO.setSosLon(position.getDouble("lon")+"");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if (deviceDO.getCategoryCode().equals("7")) {
 | 
	
		
			
				|  |  |                     params.add(new BasicNameValuePair("orderSource", "3"));
 | 
	
		
			
				|  |  |                     logDO.setSosAddress(deviceDO.getSosAddress());
 | 
	
		
			
				|  |  |                     Map<String, String> json = null;
 | 
	
		
			
				|  |  |                     if (StringUtils.isNotBlank(deviceDO.getSosAddress())) {
 | 
	
		
			
				|  |  |                         json = LatitudeUtils.getGeocoderLatitude(deviceDO.getSosAddress().replace("G.", "").replace("(糖友网)", "").replace("(高友网)", ""));
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     if (json != null) {
 | 
	
		
			
				|  |  |                         logDO.setSosLat(json.get("lat").toString());
 | 
	
		
			
				|  |  |                         logDO.setSosLon(json.get("lng").toString());
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 String response = httpClientUtil.post(url, params,"UTF-8");
 | 
	
		
			
				|  |  |                 System.out.println(response);
 | 
	
		
			
				|  |  |                 //发送紧急救助
 | 
	
		
			
				|  |  |                 String sql =" select Distinct pack.org_code,pack.org_name\n" +
 | 
	
		
			
				|  |  |                         "from base_service_package_sign_record sr INNER JOIN base_service_package_record pr\n" +
 | 
	
		
			
				|  |  |                         "on sr.id = pr.sign_id and sr.status=1 INNER JOIN base_service_package_item item on pr.service_package_id = item.service_package_id and item.del=1 \n" +
 | 
	
		
			
				|  |  |                         "INNER JOIN base_service_package pack pack on pr.service_package_id = pack.id where item.code='emergencyAssistance' and sr.patient='"+patientDO.getId()+"'";
 | 
	
		
			
				|  |  |                 List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql);
 | 
	
		
			
				|  |  |                 if (sqlResult.size()>0){
 | 
	
		
			
				|  |  |                     JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |                     jsonObject.put("serveAddress",logDO.getSosAddress());
 | 
	
		
			
				|  |  |                     jsonObject.put("serveLon",logDO.getSosLon());
 | 
	
		
			
				|  |  |                     jsonObject.put("serveLat",logDO.getSosLat());
 | 
	
		
			
				|  |  |                     jsonObject.put("orgCode",sqlResult.get(0).get("org_code").toString());
 | 
	
		
			
				|  |  |                     jsonObject.put("orgName",sqlResult.get(0).get("org_name").toString());
 | 
	
		
			
				|  |  |                     jsonObject.put("patient",logDO.getPatient());
 | 
	
		
			
				|  |  |                     jsonObject.put("patientName",logDO.getPatientName());
 | 
	
		
			
				|  |  |                     jsonObject.put("deviceSn",logDO.getDeviceSn());
 | 
	
		
			
				|  |  |                     String url = cloudCareUrl+"cloudCare/noLogin/emergency_assistance/newOrder";
 | 
	
		
			
				|  |  |                     List<NameValuePair> params = new ArrayList<>();
 | 
	
		
			
				|  |  |                     params.add(new BasicNameValuePair("jsonData", jsonObject.toJSONString()));
 | 
	
		
			
				|  |  |                     params.add(new BasicNameValuePair("patientId", logDO.getPatient()));
 | 
	
		
			
				|  |  |                     if (deviceDO.getCategoryCode().equals("4")) {
 | 
	
		
			
				|  |  |                         params.add(new BasicNameValuePair("orderSource", "2"));//工单来源工单发起来源状态 1APP 2手环 3居家报警
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     if (deviceDO.getCategoryCode().equals("7")) {
 | 
	
		
			
				|  |  |                         params.add(new BasicNameValuePair("orderSource", "3"));
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     String response = httpClientUtil.post(url, params,"UTF-8");
 | 
	
		
			
				|  |  |                     System.out.println(response);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 sosLogDao.save(logDO);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             sosLogDao.save(logDO);
 | 
	
		
			
				|  |  |         }catch(Exception e){
 | 
	
		
			
				|  |  |                 e.printStackTrace();
 | 
	
		
			
				|  |  |             }
 | 
	
	
		
			
				|  | @ -552,6 +554,7 @@ public class DeviceService {
 | 
	
		
			
				|  |  |                 List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(device);
 | 
	
		
			
				|  |  |                 if (devicePatientDeviceDos.size()>0){
 | 
	
		
			
				|  |  |                     Date timeDate = DateUtil.strToDate(time_begin);//当前时间
 | 
	
		
			
				|  |  |                     String dayTime = null;//检测日期
 | 
	
		
			
				|  |  |                     String patient = devicePatientDeviceDos.get(0).getUser();
 | 
	
		
			
				|  |  |                     List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatientAndDeviceSn(patient,device);
 | 
	
		
			
				|  |  |                     BaseSleepPlanDetail planDetail = new BaseSleepPlanDetail();
 | 
	
	
		
			
				|  | @ -577,7 +580,7 @@ public class DeviceService {
 | 
	
		
			
				|  |  |                         String inTime = sleepPlan.getNightRestTime();
 | 
	
		
			
				|  |  |                         Date bedIn = null;// 入睡时间
 | 
	
		
			
				|  |  |                         Date bedBegin = null;// 入睡开始时间
 | 
	
		
			
				|  |  |                         String dayTime = DateUtil.dateToStr(bedUp,DateUtil.YYYY_MM_DD);//监测日期
 | 
	
		
			
				|  |  |                         dayTime = DateUtil.dateToStr(bedUp,DateUtil.YYYY_MM_DD);//监测日期
 | 
	
		
			
				|  |  |                         if (inTime.charAt(0)=='0'&&inTime.charAt(1)!='0') {//0点后为睡觉日期
 | 
	
		
			
				|  |  |                             bedIn = DateUtil.strToDate(dayTime+" "+sleepPlan.getNightRestTime()+":00");
 | 
	
		
			
				|  |  |                             bedIn = DateUtil.getNextDay1(bedIn,1);
 | 
	
	
		
			
				|  | @ -627,7 +630,7 @@ public class DeviceService {
 | 
	
		
			
				|  |  |                                         orderCreate=true;
 | 
	
		
			
				|  |  |                                     }
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                                 else if(1 == planDetail.getSiestaStatus()&&null==planDetail.getSiestaTimeEnd()){//午睡起床
 | 
	
		
			
				|  |  |                                 else if(1 == planDetail.getSiestaStatus()&&null==planDetail.getSiestaLong()){//午睡起床
 | 
	
		
			
				|  |  |                                     planDetail.setSiestaTimeEnd(timeDate);
 | 
	
		
			
				|  |  |                                     timeDiffer = (planDetail.getSiestaTimeEnd().getTime()-planDetail.getSiestaTimeBegin().getTime())/1000;
 | 
	
		
			
				|  |  |                                     planDetail.setSiestaLong(timeDiffer+"");
 | 
	
	
		
			
				|  | @ -686,7 +689,7 @@ public class DeviceService {
 | 
	
		
			
				|  |  |                                     if (timeDiffer>3600*nightLongWarn*1000){
 | 
	
		
			
				|  |  |                                         planDetail.setInStatus(0);
 | 
	
		
			
				|  |  |                                         planDetail.setBedStatus(1);
 | 
	
		
			
				|  |  |                                         planDetail.setSleepNightRecordList(records);
 | 
	
		
			
				|  |  |                                         planDetail.setSleepNightRecordList(nightRecord.findBySnPaTime(device,patient,dayTime));
 | 
	
		
			
				|  |  |                                         outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"超时未上床晚休",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
 | 
	
		
			
				|  |  |                                         orderCreate=true;
 | 
	
		
			
				|  |  |                                     }
 | 
	
	
		
			
				|  | @ -703,7 +706,7 @@ public class DeviceService {
 | 
	
		
			
				|  |  |                                         record = records.get(0);
 | 
	
		
			
				|  |  |                                         timeDiffer = timeDate.getTime()-record.getCreateTime().getTime();
 | 
	
		
			
				|  |  |                                         if (timeDiffer>3600*nightLongWarn*1000&&0==records.get(0).getStatus()){//超过2未回床小时 触发工单
 | 
	
		
			
				|  |  |                                             planDetail.setSleepNightRecordList(records);
 | 
	
		
			
				|  |  |                                             planDetail.setSleepNightRecordList(nightRecord.findBySnPaTime(device,patient,dayTime));
 | 
	
		
			
				|  |  |                                             planDetail.setBedStatus(0);
 | 
	
		
			
				|  |  |                                             outBedOrder(records.get(0),timeDate,devicePatientDeviceDos.get(0),patient,device,"起夜超时未回床",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
 | 
	
		
			
				|  |  |                                             orderCreate=true;
 | 
	
	
		
			
				|  | @ -728,6 +731,7 @@ public class DeviceService {
 | 
	
		
			
				|  |  |                                     planDetail.setBreath(breath);
 | 
	
		
			
				|  |  |                                     planDetail.setHeartRate(heartrate);
 | 
	
		
			
				|  |  |                                     planDetail.setBedStatus(1);
 | 
	
		
			
				|  |  |                                     planDetail.setSleepNightRecordList(nightRecord.findBySnPaTime(device,patient,dayTime));
 | 
	
		
			
				|  |  |                                     outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
 | 
	
		
			
				|  |  |                                     return null;
 | 
	
		
			
				|  |  |                                 }
 | 
	
	
		
			
				|  | @ -738,6 +742,7 @@ public class DeviceService {
 | 
	
		
			
				|  |  |                                     planDetail.setBreath(breath);
 | 
	
		
			
				|  |  |                                     planDetail.setHeartRate(heartrate);
 | 
	
		
			
				|  |  |                                     planDetail.setBedStatus(1);
 | 
	
		
			
				|  |  |                                     planDetail.setSleepNightRecordList(nightRecord.findBySnPaTime(device,patient,dayTime));
 | 
	
		
			
				|  |  |                                     outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
 | 
	
		
			
				|  |  |                                     return null;
 | 
	
		
			
				|  |  |                                 }
 | 
	
	
		
			
				|  | @ -745,7 +750,6 @@ public class DeviceService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 |