Selaa lähdekoodia

add 完善日志
add 记录阿里云消息id

A17404李放 3 vuotta sitten
vanhempi
commit
425d0f1a3d

+ 6 - 0
nb-common/src/main/java/com/nb/common/util/RedissonUtil.java

@@ -116,4 +116,10 @@ public class RedissonUtil {
                 .getScoredSortedSet(name);
     }
 
+
+    public int removeRangeScore(String name,double startScore, boolean startScoreInclusive, double endScore, boolean endScoreInclusive){
+        return this.getScoreRange(name)
+                .removeRangeByScore(startScore,startScoreInclusive,endScore, endScoreInclusive);
+    }
+
 }

+ 1 - 0
nb-system/src/main/java/com/nb/aliyun/AliyunConsumerGroupService.java

@@ -174,6 +174,7 @@ public class AliyunConsumerGroupService {
                 log.info("上传设备属性:【{}】",JSONUtil.toJsonStr(items));
                 BusDeviceRunningEntity deviceRunning = new BusDeviceRunningEntity();
                 deviceRunning.updateFieldsByItems(deviceName,items);
+                deviceRunning.setMsgId(messageId);
                 hospitalLog.setTenantId(deviceInfoListener.deviceInfoDetail(new DeviceInfoEvent(this,deviceRunning,deviceName)));
             }else if(topic.matches("[\\w\\/]+thing/lifecycle$")){// 设备生命周期
                 // 获取生命周期类型

+ 3 - 0
nb-system/src/main/java/com/nb/bus/entity/BusDeviceRunningEntity.java

@@ -33,6 +33,9 @@ import java.util.Optional;
 @ApiModel(value="设备运行状态", description="设备运行状态")
 public class BusDeviceRunningEntity extends CommonDeviceParam<String,String> {
 
+    @ApiModelProperty(value = "阿里云传输过来的消息id")
+    private String msgId;
+
     @ApiModelProperty(value = "公共-此次输注过程中到此为止的总追加量")
     private BigDecimal totalAppendDose;
 

+ 6 - 0
nb-system/src/main/java/com/nb/bus/entity/BusInfusionHistoryEntity.java

@@ -31,6 +31,11 @@ import java.util.Date;
 @ApiModel(value="设备输注历史信息记录", description="设备的classification标识每改变一次,就算一次新的输注记录")
 public class BusInfusionHistoryEntity extends CommonDeviceParam<String,String> {
 
+    @ApiModelProperty(value = "从阿里云接收到的消息id")
+    @JsonIgnore
+    @TableField(updateStrategy = FieldStrategy.NEVER)
+    private String msgId;
+
     @ApiModelProperty(value = "公共-此次输注过程中到此为止的总追加量")
     private BigDecimal totalAppendDose;
 
@@ -87,6 +92,7 @@ public class BusInfusionHistoryEntity extends CommonDeviceParam<String,String> {
         entity.setStartTime(running.getStartTime());
         entity.setPatientId(running.getPatientId());
         entity.setLastUploadTime(running.getUploadTime());
+        entity.setMsgId(running.getMsgId());
 //        if(DeviceStatusEnum.Shutdown.equals(running.getRunState())){
 //            entity.setFinished(true);
 //        }

+ 20 - 5
nb-system/src/main/java/com/nb/bus/hospital/config/HospitalFunctionAnalConfigHandler.java

@@ -2,6 +2,7 @@ package com.nb.bus.hospital.config;
 
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.nb.bus.hospital.config.bean.FunctionAnalConfig;
@@ -15,6 +16,7 @@ import com.nb.bus.utils.WsPublishUtils;
 import com.nb.common.cache.ConfigStorage;
 import com.nb.common.cache.value.Value;
 import com.nb.common.entity.AbstractMsgId;
+import com.nb.common.util.ExceptionUtil;
 import com.nb.common.util.RedissonUtil;
 import lombok.Builder;
 import lombok.Data;
@@ -107,11 +109,13 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
         }
 
         Long startTime=endTime-TimeUnit.MINUTES.toMillis(insufficientTime);
-
+        long now = System.currentTimeMillis();
+        long delStartTime =now - TimeUnit.DAYS.toMillis(7);
         //获取该次输注过程中,以当前输注上传时间为结束时间,以判定时间区间为区间范围的时间窗口数据
         Collection<Object> valueRange = redissonUtil.getValueRange(analSortKey, startTime, true, endTime, true);
         if(CollUtil.isEmpty(valueRange)){
-            log.warn("设备【{}】判定低输注时,从缓存获取得分数据为空,设备信息【{}】",source.getId(), JSONUtil.toJsonStr(source));
+            //缓存中只保留7天的历史数据
+            log.warn("消息【{}】,设备【{}】判定低输注时,从缓存获取得分数据为空,设备信息【{}】",source.getMsgId(),source.getId(), JSONUtil.toJsonStr(source));
             return;
         }
         List<AnalEntity> anals = valueRange.stream().map(Value::simple).map(value -> value.as(AnalEntity.class)).collect(Collectors.toList());
@@ -130,7 +134,7 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
                 subCount=Math.subtractExact(source.getPcaInvalidCount(), Optional.ofNullable(firstAnal.getPcaInvalidCount()).orElse(0));
             }
             if(subCount>=analConfig.getInsufficientCount()){
-                log.info("设备:{}镇痛不足--实时判定",source.getDeviceId());
+                log.info("消息【{}】,设备【{}】由引起镇痛不足--实时判定",source.getMsgId(),source.getDeviceId());
                 source.setWarnAnalgesicPoor(true);
                 //镇痛消失延迟队列
                 RDelayedQueue<AbstractMsgId> noneAnalDelayedQueue = redissonUtil.getDelayedQueue("none-" + getId(), e -> {
@@ -143,6 +147,7 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
                         .tenantId(firstAnal.getTenantId())
                         .timeout(analConfig.getDisappearTime())
                         .unit(TimeUnit.MINUTES)
+                        .iotMsgId(source.getMsgId())
                         .infusionId(firstAnal.getInfusionId())
                         .historyId(firstAnal.getHistoryId())
                         .timestamp(new Date())
@@ -150,14 +155,20 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
                 redissonUtil.offerQueue(noneAnalDelayedQueue,noneAnal,noneAnal.getTimeout(),noneAnal.getUnit());
             }
         }catch (Exception e){
-            log.debug("镇痛不足缓存解析失败,设备号【{}】",source.getDeviceId(),e);
+            log.debug("消息【{}】,镇痛不足缓存解析失败,设备号【{}】",source.getMsgId(),source.getDeviceId(), ExceptionUtil.getExceptionMsg(e));
         }
 
+        int delCount = redissonUtil.removeRangeScore(analSortKey, delStartTime, true, startTime, false);
+        if(delCount!=0){
+            log.info("消息【{}】,设备【{}】清除了【{}】-【{}】时间段内【{}】条PCA缓存数据",source.getMsgId(),source.getDeviceId(),new Date(delStartTime),new Date(now),delCount);
+        }
     }
 
 
     /**
      * 描述: 镇痛消失处理
+     * 取消镇痛时,谨遵询谁引起谁取消的原则
+     * 即根据阿里云所发送的消息id进行判定
      * @author lifang
      * @date 2022/5/30 21:09
      * @param noneAnal
@@ -172,9 +183,12 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
         }
         //镇痛不足取消
         if(Boolean.TRUE.equals(infusionHistory.getWarnAnalgesicPoor())){
-            log.info("设备:{}取消镇痛不足",deviceId);
+            log.info("消息【{}】,设备【{}】取消镇痛不足",noneAnal.getIotMsgId(),deviceId);
+            //那条消息引起的镇痛不足,就由那条消息的取消镇痛不足任务来结束
             infusionHistoryService.update(new UpdateWrapper<BusInfusionHistoryEntity>().lambda()
                     .eq(BusInfusionHistoryEntity::getId,infusionHistory.getId())
+                    .eq(BusInfusionHistoryEntity::getWarnAnalgesicPoor,true)
+                    .eq(BusInfusionHistoryEntity::getMsgId,noneAnal.getIotMsgId())
                     .set(BusInfusionHistoryEntity::getWarnAnalgesicPoor,false));
             deviceRegistry.getOperator(deviceId).setAlarmOrWarn(null);
             //发布推送
@@ -209,6 +223,7 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
         private String historyId;
         private Date timestamp;
         private String infusionId;
+        private String iotMsgId;
     }
 
 }

+ 22 - 1
nb-system/src/main/java/com/nb/bus/websocket/listener/DeviceInfoListener.java

@@ -89,7 +89,7 @@ public class DeviceInfoListener {
             BusDeviceRunningEntity device = infoEvent.getContent();
             String classification = device.getClassification();
             if(StrUtil.isBlank(classification)){
-                log.error("设备号:[{}]分包标识号为空,无法更新开始时间");
+                log.error("消息【{}】,设备号:【{}】分包标识号为空,无法更新开始时间",device.getMsgId(),device.getDeviceId());
                 throw new RuntimeException("设备数据中分包标识不能为空");
             }
             long startTime = System.currentTimeMillis();
@@ -104,14 +104,29 @@ public class DeviceInfoListener {
 
             //处理输注参数
             BusInfusionHistoryEntity infusionHistory = handleInfusionHistory(device, deviceOperator, cacheOperation);
+            if(log.isDebugEnabled()){
+                log.debug("消息【{}】,设备号【{}】处理输注参数成功",device.getMsgId(),device.getDeviceId());
+            }
             //格式化病号
             formatPatientCode(device);
+            if(log.isDebugEnabled()){
+                log.debug("消息【{}】,设备号【{}】格式化病号",device.getMsgId(),device.getDeviceId());
+            }
             //处理输注修改参数,处理病人信息
             handleInfusionModify(device,deviceOperator,cacheOperation);
+            if(log.isDebugEnabled()){
+                log.debug("消息【{}】,设备号【{}】处理输注修改参数、病人信息成功",device.getMsgId(),device.getDeviceId());
+            }
             //处理历史运行数据
             BusDeviceHistoryEntity history=handleRunningHistory(device);
+            if(log.isDebugEnabled()){
+                log.debug("消息【{}】,设备号【{}】处理历史运行数据成功",device.getMsgId(),device.getDeviceId());
+            }
             //处理报警、提醒信息
             handleAlarmOrWarn(history,deviceOperator,cacheOperation);
+            if(log.isDebugEnabled()){
+                log.debug("消息【{}】,设备号【{}】处理报警、提醒信息成功",device.getMsgId(),device.getDeviceId());
+            }
             //根据功能配置进行最后的一些状态处理
             handleHospitalConfigLast(device,infusionHistory);
             if(device.isNewInfusion()){
@@ -121,8 +136,14 @@ public class DeviceInfoListener {
                         .set(BusDeviceEntity::getInfusionId,device.getInfusionId())
                 );
                 infusionHistoryService.save(infusionHistory);
+                if(log.isDebugEnabled()){
+                    log.debug("消息【{}】,设备号【{}】产生了新的输注【{}】",device.getMsgId(),device.getDeviceId(),device.getInfusionId());
+                }
             }else {
                 infusionHistoryService.updateById(infusionHistory);
+                if(log.isDebugEnabled()){
+                    log.debug("消息【{}】,设备号【{}】更新了输注【{}】",device.getMsgId(),device.getDeviceId(),device.getInfusionId());
+                }
             }
 
             cacheOperation.add(()->{