Sfoglia il codice sorgente

add 设备数据报警处理
add 设备数据历史数据处理
add 设备数据输注历史处理
add 设备数据输注参数处理

18339543638 3 anni fa
parent
commit
fe08a2f498
17 ha cambiato i file con 598 aggiunte e 350 eliminazioni
  1. 1 1
      coffee-system/src/main/java/com/coffee/bus/controller/BusAlarmController.java
  2. 4 12
      coffee-system/src/main/java/com/coffee/bus/controller/BusDocController.java
  3. 3 4
      coffee-system/src/main/java/com/coffee/bus/controller/BusHospitalConfigController.java
  4. 14 10
      coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceAlarmEntity.java
  5. 180 127
      coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceHistoryEntity.java
  6. 6 0
      coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceRunningEntity.java
  7. 4 1
      coffee-system/src/main/java/com/coffee/bus/entity/BusDocEntity.java
  8. 52 0
      coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionHistoryEntity.java
  9. 94 0
      coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionModifyEntity.java
  10. 1 1
      coffee-system/src/main/java/com/coffee/bus/enums/DeviceEnum.java
  11. 1 1
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceAlarmService.java
  12. 40 40
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceRunningService.java
  13. 0 7
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusDocService.java
  14. 1 1
      coffee-system/src/main/java/com/coffee/bus/service/constant/AbstractConstantService.java
  15. 0 51
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceAlarmListener.java
  16. 154 51
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java
  17. 43 43
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/HistoryInfoListener.java

+ 1 - 1
coffee-system/src/main/java/com/coffee/bus/controller/BusAlarmController.java

@@ -48,7 +48,7 @@ public class BusAlarmController extends BaseCrudController<BusDeviceAlarmEntity,
     }
 
     public static void main(String[] args) {
-        set(DeviceEnum.net);
+        set(DeviceEnum.continuous);
     }
 
 

+ 4 - 12
coffee-system/src/main/java/com/coffee/bus/controller/BusDocController.java

@@ -1,20 +1,12 @@
 package com.coffee.bus.controller;
 
-import cn.dev33.satoken.annotation.SaCheckPermission;
-import cn.dev33.satoken.exception.NotLoginException;
-import cn.dev33.satoken.stp.StpUtil;
-import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.Mapper;
-import com.coffee.bus.entity.BusDeviceEntity;
 import com.coffee.bus.entity.BusDocEntity;
-import com.coffee.bus.service.LocalBusDeviceService;
 import com.coffee.bus.service.LocalBusDocService;
-import com.coffee.common.bo.LoginUser;
 import com.coffee.common.crud.BaseService;
 import com.coffee.common.crud.controller.BaseCrudController;
 import com.coffee.common.result.R;
-import com.coffee.common.util.SecurityUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -47,13 +39,13 @@ public class BusDocController extends BaseCrudController<BusDocEntity, String> {
     }
 
 
-    @GetMapping("/get")
+    @GetMapping("/get/{type}")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "tenantId",value = "医院id",required = true,example = "当前用户医院id")
+            @ApiImplicitParam(name = "type",value = "文档分类",required = true,example = "文档分类")
     })
     @ApiOperation(value = "获取当前医院的宣教文档",notes = "当用户未登录、用户为系统用户、用户租户id为空时,返回值为空,权限为空")
-    public R getCurrentHospital(@RequestParam(value = "tenantId",required = false) String tenantId){
-        return  R.success(docService.getOne(new QueryWrapper<BusDocEntity>().lambda().eq(StrUtil.isNotEmpty(tenantId),BusDocEntity::getTenantId,tenantId)));
+    public R getCurrentHospital(@PathVariable(value = "type") String type){
+        return  R.success(docService.getOne(new QueryWrapper<BusDocEntity>().lambda().eq(BusDocEntity::getType,type)));
     }
 
     @Override

+ 3 - 4
coffee-system/src/main/java/com/coffee/bus/controller/BusHospitalConfigController.java

@@ -12,10 +12,7 @@ import com.coffee.common.result.R;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * @author lifang
@@ -53,6 +50,8 @@ public class BusHospitalConfigController extends BaseCrudController<BusHospitalC
     public R undoConfig(@RequestBody UndoConfig evalConfig){
         return R.success();
     }
+
+
     /**
      * 权限控制前缀
      * @return

+ 14 - 10
coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceAlarmEntity.java

@@ -51,11 +51,12 @@ public class BusDeviceAlarmEntity extends TenantGenericEntity<String,String> {
     @ApiModelProperty(value = "是否已处理 0、未处理,1、已处理,暂未使用")
     private Boolean dealing;
 
-
     @ApiModelProperty(value = "报警记录所绑定的历史记录id,后续用于更新操作",hidden = true)
     @JsonIgnoreProperties(allowSetters = true)
-    private String deviceHistoryId;
+    private String historyId;
 
+    @ApiModelProperty(value = "输注记录")
+    private String infusionId;
 
     @ApiModelProperty(value = "临床id",readOnly = true)
     private String clinicId;
@@ -65,13 +66,16 @@ public class BusDeviceAlarmEntity extends TenantGenericEntity<String,String> {
     @JsonIgnoreProperties(allowSetters = true)
     private String classification;
 
-    public BusDeviceAlarmEntity(String deviceId, DeviceAlarmEnum alarm, Date alarmTime, Boolean doing, String deviceHistoryId, String clinicId, String classification) {
-        this.deviceId = deviceId;
-        this.alarm = alarm;
-        this.alarmTime = alarmTime;
-        this.doing = doing;
-        this.deviceHistoryId = deviceHistoryId;
-        this.clinicId = clinicId;
-        this.classification = classification;
+    public static BusDeviceAlarmEntity parseRunningInfo(BusDeviceHistoryEntity history){
+        BusDeviceAlarmEntity entity = new BusDeviceAlarmEntity();
+        entity.setDeviceId(history.getDeviceId());
+        entity.setAlarm(history.getAlarm());
+        entity.setAlarmTime(history.getUploadTime());
+        entity.setHistoryId(history.getId());
+        entity.setInfusionId(history.getInfusionId());
+        entity.setClinicId(history.getClinicId());
+        entity.setClassification(history.getClassification());
+        entity.setTenantId(history.getTenantId());
+        return entity;
     }
 }

+ 180 - 127
coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceHistoryEntity.java

@@ -1,13 +1,14 @@
 package com.coffee.bus.entity;
 
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.coffee.bus.enums.DeviceAlarmEnum;
+import com.coffee.bus.enums.DeviceEnum;
 import com.coffee.bus.enums.DeviceStatusEnum;
-import com.coffee.bus.enums.DeviceWarnEnum;
 import com.coffee.common.config.mybatis.DateToBigIntHandler;
 import com.coffee.common.entity.TenantGenericEntity;
-import com.coffee.common.enums.SexEnum;
-import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -15,175 +16,227 @@ import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 import org.apache.ibatis.type.EnumOrdinalTypeHandler;
 
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.DecimalMin;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
 import java.math.BigDecimal;
 import java.util.Date;
 
 /**
- * <p>
- * 
- * </p>
- *
- * @author fanfan
- * @since 2020-07-03
- */
+ * @Author lifang
+ * @Date 10:52 2022/4/13
+ * @Description 设备历史运行数据记录
+ * @Param
+ * @return
+ **/
+
 @Data
 @EqualsAndHashCode(callSuper = false)
 @Accessors(chain = true)
-@TableName(value = "bus_pump_history",autoResultMap = true)
-@ApiModel(value="网络泵历史数据", description="")
+@TableName(value = "bus_device_history",autoResultMap = true)
+@ApiModel(value="设备历史运行数据", description="设备历史运行数据记录")
 public class BusDeviceHistoryEntity extends TenantGenericEntity<String,String> {
 
     @ApiModelProperty(value = "网络泵id")
+    @JsonIgnoreProperties
     private String deviceId;
 
     @ApiModelProperty(value = "临床id")
+    @JsonIgnoreProperties
     private String clinicId;
 
-    @ApiModelProperty(value = "病号")
-    private String patientCode;
+    @ApiModelProperty(value = "输注记录id")
+    @JsonIgnoreProperties
+    private String infusionId;
+
 
-    @ApiModelProperty(value = "病人名称")
-    private String patientName;
+    @ApiModelProperty(value = "总量",readOnly = true)
+    @Max(value = 999,message = "总量最大值不得超过999")
+    @Min(value = 0,message ="总量最小值不得超过0" )
+    private Integer totalDose;
 
-    @ApiModelProperty(value = "别名")
-    private String alias;
+    @ApiModelProperty(value = "公共参数-首次量",readOnly = true)
+    @Max(value = 50,message = "首次量最大值不得超过50")
+    @Min(value = 0,message ="首次量最小值不得超过0" )
+    private Integer firstDose;
 
-    @ApiModelProperty(value = "病人性别")
-    @TableField(typeHandler = EnumOrdinalTypeHandler.class)
-    private SexEnum patientSex;
 
-    @ApiModelProperty(value = "病区")
-    private String ward;
+    @ApiModelProperty(value = "公共参数-剩余量",readOnly = true)
+    private BigDecimal remainDose;
 
-    @ApiModelProperty(value = "床号")
-    private String bedNo;
+    @ApiModelProperty(value = "公共参数-已输入量",readOnly = true)
+    private BigDecimal inputDose;
 
-    @ApiModelProperty(value = "剩余量")
-    private BigDecimal remainQuantity;
+    @ApiModelProperty(value = "公共参数-追加量",readOnly = true)
+    @DecimalMax(value = "10",message = "PCA追加量最大值不得超过10")
+    @DecimalMin(value = "0",message ="PCA追加量最小值不得超过0" )
+    private BigDecimal appendDose;
 
-    @ApiModelProperty(value = "持续量")
-    private BigDecimal continueQuantity;
+    @ApiModelProperty(value = "公共参数-追加锁时",readOnly = true)
+    @DecimalMax(value = "99",message = "PCA追加量最大值不得超过99")
+    @DecimalMin(value = "1",message ="PCA追加量最小值不得超过0" )
+    private BigDecimal appendLockTime;
 
-    @ApiModelProperty(value = "自控锁时")
+    @ApiModelProperty(value = "公共参数-极限量",readOnly = true)
+    @DecimalMax(value = "90",message = "PCA追加量最大值不得超过90")
+    @DecimalMin(value = "0",message ="PCA追加量最小值不得超过0" )
+    private BigDecimal maxDose;
+
+    @ApiModelProperty(value = "公共参数-自控锁时",readOnly = true)
     private BigDecimal selfControlLockTime;
 
-    @ApiModelProperty(value = "已输入量")
-    private BigDecimal inputQuantity;
+    @ApiModelProperty(value = "公共参数-自控次数",readOnly = true)
+    private BigDecimal selfControlCount;
+
+    @ApiModelProperty(value = "公共参数-pca有效次数",readOnly = true)
+    private Integer pcaValidCount;
+
+    @ApiModelProperty(value = "公共参数-pca无效次数",readOnly = true)
+    private Integer pcaInvalidCount;
+
+    @ApiModelProperty(value = "公共参数-pca总按次数",readOnly = true)
+    private Integer pcaTotalCount;
+
+    @ApiModelProperty(value = "持续泵参数-持续量",readOnly = true)
+    @DecimalMax(value = "50",message = "持续给液量最大值不得超过50")
+    @DecimalMin(value = "0",message ="持续给液量最小值不得超过0" )
+    private BigDecimal continueDose;
+
+    @ApiModelProperty(value = "脉冲泵参数-脉冲量",readOnly = true)
+    @Max(value = 20,message = "脉冲量最大值不得超过20")
+    @Min(value = 0,message ="脉冲量最小值不得超过0" )
+    private Integer pulseDose;
 
-    @ApiModelProperty(value = "有效次数")
-    private Integer validTime;
+    @ApiModelProperty(value = "脉冲泵参数-脉冲锁时",readOnly = true)
+    @Max(value = 90,message = "脉冲锁时最大值不得超过90")
+    @Min(value = 30,message ="脉冲锁时最小值不得超过30" )
+    private Integer pulseLockTime;
 
-    @ApiModelProperty(value = "无效次数")
-    private Integer invalidTime;
+    @ApiModelProperty(value = "脉冲泵参数-脉冲首次锁时",readOnly = true)
+    @Max(value = 60,message = "脉冲首次锁时最大值不得超过60")
+    @Min(value = 0,message ="脉冲首次锁时最小值不得超过0" )
+    private Integer pulseFirstLockTime;
 
-    @ApiModelProperty(value = "极限量")
-    private BigDecimal maxQuantity;
+    @ApiModelProperty(value = "智能泵参数-加档周期",readOnly = true)
+    @DecimalMax(value = "10",message = "加档周期最大值不得超过10")
+    @DecimalMin(value = "0.5",message ="加档周期最小值不得超过0.5" )
+    private BigDecimal flowUpCycle;
 
-    @ApiModelProperty(value = "首次量")
-    private Integer firstQuantity;
+    @ApiModelProperty(value = "智能泵参数-减档周期",readOnly = true)
+    @DecimalMax(value = "10",message = "减档周期最大值不得超过10")
+    @DecimalMin(value = "0.5",message ="减档周期最小值不得超过0.5" )
+    private BigDecimal flowDownCycle;
 
-    @ApiModelProperty(value = "追加量")
-    private BigDecimal singleQuantity;
+    @ApiModelProperty(value = "智能泵参数-计次",readOnly = true)
+    @DecimalMax(value = "10",message = "PCA追加量最大值不得超过10")
+    @DecimalMin(value = "1",message ="PCA追加量最小值不得超过1" )
+    private BigDecimal flowCount;
 
-    @ApiModelProperty(value = "总量")
-    private Integer totalQuantity;
+    @ApiModelProperty(value = "智能泵参数-上限",readOnly = true)
+    @DecimalMax(value = "50",message = "智能泵上限值最大值不得超过90")
+    @DecimalMin(value = "1",message ="智能泵上限值最小值不得超过0" )
+    private BigDecimal flowUpLimit;
 
-    @ApiModelProperty(value = "总按次数")
-    private Integer totalCount;
+    @ApiModelProperty(value = "智能泵参数-下限",readOnly = true)
+    @DecimalMax(value = "50",message = "智能泵下限值最大值不得超过50")
+    @DecimalMin(value = "0.1",message ="智能泵下限值最小值不得超过0.1" )
+    private BigDecimal flowDownLimit;
 
+    @ApiModelProperty(value = "智能泵参数-自调比例",readOnly = true)
+    @DecimalMax(value = "95",message = "自调比例不得超过95")
+    @DecimalMin(value = "0",message ="自调比例最小值不得超过0" )
+    private BigDecimal flowAdjustRate;
 
-    @ApiModelProperty(value = "镇痛泵运行状态")
-    @TableField(typeHandler = EnumOrdinalTypeHandler.class)
+
+    @ApiModelProperty(value = "泵运行状态",readOnly = true)
+    @TableField(typeHandler = EnumOrdinalTypeHandler.class,javaType = true,updateStrategy = FieldStrategy.IGNORED)
     private DeviceStatusEnum runState;
 
-    @ApiModelProperty(value = "提醒信息")
-    @TableField(typeHandler = EnumOrdinalTypeHandler.class)
-    private DeviceWarnEnum warn;
+    @ApiModelProperty(value = "报警信息",readOnly = true)
+    @TableField(typeHandler = EnumOrdinalTypeHandler.class,javaType = true,updateStrategy = FieldStrategy.IGNORED)
+    private DeviceAlarmEnum alarm;
 
-    @ApiModelProperty(value = "开始时间")
-    @TableField(typeHandler = DateToBigIntHandler.class)
-    private Date startTime;
+    @ApiModelProperty(value = "报警原因")
+    private String alarmCause;
 
-    @ApiModelProperty(value = "是否已撤泵,0、未撤泵1、已撤泵")
-    private Integer isUndo;
+    @ApiModelProperty(value = "输注即将结束提醒",readOnly = true)
+    private Boolean warnWillFinished;
 
-    @ApiModelProperty(value = "备注")
-    private String remark;
+    @ApiModelProperty(value = "镇痛不足提醒",readOnly = true)
+    private Boolean warnAnalgesicPoor;
 
-    @ApiModelProperty(value = "最后上传时间")
-    @TableField(typeHandler = DateToBigIntHandler.class)
-    private Date lastUploadTime;
+    @ApiModelProperty(value = "电量偏低提醒",readOnly = true)
+    private Boolean warnLowBattery;
 
-    @TableField(typeHandler = DateToBigIntHandler.class)
-    private Date registerTime;
+    @ApiModelProperty(value = "是否已撤泵,0、未撤泵1、已撤泵")
+    @JsonIgnoreProperties
+    private Boolean isUndo;
 
-    @ApiModelProperty(value = "撤泵人")
-    private String undoBy;
+    @ApiModelProperty(value = "是否为主泵数据, 0、副泵 1、主泵(即当前临床绑定的泵)")
+    @JsonIgnoreProperties
+    private Boolean master;
 
-    @ApiModelProperty(value = "销毁人")
-    private String destroyer;
+    @ApiModelProperty(value = "分包标记位",readOnly = true)
+    @JsonIgnoreProperties(allowSetters = true)
+    private String classification;
 
-    @ApiModelProperty(value = "见证人")
-    private String witnesses;
+    @ApiModelProperty(value = "泵类型",readOnly = true)
+    @TableField(typeHandler = EnumOrdinalTypeHandler.class,javaType = true,updateStrategy = FieldStrategy.NEVER)
+    private DeviceEnum type;
 
+    @ApiModelProperty(value = "数据上传时间",readOnly = true,hidden = true)
     @TableField(typeHandler = DateToBigIntHandler.class)
-    private Date undoTime;
-
-    @ApiModelProperty(value = "监护类型,1、有泵监护 2、无泵监护")
-    private Integer monitorType;
-
-    @ApiModelProperty(value = "是否为主泵数据")
-    private Integer master;
-
-    @ApiModelProperty(value = "当his信息不存在时,向his发起的请求id",hidden = true)
-    @TableField(exist = false)
-    @JsonIgnore
-    private Long requestId;
-
-    @ApiModelProperty(value = "泵类型")
-    private String type;
-    /**
-     * 填充临床信息
-     * @param clinic
-     */
-    public void fillClinic(BusClinicEntity clinic){
-        this.clinicId=clinic.getId();
-        this.patientName=clinic.getPatientName();
-        this.patientSex=clinic.getPatientGender();
-        this.ward=clinic.getWard();
-        this.bedNo=clinic.getBedNo();
-    }
-
-    public static BusDeviceHistoryEntity of(BusDeviceRunningEntity pump, BusClinicEntity clinic){
-        BusDeviceHistoryEntity history = new BusDeviceHistoryEntity();
-
-        //临床信息
-        history.setClinicId(clinic.getId());
-        history.setPatientCode(clinic.getPatientCode());
-        history.setWard(clinic.getWard());
-        history.setBedNo(clinic.getBedNo());
-
-        //设备信息
-        history.setDeviceId(pump.getDeviceId());
-        history.setTenantId(pump.getTenantId());
-        history.setPatientName(pump.getPatientName());
-        history.setPatientSex(pump.getPatientSex());
-        history.setAlias(pump.getAlias());
-        history.setRemainQuantity(pump.getRemainDose());
-        history.setContinueQuantity(pump.getContinueDose());
-        history.setSelfControlLockTime(pump.getSelfControlLockTime());
-        history.setInputQuantity(pump.getInputDose());
-        history.setValidTime(pump.getPcaValidCount());
-        history.setInvalidTime(pump.getPcaInvalidCount());
-        history.setMaxQuantity(pump.getMaxDose());
-        history.setFirstQuantity(pump.getFirstDose());
-        history.setSingleQuantity(pump.getAppendDose());
-        history.setTotalQuantity(pump.getTotalDose());
-        history.setTotalCount(pump.getPcaTotalCount());
-        history.setRunState(pump.getRunState());
-        history.setStartTime(pump.getStartTime());
-//        history.setMonitorType(pump.getMonitorType());
-//        history.setMaster(pump.getMaster());
-        return history;
+    @JsonIgnoreProperties(allowSetters = true)
+    private Date uploadTime;
+
+
+    public static BusDeviceHistoryEntity parseRunningInfo(BusDeviceRunningEntity running){
+        BusDeviceHistoryEntity entity = new BusDeviceHistoryEntity();
+        entity.setDeviceId(running.getDeviceId());
+        entity.setClinicId(running.getClinicId());
+        entity.setType(running.getType());
+        entity.setClassification(running.getClassification());
+        entity.setTenantId(running.getTenantId());
+        entity.setInfusionId(running.getInfusionId());
+
+        entity.setTotalDose(running.getTotalDose());
+        entity.setFirstDose(running.getFirstDose());
+        entity.setRemainDose(running.getRemainDose());
+        entity.setInputDose(running.getInputDose());
+        entity.setContinueDose(running.getContinueDose());
+        entity.setAppendDose(running.getAppendDose());
+        entity.setMaxDose(running.getMaxDose());
+        entity.setSelfControlLockTime(running.getSelfControlLockTime());
+        entity.setSelfControlCount(running.getSelfControlCount());
+        entity.setPcaValidCount(running.getPcaValidCount());
+        entity.setPcaInvalidCount(running.getPcaInvalidCount());
+        entity.setPcaTotalCount(running.getPcaTotalCount());
+        /**
+         * 脉冲泵参数
+         */
+        entity.setPulseDose(running.getPulseDose());
+        entity.setPulseFirstLockTime(running.getPulseFirstLockTime());
+        entity.setPulseLockTime(running.getPulseLockTime());
+        /**
+         * 智能泵参数
+         */
+        entity.setFlowAdjustRate(running.getFlowAdjustRate());
+        entity.setFlowCount(running.getFlowCount());
+        entity.setFlowDownCycle(running.getFlowDownCycle());
+        entity.setFlowUpCycle(running.getFlowUpCycle());
+        entity.setFlowDownLimit(running.getFlowDownLimit());
+        entity.setFlowUpLimit(running.getFlowUpLimit());
+
+        entity.setUploadTime(running.getUploadTime());
+        entity.setRunState(running.getRunState());
+        entity.setWarnAnalgesicPoor(running.getWarnAnalgesicPoor());
+        entity.setWarnLowBattery(running.getWarnAnalgesicPoor());
+        entity.setWarnWillFinished(running.getWarnAnalgesicPoor());
+        entity.setAlarm(running.getAlarm());
+
+        entity.setMaster(running.getMaster());
+        entity.setTenantId(running.getTenantId());
+        return entity;
     }
 }

+ 6 - 0
coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceRunningEntity.java

@@ -44,6 +44,9 @@ public class BusDeviceRunningEntity extends TenantGenericEntity<String,String> {
     @ApiModelProperty(value = "网络泵id",readOnly = true)
     private String deviceId;
 
+    @ApiModelProperty(value = "输注记录")
+    private String infusionId;
+
     @ApiModelProperty(value = "病号")
     private String patientCode;
 
@@ -103,6 +106,9 @@ public class BusDeviceRunningEntity extends TenantGenericEntity<String,String> {
     @ApiModelProperty(value = "公共参数-自控锁时",readOnly = true)
     private BigDecimal selfControlLockTime;
 
+    @ApiModelProperty(value = "公共参数-自控次数",readOnly = true)
+    private BigDecimal selfControlCount;
+
     @ApiModelProperty(value = "公共参数-pca有效次数",readOnly = true)
     private Integer pcaValidCount;
 

+ 4 - 1
coffee-system/src/main/java/com/coffee/bus/entity/BusDocEntity.java

@@ -23,8 +23,11 @@ import javax.validation.constraints.NotBlank;
 @TableName(value = "bus_doc",autoResultMap = true)
 @ApiModel(value="医院宣教文档管理", description="宣教文档管理")
 @ToString
-public class BusDocEntity extends TenantGenericEntity<String,String> {
+public class BusDocEntity extends GenericEntity<String> {
     @ApiModelProperty("文档内容")
     @NotBlank(message = "文档内容不能为空")
     private String content;
+
+    @ApiModelProperty("文档分类")
+    private String type;
 }

+ 52 - 0
coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionHistoryEntity.java

@@ -87,6 +87,9 @@ public class BusInfusionHistoryEntity extends TenantGenericEntity<String,String>
     @ApiModelProperty(value = "公共参数-自控锁时",readOnly = true)
     private BigDecimal selfControlLockTime;
 
+    @ApiModelProperty(value = "公共参数-自控次数",readOnly = true)
+    private BigDecimal selfControlCount;
+
     @ApiModelProperty(value = "公共参数-pca有效次数",readOnly = true)
     private Integer pcaValidCount;
 
@@ -201,4 +204,53 @@ public class BusInfusionHistoryEntity extends TenantGenericEntity<String,String>
     @TableField(typeHandler = DateToBigIntHandler.class)
     private Date undoTime;
 
+    public static BusInfusionHistoryEntity parseRunningInfo(BusDeviceRunningEntity running){
+        BusInfusionHistoryEntity entity = new BusInfusionHistoryEntity();
+        entity.setDeviceId(running.getDeviceId());
+        entity.setClinicId(running.getClinicId());
+        entity.setPatientCode(running.getPatientCode());
+        entity.setType(running.getType());
+        entity.setWard(running.getWard());
+        entity.setBedNo(running.getBedNo());
+        entity.setClassification(running.getClassification());
+        entity.setStartTime(running.getStartTime());
+        entity.setTenantId(running.getTenantId());
+
+        entity.setTotalDose(running.getTotalDose());
+        entity.setFirstDose(running.getFirstDose());
+        entity.setRemainDose(running.getRemainDose());
+        entity.setInputDose(running.getInputDose());
+        entity.setContinueDose(running.getContinueDose());
+        entity.setAppendDose(running.getAppendDose());
+        entity.setMaxDose(running.getMaxDose());
+        entity.setSelfControlLockTime(running.getSelfControlLockTime());
+        entity.setSelfControlCount(running.getSelfControlCount());
+        entity.setPcaValidCount(running.getPcaValidCount());
+        entity.setPcaInvalidCount(running.getPcaInvalidCount());
+        entity.setPcaTotalCount(running.getPcaTotalCount());
+        /**
+         * 脉冲泵参数
+         */
+        entity.setPulseDose(running.getPulseDose());
+        entity.setPulseFirstLockTime(running.getPulseFirstLockTime());
+        entity.setPulseLockTime(running.getPulseLockTime());
+        /**
+         * 智能泵参数
+         */
+        entity.setFlowAdjustRate(running.getFlowAdjustRate());
+        entity.setFlowCount(running.getFlowCount());
+        entity.setFlowDownCycle(running.getFlowDownCycle());
+        entity.setFlowUpCycle(running.getFlowUpCycle());
+        entity.setFlowDownLimit(running.getFlowDownLimit());
+        entity.setFlowUpLimit(running.getFlowUpLimit());
+
+        entity.setLastUploadTime(running.getUploadTime());
+        entity.setRunState(running.getRunState());
+        entity.setWarnAnalgesicPoor(running.getWarnAnalgesicPoor());
+        entity.setWarnLowBattery(running.getWarnAnalgesicPoor());
+        entity.setWarnWillFinished(running.getWarnAnalgesicPoor());
+        entity.setAlarm(running.getAlarm());
+
+        return entity;
+    }
 }

+ 94 - 0
coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionModifyEntity.java

@@ -1,7 +1,11 @@
 package com.coffee.bus.entity;
 
+import cn.hutool.crypto.asymmetric.Sign;
+import cn.hutool.json.JSONObject;
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.coffee.bus.enums.DeviceEnum;
 import com.coffee.common.config.mybatis.DateToBigIntHandler;
 import com.coffee.common.entity.TenantGenericEntity;
 import io.swagger.annotations.ApiModel;
@@ -10,6 +14,8 @@ import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.ToString;
 import lombok.experimental.Accessors;
+import org.apache.commons.collections4.map.HashedMap;
+import org.apache.ibatis.type.EnumOrdinalTypeHandler;
 
 import javax.validation.constraints.DecimalMax;
 import javax.validation.constraints.DecimalMin;
@@ -17,6 +23,7 @@ import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.Map;
 
 /**
  * @author 龙三郎
@@ -41,6 +48,10 @@ public class BusInfusionModifyEntity extends TenantGenericEntity<String,String>
     @ApiModelProperty(value = "临床号")
     private String clinicId;
 
+    @ApiModelProperty(value = "泵类型",readOnly = true)
+    @TableField(typeHandler = EnumOrdinalTypeHandler.class,javaType = true,updateStrategy = FieldStrategy.NEVER)
+    private DeviceEnum type;
+
     @ApiModelProperty(value = "总量",readOnly = true)
     @Max(value = 999,message = "总量最大值不得超过999")
     @Min(value = 0,message ="总量最小值不得超过0" )
@@ -75,6 +86,9 @@ public class BusInfusionModifyEntity extends TenantGenericEntity<String,String>
     @ApiModelProperty(value = "公共参数-自控锁时",readOnly = true)
     private BigDecimal selfControlLockTime;
 
+    @ApiModelProperty(value = "公共参数-自控次数",readOnly = true)
+    private BigDecimal selfControlCount;
+
     @ApiModelProperty(value = "公共参数-pca有效次数",readOnly = true)
     private Integer pcaValidCount;
 
@@ -138,4 +152,84 @@ public class BusInfusionModifyEntity extends TenantGenericEntity<String,String>
     @TableField(typeHandler = DateToBigIntHandler.class)
     private Date modifyTime;
 
+    public static BusInfusionModifyEntity parseRunningInfo(BusDeviceRunningEntity running){
+        BusInfusionModifyEntity entity = new BusInfusionModifyEntity();
+        entity.setDeviceId(running.getDeviceId());
+        entity.setClinicId(running.getClinicId());
+        entity.setTenantId(running.getTenantId());
+        entity.setInfusionId(running.getInfusionId());
+        entity.setType(running.getType());
+
+        entity.setTotalDose(running.getTotalDose());
+        entity.setFirstDose(running.getFirstDose());
+        entity.setRemainDose(running.getRemainDose());
+        entity.setInputDose(running.getInputDose());
+        entity.setContinueDose(running.getContinueDose());
+        entity.setAppendDose(running.getAppendDose());
+        entity.setMaxDose(running.getMaxDose());
+        entity.setSelfControlLockTime(running.getSelfControlLockTime());
+        entity.setSelfControlCount(running.getSelfControlCount());
+        entity.setPcaValidCount(running.getPcaValidCount());
+        entity.setPcaInvalidCount(running.getPcaInvalidCount());
+        entity.setPcaTotalCount(running.getPcaTotalCount());
+        /**
+         * 脉冲泵参数
+         */
+        entity.setPulseDose(running.getPulseDose());
+        entity.setPulseFirstLockTime(running.getPulseFirstLockTime());
+        entity.setPulseLockTime(running.getPulseLockTime());
+        /**
+         * 智能泵参数
+         */
+        entity.setFlowAdjustRate(running.getFlowAdjustRate());
+        entity.setFlowCount(running.getFlowCount());
+        entity.setFlowDownCycle(running.getFlowDownCycle());
+        entity.setFlowUpCycle(running.getFlowUpCycle());
+        entity.setFlowDownLimit(running.getFlowDownLimit());
+        entity.setFlowUpLimit(running.getFlowUpLimit());
+
+        entity.setModifyTime(running.getUploadTime());
+
+        return entity;
+    }
+
+    public String signParam(Sign sign){
+        //保证参数有序
+        JSONObject param = new JSONObject(true);
+
+        switch (this.getType()){
+            case continuous:
+                param.putOpt("continueDose",this.continueDose);
+                param.putOpt("firstDose",this.firstDose);
+                param.putOpt("appendDose",this.appendDose);
+                param.putOpt("appendLockTime",this.appendLockTime);
+                param.putOpt("maxDose",this.maxDose);
+                break;
+            case pulse:
+                param.putOpt("firstDose",this.firstDose);
+                param.putOpt("firstLockTime",this.pulseFirstLockTime);
+                param.putOpt("continueDose",this.continueDose);
+                param.putOpt("pulseDose",this.pulseDose);
+                param.putOpt("lockTime",this.pulseLockTime);
+                param.putOpt("appendDose",this.appendDose);
+                param.putOpt("appendLockTime",this.appendLockTime);
+                param.putOpt("maxDose",this.maxDose);
+                break;
+            case intelligent:
+                param.putOpt("firstDose",this.firstDose);
+                param.putOpt("appendDose",this.appendDose);
+                param.putOpt("appendLockTime",this.appendLockTime);
+                param.putOpt("flowUpCycle",this.flowUpCycle);
+                param.putOpt("flowCount",this.flowCount);
+                param.putOpt("flowDownCycle",this.flowDownCycle);
+                param.putOpt("flowAdjustRate",this.flowAdjustRate);
+                param.putOpt("flowUpLimit",this.flowUpLimit);
+                param.putOpt("flowDownLimit",this.flowDownLimit);
+                param.putOpt("continueDose",this.continueDose);
+                param.putOpt("maxDose",this.maxDose);
+                break;
+            default:break;
+        }
+        return sign.signHex(param.toString());
+    }
 }

+ 1 - 1
coffee-system/src/main/java/com/coffee/bus/enums/DeviceEnum.java

@@ -15,7 +15,7 @@ import lombok.Getter;
 @AllArgsConstructor
 @JsonFormat(shape = JsonFormat.Shape.OBJECT)
 public enum  DeviceEnum {
-    net(0,"网络泵"),
+    continuous(0,"持续型网络泵"),
     intelligent(1,"智能泵"),
     pulse(2,"脉冲泵");
 

+ 1 - 1
coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceAlarmService.java

@@ -45,7 +45,7 @@ public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper
         if(alarm==null){
             return ;
         }
-        if(StrUtil.isNotEmpty(alarm.getDeviceHistoryId())){
+        if(StrUtil.isNotEmpty(alarm.getHistoryId())){
             //todo 更新历史消息
         }
         this.update(new UpdateWrapper<BusDeviceAlarmEntity>().lambda().eq(BusDeviceAlarmEntity::getId,id).set(BusDeviceAlarmEntity::getCause,cause));

+ 40 - 40
coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceRunningService.java

@@ -59,45 +59,45 @@ public class LocalBusDeviceRunningService extends BaseService<BusDeviceRunningMa
      */
     @Transactional(rollbackFor = Exception.class)
     public void undo(ManualUndoConfig manualUndoConfig) {
-        List<String> ids = manualUndoConfig.getIds();
-        if(CollectionUtil.isEmpty(ids)){
-            return;
-        }
-        /****************将撤泵记录存入到泵的使用历史记录中***************/
-        List<BusDeviceRunningEntity> pumps = this.listByIds(ids);
-        //获取有泵监护的临床信息
-        Set<String> clinicIds = pumps.stream().map(BusDeviceRunningEntity::getClinicId).collect(Collectors.toSet());
-        List<BusClinicEntity> clinics = clinicService.listByIds(clinicIds);
-        Map<String, List<BusClinicEntity>> clinicMap = clinics.stream().collect(Collectors.groupingBy(BusClinicEntity::getId));
-        //泵的撤泵数据插入到历史数据中
-        List<BusDeviceHistoryEntity> pumpHistories = pumps.stream().map(pump -> {
-            BusDeviceHistoryEntity history = BusDeviceHistoryEntity.of(pump, clinicMap.get(pump.getClinicId()).get(0));
-            history.setUndoBy(manualUndoConfig.getUndoBy());
-            history.setUndoTime(manualUndoConfig.getUndoTime());
-            history.setDestroyer(manualUndoConfig.getDestroyer());
-            history.setWitnesses(manualUndoConfig.getWitnesses());
-            history.setIsUndo(1);
-            return history;
-        }).collect(Collectors.toList());
-        historyService.saveBatch(pumpHistories);
-        /****************将撤泵记录存入到泵的使用历史记录中***************/
-
-        /****************将泵改为撤泵状态***************/
-        this.updateBatchById(ids.stream().map(id->{
-            BusDeviceRunningEntity pump = new BusDeviceRunningEntity();
-            pump.setId(id);
-            pump.setIsUndo(true);
-            return pump;
-        }).collect(Collectors.toList()));
-        /****************将泵改为撤泵状态***************/
-
-
-        /****************对临床时间进行记录***************/
-        clinics.forEach(clinic->{
-            clinic.setEndTime(new Date());
-            clinic.setFinished(1);
-        });
-        clinicService.updateBatchById(clinics);
-        /****************对临床时间进行记录***************/
+//        List<String> ids = manualUndoConfig.getIds();
+//        if(CollectionUtil.isEmpty(ids)){
+//            return;
+//        }
+//        /****************将撤泵记录存入到泵的使用历史记录中***************/
+//        List<BusDeviceRunningEntity> pumps = this.listByIds(ids);
+//        //获取有泵监护的临床信息
+//        Set<String> clinicIds = pumps.stream().map(BusDeviceRunningEntity::getClinicId).collect(Collectors.toSet());
+//        List<BusClinicEntity> clinics = clinicService.listByIds(clinicIds);
+//        Map<String, List<BusClinicEntity>> clinicMap = clinics.stream().collect(Collectors.groupingBy(BusClinicEntity::getId));
+//        //泵的撤泵数据插入到历史数据中
+//        List<BusDeviceHistoryEntity> pumpHistories = pumps.stream().map(pump -> {
+//            BusDeviceHistoryEntity history = BusDeviceHistoryEntity.of(pump, clinicMap.get(pump.getClinicId()).get(0));
+//            history.setUndoBy(manualUndoConfig.getUndoBy());
+//            history.setUndoTime(manualUndoConfig.getUndoTime());
+//            history.setDestroyer(manualUndoConfig.getDestroyer());
+//            history.setWitnesses(manualUndoConfig.getWitnesses());
+//            history.setIsUndo(1);
+//            return history;
+//        }).collect(Collectors.toList());
+//        historyService.saveBatch(pumpHistories);
+//        /****************将撤泵记录存入到泵的使用历史记录中***************/
+//
+//        /****************将泵改为撤泵状态***************/
+//        this.updateBatchById(ids.stream().map(id->{
+//            BusDeviceRunningEntity pump = new BusDeviceRunningEntity();
+//            pump.setId(id);
+//            pump.setIsUndo(true);
+//            return pump;
+//        }).collect(Collectors.toList()));
+//        /****************将泵改为撤泵状态***************/
+//
+//
+//        /****************对临床时间进行记录***************/
+//        clinics.forEach(clinic->{
+//            clinic.setEndTime(new Date());
+//            clinic.setFinished(1);
+//        });
+//        clinicService.updateBatchById(clinics);
+//        /****************对临床时间进行记录***************/
     }
 }

+ 0 - 7
coffee-system/src/main/java/com/coffee/bus/service/LocalBusDocService.java

@@ -1,16 +1,9 @@
 package com.coffee.bus.service;
 
-import cn.hutool.core.util.StrUtil;
-import com.coffee.bus.entity.BusDeviceEntity;
 import com.coffee.bus.entity.BusDocEntity;
-import com.coffee.bus.mapper.BusDeviceMapper;
 import com.coffee.bus.mapper.BusDocMapper;
-import com.coffee.bus.registry.device.DeviceOperator;
-import com.coffee.bus.registry.device.DeviceRegistry;
 import com.coffee.common.crud.BaseService;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
 /**

+ 1 - 1
coffee-system/src/main/java/com/coffee/bus/service/constant/AbstractConstantService.java

@@ -9,7 +9,7 @@ import java.io.Serializable;
 /**
  * @author lifang
  * @version 1.0.0
- * @ClassName IConstant.java
+ * @ClassName AbstractConstantService.java
  * @Description 常量继承类
  * @createTime 2022年04月09日 10:19:00
  */

+ 0 - 51
coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceAlarmListener.java

@@ -1,51 +0,0 @@
-package com.coffee.bus.websocket.listener;
-
-import cn.hutool.core.lang.Assert;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.coffee.bus.entity.BusDeviceAlarmEntity;
-import com.coffee.bus.listener.event.bean.DeviceAlarmEvent;
-import com.coffee.bus.service.LocalBusDeviceAlarmService;
-import com.coffee.common.config.websocket.WebSocketConstant;
-import lombok.AllArgsConstructor;
-import org.springframework.context.event.EventListener;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
-
-/**
- * @author lifang
- * @version 1.0.0
- * @ClassName DeviceAlarmListener.java
- * @Description TODO
- * @createTime 2022年04月07日 21:52:00
- */
-@Component
-@AllArgsConstructor
-public class DeviceAlarmListener {
-    private final LocalBusDeviceAlarmService alarmService;
-    private final RedisTemplate redisTemplate;
-    /**
-     * 监听设备的报警信息,
-     * @param alarmEvent
-     */
-    @EventListener
-    @Transactional(rollbackFor = Exception.class)
-    public void deviceAlarm(DeviceAlarmEvent alarmEvent){
-        BusDeviceAlarmEntity alarmEntity = alarmEvent.getContent();
-        alarmEntity.tryValidate(entity -> {
-            BusDeviceAlarmEntity alarm= (BusDeviceAlarmEntity) entity;
-            Assert.notBlank(alarm.getDeviceId());
-            Assert.notBlank(alarm.getDeviceHistoryId());
-            Assert.notBlank(alarm.getClassification());
-            Assert.notBlank(alarm.getTenantId());
-            Assert.notNull(alarm.getAlarm());
-            return true;
-        });
-        alarmService.save(alarmEntity);
-        String tenantId = alarmEntity.getTenantId();
-        long count = alarmService.count(new QueryWrapper<BusDeviceAlarmEntity>().lambda().eq(BusDeviceAlarmEntity::getDoing, true).eq(BusDeviceAlarmEntity::getTenantId,tenantId));
-        //报警信息推送
-        String topic = WebSocketConstant.getDeviceStateCount(null, null, tenantId);
-        redisTemplate.convertAndSend(topic, count);
-    }
-}

+ 154 - 51
coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java

@@ -3,15 +3,17 @@ package com.coffee.bus.websocket.listener;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.crypto.SignUtil;
+import cn.hutool.crypto.asymmetric.Sign;
+import cn.hutool.crypto.asymmetric.SignAlgorithm;
 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.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
-import com.coffee.bus.entity.BusDeviceAlarmEntity;
-import com.coffee.bus.entity.BusDeviceRunningEntity;
+import com.coffee.bus.entity.*;
 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.enums.DeviceEnum;
 import com.coffee.bus.registry.device.DeviceRegistry;
 import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
 import com.coffee.bus.registry.device.bean.DeviceCacheInfo;
@@ -20,21 +22,19 @@ 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.LocalBusDeviceRunningService;
-import com.coffee.common.cache.value.Value;
+import com.coffee.bus.service.*;
 import com.coffee.common.config.websocket.WebSocketConstant;
 import lombok.AllArgsConstructor;
 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.*;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
@@ -56,17 +56,23 @@ public class DeviceInfoListener {
 
     private final DeviceRegistry deviceRegistry;
 
+    private final LocalBusDeviceAlarmService alarmService;
+
     private final PatientRegistry patientRegistry;
 
-    private final LocalBusDeviceAlarmService alarmService;
+    private final LocalBusInfusionHistoryService infusionHistoryService;
+
+    private final LocalBusInfusionModifyService infusionModifyService;
 
+    private final Sign sign = SignUtil.sign(SignAlgorithm.MD5withRSA);
+
+    private final LocalBusDeviceHistoryService historyService;
     /**
      * 监听上传的数据信息,
      * 若设备详情发生变化,则及时通知相应的ws通道
      * @param infoEvent
      */
     @EventListener
-    @Async
     @Transactional(rollbackFor = Exception.class)
     public void deviceInfoDetail(DeviceInfoEvent infoEvent){
         //保证统一设备数据顺序处理,若数据发送过快,为防止冲突,请在此加锁处理 todo
@@ -77,25 +83,35 @@ public class DeviceInfoListener {
             //1、判断该设备是否已和医院绑定并开启使用
             String deviceId = device.getDeviceId();
             DeviceOperator<DeviceCacheInfo> deviceOperator = deviceRegistry.getDevice(deviceId);
-
             if (deviceOperator==null||!Boolean.TRUE.equals(deviceOperator.getEnable())) {
                 log.warn("设备[{}]暂不可用,数据已丢弃",deviceId);
                 return ;
             }
+            device.setUploadTime(device.getUploadTime()==null?new Date():device.getUploadTime());
             log.info("接收到设备数据:[{}]",infoEvent.getContent().toString());
+            AtomicBoolean newInfusion=new AtomicBoolean(false);
             //缓存操作
             List<Supplier<?>> cacheOperation=new ArrayList<>();
-
             //处理设备运行数据
-            boolean first = handleRunningInfo(device, deviceOperator,cacheOperation);
+            boolean first = handleRunningInfo(device, deviceOperator,newInfusion,cacheOperation);
             //处理病患数据,解决泵重复,无泵等问题
             handlePatient(device,cacheOperation);
-            //绑定临床信息 todo
+            //todo 绑定当前临床信息
+            //更新/保存当前输注信息
+            handleInfusionHistory(device,deviceOperator,newInfusion,cacheOperation);
+            //处理输注参数
+            handleInfusionParam(device,deviceOperator,newInfusion,cacheOperation);
+            //处理历史运行数据
+            BusDeviceHistoryEntity history=handleRunningHistory(device);
+            //处理报警信息
+            handleAlarm(history,deviceOperator,cacheOperation);
             if(first){
                 deviceUsingService.save(device);
             }else {
                 deviceUsingService.updateById(device);
             }
+            //医院相关配置处理
+            handleHospitalConfig(device);
             /****************处理泵与患者关系****************/
 
             //则推送设备上报消息
@@ -113,9 +129,10 @@ public class DeviceInfoListener {
      * 设备运行数据处理,返回是否为第一次接受数据消息
      * @param device 接收到的设备信息
      * @param deviceOperator 设备缓存信息操作符
+     * @param newInfusion 是否为新的输注
      * @return 是否为第一次接收数据消息
      */
-    private boolean handleRunningInfo( BusDeviceRunningEntity device,DeviceOperator<DeviceCacheInfo> deviceOperator,List<Supplier<?>> suppliers){
+    private boolean handleRunningInfo( BusDeviceRunningEntity device,DeviceOperator<DeviceCacheInfo> deviceOperator,AtomicBoolean newInfusion,List<Supplier<?>> suppliers){
         //判断此条数据的分包标识是否发生了改变,若改变则
         String originClassify = deviceOperator.getClassification();
         String classification = device.getClassification();
@@ -123,10 +140,12 @@ public class DeviceInfoListener {
         device.setMaster(true);
         if(classification==null){
             log.error("设备号:[{}]分包标识号为空,无法更新开始时间");
+            newInfusion.set(true);
             classification="-1";
+            throw new RuntimeException("设备数据中分包标识不能为空");
         }
         if(!classification.equals(originClassify)){
-            deviceOperator.setClassification(classification);
+            newInfusion.set(true);
             //分包标识发生了改变,设备开机时间重新计算
             device.setStartTime(new Date());
         }
@@ -141,7 +160,6 @@ public class DeviceInfoListener {
             device.setId(String.valueOf(IdWorker.getId()));
             device.setStartTime(new Date());
             device.setAlias(deviceOperator.getAlias());
-
             first=true;
         }else {
             device.setId(usingId);
@@ -159,7 +177,6 @@ public class DeviceInfoListener {
             return null;
         });
         return first;
-
     }
 
     /**
@@ -265,50 +282,132 @@ public class DeviceInfoListener {
     }
 
     /**
-     * 判断是否为报警信息并处理
-     * @param historyId 设备存储的历史数据id
-     * @param device 设备信息
-     * @param deviceOperator 设备操作符
+     * 处理输注历史记录信息
+     * @param device 设备当前运行数据
+     * @param deviceOperator 设备数据操作符
+     * @param newInfusion 是否创建新的输注记录
+     * @param cacheOperation 缓存操作
      */
-    private void handleAlarm(String historyId, BusDeviceRunningEntity device, DeviceOperator deviceOperator){
-        Value value = deviceOperator.getValue(DeviceKeyConstant.ALARM);
-        BusDeviceAlarmEntity alarm = new BusDeviceAlarmEntity(device.getDeviceId(),device.getAlarm(),new Date(),false,historyId,device.getClinicId(),device.getClassification());
-        if(Objects.isNull(value.get())){
-            if (device.getAlarm()==null) {
-                //未发生报警且上一信息不为报警信息,将报警信息置为历史信息
-                return;
+    private void handleInfusionHistory(BusDeviceRunningEntity device, DeviceOperator<DeviceCacheInfo> deviceOperator, AtomicBoolean newInfusion, List<Supplier<?>> cacheOperation) {
+        BusInfusionHistoryEntity infusionHistory = BusInfusionHistoryEntity.parseRunningInfo(device);
+        if (newInfusion.get()) {
+            //检测数据库是否存在该输注信息
+            BusInfusionHistoryEntity existInfusion =
+                    infusionHistoryService.getOne(new QueryWrapper<BusInfusionHistoryEntity>().lambda().eq(BusInfusionHistoryEntity::getDeviceId, device.getDeviceId())
+                            .eq(BusInfusionHistoryEntity::getClassification, device.getClassification()));
+            if(existInfusion==null){
+                infusionHistory.setId(String.valueOf(IdWorker.getId()));
+                infusionHistoryService.save(infusionHistory);
             }else {
-                //发生报警且上一信息不为报警信息, todo 处理报警信息
-                SpringUtil.publishEvent(new DeviceAlarmEvent(this,alarm,historyId));
+                infusionHistory.setId(existInfusion.getId());
+                infusionHistoryService.updateById(infusionHistory);
             }
         }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,false)
-                        .set(BusDeviceAlarmEntity::getDoing,true));
-                SpringUtil.publishEvent(new DeviceAlarmEvent(this,alarm,historyId));
-            } else {
-                //重复报警
-                return;
-            }
+            infusionHistory.setId(deviceOperator.getInfusionId());
+            infusionHistoryService.updateById(infusionHistory);
+        }
+        device.setInfusionId(infusionHistory.getId());
+        cacheOperation.add(()->{
+            deviceOperator.setInfusionId(device.getInfusionId());
+            return null;
+        });
+    }
+
+    /**
+     * 对输注参数进行判断处理
+     * @param device 设备运行数据
+     * @param deviceOperator 设备操作符
+     * @param  newInfusion 是否为新的输注记录
+     * @param cacheOperation 缓存操作
+     */
+    private void handleInfusionParam(BusDeviceRunningEntity device, DeviceOperator<DeviceCacheInfo> deviceOperator,  AtomicBoolean newInfusion,List<Supplier<?>> cacheOperation) {
+        BusInfusionModifyEntity busInfusionModify = BusInfusionModifyEntity.parseRunningInfo(device);
+        String signHex = busInfusionModify.signParam(sign);
+        if(newInfusion.get()){
+            //新的输注记录直接生成新的输注参数
+            infusionModifyService.save(busInfusionModify);
+            cacheOperation.add(()->{
+                deviceOperator.setInfusionParam(signHex);
+                return null;
+            });
+            return;
+        }
+        String infusionParam = deviceOperator.getInfusionParam();
+        if(StrUtil.isEmpty(infusionParam)||!infusionParam.equals(signHex)){
+            //输注参数发生变化
+            infusionModifyService.save(busInfusionModify);
+            cacheOperation.add(()->{
+                deviceOperator.setInfusionParam(signHex);
+                return null;
+            });
         }
     }
 
 
-    public static boolean s=false;
-    @Scheduled(cron = "0/15 * * * * ?")
+    /**
+     * 医院相关配置对于设备数据的处理 todo
+     * @param device 设备运行数据
+     */
+    private void handleHospitalConfig(BusDeviceRunningEntity device) {
+
+    }
+
+
+    /**
+     * 处理运行数据的历史记录
+     * @param device 接收到的设备信息
+     * @return 历史记录id
+     */
+    private BusDeviceHistoryEntity handleRunningHistory(BusDeviceRunningEntity device) {
+        BusDeviceHistoryEntity entity = BusDeviceHistoryEntity.parseRunningInfo(device);
+        entity.setId(String.valueOf(IdWorker.getId()));
+        historyService.save(entity);
+        return entity;
+    }
+
+    /**
+     * 判断是否为报警信息并处理
+     * @param history 设备当前数据的历史数据
+     * @param deviceOperator 设备操作符
+     */
+    private void handleAlarm(BusDeviceHistoryEntity history,DeviceOperator deviceOperator,List<Supplier<?>> cacheOperation){
+        //不存在报警信息
+        if(history.getAlarm()==null){
+            cacheOperation.add(()->{
+                deviceOperator.setAlarm(null);
+                return null;
+            });
+            return;
+        }
+        //获取上一状态下的报警信息
+        DeviceAlarmEnum originAlarm = deviceOperator.getAlarm();
+        DeviceAlarmEnum alarm = history.getAlarm();
+        //产生新的报警信息或报警信息发生变化
+        if(originAlarm==null||originAlarm!=alarm){
+            BusDeviceAlarmEntity deviceAlarm = BusDeviceAlarmEntity.parseRunningInfo(history);
+            alarmService.save(deviceAlarm);
+            cacheOperation.add(()->{
+                //todo 发布报警信息
+                deviceOperator.setAlarm(alarm);
+                return null;
+            });
+        }
+    }
+
+    public static int count=1;
+    public static int mark=0;
+    @Scheduled(cron = "0/20 * * * * ?")
     public void send() throws InterruptedException {
 //        List<BusDeviceRunningEntity> list = deviceUsingService.list();
 //        list.forEach(pump->{
-        if(s){
+        while (count>3){
             return;
         }
-        s=true;
+        ++count;
+        mark=mark+1;
         BusDeviceRunningEntity pump = new BusDeviceRunningEntity();
-        pump.setClassification("-1");
+        pump.setType(DeviceEnum.continuous);
+        pump.setClassification(String.valueOf(mark));
         pump.setDeviceId("123");
         pump.setPatientCode("456");
         pump.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
@@ -323,7 +422,8 @@ public class DeviceInfoListener {
 
         BusDeviceRunningEntity pump1 = new BusDeviceRunningEntity();
         pump1.setDeviceId("456");
-        pump1.setClassification("-1");
+        pump1.setType(DeviceEnum.continuous);
+        pump1.setClassification(String.valueOf(mark));
         pump1.setPatientCode("456");
         pump1.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
         pump1.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
@@ -336,8 +436,9 @@ public class DeviceInfoListener {
         Thread.sleep(5000);
 
         BusDeviceRunningEntity pump2 = new BusDeviceRunningEntity();
+        pump2.setType(DeviceEnum.continuous);
         pump2.setDeviceId("456");
-        pump2.setClassification("-1");
+        pump2.setClassification(String.valueOf(mark));
         pump2.setPatientCode("789");
         pump2.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
         pump2.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
@@ -345,6 +446,7 @@ public class DeviceInfoListener {
         pump2.setPcaValidCount(RandomUtil.randomInt(100));
         pump2.setPcaInvalidCount(RandomUtil.randomInt(100));
         pump2.setPcaTotalCount(RandomUtil.randomInt(100));
+        pump2.setAlarm(DeviceAlarmEnum.Bubble);
         SpringUtil.publishEvent(new DeviceInfoEvent(this,pump2,pump2.getDeviceId()));
 
 
@@ -352,7 +454,8 @@ public class DeviceInfoListener {
 
         BusDeviceRunningEntity pump3 = new BusDeviceRunningEntity();
         pump3.setDeviceId("456");
-        pump3.setClassification("-1");
+        pump3.setClassification(String.valueOf(mark));
+        pump3.setType(DeviceEnum.continuous);
         pump3.setPatientCode("456");
         pump3.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
         pump3.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));

+ 43 - 43
coffee-system/src/main/java/com/coffee/bus/websocket/listener/HistoryInfoListener.java

@@ -107,7 +107,7 @@ public class HistoryInfoListener {
         //判断临床的唯一性
         BusClinicEntity currentClinic = clinicService.getCurrentClinic(hisInfo.getHospitalId(), hisInfo.getPatientCode());
         if (currentClinic==null) {
-            historyInfoListener.updateClinic(clinic,requestId);
+//            historyInfoListener.updateClinic(clinic,requestId);
         }else {
             //临床信息已存在,判断上传信息是否发生重复,是否为最新临床信息
             if(currentClinic.getName().equals(clinic.getName())&&currentClinic.getStartTime().equals(clinic.getStartTime())){
@@ -115,7 +115,7 @@ public class HistoryInfoListener {
                 return ;
             }else {
                 //不同的临床信息,则进行更新
-                historyInfoListener.updateClinic(clinic,requestId);
+//                historyInfoListener.updateClinic(clinic,requestId);
             }
         }
         //发送临床信息
@@ -125,45 +125,45 @@ public class HistoryInfoListener {
 
 
 
-    /**
-     * 针对临床信息更新设备以及设备历史信息
-     * @param clinic
-     * @param clinic
-     */
-
-    @Async
-    @Transactional(rollbackFor = Exception.class)
-    public void updateClinic(BusClinicEntity clinic,Long requestId){
-        clinic.setId(String.valueOf(IdWorker.getId()));
-        //找到此病号信息且未绑定临床号,获取临床绑定设备号,并将临床信息与此次信息进行绑定
-        List<BusDeviceHistoryEntity> historyList = historyService.list(
-                new QueryWrapper<BusDeviceHistoryEntity>()
-                        .lambda()
-                        .select(BusDeviceHistoryEntity::getId)
-                        .select(BusDeviceHistoryEntity::getDeviceId)
-                        .eq(BusDeviceHistoryEntity::getTenantId, clinic.getTenantId())
-                        .eq(BusDeviceHistoryEntity::getPatientCode, clinic.getPatientCode())
-                        .le(requestId!=null, BusDeviceHistoryEntity::getRequestId,requestId)
-                        .isNull(BusDeviceHistoryEntity::getClinicId));
-        if (CollectionUtil.isNotEmpty(historyList)) {
-            //历史信息与临床号绑定
-            historyList.forEach(history-> history.fillClinic(clinic));
-            historyService.updateBatchById(historyList);
-            clinic.setDeviceCodes(historyList.stream().map(BusDeviceHistoryEntity::getDeviceId).collect(Collectors.toSet()));
-        }
-
-        pumpService.update(new UpdateWrapper<BusDeviceRunningEntity>()
-                .lambda()
-                .eq(BusDeviceRunningEntity::getPatientCode,clinic.getPatientCode())
-                .eq(BusDeviceRunningEntity::getTenantId,clinic.getTenantId())
-                .isNull(BusDeviceRunningEntity::getClinicId)
-                .set(BusDeviceRunningEntity::getClinicId,clinic.getId())
-                .set(BusDeviceRunningEntity::getPatientSex,clinic.getPatientGender())
-                .set(BusDeviceRunningEntity::getWard,clinic.getWard())
-                .set(BusDeviceRunningEntity::getBedNo,clinic.getBedNo())
-                .set(BusDeviceRunningEntity::getPatientName,clinic.getPatientName()));
-
-        clinicService.save(clinic);
-        log.info("新增临床信息,[{}]",clinic);
-    }
+//    /**
+//     * 针对临床信息更新设备以及设备历史信息
+//     * @param clinic
+//     * @param clinic
+//     */
+//
+//    @Async
+//    @Transactional(rollbackFor = Exception.class)
+//    public void updateClinic(BusClinicEntity clinic,Long requestId){
+//        clinic.setId(String.valueOf(IdWorker.getId()));
+//        //找到此病号信息且未绑定临床号,获取临床绑定设备号,并将临床信息与此次信息进行绑定
+//        List<BusDeviceHistoryEntity> historyList = historyService.list(
+//                new QueryWrapper<BusDeviceHistoryEntity>()
+//                        .lambda()
+//                        .select(BusDeviceHistoryEntity::getId)
+//                        .select(BusDeviceHistoryEntity::getDeviceId)
+//                        .eq(BusDeviceHistoryEntity::getTenantId, clinic.getTenantId())
+//                        .eq(BusDeviceHistoryEntity::getPatientCode, clinic.getPatientCode())
+//                        .le(requestId!=null, BusDeviceHistoryEntity::getRequestId,requestId)
+//                        .isNull(BusDeviceHistoryEntity::getClinicId));
+//        if (CollectionUtil.isNotEmpty(historyList)) {
+//            //历史信息与临床号绑定
+//            historyList.forEach(history-> history.fillClinic(clinic));
+//            historyService.updateBatchById(historyList);
+//            clinic.setDeviceCodes(historyList.stream().map(BusDeviceHistoryEntity::getDeviceId).collect(Collectors.toSet()));
+//        }
+//
+//        pumpService.update(new UpdateWrapper<BusDeviceRunningEntity>()
+//                .lambda()
+//                .eq(BusDeviceRunningEntity::getPatientCode,clinic.getPatientCode())
+//                .eq(BusDeviceRunningEntity::getTenantId,clinic.getTenantId())
+//                .isNull(BusDeviceRunningEntity::getClinicId)
+//                .set(BusDeviceRunningEntity::getClinicId,clinic.getId())
+//                .set(BusDeviceRunningEntity::getPatientSex,clinic.getPatientGender())
+//                .set(BusDeviceRunningEntity::getWard,clinic.getWard())
+//                .set(BusDeviceRunningEntity::getBedNo,clinic.getBedNo())
+//                .set(BusDeviceRunningEntity::getPatientName,clinic.getPatientName()));
+//
+//        clinicService.save(clinic);
+//        log.info("新增临床信息,[{}]",clinic);
+//    }
 }