Browse Source

代码修改

liubing 3 years ago
parent
commit
b206fa0f94

+ 25 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/device/BaseSleepNightRecordDao.java

@ -0,0 +1,25 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.BaseSleepNightRecord;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
/**
 * Created by Bing on 2021/8/17.
 */
public interface BaseSleepNightRecordDao extends PagingAndSortingRepository<BaseSleepNightRecord,Long>,
        JpaSpecificationExecutor<BaseSleepNightRecord> {
    @Query(value = "select r from BaseSleepNightRecord r where r.deviceSn=?1 and r.patient=?2 order by r.createTime desc")
    List<BaseSleepNightRecord> findByDeviceSnAndPatient(String deviceSn, String patient);
    @Query(value = "select r from BaseSleepNightRecord r where r.deviceSn=?1 and r.patient=?2 and r.status=?3 and r.createTime>?4 order by r.createTime desc")
    List<BaseSleepNightRecord> findBySnStaPaTime(String deviceSn,String patient,Integer status, Date benIn);
    List<BaseSleepNightRecord> findByPatientAndDayOrderByCreateTimeDesc(String patient,String day);
}

+ 5 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/device/BaseSleepPlanDao.java

@ -5,6 +5,9 @@ import com.yihu.jw.entity.care.device.BaseSleepPlan;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.awt.print.Pageable;
import java.util.List;
/***
 * @ClassName: BaseSleepPlanDao
 * @Description:
@ -13,4 +16,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 */
public interface BaseSleepPlanDao extends PagingAndSortingRepository<BaseSleepPlan,Long>,
        JpaSpecificationExecutor<BaseSleepPlan> {
    List<BaseSleepPlan> findByPatient(String patient);
}

+ 24 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/device/BaseSleepPlanDetailDao.java

@ -0,0 +1,24 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.BaseSleepPlanDetail;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;
/**
 * Created by Bing on 2021/8/23.
 */
public interface BaseSleepPlanDetailDao extends PagingAndSortingRepository<BaseSleepPlanDetail,Long>,
        JpaSpecificationExecutor<BaseSleepPlanDetail> {
    List<BaseSleepPlanDetail> findByPatientAndDay(String patient, String day);
    @Query("SELECT a FROM BaseSleepPlanDetail a WHERE a.patient = ?1 AND a.day>=?2 and a.day<=?3")
    Page<BaseSleepPlanDetail> findByListByPage(String patient, String begin, String end, Pageable pageRequest);
}

+ 44 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/security/SecurityMonitoringOrderEndpoint.java

@ -411,4 +411,48 @@ public class SecurityMonitoringOrderEndpoint extends EnvelopRestEndpoint {
            return failedObjEnvelopException2(e);
        }
    }
    @GetMapping(value = "getPatientSleepPlan")
    @ApiOperation(value = "获取居民睡眠计划")
    public ObjEnvelop getPatientSleepPlan(@ApiParam(name="patient",value = "patient")
                                           @RequestParam(value = "patient") String patient){
        try {
            return ObjEnvelop.getSuccess("获取成功",securityMonitoringOrderService.getPatientSleepPlan(patient));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @GetMapping(value = "getPatientSleepDetainList")
    @ApiOperation(value = "获取居民睡眠监护列表")
    public ObjEnvelop getPatientSleepDetainList(@ApiParam(name="patient",value = "patient")
                                          @RequestParam(value = "patient") String patient,
                                          @ApiParam(name="begin",value = "beginTime yyyy-MM-dd hh:mm:ss")
                                          @RequestParam(value = "begin") String begin,
                                          @ApiParam(name="end",value = "endTime")
                                          @RequestParam(value = "end") String end,
                                          @ApiParam(name="page",value = "page")
                                          @RequestParam(value = "page",defaultValue = "0") Integer page,
                                          @ApiParam(name="pageSize",value = "pageSize")
                                          @RequestParam(value = "pageSize",defaultValue = "1") Integer pageSize){
        try {
            return ObjEnvelop.getSuccess("查询成功",securityMonitoringOrderService.getPatientSleepDetainList(patient,begin,end,page,pageSize)) ;
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @GetMapping(value = "getPatientSleepNightRecord")
    @ApiOperation(value = "获取居民起夜记录")
    public ListEnvelop getPatientSleepPlan(@ApiParam(name="patient",value = "patient")
                                          @RequestParam(value = "patient") String patient,
                                          @ApiParam(name="day",value = "监护日期 yyyy-MM-dd")
                                          @RequestParam(value = "day") String day){
        try {
            return ListEnvelop.getSuccess("获取成功",securityMonitoringOrderService.getPatientSleepNightRecord(patient,day));
        }catch (Exception e){
            return failedListEnvelopException2(e);
        }
    }
}

+ 95 - 4
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/security/SecurityMonitoringOrderService.java

@ -5,8 +5,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.care.dao.device.BasePatientOutBedDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.device.*;
import com.yihu.jw.care.dao.security.*;
import com.yihu.jw.care.dao.team.BaseTeamMemberDao;
import com.yihu.jw.care.service.common.DictService;
@ -26,8 +25,7 @@ import com.yihu.jw.entity.base.im.ConsultDo;
import com.yihu.jw.entity.base.im.ConsultTeamDo;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
import com.yihu.jw.entity.care.device.BasePatientOutBed;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.*;
import com.yihu.jw.entity.care.securitymonitoring.*;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
@ -47,6 +45,8 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -117,6 +117,12 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
    private ObjectMapper objectMapper;
    @Autowired
    private BasePatientOutBedDao outBedDao;
    @Autowired
    private BaseSleepPlanDao sleepPlanDao;
    @Autowired
    private BaseSleepPlanDetailDao sleepPlanDetailDao;
    @Autowired
    private BaseSleepNightRecordDao nightRecordDao;
    private Logger logger = LoggerFactory.getLogger(SecurityMonitoringOrderService.class);
@ -351,6 +357,19 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        if (5==orderDO.getOrderSource()){//睡眠带工单
            try {
                JSONObject monitorInfo = JSONObject.parseObject(orderDO.getWarnInfo());
                List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatient(patientDO.getId());
                if (sleepPlans.size()>0){
                    BaseSleepPlan sleepPlan = sleepPlans.get(0);
                    String endTime = DateUtil.getNextMin(sleepPlan.getGetUpTime(),-1);
                    monitorInfo.put("sleepPlan",true);
                    monitorInfo.put("getUpTime",sleepPlan.getGetUpTime());
                    monitorInfo.put("siestaTime",sleepPlan.getNapTime());
                    monitorInfo.put("nightRestTime",sleepPlan.getNightRestTime());
                    monitorInfo.put("nightRecordTime",sleepPlan.getNightRestTime()+"-隔日"+endTime);
                }else {
                    monitorInfo.put("sleepPlan",false);
                }
                monitorInfo = patientSignTopicInfo(monitorInfo,orderDO.getPatient(),"preventFall");
                emergencyOrderVO.setInformation(monitorInfo);
            }catch (Exception e){
@ -1297,6 +1316,25 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
                    result.put("sleepStatus",true);
                    JSONObject tmp = objInfo.getJSONObject(0);
                    JSONObject sleepInfo = new JSONObject();
                    List<BaseSleepPlanDetail> planDetails = sleepPlanDetailDao.findByPatientAndDay(patient,getSleepMonitoringDay(new Date(),patient));
                    if (planDetails.size()>0){
                        BaseSleepPlanDetail planDetail =  planDetails.get(0);
                        String jsonStr = JSON.toJSONStringWithDateFormat(planDetail, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue);
                        sleepInfo = JSONObject.parseObject(jsonStr);
                    }
                    List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatient(patient);
                    if (sleepPlans.size()>0){
                        BaseSleepPlan sleepPlan = sleepPlans.get(0);
                        String endTime = DateUtil.getNextMin(sleepPlan.getGetUpTime(),-1);
                        sleepInfo.put("sleepPlan",true);
                        sleepInfo.put("getUpTime",sleepPlan.getGetUpTime());
                        sleepInfo.put("siestaTime",sleepPlan.getNapTime());
                        sleepInfo.put("nightRestTime",sleepPlan.getNightRestTime());
                        sleepInfo.put("nightRecordTime",sleepPlan.getNightRestTime()+"-隔日"+endTime);
                    }else {
                        sleepInfo.put("sleepPlan",false);
                    }
                    sleepInfo.put("online",tmp.getBooleanValue("online"));
                    sleepInfo.put("onbed",tmp.getBooleanValue("onbed"));
                    sleepInfo.put("heartrate",tmp.getString("heartrate"));
@ -1476,6 +1514,44 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        return result;
    }
    /**
     *获取居民睡眠计划
     */
    public BaseSleepPlan getPatientSleepPlan(String patient){
        List<BaseSleepPlan> list = sleepPlanDao.findByPatient(patient);
        if (list.size()>0){
            return list.get(0);
        }else {
            return null;
        }
    }
    /**
     *获取居民睡眠监护列表
     */
    public Page<BaseSleepPlanDetail> getPatientSleepDetainList(String patient,String begin,String end,Integer page,Integer pageSize){
        page=page>0?page-1:0;
        PageRequest pageRequest = new PageRequest(page, pageSize);
        begin = begin.substring(0,begin.indexOf(" "));
        end = end.substring(0,end.indexOf(" "));
        Page<BaseSleepPlanDetail> list = sleepPlanDetailDao.findByListByPage(patient,begin,end,pageRequest);
        for (BaseSleepPlanDetail tmp:list){
            List<BaseSleepNightRecord> records = nightRecordDao.findByPatientAndDayOrderByCreateTimeDesc(patient,tmp.getDay());
            tmp.setSleepNightRecordList(records);
        }
        return list;
    }
    /**
     *获取居民起夜记录
     */
    public List<BaseSleepNightRecord> getPatientSleepNightRecord(String patient, String day){
        List<BaseSleepNightRecord> records = nightRecordDao.findByPatientAndDayOrderByCreateTimeDesc(patient,day);
        return records;
    }
    private String getRandomIntStr(){
        Random rand = new Random();
        int i = rand.nextInt(); //int范围类的随机数
@ -1490,4 +1566,19 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        one.setUpdateUserName(one.getDoctorName());
    }
    private String getSleepMonitoringDay(Date date,String patient){
        List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatient(patient);
        if (sleepPlans.size()>0){
            String bedUpStr = sleepPlans.get(0).getGetUpTime();
            Date bedUp = DateUtil.strToDate(DateUtil.getStringDateShort()+" "+bedUpStr+":00");// 起床时间 起床前一小时内算为起床
            if (date.before(bedUp)&&bedUp.getTime()-date.getTime()>1000*1*3600){
                bedUp = DateUtil.getNextDay1(bedUp,-1);
            }
            String dayTime = DateUtil.dateToStr(bedUp,DateUtil.YYYY_MM_DD);//监测日期
            return dayTime;
        }else {
            return null;
        }
    }
}

+ 1 - 1
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/dao/device/BaseSleepPlanDetailDao.java

@ -12,5 +12,5 @@ import java.util.List;
public interface BaseSleepPlanDetailDao extends PagingAndSortingRepository<BaseSleepPlanDetail,Long>,
        JpaSpecificationExecutor<BaseSleepPlanDetail> {
    List<BaseSleepPlanDetail> findByDay(String day);
    List<BaseSleepPlanDetail> findByPatientAndDay(String patient, String day);
}

+ 14 - 16
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceService.java

@ -572,7 +572,7 @@ public class DeviceService {
                    if (null!=sleepPlan){
                        Date timeDate = DateUtil.strToDate(time_begin);//当前时间
                        Date bedUp = DateUtil.strToDate(DateUtil.getStringDateShort()+" "+sleepPlan.getGetUpTime()+":00");// 起床时间 起床前一小时内算为起床
                        if (timeDate.before(bedUp)){
                        if (timeDate.before(bedUp)&&bedUp.getTime()-timeDate.getTime()>1000*1*3600){
                            bedUp = DateUtil.getNextDay1(bedUp,-1);
                        }
                        Date bedUpBegin = DateUtil.getNextMin(bedUp,-60);//起床时间 起床前一小时内算为起床
@ -589,14 +589,15 @@ public class DeviceService {
                        Date bedIn = null;// 入睡时间
                        Date bedBegin = null;// 入睡开始时间
                        String dayTime = DateUtil.dateToStr(bedUp,DateUtil.YYYY_MM_DD);//监测日期
                        if (inTime.charAt(0)=='0') {
                        if (inTime.charAt(0)=='0'&&inTime.charAt(1)!='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);
                        List<BaseSleepPlanDetail> planDetails = sleepPlanDetailDao.findByPatientAndDay(patient,dayTime);
                        if (planDetails.size()>0){
                            planDetail = planDetails.get(0);
                        }
@ -613,18 +614,15 @@ public class DeviceService {
                                }
                            }
                        }
                        else if (3600*upLongWarn*1000<timeDiffer&&timeDiffer<(3600*upLongWarn+600)*1000){//距离起床超过三个小时还在床
                        else if (3600*upLongWarn*1000<timeDiffer){//距离起床超过三个小时还在床
                            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;
                                    }
                                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;
                                }
                            }
                        }
@ -674,7 +672,7 @@ public class DeviceService {
                                    planDetail.setInTimeBegin(timeDate);
                                }
                                else if (1==planDetail.getInStatus()){//在床记录起夜时长
                                    List<BaseSleepNightRecord> records = nightRecord.findBySnStaPaTime(device,patient,0,bedIn);
                                    List<BaseSleepNightRecord> records = nightRecord.findBySnStaPaTime(device,patient,0,bedBegin);
                                    if (records.size()>0){//
                                        record = records.get(0);
                                        record.setStatus(1);
@ -687,7 +685,7 @@ public class DeviceService {
                                }
                            }
                            if ("0".equals(bed_status)){//离床
                                List<BaseSleepNightRecord> records = nightRecord.findBySnStaPaTime(device,patient,0,bedIn);
                                List<BaseSleepNightRecord> records = nightRecord.findBySnStaPaTime(device,patient,0,bedBegin);
                                if(null==planDetail.getInStatus()){
                                    timeDiffer = timeDate.getTime() - bedIn.getTime();
                                    if (timeDiffer>3600*nightLongWarn*1000){