|
@@ -8,12 +8,13 @@ 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.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.DeviceRegistry;
|
|
import com.coffee.bus.registry.device.DeviceRegistry;
|
|
|
import com.coffee.bus.entity.BusPumpEntity;
|
|
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.DeviceCacheInfo;
|
|
|
|
|
+import com.coffee.bus.registry.device.bean.DeviceOperator;
|
|
|
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;
|
|
@@ -67,31 +68,30 @@ public class DeviceInfoListener {
|
|
|
@Async
|
|
@Async
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void deviceInfoDetail(DeviceInfoEvent infoEvent){
|
|
public void deviceInfoDetail(DeviceInfoEvent infoEvent){
|
|
|
|
|
+ //若数据发送过快,为防止冲突,请在此加锁处理 todo
|
|
|
/****************处理泵数据****************/
|
|
/****************处理泵数据****************/
|
|
|
BusPumpEntity device = infoEvent.getContent();
|
|
BusPumpEntity device = infoEvent.getContent();
|
|
|
//1、判断该设备是否已和医院绑定并开启使用
|
|
//1、判断该设备是否已和医院绑定并开启使用
|
|
|
String deviceId = device.getDeviceId();
|
|
String deviceId = device.getDeviceId();
|
|
|
- DeviceOperator deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
|
|
|
|
|
+ DeviceOperator<DeviceCacheInfo> deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
|
PatientOperator patientOperator =null;
|
|
PatientOperator patientOperator =null;
|
|
|
- if (!deviceOperator.canUse()) {
|
|
|
|
|
|
|
+ if (deviceOperator==null||!Boolean.TRUE.equals(deviceOperator.getEnable())) {
|
|
|
log.warn("设备[{}]暂不可用,数据已丢弃",deviceId);
|
|
log.warn("设备[{}]暂不可用,数据已丢弃",deviceId);
|
|
|
return ;
|
|
return ;
|
|
|
}
|
|
}
|
|
|
log.info("接收到设备数据:[{}]",infoEvent.getContent().toString());
|
|
log.info("接收到设备数据:[{}]",infoEvent.getContent().toString());
|
|
|
device.setMonitorType(1);
|
|
device.setMonitorType(1);
|
|
|
- //首次运行需要与病人、医院进行绑定
|
|
|
|
|
- if(deviceOperator.isFirst()){
|
|
|
|
|
|
|
+ //不存在运行id,即首次运行,需要与病人、医院进行绑定
|
|
|
|
|
+ String usingId = deviceOperator.getUsingId();
|
|
|
|
|
+ if(StrUtil.isEmpty(usingId)){
|
|
|
initDevice(device,deviceOperator);
|
|
initDevice(device,deviceOperator);
|
|
|
|
|
+ //todo
|
|
|
patientOperator = patientRegistry.getPatient(device.getTenantId(), device.getPatientCode());
|
|
patientOperator = patientRegistry.getPatient(device.getTenantId(), device.getPatientCode());
|
|
|
initPatient(device,patientOperator);
|
|
initPatient(device,patientOperator);
|
|
|
- //二次确认
|
|
|
|
|
- deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
|
|
|
- if(device.getId().equals(deviceOperator.getRunId())){
|
|
|
|
|
- deviceUsingService.save(device);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ deviceUsingService.save(device);
|
|
|
}
|
|
}
|
|
|
else {
|
|
else {
|
|
|
- device.setId(deviceOperator.getRunId());
|
|
|
|
|
|
|
+ device.setId(usingId);
|
|
|
deviceUsingService.updateById(device);
|
|
deviceUsingService.updateById(device);
|
|
|
}
|
|
}
|
|
|
/****************处理泵数据****************/
|
|
/****************处理泵数据****************/
|
|
@@ -150,12 +150,20 @@ public class DeviceInfoListener {
|
|
|
|
|
|
|
|
/****************处理泵与患者关系****************/
|
|
/****************处理泵与患者关系****************/
|
|
|
|
|
|
|
|
- if(!deviceOperator.isFirst()){
|
|
|
|
|
- //非首次注册,则推送设备消息
|
|
|
|
|
- String topic = WebSocketConstant.getDeviceInfoDetailTopic(null, device.getId(), device.getTenantId());
|
|
|
|
|
- redisTemplate.convertAndSend(topic, device);
|
|
|
|
|
- }
|
|
|
|
|
-// SpringUtil.publishEvent(new DeviceAlarmEvent(this,device));
|
|
|
|
|
|
|
+ //则推送设备上报消息
|
|
|
|
|
+ String topic = WebSocketConstant.getDeviceInfoDetailTopic(null, device.getId(), device.getTenantId());
|
|
|
|
|
+ redisTemplate.convertAndSend(topic, device);
|
|
|
|
|
+
|
|
|
|
|
+ //更新设备缓存信息
|
|
|
|
|
+ DeviceCacheInfo cacheInfo = DeviceCacheInfo.builder()
|
|
|
|
|
+ .usingId(device.getId())
|
|
|
|
|
+ .status(device.getRunState())
|
|
|
|
|
+ .startTime(device.getStartTime())
|
|
|
|
|
+ .master(device.getMaster() == 1)
|
|
|
|
|
+ .patientCode(device.getPatientCode())
|
|
|
|
|
+ .mark(device.getMark())
|
|
|
|
|
+ .build();
|
|
|
|
|
+ deviceOperator.set(cacheInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -175,6 +183,7 @@ public class DeviceInfoListener {
|
|
|
* @param alarmEvent
|
|
* @param alarmEvent
|
|
|
*/
|
|
*/
|
|
|
@EventListener
|
|
@EventListener
|
|
|
|
|
+ @Async
|
|
|
public void deviceAlarm(DeviceAlarmEvent alarmEvent){
|
|
public void deviceAlarm(DeviceAlarmEvent alarmEvent){
|
|
|
BusPumpEntity pump = alarmEvent.getContent();
|
|
BusPumpEntity pump = alarmEvent.getContent();
|
|
|
//获取医院配置,对医院功能配置进行过滤筛选
|
|
//获取医院配置,对医院功能配置进行过滤筛选
|
|
@@ -204,19 +213,14 @@ public class DeviceInfoListener {
|
|
|
private void initDevice(BusPumpEntity pump, DeviceOperator deviceOperator){
|
|
private void initDevice(BusPumpEntity pump, DeviceOperator deviceOperator){
|
|
|
//处理无泵状态(即泵首次与医院进行绑定)
|
|
//处理无泵状态(即泵首次与医院进行绑定)
|
|
|
Date now = new Date();
|
|
Date now = new Date();
|
|
|
-
|
|
|
|
|
//设置注册时间和泵的开始时间
|
|
//设置注册时间和泵的开始时间
|
|
|
pump.setId(String.valueOf(IdWorker.getId()));
|
|
pump.setId(String.valueOf(IdWorker.getId()));
|
|
|
pump.setRegisterTime(now);
|
|
pump.setRegisterTime(now);
|
|
|
pump.setStartTime(now);
|
|
pump.setStartTime(now);
|
|
|
pump.setAlias(deviceOperator.getAlias());
|
|
pump.setAlias(deviceOperator.getAlias());
|
|
|
-
|
|
|
|
|
//设备绑定医院
|
|
//设备绑定医院
|
|
|
pump.setTenantId(deviceOperator.getTenantId());
|
|
pump.setTenantId(deviceOperator.getTenantId());
|
|
|
|
|
|
|
|
- //缓存存储泵的开始时间和注册时间 todo 缓存更新放在最后进行
|
|
|
|
|
- deviceOperator.updateStartTime(now);
|
|
|
|
|
- deviceOperator.updateRunId(pump.getId());
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Scheduled(cron = "0/50 * * * * ?")
|
|
@Scheduled(cron = "0/50 * * * * ?")
|