|
|
@@ -14,9 +14,11 @@ import com.coffee.bus.enums.NetPumpStatusEnum;
|
|
|
import com.coffee.bus.listener.event.bean.DeviceAlarmEvent;
|
|
|
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.device.DeviceOperator;
|
|
|
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.LocalBusPatientService;
|
|
|
import com.coffee.common.config.websocket.WebSocketConstant;
|
|
|
@@ -25,16 +27,13 @@ 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.Arrays;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.function.Supplier;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author lifang
|
|
|
@@ -69,101 +68,116 @@ public class DeviceInfoListener {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void deviceInfoDetail(DeviceInfoEvent infoEvent){
|
|
|
//若数据发送过快,为防止冲突,请在此加锁处理 todo
|
|
|
- /****************处理泵数据****************/
|
|
|
- BusPumpEntity device = infoEvent.getContent();
|
|
|
- //1、判断该设备是否已和医院绑定并开启使用
|
|
|
- String deviceId = device.getDeviceId();
|
|
|
- DeviceOperator<DeviceCacheInfo> deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
|
- PatientOperator patientOperator =null;
|
|
|
- if (deviceOperator==null||!Boolean.TRUE.equals(deviceOperator.getEnable())) {
|
|
|
- log.warn("设备[{}]暂不可用,数据已丢弃",deviceId);
|
|
|
- return ;
|
|
|
- }
|
|
|
- log.info("接收到设备数据:[{}]",infoEvent.getContent().toString());
|
|
|
- device.setMonitorType(1);
|
|
|
- //不存在运行id,即首次运行,需要与病人、医院进行绑定
|
|
|
- String usingId = deviceOperator.getUsingId();
|
|
|
- if(StrUtil.isEmpty(usingId)){
|
|
|
- initDevice(device,deviceOperator);
|
|
|
- //todo
|
|
|
- patientOperator = patientRegistry.getPatient(device.getTenantId(), device.getPatientCode());
|
|
|
- initPatient(device,patientOperator);
|
|
|
- deviceUsingService.save(device);
|
|
|
- }
|
|
|
- else {
|
|
|
- device.setId(usingId);
|
|
|
- deviceUsingService.updateById(device);
|
|
|
- }
|
|
|
- /****************处理泵数据****************/
|
|
|
+ synchronized (infoEvent.getDeviceId()){
|
|
|
+ /****************处理泵数据****************/
|
|
|
+ BusPumpEntity device = infoEvent.getContent();
|
|
|
+ //1、判断该设备是否已和医院绑定并开启使用
|
|
|
+ String deviceId = device.getDeviceId();
|
|
|
+ DeviceOperator<DeviceCacheInfo> deviceOperator = deviceRegistry.getDevice(deviceId);
|
|
|
+ if (deviceOperator==null||!Boolean.TRUE.equals(deviceOperator.getEnable())) {
|
|
|
+ log.warn("设备[{}]暂不可用,数据已丢弃",deviceId);
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ log.info("接收到设备数据:[{}]",infoEvent.getContent().toString());
|
|
|
+ String tenantId = deviceOperator.getTenantId();
|
|
|
+ PatientOperator<PatientCacheInfo> patientOperator =patientRegistry.getPatient(tenantId, device.getPatientCode());
|
|
|
+ device.setTenantId(tenantId);
|
|
|
+ device.setMonitorType(1);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ /****************处理泵数据****************/
|
|
|
|
|
|
- /****************处理泵与患者关系****************/
|
|
|
- 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);
|
|
|
+ /****************处理泵与患者关系****************/
|
|
|
+ //泵绑定重复判定
|
|
|
+ //获取病号当前绑定的泵号
|
|
|
+ String bindDeviceId = patientOperator.getBindDeviceId();
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StrUtil.isNullOrUndefined(bindDeviceId)) {
|
|
|
+ //之前的病号为无泵状态,无泵 -》 有泵 做处理 todo
|
|
|
}
|
|
|
- }else {
|
|
|
- patientOperator.updateDeviceId(deviceId);
|
|
|
- }
|
|
|
|
|
|
- //当泵所绑定的病号发生变化时,进行无泵判定
|
|
|
- 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;
|
|
|
+ //无泵判断处理
|
|
|
+ //上条记录所绑定的病号
|
|
|
+ String originPatientCode=deviceOperator.getPatientCode();
|
|
|
+ //当泵所绑定的病号发生变化时,进行原先泵号无泵判定
|
|
|
+ if(!device.getPatientCode().equals(originPatientCode)){
|
|
|
+ //检查是原先的病号是否发生了无泵异常
|
|
|
+ PatientOperator 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)){
|
|
|
+ //todo 发起无泵报警,处理原先泵的无泵信息
|
|
|
+ originPatientOperator.setBindDeviceId(null);
|
|
|
+ originPatientOperator.setAllDevice(new ArrayList<>());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //将开始时间最大的泵设置为主泵
|
|
|
+ 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));
|
|
|
+ //更新泵原来绑定病人缓存信息
|
|
|
+ originPatientOperator.setBindDeviceId(master.get().getDeviceId());
|
|
|
}
|
|
|
- })
|
|
|
- .orElseGet(new Supplier<BusPumpEntity>() {
|
|
|
- @Override
|
|
|
- public BusPumpEntity get() {
|
|
|
- //todo 发起无泵报警
|
|
|
- return null;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- if(master!=null){
|
|
|
- master.setMaster(1);
|
|
|
- deviceUsingService.updateById(master);
|
|
|
}
|
|
|
-
|
|
|
+ //更新泵原来绑定病人缓存信息
|
|
|
+ originPatientOperator.setAllDevice(originRemainPatientBindDevices);
|
|
|
}
|
|
|
+
|
|
|
+ /****************处理泵与患者关系****************/
|
|
|
+
|
|
|
+ //则推送设备上报消息
|
|
|
+ String topic = WebSocketConstant.getDeviceInfoDetailTopic(null, device.getId(), device.getTenantId());
|
|
|
+ redisTemplate.convertAndSend(topic, device);
|
|
|
+
|
|
|
+ //更新设备缓存信息
|
|
|
+ DeviceCacheInfo deviceCacheInfo = DeviceCacheInfo.builder()
|
|
|
+ .tenantId(device.getTenantId())
|
|
|
+ .usingId(device.getId())
|
|
|
+ .status(device.getRunState())
|
|
|
+ .startTime(device.getStartTime())
|
|
|
+ .master(device.getMaster() == 1)
|
|
|
+ .patientCode(device.getPatientCode())
|
|
|
+ .mark(device.getMark())
|
|
|
+ .build();
|
|
|
+ deviceOperator.set(deviceCacheInfo);
|
|
|
+ //更新病人缓存信息
|
|
|
+ Set allDevice = patientOperator.getAllDevice();
|
|
|
+ allDevice.add(DeviceTimeSmallInfo.of(deviceId,device.getStartTime()));
|
|
|
+ PatientCacheInfo patientCacheInfo = PatientCacheInfo.builder()
|
|
|
+ .bindDeviceId(deviceId)
|
|
|
+// .clinicId()
|
|
|
+ .code(device.getPatientCode())
|
|
|
+// .isFinished()
|
|
|
+// .name()
|
|
|
+// .startTime()
|
|
|
+ .tenantId(device.getTenantId())
|
|
|
+// .gender()
|
|
|
+ .devices(allDevice)
|
|
|
+ .build();
|
|
|
+ patientOperator.set(patientCacheInfo);
|
|
|
}
|
|
|
|
|
|
- /****************处理泵与患者关系****************/
|
|
|
-
|
|
|
- //则推送设备上报消息
|
|
|
- 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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -173,8 +187,8 @@ public class DeviceInfoListener {
|
|
|
*/
|
|
|
private void initPatient(BusPumpEntity pump, PatientOperator patientOperator) {
|
|
|
//填充病人名称和病人性别
|
|
|
- pump.setPatientName(patientOperator.getPatientName(true));
|
|
|
- pump.setPatientSex(patientOperator.getPatientGender(true));
|
|
|
+ pump.setPatientName(patientOperator.getName());
|
|
|
+ pump.setPatientSex(patientOperator.getGender());
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -218,22 +232,19 @@ public class DeviceInfoListener {
|
|
|
pump.setRegisterTime(now);
|
|
|
pump.setStartTime(now);
|
|
|
pump.setAlias(deviceOperator.getAlias());
|
|
|
- //设备绑定医院
|
|
|
- pump.setTenantId(deviceOperator.getTenantId());
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- @Scheduled(cron = "0/50 * * * * ?")
|
|
|
+ // @Scheduled(cron = "0/10 * * * * ?")
|
|
|
public void send(){
|
|
|
// List<BusPumpEntity> list = deviceUsingService.list();
|
|
|
// list.forEach(pump->{
|
|
|
|
|
|
- ThreadUtil.concurrencyTest(5,()-> {
|
|
|
+ ThreadUtil.concurrencyTest(1,()-> {
|
|
|
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.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));
|