|
@@ -1,9 +1,12 @@
|
|
|
package com.coffee.bus.websocket.listener;
|
|
package com.coffee.bus.websocket.listener;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.coffee.bus.registry.device.DeviceOperator;
|
|
import com.coffee.bus.registry.device.DeviceOperator;
|
|
|
import com.coffee.bus.registry.device.DeviceRegistry;
|
|
import com.coffee.bus.registry.device.DeviceRegistry;
|
|
@@ -11,7 +14,6 @@ import com.coffee.bus.entity.BusPumpEntity;
|
|
|
import com.coffee.bus.enums.NetPumpStatusEnum;
|
|
import com.coffee.bus.enums.NetPumpStatusEnum;
|
|
|
import com.coffee.bus.listener.event.bean.DeviceAlarmEvent;
|
|
import com.coffee.bus.listener.event.bean.DeviceAlarmEvent;
|
|
|
import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
|
|
import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
|
|
|
-import com.coffee.bus.registry.device.bean.DeviceBasicInfo;
|
|
|
|
|
import com.coffee.bus.registry.patient.PatientOperator;
|
|
import com.coffee.bus.registry.patient.PatientOperator;
|
|
|
import com.coffee.bus.registry.patient.PatientRegistry;
|
|
import com.coffee.bus.registry.patient.PatientRegistry;
|
|
|
import com.coffee.bus.service.LocalBusPumpService;
|
|
import com.coffee.bus.service.LocalBusPumpService;
|
|
@@ -19,7 +21,6 @@ import com.coffee.bus.service.LocalBusPatientService;
|
|
|
import com.coffee.common.config.websocket.WebSocketConstant;
|
|
import com.coffee.common.config.websocket.WebSocketConstant;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.context.event.EventListener;
|
|
import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -29,8 +30,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.function.Supplier;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author lifang
|
|
* @author lifang
|
|
@@ -46,7 +49,7 @@ public class DeviceInfoListener {
|
|
|
|
|
|
|
|
private final RedisTemplate redisTemplate;
|
|
private final RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
- private final LocalBusPumpService deviceRunInfoService;
|
|
|
|
|
|
|
+ private final LocalBusPumpService deviceUsingService;
|
|
|
|
|
|
|
|
private final LocalBusPatientService patientService;
|
|
private final LocalBusPatientService patientService;
|
|
|
|
|
|
|
@@ -64,10 +67,12 @@ public class DeviceInfoListener {
|
|
|
@Async
|
|
@Async
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void deviceInfoDetail(DeviceInfoEvent infoEvent){
|
|
public void deviceInfoDetail(DeviceInfoEvent infoEvent){
|
|
|
|
|
+ /****************处理泵数据****************/
|
|
|
BusPumpEntity device = infoEvent.getContent();
|
|
BusPumpEntity device = infoEvent.getContent();
|
|
|
//1、判断该设备是否已和医院绑定并开启使用
|
|
//1、判断该设备是否已和医院绑定并开启使用
|
|
|
String deviceId = device.getDeviceId();
|
|
String deviceId = device.getDeviceId();
|
|
|
DeviceOperator deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
DeviceOperator deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
|
|
|
+ PatientOperator patientOperator =null;
|
|
|
if (!deviceOperator.canUse()) {
|
|
if (!deviceOperator.canUse()) {
|
|
|
log.warn("设备[{}]暂不可用,数据已丢弃",deviceId);
|
|
log.warn("设备[{}]暂不可用,数据已丢弃",deviceId);
|
|
|
return ;
|
|
return ;
|
|
@@ -77,25 +82,74 @@ public class DeviceInfoListener {
|
|
|
//首次运行需要与病人、医院进行绑定
|
|
//首次运行需要与病人、医院进行绑定
|
|
|
if(deviceOperator.isFirst()){
|
|
if(deviceOperator.isFirst()){
|
|
|
initDevice(device,deviceOperator);
|
|
initDevice(device,deviceOperator);
|
|
|
- PatientOperator patientOperator = patientRegistry.getPatient(device.getTenantId(), device.getPatientCode());
|
|
|
|
|
|
|
+ patientOperator = patientRegistry.getPatient(device.getTenantId(), device.getPatientCode());
|
|
|
initPatient(device,patientOperator);
|
|
initPatient(device,patientOperator);
|
|
|
//二次确认
|
|
//二次确认
|
|
|
deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
|
if(device.getId().equals(deviceOperator.getRunId())){
|
|
if(device.getId().equals(deviceOperator.getRunId())){
|
|
|
- deviceRunInfoService.save(device);
|
|
|
|
|
|
|
+ deviceUsingService.save(device);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
device.setId(deviceOperator.getRunId());
|
|
device.setId(deviceOperator.getRunId());
|
|
|
- deviceRunInfoService.updateById(device);
|
|
|
|
|
|
|
+ deviceUsingService.updateById(device);
|
|
|
|
|
+ }
|
|
|
|
|
+ /****************处理泵数据****************/
|
|
|
|
|
+
|
|
|
|
|
+ /****************处理泵与患者关系****************/
|
|
|
|
|
+ if(patientOperator==null){
|
|
|
|
|
+ patientOperator = patientRegistry.getPatient(device.getTenantId(), device.getPatientCode());
|
|
|
|
|
+ }
|
|
|
|
|
+ //泵绑定重复判定
|
|
|
|
|
+ if(StrUtil.isNotEmpty(patientOperator.getDeviceId())&&deviceId.equals(patientOperator.getDeviceId())){
|
|
|
|
|
+ //泵号发生改变,判断泵的开始时间,将开始时间稍后的泵设置为主泵再与设备绑定
|
|
|
|
|
+ DeviceOperator currentBindDevice = deviceRegistry.getDevice(patientOperator.getDeviceId());
|
|
|
|
|
+ if (currentBindDevice.getStartTime().before(device.getStartTime())) {
|
|
|
|
|
+ //设置当前上传信息的泵为主泵,将旧泵设置为副泵吗,并更新病人绑定泵的信息
|
|
|
|
|
+ deviceUsingService.update(new UpdateWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getDeviceId,deviceId).set(BusPumpEntity::getMaster,1));
|
|
|
|
|
+ deviceUsingService.update(new UpdateWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getDeviceId,patientOperator.getDeviceId()).set(BusPumpEntity::getMaster,0));
|
|
|
|
|
+ //todo 缓存更新放在最后
|
|
|
|
|
+ patientOperator.updateDeviceId(deviceId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ patientOperator.updateDeviceId(deviceId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //病号是否进行换泵操作
|
|
|
|
|
-// if (patientService.isChangedDevice(device.getTenantId(),device.getPatientCode(),device.getDeviceId(),device.getStartTime())) {
|
|
|
|
|
-// patientService.changePump(device.getTenantId(),device.getPatientCode(),device.getDeviceId());
|
|
|
|
|
-// }
|
|
|
|
|
- //发送设备报警
|
|
|
|
|
|
|
+ //当泵所绑定的病号发生变化时,进行无泵判定
|
|
|
|
|
+ if(device.getPatientCode().equals(deviceOperator.getPatientCode())){
|
|
|
|
|
+ //临床无泵绑定时,查看是否存在副泵,若存在将开始时间稍后的泵设置为副泵,若不存在,则报无泵异常
|
|
|
|
|
+ List<BusPumpEntity> usingDevices = deviceUsingService.list(new QueryWrapper<BusPumpEntity>().lambda()
|
|
|
|
|
+ .eq(BusPumpEntity::getTenantId, device.getTenantId())
|
|
|
|
|
+ .eq(BusPumpEntity::getPatientCode, device.getPatientCode()));
|
|
|
|
|
+ if(CollectionUtil.isEmpty(usingDevices)){
|
|
|
|
|
+ //todo 发起无泵报警
|
|
|
|
|
+
|
|
|
|
|
+ }else {
|
|
|
|
|
+ //将开始时间最大的泵设置为主泵
|
|
|
|
|
+ BusPumpEntity master = usingDevices.stream().max(new Comparator<BusPumpEntity>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int compare(BusPumpEntity o1, BusPumpEntity o2) {
|
|
|
|
|
+ return o1.getStartTime().before(o2.getStartTime()) ? 1 : 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .orElseGet(new Supplier<BusPumpEntity>() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public BusPumpEntity get() {
|
|
|
|
|
+ //todo 发起无泵报警
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if(master!=null){
|
|
|
|
|
+ master.setMaster(1);
|
|
|
|
|
+ deviceUsingService.updateById(master);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /****************处理泵与患者关系****************/
|
|
|
|
|
+
|
|
|
if(!deviceOperator.isFirst()){
|
|
if(!deviceOperator.isFirst()){
|
|
|
//非首次注册,则推送设备消息
|
|
//非首次注册,则推送设备消息
|
|
|
String topic = WebSocketConstant.getDeviceInfoDetailTopic(null, device.getId(), device.getTenantId());
|
|
String topic = WebSocketConstant.getDeviceInfoDetailTopic(null, device.getId(), device.getTenantId());
|
|
@@ -131,7 +185,7 @@ public class DeviceInfoListener {
|
|
|
//存储报警信息 todo
|
|
//存储报警信息 todo
|
|
|
String topic = WebSocketConstant.getDeviceStateCount(null, runState.name(), pump.getTenantId());
|
|
String topic = WebSocketConstant.getDeviceStateCount(null, runState.name(), pump.getTenantId());
|
|
|
//获取报警设备数量
|
|
//获取报警设备数量
|
|
|
- List<BusPumpEntity> alarmList = deviceRunInfoService.list(new QueryWrapper<BusPumpEntity>()
|
|
|
|
|
|
|
+ List<BusPumpEntity> alarmList = deviceUsingService.list(new QueryWrapper<BusPumpEntity>()
|
|
|
.lambda()
|
|
.lambda()
|
|
|
.select(BusPumpEntity::getId)
|
|
.select(BusPumpEntity::getId)
|
|
|
.eq(BusPumpEntity::getRunState, runState));
|
|
.eq(BusPumpEntity::getRunState, runState));
|
|
@@ -160,15 +214,14 @@ public class DeviceInfoListener {
|
|
|
//设备绑定医院
|
|
//设备绑定医院
|
|
|
pump.setTenantId(deviceOperator.getTenantId());
|
|
pump.setTenantId(deviceOperator.getTenantId());
|
|
|
|
|
|
|
|
- //缓存存储泵的开始时间和注册时间
|
|
|
|
|
- deviceOperator.updateRegisterTime(now);
|
|
|
|
|
|
|
+ //缓存存储泵的开始时间和注册时间 todo 缓存更新放在最后进行
|
|
|
deviceOperator.updateStartTime(now);
|
|
deviceOperator.updateStartTime(now);
|
|
|
deviceOperator.updateRunId(pump.getId());
|
|
deviceOperator.updateRunId(pump.getId());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Scheduled(cron = "0/50 * * * * ?")
|
|
@Scheduled(cron = "0/50 * * * * ?")
|
|
|
public void send(){
|
|
public void send(){
|
|
|
-// List<BusPumpEntity> list = deviceRunInfoService.list();
|
|
|
|
|
|
|
+// List<BusPumpEntity> list = deviceUsingService.list();
|
|
|
// list.forEach(pump->{
|
|
// list.forEach(pump->{
|
|
|
|
|
|
|
|
ThreadUtil.concurrencyTest(5,()-> {
|
|
ThreadUtil.concurrencyTest(5,()-> {
|