|
|
@@ -1,6 +1,7 @@
|
|
|
package com.coffee.bus.websocket.listener;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
@@ -68,6 +69,7 @@ public class DeviceInfoListener {
|
|
|
public void deviceInfoDetail(DeviceInfoEvent infoEvent){
|
|
|
//若数据发送过快,为防止冲突,请在此加锁处理 todo
|
|
|
synchronized (infoEvent.getDeviceId()){
|
|
|
+ log.info("开始处理时间------------------------[{}]",System.currentTimeMillis());
|
|
|
/****************处理泵数据****************/
|
|
|
BusDeviceUsingEntity device = infoEvent.getContent();
|
|
|
//1、判断该设备是否已和医院绑定并开启使用
|
|
|
@@ -78,7 +80,18 @@ public class DeviceInfoListener {
|
|
|
return ;
|
|
|
}
|
|
|
log.info("接收到设备数据:[{}]",infoEvent.getContent().toString());
|
|
|
-// deviceOperator.setStartTime(new Date());
|
|
|
+ /********************根据分包标记标识判断是否为新的开机时间*******************/
|
|
|
+ Integer mark = deviceOperator.getMark();
|
|
|
+ Integer deviceMark = device.getMark();
|
|
|
+ if(deviceMark==null){
|
|
|
+ log.error("设备号:[{}]分包标识号为空,无法更新开始时间");
|
|
|
+ deviceMark=-1;
|
|
|
+ }
|
|
|
+ if(!deviceMark.equals(mark)){
|
|
|
+ deviceOperator.setMark(deviceMark);
|
|
|
+ deviceOperator.setStartTime(new Date());
|
|
|
+ }
|
|
|
+ /********************根据分包标记标识判断是否为新的开机时间*******************/
|
|
|
String tenantId = deviceOperator.getTenantId();
|
|
|
PatientOperator<PatientCacheInfo> patientOperator =patientRegistry.getPatient(tenantId, device.getPatientCode());
|
|
|
device.setTenantId(tenantId);
|
|
|
@@ -106,6 +119,7 @@ public class DeviceInfoListener {
|
|
|
//泵号发生改变,判断泵的开始时间,将开始时间稍后的泵设置为主泵再与设备绑定
|
|
|
DeviceOperator currentBindDevice = deviceRegistry.getDevice(bindDeviceId);
|
|
|
if (currentBindDevice.getStartTime().before(device.getStartTime())) {
|
|
|
+ log.error("病号:[{}],之前主泵为:[{}],现在主泵为:[{}]",device.getPatientCode(),bindDeviceId,deviceId);
|
|
|
//设置当前上传信息的泵为主泵,将旧泵设置为副泵吗,并更新病人绑定泵的信息, todo 发生泵重复报警
|
|
|
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));
|
|
|
@@ -115,6 +129,7 @@ public class DeviceInfoListener {
|
|
|
}
|
|
|
if (StrUtil.isNullOrUndefined(bindDeviceId)) {
|
|
|
//之前的病号为无泵状态,无泵 -》 有泵 做处理 todo
|
|
|
+ log.error("病号:【{}】临床发生由无泵转为有泵",patientOperator.getCode());
|
|
|
}
|
|
|
|
|
|
//无泵判断处理
|
|
|
@@ -130,13 +145,19 @@ public class DeviceInfoListener {
|
|
|
//临床无泵绑定时,查看是否存在副泵,若存在将开始时间稍后的泵设置为副泵,若不存在,则报无泵异常
|
|
|
if(CollectionUtil.isEmpty(originRemainPatientBindDevices)){
|
|
|
//todo 发起无泵报警,处理原先泵的无泵信息
|
|
|
+ log.error("病号:【{}】临床发生无泵报警",originPatientOperator.getCode());
|
|
|
+
|
|
|
originPatientOperator.setBindDeviceId(null);
|
|
|
originPatientOperator.setAllDevice(new ArrayList<>());
|
|
|
}
|
|
|
else {
|
|
|
//将开始时间最大的泵设置为主泵
|
|
|
- Optional<DeviceTimeSmallInfo> master = originRemainPatientBindDevices.stream().max((o1,o2)->o1.getStartTime().before(o2.getStartTime()) ? 1 : 0);
|
|
|
+ Optional<DeviceTimeSmallInfo> master = originRemainPatientBindDevices.stream().max((o1,o2)->
|
|
|
+ o1.getStartTime().equals(o2.getStartTime())?0:o1.getStartTime().before(o2.getStartTime()) ? -1 : 1
|
|
|
+
|
|
|
+ );
|
|
|
if(master.isPresent()){
|
|
|
+ log.error("病号:[{}],主泵变为[{}]",originPatientCode,master.get().getDeviceId());
|
|
|
deviceUsingService
|
|
|
.update(new UpdateWrapper<BusDeviceUsingEntity>().lambda()
|
|
|
.eq(BusDeviceUsingEntity::getDeviceId,master.get().getDeviceId())
|
|
|
@@ -182,6 +203,7 @@ public class DeviceInfoListener {
|
|
|
.build();
|
|
|
patientOperator.set(patientCacheInfo);
|
|
|
}
|
|
|
+ log.info("结束处理时间------------------------[{}]",System.currentTimeMillis());
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -196,34 +218,6 @@ public class DeviceInfoListener {
|
|
|
pump.setPatientSex(patientOperator.getGender());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 监听设备的报警信息,
|
|
|
- * @param alarmEvent
|
|
|
- */
|
|
|
- @EventListener
|
|
|
- @Async
|
|
|
- public void deviceAlarm(DeviceAlarmEvent alarmEvent){
|
|
|
- BusDeviceUsingEntity pump = alarmEvent.getContent();
|
|
|
- //获取医院配置,对医院功能配置进行过滤筛选
|
|
|
- NetPumpStatusEnum runState = pump.getRunState();
|
|
|
- //是否解除报警状态
|
|
|
- if(runState!=null&&Boolean.TRUE.equals(runState.getAlarm())){
|
|
|
- //设备发生报警
|
|
|
- //存储报警信息 todo
|
|
|
- String topic = WebSocketConstant.getDeviceStateCount(null, runState.name(), pump.getTenantId());
|
|
|
- //获取报警设备数量
|
|
|
- List<BusDeviceUsingEntity> alarmList = deviceUsingService.list(new QueryWrapper<BusDeviceUsingEntity>()
|
|
|
- .lambda()
|
|
|
- .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);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 初始化设备状态
|
|
|
* @param pump
|
|
|
@@ -239,11 +233,12 @@ public class DeviceInfoListener {
|
|
|
pump.setAlias(deviceOperator.getAlias());
|
|
|
}
|
|
|
|
|
|
- @Scheduled(cron = "0/20 * * * * ?")
|
|
|
+ @Scheduled(cron = "0/15 * * * * ?")
|
|
|
public void send() throws InterruptedException {
|
|
|
// List<BusDeviceUsingEntity> list = deviceUsingService.list();
|
|
|
// list.forEach(pump->{
|
|
|
BusDeviceUsingEntity pump = new BusDeviceUsingEntity();
|
|
|
+ pump.setMark(1);
|
|
|
pump.setDeviceId("123");
|
|
|
pump.setPatientCode("456");
|
|
|
pump.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
@@ -257,7 +252,8 @@ public class DeviceInfoListener {
|
|
|
Thread.sleep(5000);
|
|
|
|
|
|
BusDeviceUsingEntity pump1 = new BusDeviceUsingEntity();
|
|
|
- pump1.setDeviceId("567");
|
|
|
+ pump1.setDeviceId("456");
|
|
|
+ pump1.setMark(1);
|
|
|
pump1.setPatientCode("456");
|
|
|
pump1.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
pump1.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
@@ -266,6 +262,20 @@ public class DeviceInfoListener {
|
|
|
pump1.setInvalidTime(RandomUtil.randomInt(100));
|
|
|
pump1.setTotalCount(RandomUtil.randomInt(100));
|
|
|
SpringUtil.publishEvent(new DeviceInfoEvent(this,pump1,pump1.getDeviceId()));
|
|
|
+
|
|
|
+ Thread.sleep(5000);
|
|
|
+
|
|
|
+ BusDeviceUsingEntity pump2 = new BusDeviceUsingEntity();
|
|
|
+ pump2.setDeviceId("456");
|
|
|
+ pump2.setMark(1);
|
|
|
+ pump2.setPatientCode("789");
|
|
|
+ pump2.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
+ pump2.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
+ pump2.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
+ pump2.setValidTime(RandomUtil.randomInt(100));
|
|
|
+ pump2.setInvalidTime(RandomUtil.randomInt(100));
|
|
|
+ pump2.setTotalCount(RandomUtil.randomInt(100));
|
|
|
+ SpringUtil.publishEvent(new DeviceInfoEvent(this,pump2,pump2.getDeviceId()));
|
|
|
// });
|
|
|
}
|
|
|
}
|