| 
					
				 | 
			
			
				@ -78,6 +78,10 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseSleepNightRecordDao nightRecord; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientOutBedDao outBedDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseSleepPlanDetailDao sleepPlanDetailDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseSleepPlanDao sleepPlanDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取爱牵挂管理员cookie 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -361,13 +365,9 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setRecordDate(recordDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setSortDate(recordDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (heartrate >= theshold_heartrate_h || heartrate <= theshold_heartrate_l) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        patientHealthIndex.setStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        patientHealthIndex.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    healthIndexDao.save(patientHealthIndex); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    SystemMessageDO messageDO = new SystemMessageDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String typeName = "您有新的心率测量记录。心率:" + patientHealthIndex.getValue1() + "次/min"; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -397,6 +397,9 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String content_notice = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    for (int i=0;i<errorIndex.size();i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        com.alibaba.fastjson.JSONObject tmp = errorIndex.getJSONObject(i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (0!=tmp.getInteger("error")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            patientHealthIndex.setStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (1 == tmp.getInteger("error")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            content_notice += tmp.getString("indexName")+"、"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -406,6 +409,7 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        message.put("content_notice","您的key1过高,请注意饮食,尽量食用少油少盐食物".replace("key1",content_notice)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        messageDO.setContent("您的key1过高,请注意饮食,尽量食用少油少盐食物".replace("key1",content_notice)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    healthIndexDao.save(patientHealthIndex); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDao.save(messageDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    imUtil.sendPatientSystemMessage(messageDO.getReceiver(),JSON.toJSONString(message,SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -445,14 +449,8 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setRecordDate(recordDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setSortDate(recordDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (sbp>=sbp_h||dbp<=dbp_l){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        patientHealthIndex.setStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        patientHealthIndex.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    patientHealthIndex.setDel("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    healthIndexDao.save(patientHealthIndex); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    SystemMessageDO messageDO = new SystemMessageDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String typeName = "您有新的血压测量记录:收缩压:"+patientHealthIndex.getValue1()+"mmHg,收缩压:" 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -481,6 +479,9 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String content_notice = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    for (int i=0;i<errorIndex.size();i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        com.alibaba.fastjson.JSONObject tmp = errorIndex.getJSONObject(i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (0!=tmp.getInteger("error")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            patientHealthIndex.setStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (1 == tmp.getInteger("error")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            content_notice += tmp.getString("indexName")+"、"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -490,6 +491,8 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        message.put("content_notice","您的key1过高,请注意饮食,尽量食用少油少盐食物".replace("key1",content_notice)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        messageDO.setContent("您的key1过高,请注意饮食,尽量食用少油少盐食物".replace("key1",content_notice)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    healthIndexDao.save(patientHealthIndex); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    systemMessageDao.save(messageDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    imUtil.sendPatientSystemMessage(messageDO.getReceiver(),JSON.toJSONString(message,SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -553,86 +556,201 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    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)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                boolean orderCreate=false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Integer upLongWarn=3; //起床预警时长 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Integer siestaLongWarn=5;//午睡预警时长 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Integer nightLongWarn=2;//起夜预警时长 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (devicePatientDeviceDos.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String patient = devicePatientDeviceDos.get(0).getUser(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //更新患者在床状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    updatePatientSleepStatus(device,patient,time_begin,bed_status); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatientAndDeviceSn(patient,device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    BaseSleepPlanDetail planDetail = new BaseSleepPlanDetail(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    BaseSleepPlan sleepPlan= null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (sleepPlans.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        sleepPlan = sleepPlans.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (null!=sleepPlan){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Date timeDate = DateUtil.strToDate(time_begin);//当前时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Date bedUp = DateUtil.strToDate(DateUtil.getStringDateShort()+" "+sleepPlan.getGetUpTime()+":00");// 起床时间 起床前一小时内算为起床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (timeDate.before(bedUp)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            bedUp = DateUtil.getNextDay1(bedUp,-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Date bedUpBegin = DateUtil.getNextMin(bedUp,-60);//起床时间 起床前一小时内算为起床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Date bedUpEnd = DateUtil.getNextMin(bedUp,60*3);//起床时间 起床后一小时内算为起床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        boolean needSiesta=false;// 是否有午睡习惯 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Date SiestaTime = null;// 午睡时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Date SiestaBegin = null;// 午睡开始时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (StringUtils.isNotBlank(sleepPlan.getNapTime())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            needSiesta=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            SiestaTime = DateUtil.strToDate(DateUtil.getStringDateShort()+" "+sleepPlan.getNapTime()+":00"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            SiestaBegin = DateUtil.getNextMin(SiestaTime,-60);// 午睡开始时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        String inTime = sleepPlan.getNightRestTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Date bedIn = null;// 入睡时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Date bedBegin = null;// 入睡开始时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        String dayTime = DateUtil.dateToStr(bedUp,DateUtil.YYYY_MM_DD);//监测日期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (inTime.charAt(0)=='0') { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            bedIn = DateUtil.strToDate(dayTime+" "+sleepPlan.getNightRestTime()+":00"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            bedIn = DateUtil.getNextDay1(bedIn,1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            bedIn = DateUtil.strToDate(dayTime+" "+sleepPlan.getNightRestTime()+":00"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        bedBegin = DateUtil.getNextMin(bedIn,-60*2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        List<BaseSleepPlanDetail> planDetails = sleepPlanDetailDao.findByDay(dayTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (planDetails.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            planDetail = planDetails.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        planDetail.setDay(dayTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        planDetail.setPatient(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        planDetail.setDeviceSn(device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        /***起床***/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Long timeDiffer = timeDate.getTime() - bedUp.getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if(DateUtil.isInArea(timeDate,bedUpBegin,bedUpEnd)){//起床时间内 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if ("0".equals(bed_status)){//起床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (null==planDetail.getUpStatus()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setUpStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setUpTime(timeDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        else if (3600*upLongWarn*1000<timeDiffer&&timeDiffer<(3600*upLongWarn+600)*1000){//距离起床超过三个小时还在床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if ("1".equals(bed_status)){//还在床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (1==planDetail.getUpStatus()){}//起床后再次入睡超时未起床不触发 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    if (null==planDetail.getUpStatus()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setUpStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setBedStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setBreath(breath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setHeartRate(heartrate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        outBedOrder(null,devicePatientDeviceDos.get(0),patient,device,"超时未起床",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        orderCreate=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    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(needSiesta&&DateUtil.isInArea(timeDate,SiestaBegin,bedIn)){//午睡时段 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if ("0".equals(bed_status)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (null==planDetail.getSiestaStatus()){//超时未午睡午睡 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    timeDiffer = timeDate.getTime() - SiestaTime.getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    if (timeDiffer>3600*siestaLongWarn*1000){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setSiestaStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setBedStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        outBedOrder(null,devicePatientDeviceDos.get(0),patient,device,"超时未午睡",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        orderCreate=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                else if(1 == planDetail.getSiestaStatus()&&null==planDetail.getSiestaTimeEnd()){//午睡起床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setSiestaTimeEnd(timeDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    timeDiffer = (planDetail.getSiestaTimeEnd().getTime()-planDetail.getSiestaTimeBegin().getTime())/1000; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setSiestaLong(timeDiffer+""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if ("1".equals(bed_status)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (null==planDetail.getSiestaStatus()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setSiestaStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setSiestaTimeBegin(timeDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                else if(1==planDetail.getSiestaStatus()&&null==planDetail.getSiestaTimeEnd()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    timeDiffer = timeDate.getTime() - planDetail.getSiestaTimeBegin().getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    if(3600*siestaLongWarn*1000<timeDiffer&&timeDiffer<(3600*siestaLongWarn+600)*1000){//午睡超时未起床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setBedStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setBreath(breath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setHeartRate(heartrate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        outBedOrder(null,devicePatientDeviceDos.get(0),patient,device,"午睡超时未起床",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        orderCreate=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ("1".equals(bed_status)){//呼吸 心率检测 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Integer theshold_breath_h = 25; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Integer theshold_breath_l = 8; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Integer theshold_heartrate_h = 100; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Integer theshold_heartrate_l = 50; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        /**晚休***/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        timeDiffer = timeDate.getTime() - bedBegin.getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (timeDiffer>0&&timeDate.after(bedBegin)){ //起夜记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            BaseSleepNightRecord record = new BaseSleepNightRecord(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if ("1".equals(bed_status)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (null==planDetail.getInStatus()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setInStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setInTimeBegin(timeDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                else if (1==planDetail.getInStatus()){//在床记录起夜时长 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if ("0".equals(bed_status)){//离床 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                List<BaseSleepNightRecord> records = nightRecord.findBySnStaPaTime(device,patient,0,bedIn); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if(null==planDetail.getInStatus()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    timeDiffer = timeDate.getTime() - bedIn.getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    if (timeDiffer>3600*nightLongWarn*1000){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setInStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setBedStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        planDetail.setSleepNightRecordList(records); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        outBedOrder(null,devicePatientDeviceDos.get(0),patient,device,"超时未上床晚休",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        orderCreate=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                else if (1==planDetail.getInStatus()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    if (records.size()==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        record.setPatient(devicePatientDeviceDos.get(0).getUser()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        record.setDeviceSn(device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        record.setStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        record.setDay(DateUtil.dateToStr(bedUp,DateUtil.YYYY_MM_DD)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        record.setCreateTime(timeDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        nightRecord.save(record); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    }else {//是否触发工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        record = records.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        timeDiffer = timeDate.getTime()-record.getCreateTime().getTime(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        if (timeDiffer>3600*nightLongWarn*1000){//超过2未回床小时 触发工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            planDetail.setSleepNightRecordList(records); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            planDetail.setBedStatus(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            outBedOrder(records.get(0),devicePatientDeviceDos.get(0),patient,device,"起夜超时未回床",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                            orderCreate=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        sleepPlanDetailDao.save(planDetail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //更新患者在床状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    updatePatientSleepStatus(device,patient,time_begin,bed_status); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (!orderCreate){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if ("1".equals(bed_status)){//呼吸 心率检测 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            Integer theshold_breath_h = 25; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            Integer theshold_breath_l = 8; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            Integer theshold_heartrate_h = 100; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            Integer theshold_heartrate_l = 50; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if (StringUtils.isNotBlank(breath)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                Integer breath1 = Integer.parseInt(breath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (breath1>theshold_breath_h||breath1<theshold_breath_l){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setBreath(breath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setHeartRate(heartrate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setBedStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    outBedOrder(null,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            if (StringUtils.isNotBlank(heartrate)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                Integer heartrate1 = Integer.parseInt(heartrate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                if (heartrate1>theshold_heartrate_h||theshold_heartrate_h<theshold_heartrate_l){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setBreath(breath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setHeartRate(heartrate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    planDetail.setBedStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    outBedOrder(null,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -643,7 +761,7 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void outBedOrder(BaseSleepNightRecord record,DevicePatientDevice patientDevice,String patient ,String device,String serverName)throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void outBedOrder(BaseSleepNightRecord record,DevicePatientDevice patientDevice,String patient ,String device,String serverName,String warnInfo)throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // //夜间十二点 起床半小时后未回床 触发安防工单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BasePatientDO patientDO = patientDao.findById(patient); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(null!=patientDO){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -677,6 +795,7 @@ public class DeviceService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("serveLon",lng); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("topicItem","preventOutOfBed"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("deviceSn",device); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObject.put("warnInfo",warnInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONObject jsonObjectParam = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    jsonObjectParam.put("order", jsonObject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    map.put("jsonData", jsonObjectParam.toJSONString()); 
			 |