|
|
@@ -1,15 +1,14 @@
|
|
|
package com.coffee.bus.websocket.listener;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
-import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
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.coffee.bus.entity.BusDeviceUsingEntity;
|
|
|
import com.coffee.bus.registry.device.DeviceRegistry;
|
|
|
-import com.coffee.bus.entity.BusPumpEntity;
|
|
|
import com.coffee.bus.enums.NetPumpStatusEnum;
|
|
|
import com.coffee.bus.listener.event.bean.DeviceAlarmEvent;
|
|
|
import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
|
|
|
@@ -19,7 +18,7 @@ import com.coffee.bus.registry.patient.PatientOperator;
|
|
|
import com.coffee.bus.registry.patient.PatientRegistry;
|
|
|
import com.coffee.bus.registry.patient.bean.DeviceTimeSmallInfo;
|
|
|
import com.coffee.bus.registry.patient.bean.PatientCacheInfo;
|
|
|
-import com.coffee.bus.service.LocalBusPumpService;
|
|
|
+import com.coffee.bus.service.LocalBusDeviceUsingService;
|
|
|
import com.coffee.bus.service.LocalBusPatientService;
|
|
|
import com.coffee.common.config.websocket.WebSocketConstant;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
@@ -27,12 +26,12 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
-import java.util.function.Supplier;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -49,7 +48,7 @@ public class DeviceInfoListener {
|
|
|
|
|
|
private final RedisTemplate redisTemplate;
|
|
|
|
|
|
- private final LocalBusPumpService deviceUsingService;
|
|
|
+ private final LocalBusDeviceUsingService deviceUsingService;
|
|
|
|
|
|
private final LocalBusPatientService patientService;
|
|
|
|
|
|
@@ -70,7 +69,7 @@ public class DeviceInfoListener {
|
|
|
//若数据发送过快,为防止冲突,请在此加锁处理 todo
|
|
|
synchronized (infoEvent.getDeviceId()){
|
|
|
/****************处理泵数据****************/
|
|
|
- BusPumpEntity device = infoEvent.getContent();
|
|
|
+ BusDeviceUsingEntity device = infoEvent.getContent();
|
|
|
//1、判断该设备是否已和医院绑定并开启使用
|
|
|
String deviceId = device.getDeviceId();
|
|
|
DeviceOperator<DeviceCacheInfo> deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
|
@@ -79,20 +78,23 @@ public class DeviceInfoListener {
|
|
|
return ;
|
|
|
}
|
|
|
log.info("接收到设备数据:[{}]",infoEvent.getContent().toString());
|
|
|
+// deviceOperator.setStartTime(new Date());
|
|
|
String tenantId = deviceOperator.getTenantId();
|
|
|
PatientOperator<PatientCacheInfo> patientOperator =patientRegistry.getPatient(tenantId, device.getPatientCode());
|
|
|
device.setTenantId(tenantId);
|
|
|
device.setMonitorType(1);
|
|
|
+ //默认为主泵
|
|
|
+ device.setMaster(1);
|
|
|
+ device.setStartTime(deviceOperator.getStartTime());
|
|
|
+ device.setAlias(deviceOperator.getAlias());
|
|
|
String usingId = deviceOperator.getUsingId();
|
|
|
if(StrUtil.isNullOrUndefined(usingId)){
|
|
|
//不存在运行id,即首次运行,需要与病人、医院进行绑定
|
|
|
initDevice(device,deviceOperator);
|
|
|
initPatient(device,patientOperator);
|
|
|
- deviceUsingService.save(device);
|
|
|
}
|
|
|
else {
|
|
|
device.setId(usingId);
|
|
|
- deviceUsingService.updateById(device);
|
|
|
}
|
|
|
/****************处理泵数据****************/
|
|
|
|
|
|
@@ -100,13 +102,15 @@ public class DeviceInfoListener {
|
|
|
//泵绑定重复判定
|
|
|
//获取病号当前绑定的泵号
|
|
|
String bindDeviceId = patientOperator.getBindDeviceId();
|
|
|
- if(StrUtil.isNullOrUndefined(bindDeviceId)&&deviceId.equals(bindDeviceId)){
|
|
|
+ if(!StrUtil.isNullOrUndefined(bindDeviceId)&&!deviceId.equals(bindDeviceId)){
|
|
|
//泵号发生改变,判断泵的开始时间,将开始时间稍后的泵设置为主泵再与设备绑定
|
|
|
DeviceOperator currentBindDevice = deviceRegistry.getDevice(bindDeviceId);
|
|
|
if (currentBindDevice.getStartTime().before(device.getStartTime())) {
|
|
|
//设置当前上传信息的泵为主泵,将旧泵设置为副泵吗,并更新病人绑定泵的信息, todo 发生泵重复报警
|
|
|
- deviceUsingService.update(new UpdateWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getDeviceId,deviceId).set(BusPumpEntity::getMaster,1));
|
|
|
- deviceUsingService.update(new UpdateWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getDeviceId,bindDeviceId).set(BusPumpEntity::getMaster,0));
|
|
|
+ deviceUsingService.update(new UpdateWrapper<BusDeviceUsingEntity>().lambda().eq(BusDeviceUsingEntity::getDeviceId,deviceId).set(BusDeviceUsingEntity::getMaster,1));
|
|
|
+ deviceUsingService.update(new UpdateWrapper<BusDeviceUsingEntity>().lambda().eq(BusDeviceUsingEntity::getDeviceId,bindDeviceId).set(BusDeviceUsingEntity::getMaster,0));
|
|
|
+ }else {
|
|
|
+ device.setMaster(0);
|
|
|
}
|
|
|
}
|
|
|
if (StrUtil.isNullOrUndefined(bindDeviceId)) {
|
|
|
@@ -117,10 +121,11 @@ public class DeviceInfoListener {
|
|
|
//上条记录所绑定的病号
|
|
|
String originPatientCode=deviceOperator.getPatientCode();
|
|
|
//当泵所绑定的病号发生变化时,进行原先泵号无泵判定
|
|
|
- if(!device.getPatientCode().equals(originPatientCode)){
|
|
|
+ if(!StrUtil.isNullOrUndefined(originPatientCode)&&!device.getPatientCode().equals(originPatientCode)){
|
|
|
//检查是原先的病号是否发生了无泵异常
|
|
|
- PatientOperator originPatientOperator =patientRegistry.getPatient(tenantId, originPatientCode);
|
|
|
+ PatientOperator<PatientCacheInfo> originPatientOperator =patientRegistry.getPatient(tenantId, originPatientCode);
|
|
|
Set<DeviceTimeSmallInfo> originPatientBindDevices = originPatientOperator.getAllDevice();
|
|
|
+
|
|
|
Set<DeviceTimeSmallInfo> originRemainPatientBindDevices = originPatientBindDevices.stream().filter(bindDevice -> !bindDevice.getDeviceId().equals(deviceId)).collect(Collectors.toSet());
|
|
|
//临床无泵绑定时,查看是否存在副泵,若存在将开始时间稍后的泵设置为副泵,若不存在,则报无泵异常
|
|
|
if(CollectionUtil.isEmpty(originRemainPatientBindDevices)){
|
|
|
@@ -133,9 +138,9 @@ public class DeviceInfoListener {
|
|
|
Optional<DeviceTimeSmallInfo> master = originRemainPatientBindDevices.stream().max((o1,o2)->o1.getStartTime().before(o2.getStartTime()) ? 1 : 0);
|
|
|
if(master.isPresent()){
|
|
|
deviceUsingService
|
|
|
- .update(new UpdateWrapper<BusPumpEntity>().lambda()
|
|
|
- .eq(BusPumpEntity::getDeviceId,master.get().getDeviceId())
|
|
|
- .set(BusPumpEntity::getMaster,1));
|
|
|
+ .update(new UpdateWrapper<BusDeviceUsingEntity>().lambda()
|
|
|
+ .eq(BusDeviceUsingEntity::getDeviceId,master.get().getDeviceId())
|
|
|
+ .set(BusDeviceUsingEntity::getMaster,1));
|
|
|
//更新泵原来绑定病人缓存信息
|
|
|
originPatientOperator.setBindDeviceId(master.get().getDeviceId());
|
|
|
}
|
|
|
@@ -143,7 +148,7 @@ public class DeviceInfoListener {
|
|
|
//更新泵原来绑定病人缓存信息
|
|
|
originPatientOperator.setAllDevice(originRemainPatientBindDevices);
|
|
|
}
|
|
|
-
|
|
|
+ deviceUsingService.saveOrUpdate(device);
|
|
|
/****************处理泵与患者关系****************/
|
|
|
|
|
|
//则推送设备上报消息
|
|
|
@@ -156,13 +161,13 @@ public class DeviceInfoListener {
|
|
|
.usingId(device.getId())
|
|
|
.status(device.getRunState())
|
|
|
.startTime(device.getStartTime())
|
|
|
- .master(device.getMaster() == 1)
|
|
|
+ .master(device.getMaster()!=null&&device.getMaster() == 1)
|
|
|
.patientCode(device.getPatientCode())
|
|
|
.mark(device.getMark())
|
|
|
.build();
|
|
|
deviceOperator.set(deviceCacheInfo);
|
|
|
//更新病人缓存信息
|
|
|
- Set allDevice = patientOperator.getAllDevice();
|
|
|
+ Set<DeviceTimeSmallInfo> allDevice = Optional.ofNullable(patientOperator.getAllDevice()).orElse(new HashSet<>());
|
|
|
allDevice.add(DeviceTimeSmallInfo.of(deviceId,device.getStartTime()));
|
|
|
PatientCacheInfo patientCacheInfo = PatientCacheInfo.builder()
|
|
|
.bindDeviceId(deviceId)
|
|
|
@@ -185,7 +190,7 @@ public class DeviceInfoListener {
|
|
|
* @param pump
|
|
|
* @param patientOperator
|
|
|
*/
|
|
|
- private void initPatient(BusPumpEntity pump, PatientOperator patientOperator) {
|
|
|
+ private void initPatient(BusDeviceUsingEntity pump, PatientOperator patientOperator) {
|
|
|
//填充病人名称和病人性别
|
|
|
pump.setPatientName(patientOperator.getName());
|
|
|
pump.setPatientSex(patientOperator.getGender());
|
|
|
@@ -199,7 +204,7 @@ public class DeviceInfoListener {
|
|
|
@EventListener
|
|
|
@Async
|
|
|
public void deviceAlarm(DeviceAlarmEvent alarmEvent){
|
|
|
- BusPumpEntity pump = alarmEvent.getContent();
|
|
|
+ BusDeviceUsingEntity pump = alarmEvent.getContent();
|
|
|
//获取医院配置,对医院功能配置进行过滤筛选
|
|
|
NetPumpStatusEnum runState = pump.getRunState();
|
|
|
//是否解除报警状态
|
|
|
@@ -208,10 +213,10 @@ public class DeviceInfoListener {
|
|
|
//存储报警信息 todo
|
|
|
String topic = WebSocketConstant.getDeviceStateCount(null, runState.name(), pump.getTenantId());
|
|
|
//获取报警设备数量
|
|
|
- List<BusPumpEntity> alarmList = deviceUsingService.list(new QueryWrapper<BusPumpEntity>()
|
|
|
+ List<BusDeviceUsingEntity> alarmList = deviceUsingService.list(new QueryWrapper<BusDeviceUsingEntity>()
|
|
|
.lambda()
|
|
|
- .select(BusPumpEntity::getId)
|
|
|
- .eq(BusPumpEntity::getRunState, runState));
|
|
|
+ .select(BusDeviceUsingEntity::getId)
|
|
|
+ .eq(BusDeviceUsingEntity::getRunState, runState));
|
|
|
//发送告警通知,获取报警设备数量, 下标为0是报警设备总数量,下标为1是设备所属医院的报警设备总数量
|
|
|
List<? extends Number> result = Arrays.asList(alarmList.size(), alarmList.stream().filter(alarm -> alarm.getTenantId().equals(pump.getTenantId())).count());
|
|
|
redisTemplate.convertAndSend(topic, result);
|
|
|
@@ -224,7 +229,7 @@ public class DeviceInfoListener {
|
|
|
* @param pump
|
|
|
* @param deviceOperator
|
|
|
*/
|
|
|
- private void initDevice(BusPumpEntity pump, DeviceOperator deviceOperator){
|
|
|
+ private void initDevice(BusDeviceUsingEntity pump, DeviceOperator deviceOperator){
|
|
|
//处理无泵状态(即泵首次与医院进行绑定)
|
|
|
Date now = new Date();
|
|
|
//设置注册时间和泵的开始时间
|
|
|
@@ -234,23 +239,33 @@ public class DeviceInfoListener {
|
|
|
pump.setAlias(deviceOperator.getAlias());
|
|
|
}
|
|
|
|
|
|
- // @Scheduled(cron = "0/10 * * * * ?")
|
|
|
- public void send(){
|
|
|
-// List<BusPumpEntity> list = deviceUsingService.list();
|
|
|
+ @Scheduled(cron = "0/20 * * * * ?")
|
|
|
+ public void send() throws InterruptedException {
|
|
|
+// List<BusDeviceUsingEntity> list = deviceUsingService.list();
|
|
|
// list.forEach(pump->{
|
|
|
+ BusDeviceUsingEntity pump = new BusDeviceUsingEntity();
|
|
|
+ pump.setDeviceId("123");
|
|
|
+ pump.setPatientCode("456");
|
|
|
+ pump.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
+ pump.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
+ pump.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
+ pump.setValidTime(RandomUtil.randomInt(100));
|
|
|
+ pump.setInvalidTime(RandomUtil.randomInt(100));
|
|
|
+ pump.setTotalCount(RandomUtil.randomInt(100));
|
|
|
+ SpringUtil.publishEvent(new DeviceInfoEvent(this,pump,pump.getDeviceId()));
|
|
|
+
|
|
|
+ Thread.sleep(5000);
|
|
|
|
|
|
- ThreadUtil.concurrencyTest(1,()-> {
|
|
|
- BusPumpEntity pump = new BusPumpEntity();
|
|
|
- pump.setDeviceId("123");
|
|
|
- pump.setPatientCode("456");
|
|
|
- pump.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
- pump.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
- pump.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
- pump.setValidTime(RandomUtil.randomInt(100));
|
|
|
- pump.setInvalidTime(RandomUtil.randomInt(100));
|
|
|
- pump.setTotalCount(RandomUtil.randomInt(100));
|
|
|
- SpringUtil.publishEvent(new DeviceInfoEvent(this,pump,pump.getDeviceId()));
|
|
|
- });
|
|
|
+ BusDeviceUsingEntity pump1 = new BusDeviceUsingEntity();
|
|
|
+ pump1.setDeviceId("567");
|
|
|
+ pump1.setPatientCode("456");
|
|
|
+ pump1.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
+ pump1.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
+ pump1.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
+ pump1.setValidTime(RandomUtil.randomInt(100));
|
|
|
+ pump1.setInvalidTime(RandomUtil.randomInt(100));
|
|
|
+ pump1.setTotalCount(RandomUtil.randomInt(100));
|
|
|
+ SpringUtil.publishEvent(new DeviceInfoEvent(this,pump1,pump1.getDeviceId()));
|
|
|
// });
|
|
|
}
|
|
|
}
|