瀏覽代碼

fix 输注历史数据处理,设备历史数据处理

龙三郎 3 年之前
父節點
當前提交
b6abfee4be

+ 21 - 34
coffee-system/src/main/java/com/coffee/aliyun/AliyunConsumerGroupService.java

@@ -7,12 +7,14 @@ import com.coffee.aliyun.utils.Constants;
 import com.coffee.aliyun.utils.Items;
 import com.coffee.bus.bean.AliIotConfig;
 import com.coffee.bus.entity.BusDeviceEntity;
+import com.coffee.bus.entity.BusDeviceHistoryEntity;
 import com.coffee.bus.entity.BusDeviceRunningEntity;
 import com.coffee.bus.entity.BusInfusionHistoryEntity;
-import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
+import com.coffee.bus.service.LocalBusDeviceHistoryService;
 import com.coffee.bus.service.LocalBusDeviceService;
 import com.coffee.bus.service.LocalBusInfusionHistoryService;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Lazy;
@@ -48,7 +50,9 @@ public class AliyunConsumerGroupService {
     @Lazy
     private LocalBusInfusionHistoryService infusionHistoryService;
 
-
+    @Autowired
+    @Lazy
+    private LocalBusDeviceHistoryService deviceHistoryService;
 
     @Value("${aliyun.server-subscription.enable:false}")
     private boolean isEnable;
@@ -127,48 +131,33 @@ public class AliyunConsumerGroupService {
             Date now = new Date();
             // 根据topic判断数据类型
             if (topic.matches("^/as/mqtt/status/[\\w\\/]*")){//设备上下线状态
+                BusDeviceEntity device = new BusDeviceEntity();
+                device.setDeviceId(deviceName);
                 String status = content.getString(STATUS);
                 if (status.equals("online")){
                     log.info(deviceName+"设备上线");
+                    device.setStatus(1);
                 }else if (status.equals("offline")){
                     log.info(deviceName+"设备下线");
+                    device.setStatus(2);
                 }else {
                     log.info(deviceName+"设备未激活");
+                    device.setStatus(0);
                 }
+                // 更新设备状态
+                deviceService.updateByDeviceId(device);
             }else if (topic.matches("[\\w\\/]*event/property/post$")){//设备属性上报
-                /**
-                 * platformData:
-                 * {
-                 * "topic":"/a1M7k1TAECc/ceshi001/thing/event/property/post",
-                 * "messageId":"1496410088574460416",
-                 * "content":"{\"deviceType\":\"CustomCategory\",
-                 * \"iotId\":\"0syOzMqwkGebZBGKa08d000000\",
-                 * \"requestId\":\"254\",\"checkFailedData\":{},
-                 * \"productKey\":\"a1M7k1TAECc\",\"gmtCreate\":1645606941721,
-                 * \"deviceName\":\"ceshi001\",
-                 * \"items\":{
-                 * \"total\":{\"value\":100,\"time\":1645606941717},
-                 * \"pumpCode\":{\"value\":\"5719512336330299\",\"time\":1645606941717},
-                 * \"dataNumber\":{\"value\":254,\"time\":1645606941717},
-                 * \"PCAInvalid\":{\"value\":0,\"time\":1645606941717},
-                 * \"alarm\":{\"value\":0,\"time\":1645606941717},
-                 * \"flowRate\":{\"value\":2,\"time\":1645606941717},
-                 * \"PCAValid\":{\"value\":0,\"time\":1645606941717},
-                 * \"forecast\":{\"value\":0,\"time\":1645606941717},
-                 * \"finished\":{\"value\":17,\"time\":1645606941717},
-                 * \"battery\":{\"value\":65,\"time\":1645606941717},
-                 * \"runStatus\":{\"value\":2,\"time\":1645606941717},
-                 * \"patientCode\":{\"value\":111110000,\"time\":1645606941717}}}"
-                 * }
-                 */
                 // 设备属性集合
                 Items items = new Items(content.getJSONObject("items"));
                 BusInfusionHistoryEntity infusionHistory = infusionHistoryService.saveInfusion(deviceName,items);
-
-
-                // 发布设备信息事件。处理完毕,传向下一步处理
-                DeviceInfoEvent deviceInfoEvent = new DeviceInfoEvent(this,new BusDeviceRunningEntity(),"123456");
-                SpringUtil.publishEvent(deviceInfoEvent);
+                // 保存到device_history表中
+                BusDeviceHistoryEntity deviceHistory = new BusDeviceHistoryEntity();
+                // 将infusionHistory对象的值,复制到deviceHistory对象
+                BeanUtils.copyProperties(infusionHistory,deviceHistory);
+                deviceHistory.setId(null);
+                deviceHistory.setInfusionId(infusionHistory.getId());
+                // 保存设备的历史数据
+                deviceHistoryService.save(deviceHistory);
 
             }else if(topic.matches("[\\w\\/]+thing/lifecycle$")){// 设备生命周期
                 // 获取生命周期类型
@@ -197,8 +186,6 @@ public class AliyunConsumerGroupService {
                     deviceService.removeByDeviceId(deviceName);
                 }
 
-
-
             }else {
                 log.error("未知的topic:"+topic);
             }

+ 21 - 0
coffee-system/src/main/java/com/coffee/aliyun/utils/DeviceAlarmUtils.java

@@ -0,0 +1,21 @@
+package com.coffee.aliyun.utils;
+
+import com.coffee.bus.enums.DeviceAlarmEnum;
+
+/**
+ * @Author 龙三郎
+ * @Date 2022-04-29 11:04:04
+ * @Version 1.0
+ * @Description 根据阿里云发送的报警标识,获取报警枚举对象。阿里云发送的报警是0-9的整数。
+ */
+public class DeviceAlarmUtils {
+    public static DeviceAlarmEnum getAlarm(Integer i){
+        if (i == 0){
+            return DeviceAlarmEnum.Finished;
+        }else if (i == 1){
+            return DeviceAlarmEnum.Bubble;
+        }else {
+            return DeviceAlarmEnum.Finished;
+        }
+    }
+}

+ 22 - 0
coffee-system/src/main/java/com/coffee/aliyun/utils/DeviceRunStatusUtils.java

@@ -0,0 +1,22 @@
+package com.coffee.aliyun.utils;
+
+import com.coffee.bus.enums.DeviceAlarmEnum;
+import com.coffee.bus.enums.DeviceStatusEnum;
+
+/**
+ * @Author 龙三郎
+ * @Date 2022-04-29 11:36:03
+ * @Version 1.0
+ * @Description 根据阿里云发送的运行标识,获取运行枚举对象。阿里云发送的运行是0-4的整数。
+ */
+public class DeviceRunStatusUtils {
+    public static DeviceStatusEnum getRunStatus(Integer i){
+        if (i == 0){
+            return DeviceStatusEnum.Shutdown;
+        }else if (i == 1){
+            return DeviceStatusEnum.Running;
+        }else {
+            return DeviceStatusEnum.Shutdown;
+        }
+    }
+}

+ 26 - 0
coffee-system/src/main/java/com/coffee/aliyun/utils/DeviceTypeUtils.java

@@ -0,0 +1,26 @@
+package com.coffee.aliyun.utils;
+
+import com.coffee.bus.enums.DeviceAlarmEnum;
+import com.coffee.bus.enums.DeviceTypeEnum;
+
+/**
+ * @Author 龙三郎
+ * @Date 2022-04-29 11:52:36
+ * @Version 1.0
+ * @Description XXX
+ */
+public class DeviceTypeUtils {
+    public static DeviceTypeEnum getDeviceType(Integer i){
+        if (i == 0){
+            return DeviceTypeEnum.other;
+        }else if (i == 1){
+            return DeviceTypeEnum.continuous;
+        }else if (i == 2){
+            return DeviceTypeEnum.pulse;
+        }else if (i == 3){
+            return DeviceTypeEnum.intelligent;
+        }else {
+            return DeviceTypeEnum.other;
+        }
+    }
+}

+ 3 - 3
coffee-system/src/main/java/com/coffee/aliyun/utils/PumpParams.java

@@ -23,11 +23,11 @@ public enum PumpParams {
     bedNo("bedNo","床号"),
     totalDose("totalDose","总量"),
     maxDose("maxDose","极限量"),
-    singleDosis("singleDosis","追加量"),
+    singleDosis("singleDose","追加量"),
     lockTime("lockTime","锁时时间"),
     flow("flow","持续量"),
-    finishedDosis("finishedDosis","已输入量"),
-    firstDosis("firstDosis","首次量"),
+    finishedDose("finishedDose","已输入量"),
+    firstDosis("firstDose","首次量"),
     pcaValid("pcaValid","PCA有效次数"),
     pcaInvalid("pcaInvalid","PCA无效次数"),
     electricQuantity("electricQuantity","电池电量"),

+ 3 - 0
coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceEntity.java

@@ -63,4 +63,7 @@ public class BusDeviceEntity extends TenantGenericEntity<String,String> {
     @TableField(fill = FieldFill.INSERT)
     @TableLogic(value = "0",delval = "1")
     private Integer isDelete;
+
+    @ApiModelProperty(value = "设备在线状态,0未激活,1在线,2离线",readOnly = true)
+    private Integer status;
 }

+ 11 - 3
coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceHistoryEntity.java

@@ -39,10 +39,21 @@ public class BusDeviceHistoryEntity extends TenantGenericEntity<String,String> {
     @JsonIgnoreProperties
     private String deviceId;
 
+    @ApiModelProperty(value = "患者编号")
+    private String patientId;
+
     @ApiModelProperty(value = "输注记录id")
     @JsonIgnoreProperties
     private String infusionId;
 
+    @ApiModelProperty(value = "分包标记位",readOnly = true)
+    @JsonIgnoreProperties(allowSetters = true)
+    private String classification;
+
+    @ApiModelProperty(value = "数据编号",readOnly = true)
+    @JsonIgnoreProperties(allowSetters = true)
+    private String dataNumber;
+
     @ApiModelProperty(value = "输注修改记录id")
     @JsonIgnoreProperties
     private String infusionModifyId;
@@ -174,9 +185,6 @@ public class BusDeviceHistoryEntity extends TenantGenericEntity<String,String> {
     @JsonIgnoreProperties
     private Boolean master;
 
-    @ApiModelProperty(value = "分包标记位",readOnly = true)
-    @JsonIgnoreProperties(allowSetters = true)
-    private String classification;
 
     @ApiModelProperty(value = "泵类型",readOnly = true)
     @TableField(updateStrategy = FieldStrategy.NEVER)

+ 30 - 9
coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionHistoryEntity.java

@@ -1,8 +1,7 @@
 package com.coffee.bus.entity;
 
 import com.baomidou.mybatisplus.annotation.*;
-import com.coffee.aliyun.utils.Items;
-import com.coffee.aliyun.utils.PumpParams;
+import com.coffee.aliyun.utils.*;
 import com.coffee.bus.enums.DeviceAlarmEnum;
 import com.coffee.bus.enums.DeviceTypeEnum;
 import com.coffee.bus.enums.DeviceStatusEnum;
@@ -17,6 +16,7 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.ToString;
 import lombok.experimental.Accessors;
+
 import javax.validation.constraints.DecimalMax;
 import javax.validation.constraints.DecimalMin;
 import javax.validation.constraints.Max;
@@ -34,7 +34,7 @@ import java.util.Date;
 @ToString
 @Data
 @EqualsAndHashCode(callSuper = false)
-//@Accessors(chain = true)
+@Accessors(chain = true)
 @TableName(value = "bus_infusion_history",autoResultMap = true)
 @ApiModel(value="设备输注历史信息记录", description="设备的classification标识每改变一次,就算一次新的输注记录")
 public class BusInfusionHistoryEntity extends TenantGenericEntity<String,String> implements RecordCreationEntity, RecordModifierEntity {
@@ -47,7 +47,6 @@ public class BusInfusionHistoryEntity extends TenantGenericEntity<String,String>
     @ApiModelProperty(value = "患者编号")
     private String patientId;
 
-
     @ApiModelProperty(value = "数据分类号,标识某些数据属于同一个输注",readOnly = true)
     @JsonIgnoreProperties(allowSetters = true)
     private String classification;
@@ -169,10 +168,12 @@ public class BusInfusionHistoryEntity extends TenantGenericEntity<String,String>
     @DecimalMin(value = "0",message ="自调比例最小值不得超过0" )
     private BigDecimal flowAdjustRate;
 
-//    @ApiModelProperty(value = "加减档提示",readOnly = true)
-//    @TableField(updateStrategy = FieldStrategy.IGNORED)
-//    private FlowStatusEnum warnFlow;
+    @ApiModelProperty(value = "加减档提示",readOnly = true)
+    @TableField(updateStrategy = FieldStrategy.DEFAULT)
+    private FlowStatusEnum warnFlow;
 
+    @ApiModelProperty(value = "公共参数-电量",readOnly = true)
+    private Integer electricQuantity;
 
     @ApiModelProperty(value = "泵运行状态",readOnly = true)
     @TableField(updateStrategy = FieldStrategy.IGNORED)
@@ -286,11 +287,31 @@ public class BusInfusionHistoryEntity extends TenantGenericEntity<String,String>
      * @param items
      */
     public void setFiledsByItems(Items items) {
-        this.patientCode = items.getString(PumpParams.patientCode);
         this.classification = items.getString(PumpParams.classification);
         this.dataNumber = items.getString(PumpParams.dataNumber);
+        this.patientCode = items.getString(PumpParams.patientCode);
+        this.ward = items.getString(PumpParams.ward);
+        this.bedNo = items.getString(PumpParams.bedNo);
         this.totalDose = items.getInteger(PumpParams.totalDose);
-        this.inputDose = items.getBigDecimal(PumpParams.finishedDosis);
+        this.inputDose = items.getBigDecimal(PumpParams.finishedDose);
+        this.firstDose = items.getInteger(PumpParams.firstDosis);
+        this.maxDose = items.getBigDecimal(PumpParams.maxDose);
+        this.appendLockTime = items.getBigDecimal(PumpParams.lockTime);
+        this.continueDose = items.getBigDecimal(PumpParams.flow);
+        this.deviceType = DeviceTypeUtils.getDeviceType(items.getInteger(PumpParams.pumpType));
+        this.appendDose = items.getBigDecimal(PumpParams.singleDosis);
+        this.pcaValidCount = items.getInteger(PumpParams.pcaValid);
+        this.pcaInvalidCount = items.getInteger(PumpParams.pcaInvalid);
+        this.pcaTotalCount = this.pcaInvalidCount + this.pcaValidCount;
+        this.electricQuantity = items.getInteger(PumpParams.electricQuantity);
+
+        // 运行状态
+        this.runState = DeviceRunStatusUtils.getRunStatus(items.getInteger(PumpParams.runStatus));
+        // 报警
+        this.alarm = DeviceAlarmUtils.getAlarm(items.getInteger(PumpParams.alarmStatus));
+
+        // 预报
+
     }
 
     @Override

+ 12 - 16
coffee-system/src/main/java/com/coffee/bus/enums/FlowStatusEnum.java

@@ -1,19 +1,20 @@
 package com.coffee.bus.enums;
 
+import com.baomidou.mybatisplus.annotation.IEnum;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
 import lombok.Getter;
 
 /**
- * @Author XX
+ * @Author 龙三郎
  * @Date 2022-04-26 09:28:34
  * @Version 1.0
- * @Description XXX
+ * @Description 智能泵提示
  */
 @AllArgsConstructor
 @JsonFormat(shape = JsonFormat.Shape.OBJECT)
-public enum FlowStatusEnum {
+public enum FlowStatusEnum implements IEnum<Integer> {
     /**
      * 0 --- 正常(默认值)
      * 1 --- 加档受限
@@ -22,25 +23,20 @@ public enum FlowStatusEnum {
      * 4 --- 减档
      * 5 --- 低输注状态
      */
-//    DUFAULT, ADDLIMIT, HIGHEST, UP, DOWN, LOWEST
-
-    /**
-     * 请在添加或修改的过程中不要改变枚举的顺序!!!!!!!!!!!!!!!
-     * 如若新增,请在最后尾部新增
-     * 切记不可删除!!!!!!!!!!!!
-     */
-    Running(0,"正在运行"),
-    Waiting(1,"待机中"),
-    Shutdown(2,"关机");
-
+    None(0,"正常"),
+    Limited(1,"加档受限"),
+    MaxFlow(2,"流速已达上限"),
+    Up(3,"加档"),
+    Down(4,"减档"),
+    Lowest(5,"低输注状态");
 
     /**
      * 与枚举ordinal保持一致
      */
     @Getter
-    @ApiModelProperty("运行状态编码")
+    @ApiModelProperty("状态编码")
     private Integer value;
     @Getter
-    @ApiModelProperty("运行状态内容")
+    @ApiModelProperty("状态内容")
     private String text;
 }

+ 2 - 2
coffee-system/src/main/java/com/coffee/bus/listener/event/infusion/InfusionCreateEvent.java

@@ -5,10 +5,10 @@ import lombok.Getter;
 import org.springframework.context.ApplicationEvent;
 
 /**
- * @Author XX
+ * @Author 龙三郎
  * @Date 2022-04-26 14:42:27
  * @Version 1.0
- * @Description XXX
+ * @Description 输注开始事件,当泵刚开机时,会创建一个新的输注,此时会发布该事件。用途,临床管理模块可以监听该事件,去为该输注,获取临床数据
  */
 @Getter
 public class InfusionCreateEvent extends ApplicationEvent {

+ 2 - 2
coffee-system/src/main/java/com/coffee/bus/listener/event/infusion/InfusionUpdateEvent.java

@@ -5,10 +5,10 @@ import lombok.Getter;
 import org.springframework.context.ApplicationEvent;
 
 /**
- * @Author XX
+ * @Author 龙三郎
  * @Date 2022-04-26 14:42:27
  * @Version 1.0
- * @Description XXX
+ * @Description 网络泵发送数据的时候,输注管理模块会将最新的输注信息发布。输注监护模块可以订阅该事件,将数据推送到界面。
  */
 @Getter
 public class InfusionUpdateEvent extends ApplicationEvent {

+ 13 - 5
coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceService.java

@@ -86,6 +86,17 @@ public class LocalBusDeviceService extends BaseService<BusDeviceMapper, BusDevic
     }
 
     /**
+     * @author 龙三郎
+     * 根据deviceId更新设备在线状态
+     * @param device
+     */
+    public void updateByDeviceId(BusDeviceEntity device){
+        this.update(device,new QueryWrapper<BusDeviceEntity>().lambda()
+                .eq(BusDeviceEntity::getDeviceId,device.getDeviceId()));
+    }
+
+    /**
+     * @author 龙三郎
      * 添加设备
      * @param entity
      */
@@ -98,11 +109,8 @@ public class LocalBusDeviceService extends BaseService<BusDeviceMapper, BusDevic
         }
         // 设备存在
         if (Objects.nonNull(old)){
-            // 更新设备 ? 这里阿里云参数还会变化吗? 是不是需要每一次都更新,不可全部都更新,会影响其他数据为null
-            this.update(new UpdateWrapper<BusDeviceEntity>()
-                            .lambda()
-                            .eq(BusDeviceEntity::getDeviceId,entity.getDeviceId())
-                            .set(BusDeviceEntity::getConfig,entity.getConfig()));
+            // 更新设备
+            this.updateByDeviceId(entity);
         }else {
             // 添加设备
             this.save(entity);

+ 11 - 5
coffee-system/src/main/java/com/coffee/bus/service/LocalBusInfusionHistoryService.java

@@ -11,6 +11,7 @@ import com.coffee.bus.entity.BusDeviceEntity;
 import com.coffee.bus.entity.BusInfusionHistoryEntity;
 import com.coffee.bus.entity.BusPatientEntity;
 import com.coffee.bus.listener.event.infusion.InfusionCreateEvent;
+import com.coffee.bus.listener.event.infusion.InfusionUpdateEvent;
 import com.coffee.bus.mapper.BusInfusionHistoryMapper;
 import com.coffee.common.crud.BaseService;
 import jodd.util.ObjectUtil;
@@ -70,7 +71,8 @@ public class LocalBusInfusionHistoryService extends BaseService<BusInfusionHisto
         }
         // 第二步:判断输注是否存在,处理输注
         // 根据deviceId和分类标识查询输注
-        BusInfusionHistoryEntity infusion = getOneByDeviceIdAndClassification(deviceId,items.getString(PumpParams.classification));
+        String classification = items.getString(PumpParams.classification);
+        BusInfusionHistoryEntity infusion = getOneByDeviceIdAndClassification(deviceId,classification);
         // 输注是否存在
         boolean infusionIsExists = Objects.nonNull(infusion);
         if (!infusionIsExists){
@@ -81,15 +83,19 @@ public class LocalBusInfusionHistoryService extends BaseService<BusInfusionHisto
             infusion.setUpdateBy(Constants.DefaultUpdateBy);
             // 给输注设置租户id
             infusion.setTenantId(device.getTenantId());
+            // 根据阿里云发送的数据更新输注对象。
+            infusion.setFiledsByItems(items);
             // 根据住院号和医院获取一个患者
             BusPatientEntity patient = patientService.getOneByHospitalAndPatientCode(device.getTenantId(),items.getString(PumpParams.patientCode));
             infusion.setPatientId(patient.getId());
             // 添加一个输注
             this.save(infusion);
+        }else {
+            // 更新输注数据。
+            infusion.setFiledsByItems(items);
+            this.updateById(infusion);
         }
-        // 更新输注数据。
-        infusion.setFiledsByItems(items);
-        this.updateById(infusion);
+
 
         // 输注不存在,创建新的输注的时候,需要去请求临床数据
         if (!infusionIsExists){
@@ -98,7 +104,7 @@ public class LocalBusInfusionHistoryService extends BaseService<BusInfusionHisto
             SpringUtil.publishEvent(new InfusionCreateEvent(this,infusion));
         }else {
             // 输注数据更新事件
-            SpringUtil.publishEvent(new InfusionCreateEvent(this,infusion));
+            SpringUtil.publishEvent(new InfusionUpdateEvent(this,infusion));
         }
         return infusion;
     }