| 
					
				 | 
			
			
				@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.data.redis.core.StringRedisTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.http.HttpEntity; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.http.HttpHeaders; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.http.HttpMethod; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.scheduling.annotation.Async; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -37,6 +38,7 @@ import org.springframework.util.LinkedMultiValueMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.util.MultiValueMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.text.MessageFormat; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -144,8 +146,14 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void aqgsos(String imei,String label_mac,String time_begin, HttpServletRequest request) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String address= request.getParameter("address"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Double lat= Double.parseDouble(request.getParameter("lat")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Double lon= Double.parseDouble(request.getParameter("lon")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Double lat= null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Double lon= null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (null==request.getParameter("lat")||null==request.getParameter("lon")){//呼叫时可能无该参数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                lat= Double.parseDouble(request.getParameter("lat")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                lon= Double.parseDouble(request.getParameter("lon")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(imei); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (devicePatientDeviceDos.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                DevicePatientDevice deviceDO = devicePatientDeviceDos.get(0); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -158,10 +166,27 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                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 (null==lat||null==lon){//获取最新定位 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        String url = cloudCareUrl+"cloudCare/noLogin/device/getDeviceLastLocation"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        List<NameValuePair> params = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        params.add(new BasicNameValuePair("deviceSn", imei)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        String response = httpClientUtil.get(url, params,"UTF-8"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        JSONObject resObj = JSONObject.parseObject(response); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (resObj.getInteger("status")==200){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            lat = resObj.getJSONObject("data").getJSONObject("obj").getJSONObject("locationdata").getJSONObject("point").getDouble("lat"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            lon = resObj.getJSONObject("data").getJSONObject("obj").getJSONObject("locationdata").getJSONObject("point").getDouble("lon"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            address = resObj.getJSONObject("data").getJSONObject("obj").getJSONObject("locationdata").getString("address").replace(" ",""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            logDO.setSosAddress(address); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            logDO.setSosLat(lat+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            logDO.setSosLon(lon+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        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()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -620,6 +645,7 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setBedStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setBreath(breath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setHeartRate(heartrate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        sleepPlanDetailDao.save(planDetail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        outBedOrder(null, timeDate,devicePatientDeviceDos.get(0), patient, device, "超时未起床", JSON.toJSONStringWithDateFormat(planDetail, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        orderCreate = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -634,6 +660,7 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    if (timeDiffer>3600*siestaLongWarn*1000){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setSiestaStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setBedStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        sleepPlanDetailDao.save(planDetail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"超时未午睡",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        orderCreate=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -658,6 +685,7 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            planDetail.setSiestaTimeEnd(timeDate);//设置临时结束时间但不计算时长 避免重复发起工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            planDetail.setBreath(breath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            planDetail.setHeartRate(heartrate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            sleepPlanDetailDao.save(planDetail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"午睡超时未起床",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            orderCreate=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -698,6 +726,7 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setInStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setBedStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setSleepNightRecordList(nightRecord.findBySnPaTime(device,patient,dayTime)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        sleepPlanDetailDao.save(planDetail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"超时未上床晚休",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        orderCreate=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -716,6 +745,7 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        if (timeDiffer>3600*nightLongWarn*1000&&0==records.get(0).getStatus()){//超过2未回床小时 触发工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            planDetail.setSleepNightRecordList(nightRecord.findBySnPaTime(device,patient,dayTime)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            planDetail.setBedStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            sleepPlanDetailDao.save(planDetail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            outBedOrder(records.get(0),timeDate,devicePatientDeviceDos.get(0),patient,device,"起夜超时未回床",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            orderCreate=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -901,9 +931,52 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public static void main(String[] args) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String ss="123123,2323"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        System.out.println(String.join(",",ss)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //睡眠带心率呼吸数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Async 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void sleepHealthIndex(String device,String heartrate,String breath,String time_begin) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (devicePatientDeviceDos.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (StringUtils.isNotBlank(heartrate)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (!"0".equals(heartrate)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    DevicePatientDevice devicePatientDevice = devicePatientDeviceDos.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    BasePatientDO patientDO = patientDao.findById(devicePatientDevice.getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    DevicePatientHealthIndex patientHealthIndex = new DevicePatientHealthIndex(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setName(patientDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setDeviceSn(device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setUser(devicePatientDevice.getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setIdcard(devicePatientDevice.getUserIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setValue1(heartrate + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setType(5); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Date recordDate = DateUtil.strToDate(time_begin); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setRecordDate(recordDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setSortDate(recordDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    healthIndexDao.save(patientHealthIndex); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (StringUtils.isNotBlank(breath)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (!"0".equals(breath)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    DevicePatientDevice devicePatientDevice = devicePatientDeviceDos.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    BasePatientDO patientDO = patientDao.findById(devicePatientDevice.getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    DevicePatientHealthIndex patientHealthIndex = new DevicePatientHealthIndex(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setName(patientDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setDeviceSn(device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setUser(devicePatientDevice.getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setIdcard(devicePatientDevice.getUserIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setValue1(heartrate + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setType(7); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Date recordDate = DateUtil.strToDate(time_begin); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setRecordDate(recordDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setSortDate(recordDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    healthIndexDao.save(patientHealthIndex); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |