Browse Source

物联网检测大屏,设备失联率

Shi Kejing 3 years ago
parent
commit
706a1a5df5

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

@ -35,12 +35,13 @@ public class DetectionPlatformEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private PatientDeviceService patientDeviceService;
    /**************************v1.1.0新增 设备异常动态************************************/
    @GetMapping(value = "getHealthMonitoringListNew")
    @ApiOperation(value = "体征监测/安防监护")
    public PageEnvelop getHealthMonitoringListNew(
            @ApiParam(name="page",value = "page") @RequestParam(required = true) int page,
            @ApiParam(name="size",value = "size") @RequestParam(required = true) int size,
            @ApiParam(name="type",value = "type=1(健康监测)   type=2(安防检测)") @RequestParam(required = true) int type) {
            @ApiParam(name="type",value = "type=1(健康监测)   type=2(安防检测)   type=3(设备异常)") @RequestParam(required = true) int type) {
        try {
            return platformService.getHealthMonitoringListNew(page,size,type);
        } catch (Exception e) {

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

@ -60,7 +60,7 @@ public class DetectionPlatformService  {
            sql +=" limit "+page*pageSize+","+pageSize;
            List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
            return PageEnvelop.getSuccessListWithPage("查询成功",list,page,pageSize,count);
        }else {
        }else if (type == 2){
            String sql = " select  '22' as 'OrderType',ord.id,ord.patient,p.name,ord.serve_desc,DATE_FORMAT(ord.create_time,'%Y-%m-%d %H:%i:%S') create_time,ord.`status`,ord.doctor,ord.doctor_name \n" +
                    "from base_security_monitoring_order ord INNER JOIN base_patient p on ord.patient = p.id order by create_time desc ";
            String countSql = "select count(id) from ("+sql+")A ";
@ -68,6 +68,16 @@ public class DetectionPlatformService  {
            sql +=" limit "+page*pageSize+","+pageSize;
            List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
            return PageEnvelop.getSuccessListWithPage("查询成功",list,page,pageSize,count);
        } else {
            String sql = " SELECT pd.id,pd.device_sn deviceSn,pd.`user`,p.`name`,d.contact_status_time contactStatusTime,CASE pd.category_code WHEN '1' THEN '血糖仪离线' WHEN '2' THEN '血压计离线' WHEN '13' THEN '睡眠带离线'\n" +
                    "WHEN '17' THEN '随身WiFi离线' WHEN '7' THEN '居家安全报警器离线' WHEN '12' THEN '监控器离线' WHEN '14' THEN '气感报警器离线' WHEN '15' THEN '烟感报警器离线' WHEN '16' THEN '智能拐杖离线' WHEN '4' THEN '智能手表离线' \n" +
                    "ELSE '未知' END categoryCode FROM wlyy_devices d,wlyy_patient_device pd,base_patient p\n" +
                    "WHERE d.contact_status = 0 AND pd.del = 0 AND pd.device_sn = d.device_code AND pd.`user` = p.id ORDER BY d.contact_status_time DESC ";
            String countSql = "select count(id) from ("+sql+")A ";
            long count = jdbcTemplate.queryForObject(countSql,long.class);
            sql +=" limit "+page*pageSize+","+pageSize;
            List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
            return PageEnvelop.getSuccessListWithPage("查询成功",list,page,pageSize,count);
        }
    }

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

@ -0,0 +1,24 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.Device;
import com.yihu.jw.entity.care.device.DeviceDetail;
import com.yihu.jw.restmodel.iot.device.WlyyDeviceVO;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
/***
 * @ClassName: WlyyDeviceDao
 * @Description:
 * @Auther: shi kejing
 * @Date: 2021/9/6 11:12
 */
public interface WlyyDeviceDao extends PagingAndSortingRepository<DeviceDetail, Long> {
    @Modifying
    @Query("update DeviceDetail o set o.contactStatus = 0 , o.contactStatusTime = ?1 where o.deviceCode = ?2")
    void updateContactStatus(Date contactStatusTime, String orderId);
}

+ 9 - 0
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/event/ApplicationEvent.java

@ -3,6 +3,7 @@ package com.yihu.jw.care.event;
import com.yihu.jw.care.job.BirthdayReminderJob;
import com.yihu.jw.care.job.QuartzHelper;
import com.yihu.jw.care.job.consult.FinishConsultJob;
import com.yihu.jw.care.job.device.DeviceLostAssociationJob;
import com.yihu.jw.care.job.device.PatientSosContactsJob;
import com.yihu.jw.care.job.message.DoctorSendUnreadJob;
import com.yihu.jw.care.job.message.PatientSendUnreadJob;
@ -84,6 +85,14 @@ public class ApplicationEvent implements ApplicationListener<ContextRefreshedEve
                logger.info("PATIENT_SOS_CONTACTS_JOB exist");
            }
            if (!quartzHelper.isExistJob("DEVICE_LOST_ASSOCIATION_JOB")) {
                String trigger = SystemConf.getInstance().getSystemProperties().getProperty("DEVICE_LOST_ASSOCIATION_JOB");
                quartzHelper.addJob(DeviceLostAssociationJob.class, trigger, "DEVICE_LOST_ASSOCIATION_JOB", new HashMap<String, Object>());
                logger.info("DEVICE_LOST_ASSOCIATION_JOB success");
            } else {
                logger.info("DEVICE_LOST_ASSOCIATION_JOB exist");
            }
        } catch (Exception e) {
            logger.info(" job start failed");
        }

+ 37 - 0
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/job/device/DeviceLostAssociationJob.java

@ -0,0 +1,37 @@
package com.yihu.jw.care.job.device;
import com.yihu.jw.care.service.device.PatientDeviceService;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/***
 * @ClassName: DeviceLostAssociationJob
 * @Description: 医养物联网检测大屏失联率
 * @Auther: shi kejing
 * @Date: 2021/9/6 13:37
 */
@DisallowConcurrentExecution
public class DeviceLostAssociationJob implements Job {
    private static Logger logger = LoggerFactory.getLogger(DeviceLostAssociationJob.class);
    @Autowired
    private PatientDeviceService patientDeviceService;
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        logger.info("DeviceLostAssociationJob start");
        try {
            patientDeviceService.selectAndUpdate();
            logger.info("DeviceLostAssociationJob end");
        } catch (Exception e) {
            logger.info(e.getMessage());
            e.printStackTrace();
        }
    }
}

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

@ -4,8 +4,11 @@ package com.yihu.jw.care.service.device;
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.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;
@ -16,12 +19,14 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import javax.annotation.PostConstruct;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
@ -41,6 +46,10 @@ public class PatientDeviceService {
    private GpsUtil gpsUtil;
    @Autowired
    private DeviceDao deviceDao;
    @Autowired
    private WlyyDeviceDao wlyyDeviceDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    Map<Integer, String> relations = new HashMap<>();
@ -218,4 +227,59 @@ public class PatientDeviceService {
    /******************************************* 爱牵挂设备end *****************************************************/
    /**************************************物联网检测大屏失联率start************************************************/
    public void selectAndUpdate(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String endTime = sdf.format(new Date());
        Calendar device1 = Calendar.getInstance();
        device1.setTime(new Date());
        device1.add(device1.DATE, -30);
        Date nowDate = device1.getTime();
        String startTimeDevice1 = sdf.format(nowDate);
        Calendar device2 = Calendar.getInstance();
        device2.setTime(new Date());
        device2.add(device2.DATE, -2);
        Date nowDate2 = device2.getTime();
        String startTimeDevice2 = sdf.format(nowDate2);
        try {
            /**血糖仪**/
            String sql1 = "SELECT pd.device_sn FROM base.wlyy_patient_device pd WHERE (SELECT COUNT(1) FROM base.wlyy_patient_health_index WHERE \n" +
                    "record_date BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"' ) = 0 AND del = 0 AND category_code = 1";
            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"));
                }
            }
            /**血压计**/
            String sql2 = "SELECT pd.device_sn FROM base.wlyy_patient_device pd WHERE (SELECT COUNT(1) FROM base.wlyy_patient_health_index WHERE \n" +
                    "record_date BETWEEN '"+startTimeDevice1+"' AND '"+endTime+"' ) = 0 AND del = 0 AND category_code = 2";
            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"));
                }
            }
            /**智能手表**/
            //startTimeDevice2   2天
            /**智能拐杖**/
            String sql3 = "SELECT pd.device_sn FROM base.wlyy_patient_device pd WHERE (SELECT COUNT(1) FROM base.base_yxdevice_index WHERE \n" +
                    "create_time BETWEEN '"+startTimeDevice2+"' AND '"+endTime+"' ) = 0 AND del = 0 AND category_code = 16";
            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"));
                }
            }
        } catch (Exception e) {
            logger.info(e.getMessage());
        }
    }
}

+ 15 - 0
svr/svr-cloud-job/src/main/java/com/yihu/jw/care/web/JobController.java

@ -3,6 +3,7 @@ package com.yihu.jw.care.web;
import com.yihu.jw.care.job.BirthdayReminderJob;
import com.yihu.jw.care.job.QuartzHelper;
import com.yihu.jw.care.job.consult.FinishConsultJob;
import com.yihu.jw.care.job.device.DeviceLostAssociationJob;
import com.yihu.jw.care.job.message.DoctorSendUnreadJob;
import com.yihu.jw.care.job.message.PatientSendUnreadJob;
import com.yihu.jw.care.service.BirthdayReminderService;
@ -19,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.UUID;
/**
 * 任务启动
@ -37,6 +39,19 @@ public class JobController extends BaseController {
    @Autowired
    private BirthdayReminderService birthdayReminderService;
    @RequestMapping(value = "/deviceLostAssociationJob", method = RequestMethod.POST)
    @ApiOperation("医养物联网检测大屏失联率")
    public String deviceLostAssociationJob() {
        try {
            quartzHelper.startNow(DeviceLostAssociationJob.class, null, null);
            return write(200, "启动成功");
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
    @Autowired
    public JobController(JobService jobService, QuartzHelper quartzHelper) {
        this.jobService = jobService;

+ 10 - 7
svr/svr-cloud-job/src/main/resources/system.properties

@ -1,18 +1,21 @@
#居民24小时未回复的咨询自动关闭 每小时59分开始执行一次
#\u5C45\u6C1124\u5C0F\u65F6\u672A\u56DE\u590D\u7684\u54A8\u8BE2\u81EA\u52A8\u5173\u95ED \u6BCF\u5C0F\u65F659\u5206\u5F00\u59CB\u6267\u884C\u4E00\u6B21
finish_consult_job=0 59 * * * ?
#每天的早上9:00,给所有医生/助老员/教师发送一条短信
#\u6BCF\u5929\u7684\u65E9\u4E0A9:00\uFF0C\u7ED9\u6240\u6709\u533B\u751F/\u52A9\u8001\u5458/\u6559\u5E08\u53D1\u9001\u4E00\u6761\u77ED\u4FE1
DOCTOR_SEND_UNREAD_MES_JOB=0 0 9 * * ?
#每天的早上9:00,给所有居民发送未读消息微信模板
#\u6BCF\u5929\u7684\u65E9\u4E0A9:00\uFF0C\u7ED9\u6240\u6709\u5C45\u6C11\u53D1\u9001\u672A\u8BFB\u6D88\u606F\u5FAE\u4FE1\u6A21\u677F
PATIENT_SEND_UNREAD_MES_JOB=0 0 9 * * ?
#每天的早上9:00,生日祝福提醒短信
#\u6BCF\u5929\u7684\u65E9\u4E0A9:00\uFF0C\u751F\u65E5\u795D\u798F\u63D0\u9192\u77ED\u4FE1
BIRTHDAY_REMINDER_JOB=0 0 9 * * ?
#取消订单支付超时的订单,每3分钟执行一次
#\u53D6\u6D88\u8BA2\u5355\u652F\u4ED8\u8D85\u65F6\u7684\u8BA2\u5355\uFF0C\u6BCF3\u5206\u949F\u6267\u884C\u4E00\u6B21
CANCEL_PAY_ORDER_OVERTIME_JOB=0 0/3 * * * ?
#居民紧急联系人数据同步更新每2分钟执行一次
PATIENT_SOS_CONTACTS_JOB=0 0/2 * * * ?
#\u5C45\u6C11\u7D27\u6025\u8054\u7CFB\u4EBA\u6570\u636E\u540C\u6B65\u66F4\u65B0\u6BCF2\u5206\u949F\u6267\u884C\u4E00\u6B21
PATIENT_SOS_CONTACTS_JOB=0 0/2 * * * ?
#\u533B\u517B\u7269\u8054\u7F51\u68C0\u6D4B\u5927\u5C4F\u5931\u8054\u7387
DEVICE_LOST_ASSOCIATION_JOB=0 30 23 * * ?