Browse Source

add 处理his信息

18339543638 3 năm trước cách đây
mục cha
commit
a78c905182
26 tập tin đã thay đổi với 544 bổ sung96 xóa
  1. 2 0
      coffee-admin/src/main/java/com/coffee/admin/AdminApplication.java
  2. 3 1
      coffee-common/src/main/java/com/coffee/common/config/websocket/DefaultMessageListener.java
  3. 39 1
      coffee-common/src/main/java/com/coffee/common/config/websocket/WebSocketConstant.java
  4. 1 1
      coffee-common/src/main/java/com/coffee/common/config/websocket/handler/Subscribe.java
  5. 0 1
      coffee-common/src/main/java/com/coffee/common/crud/BaseService.java
  6. 6 1
      coffee-framework/src/main/java/com/coffee/framework/config/mybatisplus/handler/CreateAndUpdateMetaObjectHandler.java
  7. 12 3
      coffee-system/src/main/java/com/coffee/bus/controller/BusNetPumpController.java
  8. 29 0
      coffee-system/src/main/java/com/coffee/bus/controller/vo/UndoConfig.java
  9. 14 9
      coffee-system/src/main/java/com/coffee/bus/entity/BusClinicEntity.java
  10. 30 0
      coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceUseEntity.java
  11. 5 0
      coffee-system/src/main/java/com/coffee/bus/entity/BusEvaluationTmpEntity.java
  12. 10 33
      coffee-system/src/main/java/com/coffee/bus/entity/BusNetPumpEntity.java
  13. 42 4
      coffee-system/src/main/java/com/coffee/bus/entity/BusNetPumpHistoryEntity.java
  14. 2 0
      coffee-system/src/main/java/com/coffee/bus/entity/BusPatientEntity.java
  15. 5 3
      coffee-system/src/main/java/com/coffee/bus/listener/event/bean/DeviceInfoEvent.java
  16. 9 3
      coffee-system/src/main/java/com/coffee/bus/listener/event/bean/HistoryInfoEvent.java
  17. 11 0
      coffee-system/src/main/java/com/coffee/bus/mapper/BusClinicMapper.java
  18. 16 0
      coffee-system/src/main/java/com/coffee/bus/mapper/BusDeviceUseMapper.java
  19. 35 0
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusClinicService.java
  20. 31 0
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceUseService.java
  21. 68 0
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusNetPumpService.java
  22. 57 2
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusPatientService.java
  23. 27 0
      coffee-system/src/main/java/com/coffee/bus/websocket/DeviceConflictHandler.java
  24. 0 6
      coffee-system/src/main/java/com/coffee/bus/websocket/DeviceInfoDetailHandler.java
  25. 52 15
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java
  26. 38 13
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/HistoryInfoListener.java

+ 2 - 0
coffee-admin/src/main/java/com/coffee/admin/AdminApplication.java

@@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.context.annotation.Import;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.tio.websocket.starter.EnableTioWebSocketServer;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
@@ -19,6 +20,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
 @EnableSwagger2
 @EnableTioWebSocketServer
 @EnableScheduling
+@EnableAsync
 public class AdminApplication {
 
     public static void main(String[] args) {

+ 3 - 1
coffee-common/src/main/java/com/coffee/common/config/websocket/DefaultMessageListener.java

@@ -26,8 +26,10 @@ import java.util.Set;
 @Data
 @Slf4j
 public class DefaultMessageListener implements MessageListener {
+    private final String id;
     private final Set<ChannelContext> channelContexts;
 
+
     @Override
     public void onMessage(Message message, byte[] pattern) {
         if (CollectionUtil.isNotEmpty(channelContexts)) {
@@ -35,7 +37,7 @@ public class DefaultMessageListener implements MessageListener {
                     .filter(channelContext -> !channelContext.isClosed)
                     .forEach(channel -> Tio.send(channel,
                             WsResponse.fromText(JSONUtil.toJsonStr(R.success(
-                                    new String(message.getBody())))
+                                    MessageResponse.of(id,"result",new String(message.getBody()))))
                                     ,"utf-8")));
         }
     }

+ 39 - 1
coffee-common/src/main/java/com/coffee/common/config/websocket/WebSocketConstant.java

@@ -15,7 +15,7 @@ public class WebSocketConstant {
     public static final String DEVICE_INFO_DETAIL="device-info-detail";
     public static final String DEVICE_STATE_COUNT="device-state-count";
     public static final String CLINIC_INFO = "clinic-info";
-
+    public static final String DEVICE_CONFLICT = "device-conflict";
     /**
      * 主题格式为 device-info-detail:default:45789215623:医院id
      *             alarm-count:default:电量不足:医院id
@@ -30,11 +30,49 @@ public class WebSocketConstant {
         return id+"-"+productName+"-"+param+"-"+tenantId;
     }
 
+    /**
+     * 获取 设备信息变化主题
+     * @param productName
+     * @param param
+     * @param tenantId
+     * @return
+     */
     public static String getDeviceInfoDetailTopic(String productName,String param,String tenantId){
         return getTopic(DEVICE_INFO_DETAIL,productName,param,tenantId);
     }
 
+
+    /**
+     * 获取 设备状态变化主题
+     * @param productName
+     * @param param
+     * @param tenantId
+     * @return
+     */
+    public static String getDeviceStateCount(String productName,String param,String tenantId){
+        return getTopic(DEVICE_STATE_COUNT,productName,param,tenantId);
+    }
+
+
+    /**
+     * 获取 临床信息主题
+     * @param productName
+     * @param param
+     * @param tenantId
+     * @return
+     */
     public static String getClinicInfoTopic(String productName,String param,String tenantId){
         return getTopic(CLINIC_INFO,productName,param,tenantId);
     }
+
+    /**
+     * 获取 临床设备冲突主题
+     * @param productName
+     * @param param
+     * @param tenantId
+     * @return
+     */
+    public static String getDeviceConflictTopic(String productName,String param,String tenantId){
+        return getTopic(DEVICE_CONFLICT,productName,param,tenantId);
+    }
 }

+ 1 - 1
coffee-common/src/main/java/com/coffee/common/config/websocket/handler/Subscribe.java

@@ -86,7 +86,7 @@ public abstract class Subscribe implements WsHandler {
             redisTemplate.execute(new RedisCallback<Object>() {
                 @Override
                 public Object doInRedis(RedisConnection connection) throws DataAccessException {
-                    connection.pSubscribe(new DefaultMessageListener(channelContexts),topic.getBytes());
+                    connection.pSubscribe(new DefaultMessageListener(getId(),channelContexts),topic.getBytes());
                     redisConnectionMap.put(topic,connection);
                     return null;
                 }

+ 0 - 1
coffee-common/src/main/java/com/coffee/common/crud/BaseService.java

@@ -308,5 +308,4 @@ public abstract class BaseService<M extends BaseMapper<E>, E,PK extends Serializ
 
     public  abstract void validateBeforeDelete(PK id) ;
 
-
 }

+ 6 - 1
coffee-framework/src/main/java/com/coffee/framework/config/mybatisplus/handler/CreateAndUpdateMetaObjectHandler.java

@@ -25,7 +25,9 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
 
     public static final String IS_DELETE = "isDelete";
 
-    public static final String TENANT_ID="tenant_id";
+    public static final String TENANT_ID="tenantId";
+
+    public static final String MONITOR_TYPE="monitorType";
     @Override
     public void insertFill(MetaObject metaObject) {
         try {
@@ -50,6 +52,9 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
                 LoginUser loginUser = SecurityUtil.getLoginUser();
                 this.strictUpdateFill(metaObject, TENANT_ID, String.class, Objects.isNull(loginUser) ? null : loginUser.getSysUser().getTenantId());
             }
+            if (metaObject.hasGetter(MONITOR_TYPE) && metaObject.getValue(MONITOR_TYPE) == null) {
+                this.strictUpdateFill(metaObject, MONITOR_TYPE, Integer.class, 1);
+            }
         } catch (Exception e) {
             throw new CustomException(ResultCode.INTERNAL_SERVER_ERROR.getMessage());
         }

+ 12 - 3
coffee-system/src/main/java/com/coffee/bus/controller/BusNetPumpController.java

@@ -1,6 +1,8 @@
 package com.coffee.bus.controller;
 
+import cn.dev33.satoken.annotation.SaCheckPermission;
 import com.baomidou.mybatisplus.core.mapper.Mapper;
+import com.coffee.bus.controller.vo.UndoConfig;
 import com.coffee.bus.entity.BusNetPumpEntity;
 import com.coffee.bus.enums.NetPumpWarnEnum;
 import com.coffee.bus.enums.NetPumpStatusEnum;
@@ -11,9 +13,7 @@ import com.coffee.common.result.R;
 import io.swagger.annotations.Api;
 import io.swagger.v3.oas.annotations.Operation;
 import lombok.AllArgsConstructor;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * @author lifang
@@ -41,6 +41,15 @@ public class BusNetPumpController extends BaseCrudController<BusNetPumpEntity, S
     public R status(){
         return R.success(NetPumpStatusEnum.values());
     }
+
+    @PostMapping("/undo")
+    @SaCheckPermission("bus:pump:undo")
+    @Operation(summary = "进行撤泵操作,权限为bus:pump:undo")
+    public R undo(@RequestBody UndoConfig undoConfig){
+        netPumpService.undo(undoConfig);
+        return R.success();
+    }
+
     /**
      * 权限控制前缀
      * @return

+ 29 - 0
coffee-system/src/main/java/com/coffee/bus/controller/vo/UndoConfig.java

@@ -0,0 +1,29 @@
+package com.coffee.bus.controller.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.util.*;
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName UndoConfig.java
+ * @Description TODO
+ * @createTime 2022年03月30日 08:31:00
+ */
+@Data
+@ApiModel("撤泵配置")
+public class UndoConfig {
+    private List<String> ids;
+    @ApiModelProperty("撤泵人")
+    private String undoBy;
+
+    @ApiModelProperty("撤泵时间")
+    private Date undoTime;
+
+    @ApiModelProperty("销毁人")
+    private String destroyer;
+
+    @ApiModelProperty("见证人")
+    private String witnesses;
+}

+ 14 - 9
coffee-system/src/main/java/com/coffee/bus/entity/BusClinicEntity.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
 import com.coffee.bus.bean.HisInfo;
 import com.coffee.common.config.mybatis.DateToBigIntHandler;
 import com.coffee.common.entity.TenantGenericEntity;
@@ -13,11 +14,10 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+import lombok.ToString;
 import org.apache.ibatis.type.EnumOrdinalTypeHandler;
 import org.hibernate.validator.constraints.Length;
-
-import javax.validation.constraints.Size;
-import java.util.Date;
+import java.util.*;
 
 /**
  * @author lifang
@@ -30,6 +30,7 @@ import java.util.Date;
 @Data
 @TableName(value = "bus_clinic",autoResultMap = true)
 @ApiModel(value="病人临床手术信息", description="病人临床手术信息实体类")
+@ToString
 public class BusClinicEntity extends TenantGenericEntity<String,String> {
 
     @ApiModelProperty(value = "临床手术名称")
@@ -64,9 +65,9 @@ public class BusClinicEntity extends TenantGenericEntity<String,String> {
     @ApiModelProperty(value = "患者年龄")
     private Integer patientAge;
 
-    @ApiModelProperty(value = "科室id")
-    @Length(max = 255,message = "科室id")
-    private String dept;
+    @ApiModelProperty(value = "病区")
+    @Length(max = 255,message = "病区")
+    private String ward;
 
     @ApiModelProperty(value = "病床号")
     @Length(max = 255,message = "病床号长度不得超过255个字节")
@@ -104,8 +105,12 @@ public class BusClinicEntity extends TenantGenericEntity<String,String> {
     @ApiModelProperty(value = "配方")
     private String formula;
 
-    @ApiModelProperty(value = "临床是否结束")
-    private Boolean finished;
+    @ApiModelProperty(value = "临床是否结束,0、未结束 1、结束 ")
+    private Integer finished;
+
+    @ApiModelProperty(value = "临床使用过的设备号")
+    @TableField(typeHandler = FastjsonTypeHandler.class)
+    private Set<String> deviceCodes;
 
     @TableField(fill = FieldFill.INSERT)
     @TableLogic(value = "0",delval = "1")
@@ -121,7 +126,7 @@ public class BusClinicEntity extends TenantGenericEntity<String,String> {
         clinic.setWeight(hisInfo.getWeight());
         clinic.setHeight(hisInfo.getHeight());
         //病区 需新增 todo
-        clinic.setDept(hisInfo.getWard());
+        clinic.setWard(hisInfo.getWard());
         clinic.setBedNo(hisInfo.getBedNo());
         clinic.setName(hisInfo.getOperation());
         clinic.setSurgeryDoctor(hisInfo.getSurgeon());

+ 30 - 0
coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceUseEntity.java

@@ -0,0 +1,30 @@
+package com.coffee.bus.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.coffee.common.entity.GenericEntity;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName BusDeviceUseEntity.java
+ * @Description TODO
+ * @createTime 2022年03月30日 11:01:00
+ */
+@Data
+@TableName("bus_device_use")
+public class BusDeviceUseEntity extends GenericEntity<String> {
+    @ApiModelProperty("临床id")
+    private String clinicId;
+
+    @ApiModelProperty("设备id")
+    private String deviceId;
+
+    @ApiModelProperty("是否为主设备")
+    private Integer master;
+
+    @ApiModelProperty("设备类型,即网络泵、智能泵,暂不使用")
+    private String deviceType;
+}

+ 5 - 0
coffee-system/src/main/java/com/coffee/bus/entity/BusEvaluationTmpEntity.java

@@ -31,6 +31,11 @@ public class BusEvaluationTmpEntity extends TenantGenericEntity<String,String> {
     @TableField(typeHandler = FastjsonTypeHandler.class)
     private List<String> includeConfig;
 
+//    @ApiModelProperty(value = "提醒时间间隔")
+//    private Integer remindInterval;
+//
+//    @ApiModelProperty(value = "提醒时间")
+//    private Integer remindTime;
 
     @TableField(fill = FieldFill.INSERT)
     private String createBy;

+ 10 - 33
coffee-system/src/main/java/com/coffee/bus/entity/BusNetPumpEntity.java

@@ -1,5 +1,6 @@
 package com.coffee.bus.entity;
 
+import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.coffee.bus.enums.NetPumpWarnEnum;
@@ -44,8 +45,8 @@ public class BusNetPumpEntity extends TenantGenericEntity<String,String> {
     @TableField(typeHandler = EnumOrdinalTypeHandler.class)
     private SexEnum patientSex;
 
-    @ApiModelProperty(value = "科室")
-    private String dept;
+    @ApiModelProperty(value = "临床号")
+    private String clinicId;
 
     @ApiModelProperty(value = "病区")
     private String ward;
@@ -89,7 +90,6 @@ public class BusNetPumpEntity extends TenantGenericEntity<String,String> {
     @ApiModelProperty(value = "总按次数")
     private Integer totalCount;
 
-
     @ApiModelProperty(value = "镇痛泵运行状态")
     @TableField(typeHandler = EnumOrdinalTypeHandler.class)
     private NetPumpStatusEnum runState;
@@ -98,33 +98,6 @@ public class BusNetPumpEntity extends TenantGenericEntity<String,String> {
     @TableField(typeHandler = EnumOrdinalTypeHandler.class)
     private NetPumpWarnEnum warn;
 
-//    @ApiModelProperty(value = "镇痛泵状态BUF")
-//    private Integer bufState1;
-//
-//    @ApiModelProperty(value = "镇痛泵状态BUF")
-//    private Integer bufState2;
-//
-//    @ApiModelProperty(value = "镇痛泵状态BUF")
-//    private Integer bufState3;
-//
-//    @ApiModelProperty(value = "镇痛泵状态BUF")
-//    private Integer bufState4;
-//
-//    @ApiModelProperty(value = "镇痛泵状态BUF")
-//    private Integer bufState5;
-//
-//    @ApiModelProperty(value = "镇痛泵状态BUF")
-//    private Integer bufState6;
-//
-//    @ApiModelProperty(value = "镇痛泵状态BUF")
-//    private Integer bufState7;
-//
-//    @ApiModelProperty(value = "镇痛泵状态BUF")
-//    private Integer bufState8;
-//
-//    @ApiModelProperty(value = "镇痛泵状态BUF")
-//    private Integer bufState9;
-
     @ApiModelProperty(value = "开始时间")
     @TableField(typeHandler = DateToBigIntHandler.class)
     private Date startTime;
@@ -132,9 +105,6 @@ public class BusNetPumpEntity extends TenantGenericEntity<String,String> {
     @ApiModelProperty(value = "是否已撤泵,0、未撤泵1、已撤泵")
     private Boolean isUndo;
 
-//    @ApiModelProperty(value = "显示状态")
-//    private String viewState;
-
     @ApiModelProperty(value = "备注")
     private String remark;
 
@@ -145,4 +115,11 @@ public class BusNetPumpEntity extends TenantGenericEntity<String,String> {
     @TableField(typeHandler = DateToBigIntHandler.class)
     private Date registerTime;
 
+    @ApiModelProperty(value = "监护类型,1、有泵监护 2、无泵监护")
+    @TableField(fill = FieldFill.INSERT)
+    private Integer monitorType;
+
+    @ApiModelProperty(value = "是否为主泵数据, 0、副泵 1、主泵(即当前临床绑定的泵)")
+    private Integer master;
+
 }

+ 42 - 4
coffee-system/src/main/java/com/coffee/bus/entity/BusNetPumpHistoryEntity.java

@@ -51,9 +51,6 @@ public class BusNetPumpHistoryEntity extends TenantGenericEntity<String,String>
     @TableField(typeHandler = EnumOrdinalTypeHandler.class)
     private SexEnum patientSex;
 
-    @ApiModelProperty(value = "科室")
-    private String dept;
-
     @ApiModelProperty(value = "病区")
     private String ward;
 
@@ -107,7 +104,7 @@ public class BusNetPumpHistoryEntity extends TenantGenericEntity<String,String>
     private Date startTime;
 
     @ApiModelProperty(value = "是否已撤泵,0、未撤泵1、已撤泵")
-    private Boolean isUndo;
+    private Integer isUndo;
 
     @ApiModelProperty(value = "备注")
     private String remark;
@@ -130,4 +127,45 @@ public class BusNetPumpHistoryEntity extends TenantGenericEntity<String,String>
 
     @TableField(typeHandler = DateToBigIntHandler.class)
     private Date undoTime;
+
+    @ApiModelProperty(value = "监护类型,1、有泵监护 2、无泵监护")
+    private Integer monitorType;
+
+    @ApiModelProperty(value = "是否为主泵数据")
+    private Integer master;
+
+    public static BusNetPumpHistoryEntity of(BusNetPumpEntity pump,BusClinicEntity clinic){
+        BusNetPumpHistoryEntity history = new BusNetPumpHistoryEntity();
+
+        //临床信息
+        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.getRemainQuantity());
+        history.setContinueQuantity(pump.getContinueQuantity());
+        history.setSelfControlLockTime(pump.getSelfControlLockTime());
+        history.setInputQuantity(pump.getInputQuantity());
+        history.setValidTime(pump.getValidTime());
+        history.setInvalidTime(pump.getInvalidTime());
+        history.setMaxQuantity(pump.getMaxQuantity());
+        history.setFirstQuantity(pump.getFirstQuantity());
+        history.setSingleQuantity(pump.getSingleQuantity());
+        history.setTotalQuantity(pump.getTotalQuantity());
+        history.setTotalCount(pump.getTotalCount());
+        history.setRunState(pump.getRunState());
+        history.setRegisterTime(pump.getRegisterTime());
+        history.setLastUploadTime(pump.getLastUploadTime());
+        history.setStartTime(pump.getStartTime());
+        history.setMonitorType(pump.getMonitorType());
+        history.setMaster(pump.getMaster());
+        return history;
+    }
 }

+ 2 - 0
coffee-system/src/main/java/com/coffee/bus/entity/BusPatientEntity.java

@@ -11,6 +11,7 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+import lombok.ToString;
 import org.apache.ibatis.type.EnumOrdinalTypeHandler;
 import org.hibernate.validator.constraints.Length;
 
@@ -25,6 +26,7 @@ import org.hibernate.validator.constraints.Length;
 @Data
 @TableName(value = "bus_patient",autoResultMap = true)
 @ApiModel(value="住院病人基本信息", description="住院病人基本信息实体类")
+@ToString
 public class BusPatientEntity extends TenantGenericEntity<String,String> {
     @ApiModelProperty(value = "病号")
     @Length(max = 255,message = "病号长度不得超过255个字节")

+ 5 - 3
coffee-system/src/main/java/com/coffee/bus/listener/event/bean/DeviceInfoEvent.java

@@ -7,6 +7,8 @@ import com.coffee.bus.listener.enums.ReportType;
 import lombok.Getter;
 import lombok.Setter;
 import org.springframework.context.ApplicationEvent;
+
+import javax.validation.constraints.NotNull;
 import java.time.Clock;
 
 /**
@@ -18,7 +20,6 @@ import java.time.Clock;
  * @see  BusNetPumpEntity
  * @createTime 2022年03月21日 16:21:00
  */
-@Setter
 @Getter
 public class DeviceInfoEvent extends ApplicationEvent {
 
@@ -32,13 +33,14 @@ public class DeviceInfoEvent extends ApplicationEvent {
      */
     private final String deviceId;
 
-    public DeviceInfoEvent(Object source,BusNetPumpEntity content,String deviceId) {
+
+    public DeviceInfoEvent(Object source, @NotNull BusNetPumpEntity content, @NotNull String deviceId) {
         super(source);
         this.content=content;
         this.deviceId=deviceId;
     }
 
-    public DeviceInfoEvent(Object source, Clock clock,BusNetPumpEntity content,String deviceId) {
+    public DeviceInfoEvent(Object source, Clock clock, @NotNull BusNetPumpEntity content, @NotNull String deviceId) {
         super(source, clock);
         this.content=content;
         this.deviceId=deviceId;

+ 9 - 3
coffee-system/src/main/java/com/coffee/bus/listener/event/bean/HistoryInfoEvent.java

@@ -1,7 +1,10 @@
 package com.coffee.bus.listener.event.bean;
 
 import lombok.Data;
+import lombok.Getter;
 import org.springframework.context.ApplicationEvent;
+
+import javax.validation.constraints.NotNull;
 import java.time.Clock;
 
 /**
@@ -11,19 +14,22 @@ import java.time.Clock;
  * @Description TODO
  * @createTime 2022年03月21日 16:30:00
  */
-@Data
+@Getter
 public class HistoryInfoEvent extends ApplicationEvent {
     private final String content;
     private final String historyId;
-    public HistoryInfoEvent(Object source,String content,String historyId) {
+    private final Long requestId;
+    public HistoryInfoEvent(Object source, @NotNull Long requestId,  @NotNull String content,  @NotNull String historyId) {
         super(source);
         this.content=content;
         this.historyId=historyId;
+        this.requestId=requestId;
     }
 
-    public HistoryInfoEvent(Object source, Clock clock,String content,String historyId) {
+    public HistoryInfoEvent(Object source, Clock clock, @NotNull Long requestId, @NotNull String content, @NotNull String historyId) {
         super(source, clock);
         this.content=content;
         this.historyId=historyId;
+        this.requestId=requestId;
     }
 }

+ 11 - 0
coffee-system/src/main/java/com/coffee/bus/mapper/BusClinicMapper.java

@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.coffee.bus.entity.BusClinicEntity;
 import com.coffee.bus.entity.BusPatientEntity;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 
 /**
  * @author lifang
@@ -14,4 +16,13 @@ import org.apache.ibatis.annotations.Mapper;
  */
 @Mapper
 public interface BusClinicMapper extends BaseMapper<BusClinicEntity> {
+
+    /**
+     * 获取当前病号信息
+     * @param hospitalId
+     * @param patientCode
+     * @return
+     */
+    @Select("select * from bus_clinic where tenant_id=#{hospitalId} and patient_code=#{patientCode} order by start_time DESC limit 0,1")
+    BusClinicEntity getCurrentClinic(@Param("hospitalId") String hospitalId,@Param("patientCode") String patientCode);
 }

+ 16 - 0
coffee-system/src/main/java/com/coffee/bus/mapper/BusDeviceUseMapper.java

@@ -0,0 +1,16 @@
+package com.coffee.bus.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.coffee.bus.entity.BusDeviceUseEntity;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName BusHospitalMapper.java
+ * @Description TODO
+ * @createTime 2022年03月19日 09:15:00
+ */
+@Mapper
+public interface BusDeviceUseMapper extends BaseMapper<BusDeviceUseEntity> {
+}

+ 35 - 0
coffee-system/src/main/java/com/coffee/bus/service/LocalBusClinicService.java

@@ -1,11 +1,18 @@
 package com.coffee.bus.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.coffee.bus.entity.BusClinicEntity;
+import com.coffee.bus.entity.BusNetPumpEntity;
 import com.coffee.bus.entity.BusPatientEntity;
 import com.coffee.bus.mapper.BusClinicMapper;
 import com.coffee.bus.mapper.BusPatientMapper;
 import com.coffee.common.crud.BaseService;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * @author lifang
@@ -15,7 +22,11 @@ import org.springframework.stereotype.Service;
  * @createTime 2022年03月19日 09:27:00
  */
 @Service
+@AllArgsConstructor
+@Slf4j
 public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClinicEntity,String> {
+
+    private final LocalBusNetPumpService netPumpService;
     @Override
     public void validateBeforeSave(BusClinicEntity entity) {
 
@@ -30,4 +41,28 @@ public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClini
     public void validateBeforeDelete(String id) {
 
     }
+
+    /**
+     * 判断当前病人是否存在临床信息
+     * @param  hospitalId 医院id
+     * @param patientCode 病号
+     * @return
+     */
+    public boolean existClinic(String hospitalId,String patientCode){
+        return this.getOne(new QueryWrapper<BusClinicEntity>().lambda()
+                .eq(BusClinicEntity::getPatientCode, patientCode)
+                .eq(BusClinicEntity::getTenantId,hospitalId)
+                .eq(BusClinicEntity::getFinished, 0)) == null;
+    }
+
+    /**
+     * 获取当前病号的临床信息
+     * @param hospitalId
+     * @param patientCode
+     * @return
+     */
+    public BusClinicEntity getCurrentClinic(String hospitalId,String patientCode){
+        return this.baseMapper.getCurrentClinic(hospitalId,patientCode);
+    }
+
 }

+ 31 - 0
coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceUseService.java

@@ -0,0 +1,31 @@
+package com.coffee.bus.service;
+
+import com.coffee.bus.entity.BusDeviceUseEntity;
+import com.coffee.bus.mapper.BusDeviceUseMapper;
+import com.coffee.common.crud.BaseService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName LocalBusHospitalService.java
+ * @Description 临床使用设备
+ * @createTime 2022年03月19日 09:27:00
+ */
+@Service
+public class LocalBusDeviceUseService extends BaseService<BusDeviceUseMapper, BusDeviceUseEntity,String> {
+    @Override
+    public void validateBeforeSave(BusDeviceUseEntity entity) {
+
+    }
+
+    @Override
+    public void validateBeforeUpdate(BusDeviceUseEntity entity) {
+
+    }
+
+    @Override
+    public void validateBeforeDelete(String id) {
+
+    }
+}

+ 68 - 0
coffee-system/src/main/java/com/coffee/bus/service/LocalBusNetPumpService.java

@@ -1,12 +1,25 @@
 package com.coffee.bus.service;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.coffee.bus.controller.vo.UndoConfig;
+import com.coffee.bus.entity.BusClinicEntity;
 import com.coffee.bus.entity.BusDoctorEntity;
 import com.coffee.bus.entity.BusNetPumpEntity;
+import com.coffee.bus.entity.BusNetPumpHistoryEntity;
 import com.coffee.bus.mapper.BusDoctorMapper;
 import com.coffee.bus.mapper.BusNetPumpMapper;
 import com.coffee.common.crud.BaseService;
+import lombok.AllArgsConstructor;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * @author lifang
@@ -16,7 +29,10 @@ import org.springframework.stereotype.Service;
  * @createTime 2022年03月19日 09:27:00
  */
 @Service
+@AllArgsConstructor
 public class LocalBusNetPumpService extends BaseService<BusNetPumpMapper, BusNetPumpEntity,String> {
+    private final LocalBusClinicService clinicService;
+    private final LocalBusNetPumpHistoryService historyService;
     @Override
     public void validateBeforeSave(BusNetPumpEntity entity) {
 
@@ -35,4 +51,56 @@ public class LocalBusNetPumpService extends BaseService<BusNetPumpMapper, BusNet
     public boolean firstRegister(String deviceId){
         return this.getOne(new QueryWrapper<BusNetPumpEntity>().lambda().eq(BusNetPumpEntity::getDeviceId,deviceId))!=null;
     }
+
+
+    public BusNetPumpEntity getByDeviceId(String deviceId){
+        return this.getOne(new QueryWrapper<BusNetPumpEntity>().lambda().eq(BusNetPumpEntity::getDeviceId,deviceId));
+    }
+    /**
+     * 撤泵操作
+     * @param undoConfig
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void undo(UndoConfig undoConfig) {
+        List<String> ids = undoConfig.getIds();
+        if(CollectionUtil.isEmpty(ids)){
+            return;
+        }
+        /****************将撤泵记录存入到泵的使用历史记录中***************/
+        List<BusNetPumpEntity> pumps = this.listByIds(ids);
+        //获取有泵监护的临床信息
+        Set<String> clinicIds = pumps.stream().map(BusNetPumpEntity::getClinicId).collect(Collectors.toSet());
+        List<BusClinicEntity> clinics = clinicService.listByIds(clinicIds);
+        Map<String, List<BusClinicEntity>> clinicMap = clinics.stream().collect(Collectors.groupingBy(BusClinicEntity::getId));
+        //解析成泵的历史数据
+        List<BusNetPumpHistoryEntity> pumpHistories = pumps.stream().map(pump -> {
+            BusNetPumpHistoryEntity history = BusNetPumpHistoryEntity.of(pump, clinicMap.get(pump.getClinicId()).get(0));
+            history.setUndoBy(undoConfig.getUndoBy());
+            history.setUndoTime(undoConfig.getUndoTime());
+            history.setDestroyer(undoConfig.getDestroyer());
+            history.setWitnesses(undoConfig.getWitnesses());
+            history.setIsUndo(1);
+            return history;
+        }).collect(Collectors.toList());
+        historyService.saveBatch(pumpHistories);
+        /****************将撤泵记录存入到泵的使用历史记录中***************/
+
+        /****************将泵改为撤泵状态***************/
+        this.updateBatchById(ids.stream().map(id->{
+            BusNetPumpEntity pump = new BusNetPumpEntity();
+            pump.setId(id);
+            pump.setIsUndo(true);
+            return pump;
+        }).collect(Collectors.toList()));
+        /****************将泵改为撤泵状态***************/
+
+
+        /****************对临床时间进行记录***************/
+        clinics.forEach(clinic->{
+            clinic.setEndTime(new Date());
+            clinic.setFinished(1);
+        });
+        clinicService.updateBatchById(clinics);
+        /****************对临床时间进行记录***************/
+    }
 }

+ 57 - 2
coffee-system/src/main/java/com/coffee/bus/service/LocalBusPatientService.java

@@ -1,12 +1,18 @@
 package com.coffee.bus.service;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.coffee.bus.entity.BusDoctorEntity;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.coffee.bus.entity.BusNetPumpEntity;
 import com.coffee.bus.entity.BusPatientEntity;
-import com.coffee.bus.mapper.BusDoctorMapper;
 import com.coffee.bus.mapper.BusPatientMapper;
 import com.coffee.common.crud.BaseService;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
 
 /**
  * @author lifang
@@ -16,7 +22,10 @@ import org.springframework.stereotype.Service;
  * @createTime 2022年03月19日 09:27:00
  */
 @Service
+@AllArgsConstructor
+@Slf4j
 public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPatientEntity,String> {
+    private final LocalBusNetPumpService netPumpService;
     @Override
     public void validateBeforeSave(BusPatientEntity entity) {
 
@@ -41,4 +50,50 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
         return this.getOne(new QueryWrapper<BusPatientEntity>().lambda().
                 eq(BusPatientEntity::getCode,patientCode).eq(BusPatientEntity::getTenantId,hospitalId));
     }
+
+    /**
+     * 校对该泵号所绑定病号是否需要发生换泵操作
+     * @param hospitalId 医院id
+     * @param patientCode 病人id
+     * @param checkDeviceId 需要核对的泵号
+     * @param checkStartTime 需要核对的泵的开始时间
+     * @return
+     */
+    public boolean isChangedDevice(String hospitalId, String patientCode, String checkDeviceId, Date checkStartTime){
+        BusNetPumpEntity existDevice = netPumpService
+                .getOne(new QueryWrapper<BusNetPumpEntity>().lambda().eq(BusNetPumpEntity::getTenantId, hospitalId)
+                        .eq(BusNetPumpEntity::getPatientCode, patientCode));
+        if(existDevice==null){
+            return true;
+        }
+        if (existDevice.getDeviceId().equals(checkDeviceId)) {
+            return false;
+        }
+        Date startTime = existDevice.getStartTime();
+        return checkStartTime.after(startTime);
+    }
+
+    /**
+     * 进行换泵操作
+     * @param  patientCode 病号
+     * @param hospitalId 医院id
+     * @param newDeviceId 现绑定泵id
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void changePump(String hospitalId,String patientCode,String newDeviceId){
+        log.info("医院id:[{}],病号:[{}],进行换泵操作,现设备id:[{}]",patientCode,hospitalId,newDeviceId);
+        netPumpService.update(new UpdateWrapper<BusNetPumpEntity>().lambda().eq(BusNetPumpEntity::getPatientCode,patientCode).set(BusNetPumpEntity::getMaster,0));
+        netPumpService.update(new UpdateWrapper<BusNetPumpEntity>().lambda().eq(BusNetPumpEntity::getDeviceId,newDeviceId).set(BusNetPumpEntity::getMaster,1));
+    }
+
+
+    /**
+     * 异步获取病人信息 todo
+     * @param hospitalId  医院id
+     * @param patientCode 病号
+     */
+    @Async
+    public void syncGetPatientInfoFromHis(String hospitalId,String patientCode){
+
+    }
 }

+ 27 - 0
coffee-system/src/main/java/com/coffee/bus/websocket/DeviceConflictHandler.java

@@ -0,0 +1,27 @@
+package com.coffee.bus.websocket;
+
+import com.coffee.common.config.websocket.WebSocketConstant;
+import com.coffee.common.config.websocket.handler.Subscribe;
+import org.springframework.stereotype.Component;
+import org.tio.core.ChannelContext;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName AlarmCountHandler.java
+ * @Description 临床设备冲突订阅
+ * @createTime 2022年03月25日 14:22:00
+ */
+@Component
+public class DeviceConflictHandler extends Subscribe {
+
+    @Override
+    public String getId() {
+        return WebSocketConstant.CLINIC_INFO;
+    }
+
+    @Override
+    public void close(ChannelContext channelContext) {
+
+    }
+}

+ 0 - 6
coffee-system/src/main/java/com/coffee/bus/websocket/DeviceInfoDetailHandler.java

@@ -1,15 +1,9 @@
 package com.coffee.bus.websocket;
 
-import cn.hutool.core.collection.CollectionUtil;
-import com.coffee.common.Constants;
-import com.coffee.common.bo.LoginUser;
-import com.coffee.common.config.websocket.MessagingRequest;
 import com.coffee.common.config.websocket.WebSocketConstant;
 import com.coffee.common.config.websocket.handler.Subscribe;
 import org.springframework.stereotype.Component;
 import org.tio.core.ChannelContext;
-import java.util.List;
-import java.util.stream.Collectors;
 
 /**
  * @author lifang

+ 52 - 15
coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java

@@ -7,15 +7,21 @@ import com.coffee.bus.entity.BusNetPumpEntity;
 import com.coffee.bus.enums.NetPumpStatusEnum;
 import com.coffee.bus.listener.event.bean.DeviceAlarmEvent;
 import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
+import com.coffee.bus.service.LocalBusClinicService;
 import com.coffee.bus.service.LocalBusNetPumpService;
+import com.coffee.bus.service.LocalBusPatientService;
 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.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
 import java.math.BigDecimal;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -31,33 +37,63 @@ public class DeviceInfoListener {
 
     private final RedisTemplate redisTemplate;
 
-    private final LocalBusNetPumpService netPumpService;
+    private final LocalBusNetPumpService deviceRunInfoService;
+
+    private final LocalBusPatientService patientService;
 
+    private final LocalBusClinicService clinicService;
     /**
      * 监听上传的数据信息,
      * 若设备详情发生变化,则及时通知相应的ws通道
      * @param infoEvent
      */
     @EventListener
+    @Transactional(rollbackFor = Exception.class)
     public void deviceInfoDetail(DeviceInfoEvent infoEvent){
-        boolean first=false;
-        BusNetPumpEntity pump = infoEvent.getContent();
+        BusNetPumpEntity device = infoEvent.getContent();
         //1、判断设备是否为首次注册
-        first = netPumpService.firstRegister(infoEvent.getDeviceId());
+        BusNetPumpEntity exist = deviceRunInfoService.getByDeviceId(device.getDeviceId());
         //2、设备信息发生变化
-        if(first){
+        device.setMonitorType(1);
+        if(exist==null){
             //3、将设备和医院、病人进行绑定 todo
+            Date now = new Date();
+            device.setRegisterTime(now);
+            device.setStartTime(now);
+            //获取设备绑定医院 todo
+            device.setTenantId("");
+            //判断是否存在临床信息 ,拉取临床信息
+            deviceRunInfoService.save(device);
+        }
+//        else if(exist.getIsUndo()){
+////            已撤泵
+//            return;
+//        }
+        else {
+            device.setStartTime(exist.getStartTime());
+            device.setRegisterTime(exist.getRegisterTime());
+            device.setPatientCode(exist.getPatientCode());
+            device.setPatientName(exist.getPatientName());
+            device.setPatientSex(exist.getPatientSex());
+            device.setTenantId(exist.getTenantId());
+            device.setClinicId(exist.getClinicId());
+            device.setWard(exist.getWard());
+            device.setBedNo(exist.getBedNo());
+            device.setAlias(exist.getAlias());
+            device.setRemark(exist.getRemark());
+            device.setId(exist.getId());
+        }
+        //病号是否进行换泵操作
+        if (patientService.isChangedDevice(device.getTenantId(),device.getPatientCode(),device.getDeviceId(),device.getStartTime())) {
+            patientService.changePump(device.getTenantId(),device.getPatientCode(),device.getDeviceId());
         }
-
-        NetPumpStatusEnum runState = pump.getRunState();
         //发送设备报警
-
-        if(!first){
+        if(exist!=null){
             //非首次注册,则推送设备消息
-            String topic = WebSocketConstant.getDeviceInfoDetailTopic(null, pump.getId(), pump.getTenantId());
-            redisTemplate.convertAndSend(topic, pump);
+            String topic = WebSocketConstant.getDeviceInfoDetailTopic(null, device.getId(), device.getTenantId());
+            redisTemplate.convertAndSend(topic, device);
         }
-        SpringUtil.publishEvent(new DeviceAlarmEvent(this,pump));
+        SpringUtil.publishEvent(new DeviceAlarmEvent(this,device));
     }
 
 
@@ -66,17 +102,18 @@ public class DeviceInfoListener {
      * @param alarmEvent
      */
     @EventListener
+    @Async
     public void deviceAlarm(DeviceAlarmEvent alarmEvent){
         BusNetPumpEntity pump = alarmEvent.getContent();
         //获取医院配置,对医院功能配置进行过滤筛选
         NetPumpStatusEnum runState = pump.getRunState();
+        //是否解除报警状态
         if(runState!=null&&Boolean.TRUE.equals(runState.getAlarm())){
             //设备发生报警
             //存储报警信息 todo
-
             String topic = WebSocketConstant.getDeviceStateCount(null, runState.name(), pump.getTenantId());
             //获取报警设备数量
-            List<BusNetPumpEntity> alarmList = netPumpService.list(new QueryWrapper<BusNetPumpEntity>()
+            List<BusNetPumpEntity> alarmList = deviceRunInfoService.list(new QueryWrapper<BusNetPumpEntity>()
                     .lambda()
                     .select(BusNetPumpEntity::getId)
                     .eq(BusNetPumpEntity::getRunState, runState));
@@ -90,7 +127,7 @@ public class DeviceInfoListener {
 
     @Scheduled(cron = "0/3 * * * * ?")
     public void send(){
-        List<BusNetPumpEntity> list = netPumpService.list();
+        List<BusNetPumpEntity> list = deviceRunInfoService.list();
         list.forEach(pump->{
             pump.setRemainQuantity(BigDecimal.valueOf(RandomUtil.randomInt(100)));
             pump.setContinueQuantity(BigDecimal.valueOf(RandomUtil.randomInt(100)));

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

@@ -1,11 +1,14 @@
 package com.coffee.bus.websocket.listener;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONUtil;
 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.bean.HisInfo;
 import com.coffee.bus.entity.BusClinicEntity;
+import com.coffee.bus.entity.BusNetPumpHistoryEntity;
 import com.coffee.bus.entity.BusPatientEntity;
 import com.coffee.bus.listener.event.bean.HistoryInfoEvent;
 import com.coffee.bus.script.ExecuteResult;
@@ -36,8 +39,6 @@ public class HistoryInfoListener {
 
     private final ScriptManager scriptManager;
 
-    private final LocalBusHospitalLogService hospitalLogService;
-
     private final LocalBusPatientService patientService;
 
     private final LocalBusClinicService clinicService;
@@ -47,6 +48,7 @@ public class HistoryInfoListener {
     private final LocalBusNetPumpService netPumpService;
 
     private final RedisTemplate redisTemplate;
+
     @EventListener
     public void historyInfoListener(HistoryInfoEvent infoEvent){
         log.info("接收到了医院数据,[{}]",infoEvent.getContent());
@@ -54,6 +56,7 @@ public class HistoryInfoListener {
         String content = infoEvent.getContent();
         ExecuteResult exec = scriptManager.lookUpHospital(historyId).exec(content);
         if(exec.isSuccess()){
+            log.info("医院数据解析成功,[{}]",exec.get());
             //成功
             JSONArray resultArray = (JSONArray) exec.get();
             List<HisInfo> hisInfos = resultArray.parallelStream()
@@ -62,6 +65,8 @@ public class HistoryInfoListener {
                     .peek(this::handle)
                     .collect(Collectors.toList());
             //获取到his信息进行处理 todo
+        }else {
+            log.info("医院数据解析失败,[{}]",exec.getMessage());
         }
     }
 
@@ -71,25 +76,45 @@ public class HistoryInfoListener {
      */
     @Transactional(rollbackFor = Exception.class)
     public void handle(HisInfo hisInfo){
-        //获取病人信息 todo 判断是否为首次病人信息
+        //获取病人信息
         BusPatientEntity patient = BusPatientEntity.of(hisInfo);
         if(!patientService.exist(patient.getCode(),patient.getTenantId())){
             //不存在病人信息则进行保存 ,病人基本信息不变动
             patientService.save(patient);
+            log.info("新增病人信息,[{}]",patient);
         }
         BusClinicEntity clinic = BusClinicEntity.of(hisInfo);
-        //判断临床的唯一性,todo 有没有可能同一病人同一时间多个临床信息
-        if (clinicService.getOne(new QueryWrapper<BusClinicEntity>()
-                .lambda()
-                .eq(BusClinicEntity::getStartTime,clinic.getStartTime())
-                .eq(BusClinicEntity::getPatientCode,clinic.getPatientCode())
-                .eq(BusClinicEntity::getTenantId,clinic.getTenantId()))==null) {
+        //判断临床的唯一性
+        BusClinicEntity currentClinic = clinicService.getCurrentClinic(hisInfo.getHospitalId(), hisInfo.getPatientCode());
+        if (currentClinic==null) {
+            clinic.setId(String.valueOf(IdWorker.getId()));
             //不存在此次临床信息,保存新的临床信息记录
-            clinicService.update(new UpdateWrapper<BusClinicEntity>().lambda()  .eq(BusClinicEntity::getStartTime,clinic.getStartTime())
-                    .eq(BusClinicEntity::getPatientCode,clinic.getPatientCode())
-                    .eq(BusClinicEntity::getTenantId,clinic.getTenantId())
-                    .set(BusClinicEntity::getFinished,true));
+            clinicService.update(
+                    new UpdateWrapper<BusClinicEntity>().lambda()
+                            .eq(BusClinicEntity::getStartTime,clinic.getStartTime())
+                            .eq(BusClinicEntity::getPatientCode,clinic.getPatientCode())
+                            .eq(BusClinicEntity::getTenantId,clinic.getTenantId())
+                            .set(BusClinicEntity::getFinished,true));
+            //找到此病号信息且未绑定临床号,获取临床绑定设备号,并将临床信息与此次信息进行绑定 todo
+            List<BusNetPumpHistoryEntity> historyList = historyService.list(
+                    new QueryWrapper<BusNetPumpHistoryEntity>()
+                            .lambda()
+                            .select(BusNetPumpHistoryEntity::getId)
+                            .select(BusNetPumpHistoryEntity::getDeviceId)
+                            .eq(BusNetPumpHistoryEntity::getTenantId, clinic.getTenantId())
+                            .eq(BusNetPumpHistoryEntity::getPatientCode, clinic.getPatientCode())
+                            .isNull(BusNetPumpHistoryEntity::getClinicId));
+            if (CollectionUtil.isNotEmpty(historyList)) {
+                //历史信息与临床号绑定
+                historyList.forEach(history->history.setClinicId(clinic.getId()));
+                historyService.updateBatchById(historyList);
+                clinic.setDeviceCodes(historyList.stream().map(BusNetPumpHistoryEntity::getDeviceId).collect(Collectors.toSet()));
+            }
             clinicService.save(clinic);
+            log.info("新增临床信息,[{}]",clinic);
+        }else {
+            //临床信息已存在,判断上传信息是否发生重复,是否为最新临床信息
+
         }
         //发送临床信息
         String topic = WebSocketConstant.getClinicInfoTopic(null, clinic.getPatientCode(), clinic.getTenantId());