فهرست منبع

Merge branch 'dev' of liubing/wlyy2.0 into dev

liubing 3 سال پیش
والد
کامیت
4331ae95b0

+ 2 - 1
business/base-service/src/main/java/com/yihu/jw/hospital/message/dao/SystemMessageDao.java

@ -52,6 +52,7 @@ public interface SystemMessageDao extends PagingAndSortingRepository<SystemMessa
    @Modifying
    void setMessageOverByType(String doctor, Integer type, Date start, Date end);
    @Query("select a from SystemMessageDO a where a.receiver=?1 and a.type=?2 and  a.del='1'")
    List<SystemMessageDO> getByReceiverAndType(String doctor,String type);
}

+ 1 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/hospital/message/SystemMessageDO.java

@ -21,6 +21,7 @@ public class SystemMessageDO extends UuidIdentityEntity {
     *消息类型 上门服务400开头,生活照料500开头 ,安防监控600开头, 上门辅导700开头,紧急救助800开头
     * 人文关怀系统消息 41
     * 体征设备测量系统消息 42
     * 设备离线系统消息 43
     * 家属紧急预警系统消息 50
     * 新生儿在线咨询 850
     * 老人在线咨询 851

+ 41 - 1
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/message/DoctorMessageEndpoint.java

@ -2,7 +2,9 @@ package com.yihu.jw.care.endpoint.message;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.service.message.DoctorMessageService;
import com.yihu.jw.care.service.message.PatientMessageService;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
@ -21,10 +23,12 @@ import org.springframework.web.bind.annotation.*;
public class DoctorMessageEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private DoctorMessageService doctorMessageService;
    @Autowired
    private PatientMessageService patientMessageService;
    @GetMapping(value = "messages")
    @ApiOperation("应用消息")
    public ObjEnvelop messages(@ApiParam(name = "type", value = "消息类型 10床位申请,11安全监护,12紧急救助,13体征异常消息")
    public ObjEnvelop messages(@ApiParam(name = "type", value = "消息类型 10床位申请,11安全监护,12紧急救助,13体征异常消息,14设备离线通知")
                               @RequestParam(value = "type", required = false) String type,
                               @ApiParam(name = "doctor", value = "doctor")
                               @RequestParam(value = "doctor", required = false) String doctor){
@ -84,4 +88,40 @@ public class DoctorMessageEndpoint extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value = "getDeviceLostMessageList")
    @ApiOperation("获取设备离线通知列表")
    public ObjEnvelop getDeviceLostMessageList(@ApiParam(name="doctor",value = "医生ID,当前查看列表医生",required = true)
                                          @RequestParam(value = "doctor")String doctor){
        try {
            return ObjEnvelop.getSuccess("查询成功",doctorMessageService.getDeviceLostMessageList(doctor));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @PostMapping(value = "/updateMessageRead")
    @ApiOperation("已读消息")
    public Envelop updateMessageRead(@ApiParam(name = "messageId",required = true)
                                     @RequestParam(value = "messageId")String messageId){
        try {
            patientMessageService.updateMessageRead(messageId);
            return Envelop.getSuccess("修改成功");
        }catch (Exception e){
            return failedException2(e);
        }
    }
    @PostMapping(value = "/delMessageRead")
    @ApiOperation("删除消息")
    public Envelop delMessageRead(@ApiParam(name = "messageId",required = true)
                                     @RequestParam(value = "messageId")String messageId){
        try {
            patientMessageService.delMessageRead(messageId);
            return Envelop.getSuccess("修改成功");
        }catch (Exception e){
            return failedException2(e);
        }
    }
}

+ 18 - 2
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/message/DoctorMessageService.java

@ -13,6 +13,8 @@ import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.entity.base.notice.UserNoticeDO;
import com.yihu.jw.entity.care.message.OrgNoticeDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.util.date.DateUtil;
@ -43,11 +45,13 @@ public class DoctorMessageService {
    private OrgNoticeDao orgNoticeDao;
    @Autowired
    private UserNoticeDao userNoticeDao;
    @Autowired
    private SystemMessageDao messageDao;
    /**
     *
     * @param doctor
     * @param type  11床位申请,11安全监护 ,12紧急救助,13体征异常消息
     * @param type  11床位申请,11安全监护 ,12紧急救助,13体征异常消息,14设备离线通知
     * @return
     */
    public JSONObject findDoctorAllMessage(String doctor,String type){
@ -57,7 +61,7 @@ public class DoctorMessageService {
        BaseDoctorDO doctorDO = baseDoctorDao.findById(doctor);
        if (doctorDO==null){
            result.put(ResponseContant.resultFlag, ResponseContant.fail);
            result.put(ResponseContant.resultMsg,"患者今年已做过能力评估报告,不可重复操作");
            result.put(ResponseContant.resultMsg,"用户不存在");
        }
        List<BaseDoctorHospitalDO> hospitalDO = baseDoctorHospitalDao.findDistinctOrgByDoctorCode(doctor);
        Integer count;
@ -142,6 +146,13 @@ public class DoctorMessageService {
            tmpObj = jdbcTemplate.queryForMap(sql);
            result.put("errorHealthIndex",tmpObj);
        }
        if (typeNull||type.equals("14")){//设备离线通知
            String sql = " select count(1) as 'all',type,DATE_FORMAT(create_time,'%Y-%m-%d %H:%i:%S') create_time from base_system_message " +
                    " where type='43' and del=1 and receiver='"+doctor+"' order by create_time desc ";
            Map<String,Object> tmpObj = new HashMap<>();
            tmpObj = jdbcTemplate.queryForMap(sql);
            result.put("deviceLost",tmpObj);
        }
        return result;
    }
@ -301,4 +312,9 @@ public class DoctorMessageService {
        return orgNoticeDao.findOne(noticeId);
    }
    public List<SystemMessageDO> getDeviceLostMessageList(String doctor){
        List<SystemMessageDO> systemMessageDOS = messageDao.getByReceiverAndType(doctor,"43");
        return systemMessageDOS;
    }
}

+ 8 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/message/PatientMessageService.java

@ -147,4 +147,12 @@ public class PatientMessageService {
            }
        }
    }
    public void delMessageRead(String msgId){
        SystemMessageDO systemMessageDO = systemMessageDao.findOne(msgId);
        if (systemMessageDO!=null){
            systemMessageDO.setDel("0");
            systemMessageDao.save(systemMessageDO);
        }
    }
}

+ 10 - 10
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/statistics/StatisticsService.java

@ -408,7 +408,7 @@ public class StatisticsService {
        }
        String sql1 = "SELECT COUNT(*) c,archive_type*1 as archive_type,IFNULL(on_line,0) online from base_patient WHERE archive_type is  not null" +
                " and del='1' "+pateintFilter+" GROUP BY archive_type";
                " and del='1' "+pateintFilter+" GROUP BY archive_type,on_line";
        List<Map<String,Object>> list1 = jdbcTemplate.queryForList(sql1);
        for(Map<String,Object> map:list1){
            String archive_type = map.get("archive_type").toString();
@ -416,17 +416,17 @@ public class StatisticsService {
            Integer online = Integer.valueOf(map.get("online").toString());
            if("1".equals(archive_type)){
                if(online == 1){
                    olderOn = num;
                    olderOn += num;
                }else{
                    olderOff = num;
                    olderOff += num;
                }
                continue;
            }
            if("2".equals(archive_type)){
                if(online == 1){
                    childOn = num;
                    childOn += num;
                }else{
                    childOff = num;
                    childOff += num;
                }
            }
        }
@ -437,7 +437,7 @@ public class StatisticsService {
        String sql2 = "SELECT COUNT(a.id) c,a.doctor_level,IFNULL(a.on_line,0) online from base_doctor a,base_doctor_hospital h where a.id=h.doctor_code and a.del = '1' and h.del = '1' " +
                "and a.doctor_level is not null and h.org_code not in ( " +
                "SELECT dict_code from wlyy_hospital_sys_dict WHERE dict_name = 'jkzl_org'  " +
                ") GROUP BY a.doctor_level";
                ") GROUP BY a.doctor_level,on_line";
        List<Map<String,Object>> list2 = jdbcTemplate.queryForList(sql2);
        for(Map<String,Object> map:list2){
            String archive_type = map.get("doctor_level").toString();
@ -445,17 +445,17 @@ public class StatisticsService {
            Integer online = Integer.valueOf(map.get("online").toString());
            if("2".equals(archive_type)){
                if(online == 1){
                    helperOn = num;
                    helperOn += num;
                }else{
                    helperOff = num;
                    helperOff += num;
                }
                continue;
            }
            if("3".equals(archive_type)){
                if(online == 1){
                    teacherOn = num;
                    teacherOn += num;
                }else{
                    teacherOff = num;
                    teacherOff += num;
                }
            }
        }

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

@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.yihu.jw.care.config.AqgConfig;
import com.yihu.jw.care.dao.device.*;
import com.yihu.jw.care.util.DeviceLostMessageUtil;
import com.yihu.jw.care.util.SecurityOrderUtil;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.*;
@ -87,6 +88,10 @@ public class DeviceService {
    private BaseSleepPlanDao sleepPlanDao;
    @Autowired
    private SecurityOrderUtil orderUtil;
    @Autowired
    private DeviceLostMessageUtil deviceLostMessageUtil;
    @Autowired
    private DeviceDetailDao deviceDetailDao;
    /**
     * 获取爱牵挂管理员cookie
@ -879,6 +884,16 @@ public class DeviceService {
                    patientDeviceDao.save(tmp);
                }
            }
            DeviceDetail deviceDetail = deviceDetailDao.findBySn(device);
            if(deviceDetail!=null){
                deviceDetail.setContactStatus(Integer.parseInt(onlinestatu));
                if ("0".equals(onlinestatu)){
                    List<String> sns = new ArrayList<>();
                    sns.add(device);
                    deviceLostMessageUtil.deviceLostMessage(sns);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();

+ 1 - 1
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/DeviceUploadService.java

@ -93,7 +93,6 @@ public class DeviceUploadService {
            String userType = map.get("button").toString();//按键号 即 userType
            String measurementType=null==map.get("measurementType")?"":map.get("measurementType").toString(); //单个设备的测量类型,deviceType=4智能手表:1心率,2血压
            String paraString = JSON.toJSONString(request.getParameterMap());
            dataPushLogUtil.savePushLog(deviceSn,paraString,"体征数据接收");
            JSONObject json = new JSONObject();
            json.put("deviceSn", deviceSn);
@ -136,6 +135,7 @@ public class DeviceUploadService {
                logger.info("This device is not relate patient!:====="+dataJson);
                throw new Exception("This device is not relate patient!");
            }
            dataPushLogUtil.savePushLog(deviceSn,paraString,"体征数据接收");
            //保存消息
            BasePatientDO patientDO = patientDao.findById(result.getUser());
            if (null != patientDO){

+ 8 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/HvDeviceService.java

@ -10,6 +10,7 @@ import com.yihu.jw.care.dao.device.HvDeviceRecordDao;
import com.yihu.jw.care.dao.device.HvDeviceSosLogDao;
import com.yihu.jw.care.util.ArtemisPostTest;
import com.yihu.jw.care.util.DeviceDataPushLogUtil;
import com.yihu.jw.care.util.DeviceLostMessageUtil;
import com.yihu.jw.care.util.SecurityOrderUtil;
import com.yihu.jw.entity.care.device.DeviceDetail;
import com.yihu.jw.entity.care.device.DeviceHealthIndex;
@ -49,6 +50,8 @@ public class HvDeviceService {
    private DeviceDetailDao deviceDetailDao;
    @Autowired
    private DeviceDataPushLogUtil dataPushLogUtil;
    @Autowired
    private DeviceLostMessageUtil deviceLostMessageUtil;
    /**
     * 消息通知接收
@ -196,6 +199,11 @@ public class HvDeviceService {
        DeviceDetail deviceDetail = deviceDetailDao.findBySn(sn);
        if(deviceDetail!=null){
            deviceDetail.setContactStatus(status);
            if(0==status){
               List<String> sns =  new ArrayList<String>();
               sns.add(sn);
               deviceLostMessageUtil.deviceLostMessage(sns);
            }
            deviceDetail.setContactStatusTime(new Date());
            deviceDetailDao.save(deviceDetail);
        }

+ 103 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/util/DeviceLostMessageUtil.java

@ -0,0 +1,103 @@
package com.yihu.jw.care.util;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Created by Bing on 2021/9/13.
 */
@Component
public class DeviceLostMessageUtil {
    @Autowired
    private SystemMessageDao systemMessageDao;
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private BasePatientDao patientDao;
    /**
     * 设备离线通知
     * @param devices
     */
    public void deviceLostMessage(List<String> devices){
        List<SystemMessageDO> messageDOS = new ArrayList<>();
        for (String id:devices){
            List<DevicePatientDevice> pds =  patientDeviceDao.findByDeviceSn(id);
            if (pds.size()>0){
                DevicePatientDevice deviceDO = pds.get(0);
                String sql = "SELECT DISTINCT d.id,d.name from base_service_package_sign_record sr,base_service_package_record r,base_team_member m,base_doctor d  " +
                        "               WHERE sr.status=1 and m.team_code = r.team_code and sr.id=r.sign_id and m.doctor_code = d.id " +
                        "               and m.del = '1' and sr.patient = '"+deviceDO.getUser()+"' " ;
                List<Map<String,Object>> doctors = jdbcTemplate.queryForList(sql);
                String deviceName="";
                for (Map<String,Object> docTmp:doctors){
                    switch (deviceDO.getCategoryCode()){
                        case "1":
                            deviceName="血糖仪离线";
                            break;
                        case "2":
                            deviceName="血压计离线";
                            break;
                        case "4":
                            deviceName="智能手表离线";
                            break;
                        case "7":
                            deviceName="居家安全报警器离线";
                            break;
                        case "12":
                            deviceName="监控器离线";
                            break;
                        case "13":
                            deviceName="睡眠带离线";
                            break;
                        case "14":
                            deviceName="气感报警器离线";
                            break;
                        case "15":
                            deviceName="烟感报警器离线";
                            break;
                        case "16":
                            deviceName="智能拐杖离线";
                            break;
                        case "17":
                            deviceName="随身WiFi离线";
                            break;
                    }
                    BasePatientDO patientDO = patientDao.findById(deviceDO.getUser());
                    SystemMessageDO messageDO = new SystemMessageDO();
                    messageDO.setTitle("设备离线通知");
                    messageDO.setType("43");
                    messageDO.setSender(deviceDO.getUser());
                    messageDO.setSenderName(patientDO.getName());
                    messageDO.setRelationCode(id);
                    messageDO.setReceiver(docTmp.get("id").toString());
                    messageDO.setReceiverName(docTmp.get("name").toString());
                    messageDO.setOver("1");
                    messageDO.setData(deviceName);
                    messageDO.setDel("1");
                    messageDO.setCreateTime(new Date());
                    messageDO.setSenderPhoto(patientDO.getPhoto());
                    messageDOS.add(messageDO);
                }
            }
        }
        if (messageDOS.size()>0){
            systemMessageDao.save(messageDOS);
        }
    }
}

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

@ -7,7 +7,9 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/***
 * @ClassName: WlyyDeviceDao
@ -25,4 +27,7 @@ public interface WlyyDeviceDao extends PagingAndSortingRepository<DeviceDetail,
    @Query("update DeviceDetail o set o.contactStatus = 1 , o.contactStatusTime = ?1 where o.deviceCode = ?2")
    void updateContactStatus1(Date contactStatusTime, String orderId);
    @Modifying
    @Query("update DeviceDetail o set o.contactStatus = ?1 , o.contactStatusTime = ?2 where o.deviceCode in (?3)")
    void updateByContactStatus(Integer contactStatus,Date contactStatusTime, List<String> ids );
}

+ 43 - 64
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/service/device/PatientDeviceService.java

@ -5,10 +5,9 @@ import com.yihu.jw.care.config.AqgConfig;
import com.yihu.jw.care.dao.device.DeviceDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.device.WlyyDeviceDao;
import com.yihu.jw.care.util.DeviceLostMessageUtil;
import com.yihu.jw.entity.care.device.Device;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.restmodel.iot.device.WlyyDeviceVO;
import com.yihu.jw.restmodel.iot.device.WlyyPatientDeviceVO;
import com.yihu.jw.util.common.GpsUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
@ -50,7 +49,8 @@ public class PatientDeviceService {
    private WlyyDeviceDao wlyyDeviceDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private DeviceLostMessageUtil deviceLostMessageUtil;
    Map<Integer, String> relations = new HashMap<>();
    @PostConstruct
@ -229,6 +229,7 @@ public class PatientDeviceService {
    /**************************************物联网检测大屏失联率start************************************************/
    @Transactional
    public void selectAndUpdate(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String endTime = sdf.format(new Date());
@ -244,77 +245,55 @@ public class PatientDeviceService {
        Date nowDate2 = device2.getTime();
        String startTimeDevice2 = sdf.format(nowDate2);
        try {
            /**血糖仪,血压计。30天内有数据上传,则改为未失联**/
            String sql = "SELECT bb.device_sn  FROM (\n" +
                    "SELECT pd.device_sn FROM base.wlyy_patient_device pd  LEFT JOIN wlyy_patient_health_index phi ON pd.device_sn = phi.device_sn WHERE\n" +
                    "phi.record_date BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"' AND phi.del = 1 AND pd.category_code IN (1,2) GROUP BY phi.device_sn\n" +
                    ") aa RIGHT JOIN (SELECT device_sn FROM wlyy_patient_device WHERE category_code IN (1,2)) bb ON aa.device_sn =  bb.device_sn\n" +
                    "WHERE aa.device_sn IS NOT NULL OR aa.device_sn != ''";
            List<Map<String , Object>> list = jdbcTemplate.queryForList(sql);
            if (list.size() > 0) {
                for (int i=0;i<list.size();i++) {
                    wlyyDeviceDao.updateContactStatus1(new Date(), (String) list.get(i).get("device_sn"));
                }
            }
            /**智能拐杖、智能手表。2天内有数据上传,则改为未失联**/
            sql = "SELECT bb.device_sn  FROM (\n" +
                    "SELECT pd.device_sn FROM base.wlyy_patient_device pd  LEFT JOIN wlyy_patient_health_index phi ON pd.device_sn = phi.device_sn WHERE\n" +
                    "phi.record_date BETWEEN '"+startTimeDevice2+"' AND '"+endTime+"' AND phi.del = 1 AND pd.category_code IN (16) GROUP BY phi.device_sn\n" +
                    ") aa RIGHT JOIN (SELECT device_sn FROM wlyy_patient_device WHERE category_code IN (16)) bb ON aa.device_sn =  bb.device_sn\n" +
                    "WHERE aa.device_sn IS NOT NULL OR aa.device_sn != ''";
            list = jdbcTemplate.queryForList(sql);
            if (list.size() > 0) {
                for (int i=0;i<list.size();i++) {
                    wlyyDeviceDao.updateContactStatus1(new Date(), (String) list.get(i).get("device_sn"));
                }
            List<String> lostSN = new ArrayList<>();
            List<String> onContact = new ArrayList<>();
            /*******************未失联**/
            //血糖仪,血压计。30天内有数据上传,则改为未失联
            String sql = " SELECT pd.device_sn FROM base.wlyy_patient_device pd  where pd.del=0 and pd.category_code in (1,2) and EXISTS ( " +
                    "select dp.device_sn from device_data_push_log dp where dp.device_sn = pd.device_sn and dp.create_time " +
                    " BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"') ";
            List<String> devices = jdbcTemplate.queryForList(sql,String.class) ;
            if (devices.size() > 0) {
                onContact.addAll(devices);
            }
            //智能拐杖。手表2天内有数据上传,则改为未失联**
            sql = " SELECT pd.device_sn FROM base.wlyy_patient_device pd  where pd.del=0 and pd.category_code in (4,16) and EXISTS ( " +
                    "select dp.device_sn from device_data_push_log dp where dp.device_sn = pd.device_sn and dp.create_time " +
                    " BETWEEN '"+startTimeDevice2+"' AND '"+endTime+"') ";
            /**血糖仪**/
            String sql1 = "SELECT bb.device_sn  FROM (\n" +
                    "SELECT pd.device_sn FROM base.wlyy_patient_device pd  LEFT JOIN wlyy_patient_health_index phi ON pd.device_sn = phi.device_sn WHERE\n" +
                    "phi.record_date BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"' AND phi.del = 1 AND pd.category_code = 1 GROUP BY phi.device_sn\n" +
                    ") aa RIGHT JOIN (SELECT device_sn FROM wlyy_patient_device WHERE category_code = 1) bb ON aa.device_sn =  bb.device_sn\n" +
                    "WHERE aa.device_sn IS NULL OR aa.device_sn = ''";
            List<Map<String , Object>> list1 = jdbcTemplate.queryForList(sql1);
            if (list1.size() > 0) {
                for (int i=0;i<list1.size();i++) {
                    wlyyDeviceDao.updateContactStatus(new Date(), (String) list1.get(i).get("device_sn"));
                }
            devices = jdbcTemplate.queryForList(sql,String.class) ;
            if (devices.size() > 0) {
                onContact.addAll(devices);
            }
            /**血压计**/
            String sql2 = "SELECT bb.device_sn  FROM (\n" +
                    "SELECT pd.device_sn FROM base.wlyy_patient_device pd  LEFT JOIN wlyy_patient_health_index phi ON pd.device_sn = phi.device_sn WHERE\n" +
                    "phi.record_date BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"' AND phi.del = 1 AND pd.category_code = 2 GROUP BY phi.device_sn\n" +
                    ") aa RIGHT JOIN (SELECT device_sn FROM wlyy_patient_device WHERE category_code = 2) bb ON aa.device_sn =  bb.device_sn\n" +
                    "WHERE aa.device_sn IS NULL OR aa.device_sn = ''";
            List<Map<String , Object>> list2 = jdbcTemplate.queryForList(sql2);
            if (list2.size() > 0) {
                for (int i=0;i<list2.size();i++) {
                    wlyyDeviceDao.updateContactStatus(new Date(), (String) list2.get(i).get("device_sn"));
                }
            /***************失联**/
            //血糖仪、血压**/
            sql = " SELECT pd.device_sn FROM base.wlyy_patient_device pd  where pd.del=0 and pd.category_code in (1,2) and not EXISTS ( " +
                    "select dp.device_sn from device_data_push_log dp where dp.device_sn = pd.device_sn and dp.create_time " +
                    " BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"') ";
            devices = jdbcTemplate.queryForList(sql,String.class) ;
            if (devices.size() > 0) {
                lostSN.addAll(devices);
            }
            /**智能手表**/
            //startTimeDevice2   2天
            /**智能拐杖**/
            String sql3 = "SELECT bb.device_sn  FROM (\n" +
                    "SELECT pd.device_sn FROM base.wlyy_patient_device pd  LEFT JOIN wlyy_patient_health_index phi ON pd.device_sn = phi.device_sn WHERE\n" +
                    "phi.record_date BETWEEN '"+startTimeDevice2+"' AND '"+endTime+"' AND phi.del = 1 AND pd.category_code = 16 GROUP BY phi.device_sn\n" +
                    ") aa RIGHT JOIN (SELECT device_sn FROM wlyy_patient_device WHERE category_code = 16) bb ON aa.device_sn =  bb.device_sn\n" +
                    "WHERE aa.device_sn IS NULL OR aa.device_sn = ''";
            List<Map<String , Object>> list3 = jdbcTemplate.queryForList(sql3);
            if (list3.size() > 0) {
                for (int i=0;i<list3.size();i++) {
                    wlyyDeviceDao.updateContactStatus(new Date(), (String) list3.get(i).get("device_sn"));
                }
            //智能拐杖、手表
            sql = " SELECT pd.device_sn FROM base.wlyy_patient_device pd  where pd.del=0 and pd.category_code in (4,16) and not EXISTS ( " +
                    "select dp.device_sn from device_data_push_log dp where dp.device_sn = pd.device_sn and dp.create_time " +
                    " BETWEEN '"+startTimeDevice2+"' AND '"+endTime+"') ";
            devices = jdbcTemplate.queryForList(sql,String.class) ;
            if (devices.size() > 0) {
                lostSN.addAll(devices);
            }
            if (onContact.size()>0){
                wlyyDeviceDao.updateByContactStatus(1,new Date(),onContact);
            }
            if (lostSN.size()>0){
                wlyyDeviceDao.updateByContactStatus(0,new Date(),lostSN);
                deviceLostMessageUtil.deviceLostMessage(lostSN);
            }
        } catch (Exception e) {
            logger.info(e.getMessage());
        }
    }
}

+ 104 - 0
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/util/DeviceLostMessageUtil.java

@ -0,0 +1,104 @@
package com.yihu.jw.care.util;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.hospital.message.dao.SystemMessageDao;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.rm.base.BaseRequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Created by Bing on 2021/9/13.
 */
@Component
public class DeviceLostMessageUtil {
    @Autowired
    private SystemMessageDao systemMessageDao;
    @Autowired
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private BasePatientDao patientDao;
    /**
     * 设备离线通知
     * @param devices
     */
    public void deviceLostMessage(List<String> devices){
        List<SystemMessageDO> messageDOS = new ArrayList<>();
        for (String id:devices){
            List<DevicePatientDevice> pds =  patientDeviceDao.findByDeviceSn(id);
            if (pds.size()>0){
                DevicePatientDevice deviceDO = pds.get(0);
                String sql = "SELECT DISTINCT d.id,d.name from base_service_package_sign_record sr,base_service_package_record r,base_team_member m,base_doctor d  " +
                        "               WHERE sr.status=1 and m.team_code = r.team_code and sr.id=r.sign_id and m.doctor_code = d.id " +
                        "               and m.del = '1' and sr.patient = '"+deviceDO.getUser()+"' " ;
                List<Map<String,Object>> doctors = jdbcTemplate.queryForList(sql);
                        String deviceName="";
                for (Map<String,Object> docTmp:doctors){
                    switch (deviceDO.getCategoryCode()){
                        case "1":
                            deviceName="血糖仪离线";
                            break;
                        case "2":
                            deviceName="血压计离线";
                            break;
                        case "4":
                            deviceName="智能手表离线";
                            break;
                        case "7":
                            deviceName="居家安全报警器离线";
                            break;
                        case "12":
                            deviceName="监控器离线";
                            break;
                        case "13":
                            deviceName="睡眠带离线";
                            break;
                        case "14":
                            deviceName="气感报警器离线";
                            break;
                        case "15":
                            deviceName="烟感报警器离线";
                            break;
                        case "16":
                            deviceName="智能拐杖离线";
                            break;
                        case "17":
                            deviceName="随身WiFi离线";
                            break;
                    }
                    BasePatientDO patientDO = patientDao.findById(deviceDO.getUser());
                    SystemMessageDO messageDO = new SystemMessageDO();
                    messageDO.setTitle("设备离线通知");
                    messageDO.setType("43");
                    messageDO.setSender(deviceDO.getUser());
                    messageDO.setSenderName(patientDO.getName());
                    messageDO.setRelationCode(id);
                    messageDO.setReceiver(docTmp.get("id").toString());
                    messageDO.setReceiverName(docTmp.get("name").toString());
                    messageDO.setOver("1");
                    messageDO.setData(deviceName);
                    messageDO.setDel("1");
                    messageDO.setCreateTime(new Date());
                    messageDO.setSenderPhoto(patientDO.getPhoto());
                    messageDOS.add(messageDO);
                }
            }
        }
        if (messageDOS.size()>0){
            systemMessageDao.save(messageDOS);
        }
    }
}