|
|
@@ -1,5 +1,6 @@
|
|
|
package com.coffee.bus.websocket.listener;
|
|
|
|
|
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
@@ -21,6 +22,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
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;
|
|
|
@@ -59,6 +61,7 @@ public class DeviceInfoListener {
|
|
|
* @param infoEvent
|
|
|
*/
|
|
|
@EventListener
|
|
|
+ @Async
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void deviceInfoDetail(DeviceInfoEvent infoEvent){
|
|
|
BusPumpEntity device = infoEvent.getContent();
|
|
|
@@ -66,37 +69,39 @@ public class DeviceInfoListener {
|
|
|
String deviceId = device.getDeviceId();
|
|
|
DeviceOperator deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
|
if (!deviceOperator.canUse()) {
|
|
|
- log.warn("设备[{}]暂不可用,数据已丢弃");
|
|
|
+ log.warn("设备[{}]暂不可用,数据已丢弃",deviceId);
|
|
|
return ;
|
|
|
}
|
|
|
+ log.info("接收到设备数据:[{}]",infoEvent.getContent().toString());
|
|
|
device.setMonitorType(1);
|
|
|
//首次运行需要与病人、医院进行绑定
|
|
|
if(deviceOperator.isFirst()){
|
|
|
initDevice(device,deviceOperator);
|
|
|
PatientOperator patientOperator = patientRegistry.getPatient(device.getTenantId(), device.getPatientCode());
|
|
|
initPatient(device,patientOperator);
|
|
|
- /**
|
|
|
- * 判断是否存在临床信息 ,拉取临床信息 todo
|
|
|
- * @see com.coffee.bus.registry.patient.PatientOperator 拉取病人信息
|
|
|
- */
|
|
|
- deviceRunInfoService.save(device);
|
|
|
+ //二次确认
|
|
|
+ deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
|
+ if(device.getId().equals(deviceOperator.getRunId())){
|
|
|
+ deviceRunInfoService.save(device);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
else {
|
|
|
-// fillDeviceInfoFromCache(device,deviceOperator);
|
|
|
-// deviceRunInfoService.updateById(device);
|
|
|
+ device.setId(deviceOperator.getRunId());
|
|
|
+ deviceRunInfoService.updateById(device);
|
|
|
}
|
|
|
|
|
|
//病号是否进行换泵操作
|
|
|
- if (patientService.isChangedDevice(device.getTenantId(),device.getPatientCode(),device.getDeviceId(),device.getStartTime())) {
|
|
|
- patientService.changePump(device.getTenantId(),device.getPatientCode(),device.getDeviceId());
|
|
|
- }
|
|
|
+// if (patientService.isChangedDevice(device.getTenantId(),device.getPatientCode(),device.getDeviceId(),device.getStartTime())) {
|
|
|
+// patientService.changePump(device.getTenantId(),device.getPatientCode(),device.getDeviceId());
|
|
|
+// }
|
|
|
//发送设备报警
|
|
|
if(!deviceOperator.isFirst()){
|
|
|
//非首次注册,则推送设备消息
|
|
|
String topic = WebSocketConstant.getDeviceInfoDetailTopic(null, device.getId(), device.getTenantId());
|
|
|
redisTemplate.convertAndSend(topic, device);
|
|
|
}
|
|
|
- SpringUtil.publishEvent(new DeviceAlarmEvent(this,device));
|
|
|
+// SpringUtil.publishEvent(new DeviceAlarmEvent(this,device));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -137,24 +142,6 @@ public class DeviceInfoListener {
|
|
|
|
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
-// * 从缓存中填充设备信息
|
|
|
-// */
|
|
|
-// public void fillDeviceInfoFromCache(BusPumpEntity device,DeviceOperator operator){
|
|
|
-// device.setStartTime(operator.getStartTime());
|
|
|
-// device.setRegisterTime(operator.getRegisterTime());
|
|
|
-// device.setPatientCode(operator.getPatientCode());
|
|
|
-// device.setPatientName(operator.getPatientName());
|
|
|
-// device.setPatientSex(operator.getGender());
|
|
|
-// device.setTenantId(operator.getTenantId());
|
|
|
-// device.setClinicId(operator.getClinicId());
|
|
|
-// device.setWard(operator.getWard());
|
|
|
-// device.setBedNo(operator.getBedNo());
|
|
|
-// device.setAlias(operator.getAlias());
|
|
|
-// device.setRemark(operator.getRemark());
|
|
|
-// device.setId(operator.getRunId());
|
|
|
-// }
|
|
|
-
|
|
|
/**
|
|
|
* 初始化设备状态
|
|
|
* @param pump
|
|
|
@@ -176,19 +163,26 @@ public class DeviceInfoListener {
|
|
|
//缓存存储泵的开始时间和注册时间
|
|
|
deviceOperator.updateRegisterTime(now);
|
|
|
deviceOperator.updateStartTime(now);
|
|
|
+ deviceOperator.updateRunId(pump.getId());
|
|
|
}
|
|
|
|
|
|
- @Scheduled(cron = "0/3 * * * * ?")
|
|
|
+ @Scheduled(cron = "0/10 * * * * ?")
|
|
|
public void send(){
|
|
|
- List<BusPumpEntity> list = deviceRunInfoService.list();
|
|
|
- list.forEach(pump->{
|
|
|
+// List<BusPumpEntity> list = deviceRunInfoService.list();
|
|
|
+// list.forEach(pump->{
|
|
|
+
|
|
|
+ ThreadUtil.concurrencyTest(30,()-> {
|
|
|
+ BusPumpEntity pump = new BusPumpEntity();
|
|
|
+ pump.setDeviceId("123");
|
|
|
+ pump.setPatientCode("456");
|
|
|
pump.setRemainQuantity(BigDecimal.valueOf(RandomUtil.randomInt(100)));
|
|
|
pump.setContinueQuantity(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.getId()));
|
|
|
+ SpringUtil.publishEvent(new DeviceInfoEvent(this,pump,pump.getDeviceId()));
|
|
|
});
|
|
|
+// });
|
|
|
}
|
|
|
}
|