Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

yeshijie 3 years ago
parent
commit
6e1d14898d

+ 6 - 5
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/config/AqgConfig.java

@ -36,8 +36,14 @@ public class AqgConfig {
     * 设置智能手环安全区域
     */
    public static final String S3fence_area = baseUrl +"/api/device/{0}/fences/{1}";
    public static final String X1fence_area = baseUrl +"/api/device/{0}/4g/fences/{1}";
    /**
     * X1定位数据  即轨迹
     */
    public static final String X1_locations = baseUrl+"/api/locationdata/";
    /**
     * 睡眠带 修改心率呼吸率报警阈值
     */
@ -48,11 +54,6 @@ public class AqgConfig {
     */
    public static final String  sleepDevice_info=baseUrl+"/api/sleepdevice/";
    /**
     * X1定位数据  即轨迹
     */
    public static final String X1_locations = baseUrl+"/api/locationdata/";
    public static final String username = "13559485270";
    public static final String password = "zjxl@2021";
    public static final String redisKey = "aqgCooker";

+ 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 ORDER BY a.day desc")
    Page<BaseSleepPlanDetail> findByListByPage(String patient, String begin, String end, Pageable pageRequest);
}

+ 17 - 3
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/device/PatientDeviceController.java

@ -1,5 +1,6 @@
package com.yihu.jw.care.endpoint.device;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.endpoint.BaseController;
@ -101,8 +102,8 @@ public class PatientDeviceController extends BaseController {
    public String saveDevice(@ApiParam(name = "json", value = "设备数据json", defaultValue = "{\"deviceId\": \"3\",\"deviceName\": \"血压计-优瑞恩\",\"deviceSn\": \"7052169111\",\"categoryCode\": \"1\",\"userType\": \"-1\"}")
                             @RequestParam(value = "json", required = true) String json,
                             @ApiParam(name = "sleepPlanJson", value = "睡眠计划json") @RequestParam(value = "sleepPlanJson", required = false) String sleepPlanJson,
                             @ApiParam(name = "iotDeviceSn", value = "iotDeviceSn") @RequestParam(value = "iotDeviceSn", required = false) String iotDeviceSn,
                             @ApiParam(name = "safeAreaGz", value = "safeAreaGz") @RequestParam(value = "safeAreaGz", required = false) String safeAreaGz){
                             @ApiParam(name = "iotDeviceSn", value = "对应的设备sn码") @RequestParam(value = "iotDeviceSn", required = false) String iotDeviceSn,
                             @ApiParam(name = "safeAreaGz", value = "智能拐杖时需要传围栏地址") @RequestParam(value = "safeAreaGz", required = false) String safeAreaGz){
        //{"deviceSn": "7052169111","getUpTime": "07:00","napTime": "13:00","nightRestTime": "21:30"})
        try {
            DevicePatientDevice device = objectMapper.readValue(json, DevicePatientDevice.class);
@ -338,6 +339,19 @@ public class PatientDeviceController extends BaseController {
        }
    }
    @ApiOperation("获取X1手表定位数据列表")
    @RequestMapping(value = "getX1Locations",method = RequestMethod.GET)
    public String getX1Locations(@ApiParam(name = "deviceSn",value = "设备sn码")
                                        @RequestParam(value = "deviceSn",required = true)String deviceSn,
                                        @ApiParam(name = "time_begin",value = "YYYYMMDD 定位日期")
                                        @RequestParam(value = "time_begin",required = false)String time_begin){
        try {
            return write(200,"获取成功","data",patientDeviceService.getX1Locations(deviceSn, time_begin));
        }catch (Exception e){
            return errorResult(e);
        }
    }
    @ApiOperation("获取睡眠带设备信息")
    @RequestMapping(value = "getSleepDeviceInfo",method = RequestMethod.GET)
    public String getSleepDeviceInfo(@ApiParam(name = "deviceSn",value = "睡眠带MAC 去除符号:")
@ -392,7 +406,7 @@ public class PatientDeviceController extends BaseController {
        try {
            JSONObject result = patientDeviceService.getPatientDeviceDetail(patient,deviceSn);
            if (result.getInt(ResponseContant.resultFlag)==ResponseContant.success){
                return write(200,"获取成功","data",result.getJSONObject(ResponseContant.resultMsg));
                return write(200,"获取成功","data", JSON.parseObject(result.getString(ResponseContant.resultMsg)));
            }else {
                return error(-1,result.getString(ResponseContant.resultMsg));
            }

+ 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")
                                          @RequestParam(value = "begin") String begin,
                                          @ApiParam(name="end",value = "endTime")
                                          @RequestParam(value = "end",required = false) 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);
        }
    }
}

+ 67 - 19
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/device/PatientDeviceService.java

@ -10,6 +10,7 @@ import com.yihu.jw.care.dao.device.DeviceDetailDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.service.assistance.EmergencyAssistanceService;
import com.yihu.jw.care.service.contacts.ContactsService;
import com.yihu.jw.care.service.security.SecurityMonitoringOrderService;
import com.yihu.jw.care.service.wechat.WeiXinAccessTokenUtils;
import com.yihu.jw.care.util.ConcealUtil;
import com.yihu.jw.care.util.MyJdbcTemplate;
@ -109,6 +110,8 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
    private HealthIndexUtil healthIndexUtil;
    @Autowired
    private EmergencyAssistanceService emergencyAssistanceService;
    @Autowired
    private SecurityMonitoringOrderService securityMonitoringOrderService;
    @PostConstruct
    public void init() {
@ -385,6 +388,10 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                "when category_code=7 then '报警器'\n" +
                "when category_code=12 then '监控器'\n" +
                "when category_code=13 then '睡眠带'\n" +
                "when category_code=14 then '可燃气体探测器'\n" +
                "when category_code=15 then '火灾探测报警器'\n" +
                "when category_code=16 then '智能拐杖'\n" +
                "when category_code=17 then '随身WiFi'\n" +
                "else '未知'\n" +
                "end as categoryName\n" +
                " from dm_device where del=1 GROUP BY category_code ";
@ -869,7 +876,7 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
     * @param deviceSn 设备sn码
     * @return
     */
    public JSONObject getPatientDeviceDetail(String patient,String deviceSn){
    public JSONObject getPatientDeviceDetail(String patient,String deviceSn) throws Exception {
        JSONObject result = new JSONObject();
        BasePatientDO patientDO = patientDao.findById(patient);
        if (null==patientDO){
@ -896,8 +903,45 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                if ("4".equals(device.getCategoryCode())||"7".equals(device.getCategoryCode())){
                    devInfo.put("sosContactsDOS",contactsService.getPatientSosContacts(patient));
                }
                com.alibaba.fastjson.JSONObject devInfoObj = JSON.parseObject(JSON.toJSONString(devInfo, SerializerFeature.WriteMapNullValue));
                switch (device.getCategoryCode()){
                    case "1"://血压设备
                        break;
                    case "2"://血糖设备
                        break;
                    case "4"://手表 围栏与轨迹
                        devInfoObj =  securityMonitoringOrderService.patientSignTopicInfo(devInfoObj,patient,"preventLost");
                        //轨迹动态
                        break;
                    case "7"://报警器 紧急工单
                        break;
                    case "12"://监控 视频地址
                        com.alibaba.fastjson.JSONObject tmp =ysDeviceService.getDeviceLiveAddress(patient,deviceSn,1,null);
                        devInfoObj.put("monitorInfoStatus",tmp.getIntValue(ResponseContant.resultFlag));
                        if (tmp.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
                            devInfoObj.put("monitorInfo",tmp.getString(ResponseContant.resultMsg));
                        }
                        else {
                            devInfoObj.put("monitorInfo",tmp.getJSONObject(ResponseContant.resultMsg));
                        }
                        break;
                    case "13"://睡眠带 获取当天睡眠详情
                        securityMonitoringOrderService.preventOutOfBed(devInfoObj,patient,false);
                        break;
                    case "14"://气感报警器 当天监测记录以及最新浓度
                        List<Map<String,Object>> listTmp = gasConcentration(patient,DateUtil.getStringDateShort());
                        devInfoObj.put("monitorInfo",listTmp);
                        devInfoObj.put("day",DateUtil.getStringDateShort());
                        securityMonitoringOrderService.preventGasLeakage(devInfoObj,patient,false);
                        break;
                    case "15"://烟感报警器 获取最新浓度
                        securityMonitoringOrderService.preventFire(devInfoObj,patient,false);
                        devInfoObj.put("day",DateUtil.getStringDateShort());
                        break;
                }
                result.put(ResponseContant.resultFlag,ResponseContant.success);
                result.put(ResponseContant.resultMsg,JSON.parseObject(JSON.toJSONString(devInfo, SerializerFeature.WriteMapNullValue)));
                result.put(ResponseContant.resultMsg,JSON.toJSONString(devInfoObj,SerializerFeature.WriteMapNullValue));
            }
        }
        return result;
@ -924,24 +968,8 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
                    case "2"://血糖设备
                        result = getHealthIndex(result,deviceSn,patient,page,pageSize);
                        break;
                    case "4"://手表 紧急工单与安防工单
                        result = getEmeWarn(result,deviceSn,patient,page,pageSize);
                        break;
                    case "7"://报警器 紧急工单
                        result = getEmeWarn(result,deviceSn,patient,page,pageSize);
                        break;
                    case "12"://监控
                        com.alibaba.fastjson.JSONObject tmp =ysDeviceService.getDeviceLiveAddress(patient,deviceSn,1,null);
                        result.put("monitorInfoStatus",tmp.getIntValue(ResponseContant.resultFlag));
                        if (tmp.getIntValue(ResponseContant.resultFlag) == ResponseContant.fail){
                            result.put("monitorInfo",tmp.getString(ResponseContant.resultMsg));
                        }
                        else {
                            result.put("monitorInfo",tmp.getJSONObject(ResponseContant.resultMsg));
                        }
                        break;
                    default://安防设备
                        result = null;
                        result  = getEmeWarn(result,deviceSn,patient,page,pageSize);
                        break;
                }
            }
@ -1156,6 +1184,26 @@ public class PatientDeviceService extends BaseJpaService<DevicePatientDevice, Pa
        return response.getBody();
    }
    /**
     *获取设备轨迹
     * @param deviceSn
     * @param time_begin YYYYMMDD 日期
     * @return
     */
    public com.alibaba.fastjson.JSONObject getX1Locations(String deviceSn,String time_begin){
        String url =AqgConfig.X1_locations;
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        param.add("device", deviceSn);
        param.add("depth", "1");
        param.add("rows_per_page", "300");
        if (StringUtils.isNotBlank(time_begin)){
            param.add("time_begin", time_begin);
        }
        HttpEntity<com.alibaba.fastjson.JSONObject> response = httpClientUtil.aqgCookieHttp(url, param, HttpMethod.GET, getCookie());
        return response.getBody();
    }
    public com.alibaba.fastjson.JSONObject getSleepDeviceInfo(String deviceSn){
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        param.add("mac", deviceSn);

+ 182 - 24
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){
@ -1211,18 +1230,51 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        JSONObject result = new JSONObject();
        result.put("location",null);
        result.put("fences",null);
        result.put("smoke",null);
        result.put("gasLeakage",null);
        result.put("fire",null);
        result.put("fall",null);
        result.put("sleep",null);
        result.put("deviceSn",null);
        result.put("monitorInfo",null);
        String sql = " select count(id) from base_security_monitoring_order where patient='"+patient+"' and topic_item='preventFall' and status="+SecurityMonitoringOrderDO.Status.apply.getType();
        Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
        if (count>0){
            result.put("fall",true);
        }
        else {
            result.put("fall",false);
        String sql = " select dict.code,count(ord.id) total from base_system_dict_entry dict LEFT JOIN base_security_monitoring_order ord " +
                " on dict.code = ord.topic_item COLLATE utf8_unicode_ci and ord.status="+SecurityMonitoringOrderDO.Status.apply.getType()+" where dict.dict_code='service_item' " +
                "and dict.remark='security'  GROUP BY dict.code ";
        List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql);
        for (Map<String,Object>tmp:sqlResult){
            switch (tmp.get("code").toString()){
                case "preventGasLeakage":
                   Integer count = Integer.parseInt(tmp.get("total").toString());
                    if (count>0){
                        result.put("gasLeakage",true);
                    }else {
                        result.put("gasLeakage",false);
                    }
                    break;
                case "preventFire":
                    count = Integer.parseInt(tmp.get("total").toString());
                    if (count>0){
                        result.put("fire",true);
                    }else {
                        result.put("fire",false);
                    }
                    break;
                case "preventFall":
                    count = Integer.parseInt(tmp.get("total").toString());
                    if (count>0){
                        result.put("fall",true);
                    }else {
                        result.put("fall",false);
                    }
                    break;
                case "preventOutOfBed":
                    count = Integer.parseInt(tmp.get("total").toString());
                    if (count>0){
                        result.put("sleep",true);
                    }else {
                        result.put("sleep",false);
                    }
                    break;
            }
        }
        result = patientSignTopicInfo(result,patient,topicItem);
        return result;
@ -1284,7 +1336,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        }
    }
    public void preventOutOfBed(JSONObject result,String patient){
    public void preventOutOfBed(JSONObject result,String patient,boolean video){
        List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByUserAndCategoryCode(patient,"13");
        if (devicePatientDeviceDos.size()==0){}
        else {
@ -1297,10 +1349,34 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
                    result.put("sleepStatus",true);
                    JSONObject tmp = objInfo.getJSONObject(0);
                    JSONObject sleepInfo = new JSONObject();
                    String dayTime = getSleepMonitoringDay(new Date(),patient);
                    List<BaseSleepPlanDetail> planDetails = sleepPlanDetailDao.findByPatientAndDay(patient,dayTime);
                    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);
                        sleepInfo.put("day",dayTime);
                    }
                    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"));
                    sleepInfo.put("breathrate",tmp.getString("breathrate"));
                    if(tmp.getBooleanValue("onbed")){
                        sleepInfo.put("bedStatus",1);
                    }else {
                        sleepInfo.put("bedStatus",0);
                    }
                    sleepInfo.put("heartRate",tmp.getString("heartrate"));
                    sleepInfo.put("breath",tmp.getString("breathrate"));
                    BasePatientOutBed outBed = outBedDao.findByPatientAndDeviceSnAndStatus(patient,deviceDo.getDeviceSn(),0);
                    if (null!=outBed){
                        String outBedTime = "";
@ -1326,10 +1402,12 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
                result.put("sleepInfo","获取睡眠带数据失败");
            }
        }
        monitorInfo(result, patient);
        if (video){
            monitorInfo(result, patient);
        }
    }
    public void preventFire(JSONObject result,String patient){
    public void preventFire(JSONObject result,String patient,boolean video){
        String sql = "SELECT r.value from wlyy_patient_device pd,base_device_health_index r " +
                "WHERE pd.device_sn = r.device_sn and pd.`user` = '"+patient+"' ";
        sql += " and pd.category_code='15' ORDER BY r.create_time desc LIMIT 1";
@ -1341,7 +1419,9 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
            result.put("smoke",list1.get(0).get("value"));
        }
        result.put("smokeOrderNum",getOrder(patient,"preventFire"));
        monitorInfo(result, patient);
        if (video){
            monitorInfo(result, patient);
        }
    }
    public Integer getOrder(String patient,String topicItem){
@ -1351,7 +1431,7 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
        return num;
    }
    public void preventGasLeakage(JSONObject result,String patient){
    public void preventGasLeakage(JSONObject result,String patient,boolean video){
        String sql = "SELECT r.value from wlyy_patient_device pd,base_device_health_index r " +
                "WHERE pd.device_sn = r.device_sn and pd.`user` = '"+patient+"' ";
        sql += " and pd.category_code='14' ORDER BY r.create_time desc LIMIT 1";
@ -1363,7 +1443,9 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
            result.put("methane",list1.get(0).get("value"));
        }
        result.put("methaneOrderNum",getOrder(patient,"preventGasLeakage"));
        monitorInfo(result, patient);
        if (video){
            monitorInfo(result, patient);
        }
    }
    public void monitorInfo(JSONObject result,String patient){
@ -1401,13 +1483,13 @@ public class SecurityMonitoringOrderService extends BaseJpaService<SecurityMonit
            monitorInfo(result, patient);
        }
        if ("preventOutOfBed".equals(topicItem)||StringUtils.isBlank(topicItem)){
            preventOutOfBed(result, patient);
            preventOutOfBed(result, patient,true);
        }
        if ("preventFire".equals(topicItem)||StringUtils.isBlank(topicItem)){
            preventFire(result, patient);
            preventFire(result, patient,true);
        }
        if ("preventGasLeakage".equals(topicItem)||StringUtils.isBlank(topicItem)){
            preventGasLeakage(result, patient);
            preventGasLeakage(result, patient,true);
        }
        return result;
    }
@ -1492,6 +1574,66 @@ 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 JSONObject getPatientSleepDetainList(String patient,String begin,String end,Integer page,Integer pageSize){
        page=page>0?page-1:0;
        PageRequest pageRequest = new PageRequest(page, pageSize);
        if (StringUtils.isBlank(end)){
            end = begin;
        }
        JSONArray array = new JSONArray();
        Page<BaseSleepPlanDetail> list = sleepPlanDetailDao.findByListByPage(patient,begin,end,pageRequest);
        List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatient(patient);
        BaseSleepPlan sleepPlan=null;
        if (sleepPlans.size()>0){
            sleepPlan = sleepPlans.get(0);
        }
        for (BaseSleepPlanDetail tmp:list){
            List<BaseSleepNightRecord> records = nightRecordDao.findByPatientAndDayOrderByCreateTimeDesc(patient,tmp.getDay());
            tmp.setSleepNightRecordList(records);
            String str = JSON.toJSONStringWithDateFormat(tmp, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue);
            JSONObject jsonObject = JSONObject.parseObject(str);
            if (null==sleepPlan){
                jsonObject.put("sleepPlan",false);
            }else {
                jsonObject.put("sleepPlan",true);
                String endTime = DateUtil.getNextMin(sleepPlan.getGetUpTime(),-1);
                jsonObject.put("getUpTime",sleepPlan.getGetUpTime());
                jsonObject.put("siestaTime",sleepPlan.getNapTime());
                jsonObject.put("nightRestTime",sleepPlan.getNightRestTime());
                jsonObject.put("nightRecordTime",sleepPlan.getNightRestTime()+"-隔日"+endTime);
                array.add(jsonObject);
            }
        }
        JSONObject result = (JSONObject) JSONObject.toJSON(list);
        result.put("content",array);
        return result;
    }
    /**
     *获取居民起夜记录
     */
    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范围类的随机数
@ -1506,4 +1648,20 @@ 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){
            BaseSleepPlan sleepPlan = sleepPlans.get(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-care/src/main/java/com/yihu/jw/care/service/sign/ArchiveService.java

@ -97,7 +97,7 @@ public class ArchiveService extends BaseJpaService<ArchiveDO, ArchiveDao> {
        }
        if (signStatus!=null&&signStatus==1){//已签约不按建档查询,只要该居民服务医生就在列表中
            filters+=" UNION " +
                    " SELECT a.create_time,p.openid,p.idcard,p.mobile,p.name,p.sex,p.id,p.photo,CAST(a.sign_status AS char) sign_status \n" +
                    " SELECT a.create_time,p.openid,p.pad_imei padImei,p.idcard,p.mobile,p.name,p.sex,p.id,p.photo,CAST(a.sign_status AS char) sign_status \n" +
                    "from wlyy_archive a,base_patient p WHERE  a.patient = p.id and a.sign_status = 1 and EXISTS( " +
                    "SELECT DISTINCT sr.patient from base_service_package_sign_record sr,base_service_package_record r, " +
                    "base_service_package_item i,base_team_member m " +

+ 2 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/statistics/DetectionPlatformService.java

@ -229,7 +229,8 @@ public class DetectionPlatformService  {
                String dataSql= "";
                List<Map<String , Object>> dataList = new ArrayList<>();
                switch (categoryCode) {
                    // 1=血糖仪  2=血压计  4=智能手表  13=智能床带/睡眠带  14=燃气报警器  15=烟雾报警器
                    // 1=血糖仪  2=血压计 14=燃气报警器  15=烟雾报警器
                    // 4=智能手表  7=居家安全报警器  16=智能拐杖  13=智能床带/睡眠带
                    case "1" :
                        dataSql = "SELECT record_date recordDate,value1,value2,value3,value4,value5,value6,value7,type FROM wlyy_patient_health_index WHERE device_sn = '"+deviceSn+"' AND del = 1 ORDER BY sort_date DESC LIMIT 10";
                        dataList = jdbcTemplate.queryForList(dataSql);

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

@ -18,6 +18,6 @@ public interface BaseSleepNightRecordDao extends PagingAndSortingRepository<Base
    @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);
    @Query(value = "select r from BaseSleepNightRecord r where r.deviceSn=?1 and r.patient=?2 and r.status=?3 and r.createTime>?4 and r.day=?5 order by r.createTime desc")
    List<BaseSleepNightRecord> findBySnStaPaTime(String deviceSn,String patient,Integer status, Date benIn,String day);
}

+ 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);
}

+ 1 - 1
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/DeviceController.java

@ -136,7 +136,7 @@ public class DeviceController {
                deviceDetail.setDeviceModel(deviceModel);
                deviceDetail.setDeviceCode(deviceCode);
                deviceDetail.setSim(sim);
                deviceDetail.setBindingCount("");
                deviceDetail.setBindingCount("0");
                deviceDetail.setDeviceType(Integer.parseInt(deviceType));
                correctLs.add(deviceDetail);
            }

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

@ -562,6 +562,7 @@ public class DeviceService {
                Integer nightLongWarn=2;//起夜预警时长
                List<DevicePatientDevice> devicePatientDeviceDos = patientDeviceDao.findByDeviceSn(device);
                if (devicePatientDeviceDos.size()>0){
                    Date timeDate = DateUtil.strToDate(time_begin);//当前时间
                    String patient = devicePatientDeviceDos.get(0).getUser();
                    List<BaseSleepPlan> sleepPlans = sleepPlanDao.findByPatientAndDeviceSn(patient,device);
                    BaseSleepPlanDetail planDetail = new BaseSleepPlanDetail();
@ -570,9 +571,8 @@ public class DeviceService {
                        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)){
                        Date bedUp = DateUtil.strToDate(DateUtil.dateToStrShort(timeDate)+" "+sleepPlan.getGetUpTime()+":00");// 起床时间 起床前一小时内算为起床
                        if (timeDate.before(bedUp)&&bedUp.getTime()-timeDate.getTime()>1000*1*3600){
                            bedUp = DateUtil.getNextDay1(bedUp,-1);
                        }
                        Date bedUpBegin = DateUtil.getNextMin(bedUp,-60);//起床时间 起床前一小时内算为起床
@ -582,21 +582,22 @@ public class DeviceService {
                        Date SiestaBegin = null;// 午睡开始时间
                        if (StringUtils.isNotBlank(sleepPlan.getNapTime())){
                            needSiesta=true;
                            SiestaTime = DateUtil.strToDate(DateUtil.getStringDateShort()+" "+sleepPlan.getNapTime()+":00");
                            SiestaTime = DateUtil.strToDate(DateUtil.dateToStrShort(timeDate)+" "+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') {
                        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, timeDate,devicePatientDeviceDos.get(0), patient, device, "超时未起床", JSON.toJSONStringWithDateFormat(planDetail, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteMapNullValue));
                                    orderCreate = true;
                                }
                            }
                        }
@ -636,7 +634,7 @@ public class DeviceService {
                                    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));
                                        outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"超时未午睡",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
                                        orderCreate=true;
                                    }
                                }
@ -658,7 +656,7 @@ public class DeviceService {
                                        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));
                                        outBedOrder(null,timeDate,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,dayTime);
                                    if (records.size()>0){//
                                        record = records.get(0);
                                        record.setStatus(1);
@ -687,14 +685,14 @@ 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,dayTime);
                                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));
                                        outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"超时未上床晚休",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
                                        orderCreate=true;
                                    }
                                }
@ -712,7 +710,7 @@ public class DeviceService {
                                        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));
                                            outBedOrder(records.get(0),timeDate,devicePatientDeviceDos.get(0),patient,device,"起夜超时未回床",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
                                            orderCreate=true;
                                        }
                                    }
@ -735,7 +733,7 @@ public class DeviceService {
                                    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));
                                    outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
                                    return null;
                                }
                            }
@ -745,7 +743,7 @@ public class DeviceService {
                                    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));
                                    outBedOrder(null,timeDate,devicePatientDeviceDos.get(0),patient,device,"心率和呼吸频率异常",JSON.toJSONStringWithDateFormat(planDetail,"yyyy-MM-dd HH:mm:ss",SerializerFeature.WriteMapNullValue));
                                    return null;
                                }
                            }
@ -761,7 +759,7 @@ public class DeviceService {
        return null;
    }
    public void outBedOrder(BaseSleepNightRecord record,DevicePatientDevice patientDevice,String patient ,String device,String serverName,String warnInfo)throws Exception{
    public void outBedOrder(BaseSleepNightRecord record,Date time_date,DevicePatientDevice patientDevice,String patient ,String device,String serverName,String warnInfo)throws Exception{
        // //夜间十二点 起床半小时后未回床 触发安防工单
            BasePatientDO patientDO = patientDao.findById(patient);
            if(null!=patientDO){
@ -812,6 +810,9 @@ public class DeviceService {
            }
            if (null!=record){
                record.setStatus(-1);
                record.setUpdateTime(time_date);
                Long timeDiffer = (time_date.getTime() - record.getCreateTime().getTime())/1000;
                record.setOutTime(timeDiffer+"");
                nightRecord.save(record);
            }
    }