|
|
@@ -4,9 +4,14 @@ import cn.hutool.core.collection.CollectionUtil;
|
|
|
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.BusDeviceAlarmEntity;
|
|
|
import com.coffee.bus.entity.BusDeviceUsingEntity;
|
|
|
+import com.coffee.bus.enums.DeviceAlarmEnum;
|
|
|
+import com.coffee.bus.listener.event.bean.DeviceAlarmEvent;
|
|
|
+import com.coffee.bus.registry.constant.DeviceKeyConstant;
|
|
|
import com.coffee.bus.registry.device.DeviceRegistry;
|
|
|
import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
|
|
|
import com.coffee.bus.registry.device.bean.DeviceCacheInfo;
|
|
|
@@ -15,8 +20,10 @@ 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.LocalBusDeviceAlarmService;
|
|
|
import com.coffee.bus.service.LocalBusDeviceUsingService;
|
|
|
import com.coffee.bus.service.LocalBusPatientService;
|
|
|
+import com.coffee.common.cache.value.Value;
|
|
|
import com.coffee.common.config.websocket.WebSocketConstant;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -52,6 +59,7 @@ public class DeviceInfoListener {
|
|
|
|
|
|
private final PatientRegistry patientRegistry;
|
|
|
|
|
|
+ private final LocalBusDeviceAlarmService alarmService;
|
|
|
|
|
|
/**
|
|
|
* 监听上传的数据信息,
|
|
|
@@ -182,6 +190,7 @@ public class DeviceInfoListener {
|
|
|
.classification(device.getClassification())
|
|
|
.build();
|
|
|
deviceOperator.set(deviceCacheInfo);
|
|
|
+
|
|
|
//更新病人缓存信息
|
|
|
Set<DeviceTimeSmallInfo> allDevice = Optional.ofNullable(patientOperator.getAllDevice()).orElse(new HashSet<>());
|
|
|
allDevice.add(DeviceTimeSmallInfo.of(deviceId,device.getStartTime()));
|
|
|
@@ -223,12 +232,46 @@ public class DeviceInfoListener {
|
|
|
Date now = new Date();
|
|
|
//设置注册时间和泵的开始时间
|
|
|
pump.setId(String.valueOf(IdWorker.getId()));
|
|
|
- pump.setRegisterTime(now);
|
|
|
pump.setStartTime(now);
|
|
|
pump.setAlias(deviceOperator.getAlias());
|
|
|
}
|
|
|
|
|
|
-// @Scheduled(cron = "0/15 * * * * ?")
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否为报警信息并处理
|
|
|
+ * @param historyId 设备存储的历史数据id
|
|
|
+ * @param device 设备信息
|
|
|
+ * @param deviceOperator 设备操作符
|
|
|
+ */
|
|
|
+ private void handleAlarm(String historyId,BusDeviceUsingEntity device,DeviceOperator deviceOperator){
|
|
|
+ Value value = deviceOperator.getValue(DeviceKeyConstant.ALARM);
|
|
|
+ BusDeviceAlarmEntity alarm = new BusDeviceAlarmEntity(device.getDeviceId(),device.getAlarm(),new Date(),0,historyId,device.getClinicId(),device.getClassification());
|
|
|
+ if(Objects.isNull(value.get())){
|
|
|
+ if (device.getAlarm()==null) {
|
|
|
+ //未发生报警且上一信息不为报警信息,将报警信息置为历史信息
|
|
|
+ return;
|
|
|
+ }else {
|
|
|
+ //发生报警且上一信息不为报警信息, todo 处理报警信息
|
|
|
+ SpringUtil.publishEvent(new DeviceAlarmEvent(this,alarm,historyId));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ DeviceAlarmEnum beforeAlarm = value.as(DeviceAlarmEnum.class);
|
|
|
+ if (device.getAlarm()==null||device.getAlarm()!=beforeAlarm) {
|
|
|
+ //报警状态改变为过去式,将报警记录置为历史状态
|
|
|
+ alarmService.update(new UpdateWrapper<BusDeviceAlarmEntity>().lambda()
|
|
|
+ .eq(BusDeviceAlarmEntity::getDeviceId,device.getDeviceId())
|
|
|
+ .eq(BusDeviceAlarmEntity::getDoing,0)
|
|
|
+ .set(BusDeviceAlarmEntity::getDoing,1));
|
|
|
+ SpringUtil.publishEvent(new DeviceAlarmEvent(this,alarm,historyId));
|
|
|
+ } else {
|
|
|
+ //重复报警
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // @Scheduled(cron = "0/15 * * * * ?")
|
|
|
public void send() throws InterruptedException {
|
|
|
// List<BusDeviceUsingEntity> list = deviceUsingService.list();
|
|
|
// list.forEach(pump->{
|