Jelajahi Sumber

add 病人信息缓存
add 设备信息缓存

18339543638 3 tahun lalu
induk
melakukan
1b8779a082

+ 14 - 0
coffee-system/src/main/java/com/coffee/bus/registry/CacheInfo.java

@@ -0,0 +1,14 @@
+package com.coffee.bus.registry;
+
+import org.python.antlr.ast.Str;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName CacheInfo.java
+ * @Description 基本缓存信息主键
+ * @createTime 2022年04月02日 16:34:00
+ */
+public interface CacheInfo {
+    String getKey();
+}

+ 12 - 0
coffee-system/src/main/java/com/coffee/bus/registry/Registry.java

@@ -0,0 +1,12 @@
+package com.coffee.bus.registry;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName Operator.java
+ * @Description TODO
+ * @createTime 2022年04月02日 16:31:00
+ */
+public interface Registry {
+    String getId();
+}

+ 14 - 0
coffee-system/src/main/java/com/coffee/bus/registry/RegistryConstant.java

@@ -0,0 +1,14 @@
+package com.coffee.bus.registry;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName RegistryConstant.java
+ * @Description TODO
+ * @createTime 2022年04月02日 16:30:00
+ */
+public class RegistryConstant {
+    public static final String Device="device:";
+    public static final String Patient="patient:";
+    public static final String Clinic="clinic:";
+}

+ 13 - 7
coffee-system/src/main/java/com/coffee/bus/registry/device/ClusterDeviceRegistry.java

@@ -3,9 +3,10 @@ package com.coffee.bus.registry.device;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.coffee.bus.bean.DeviceBasicInfo;
 import com.coffee.bus.entity.BusDeviceRegisteredEntity;
 import com.coffee.bus.entity.BusPumpEntity;
+import com.coffee.bus.registry.RegistryConstant;
+import com.coffee.bus.registry.device.bean.DeviceBasicInfo;
 import com.coffee.bus.service.LocalBusDeviceRegisteredService;
 import com.coffee.bus.service.LocalBusPumpService;
 import com.coffee.common.redis.RedisUtils;
@@ -32,7 +33,8 @@ public class ClusterDeviceRegistry implements DeviceRegistry {
         if(StrUtil.isEmpty(deviceId)){
             return DeviceOperator.of(new DeviceBasicInfo(),redisUtils);
         }
-        Map<Object, Object> result = redisUtils.hmget(deviceId);
+        String key=getId()+deviceId;
+        Map<Object, Object> result = redisUtils.hmget(key);
         if(result==null||result.size()==0){
             //从数据库中获取数据
             BusPumpEntity pump = pumpService.getOne(new QueryWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getDeviceId, deviceId));
@@ -47,9 +49,9 @@ public class ClusterDeviceRegistry implements DeviceRegistry {
                 pump.setTenantId(registeredDevice.getTenantId());
                 pump.setDeviceId(registeredDevice.getDeviceId());
             }
-            DeviceOperator operator = DeviceOperator.of(DeviceBasicInfo.of(pump, registeredDevice), redisUtils);
+            DeviceOperator operator = DeviceOperator.of(DeviceBasicInfo.of(key,pump, registeredDevice), redisUtils);
             //数据同步到缓存中
-            operator.sysn();
+            operator.sync();
             return operator;
         }
         return DeviceOperator.of(JSONUtil.toBean(JSONUtil.toJsonStr(result),DeviceBasicInfo.class),redisUtils);
@@ -58,16 +60,20 @@ public class ClusterDeviceRegistry implements DeviceRegistry {
     @Override
     public void register(DeviceBasicInfo basicInfo) {
         if(StrUtil.isNotEmpty(basicInfo.getDeviceId())){
-            DeviceOperator.of(basicInfo, redisUtils).sysn();
+            DeviceOperator.of(basicInfo, redisUtils).sync();
         }
     }
 
     @Override
     public void unRegister(String deviceId) {
-        DeviceBasicInfo deviceBasicInfo = DeviceBasicInfo.of(deviceId);
-        deviceBasicInfo.setDeviceId(deviceId);
+        String key=getId()+deviceId;
+        DeviceBasicInfo deviceBasicInfo = DeviceBasicInfo.of(key,deviceId);
         DeviceOperator.of(deviceBasicInfo, redisUtils).clear();
     }
 
 
+    @Override
+    public String getId() {
+        return RegistryConstant.Device;
+    }
 }

+ 103 - 96
coffee-system/src/main/java/com/coffee/bus/registry/device/DeviceOperator.java

@@ -1,7 +1,7 @@
 package com.coffee.bus.registry.device;
 
 import cn.hutool.core.util.StrUtil;
-import com.coffee.bus.bean.DeviceBasicInfo;
+import com.coffee.bus.registry.device.bean.DeviceBasicInfo;
 import com.coffee.common.enums.SexEnum;
 import com.coffee.common.redis.RedisUtils;
 import lombok.AllArgsConstructor;
@@ -19,9 +19,9 @@ import java.util.Map;
  */
 @AllArgsConstructor
 public class DeviceOperator {
-    private final DeviceBasicInfo deviceBasicInfo;
+    private transient final DeviceBasicInfo deviceBasicInfo;
 
-    private final RedisUtils redisUtils;
+    private transient final RedisUtils redisUtils;
 
     /**
      * 该操作是否有效,即判断该操作是否存在设备id
@@ -36,30 +36,37 @@ public class DeviceOperator {
      */
     public DeviceOperator clear(){
         if(!validate)return this;
-        redisUtils.del(deviceBasicInfo.getDeviceId());
+        redisUtils.del(deviceBasicInfo.getKey());
         return this;
     }
     /**
      * 将自身同步至redis
      * @param
      */
-    public DeviceOperator sysn(){
+    public DeviceOperator sync(){
         if(!validate)return this;
-        redisUtils.hmset(this.getDeviceId(),getMap());
+        redisUtils.hmset(deviceBasicInfo.getKey(),getMap());
+        return this;
+    }
+
+    public DeviceOperator updateAlias(String alias){
+        if(!validate)return this;
+        deviceBasicInfo.setAlias(alias);
+        redisUtils.hset(deviceBasicInfo.getKey(),"alias",alias);
         return this;
     }
 
     public DeviceOperator updateEnable(Integer enable){
         if(!validate)return this;
         deviceBasicInfo.setEnable(enable);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"enable",enable);
+        redisUtils.hset(deviceBasicInfo.getKey(),"enable",enable);
         return this;
     }
 
     public DeviceOperator updateTenantId(String tenantId){
         if(!validate)return this;
         deviceBasicInfo.setTenantId(tenantId);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"tenantId",tenantId);
+        redisUtils.hset(deviceBasicInfo.getKey(),"tenantId",tenantId);
         return this;
     }
 
@@ -67,14 +74,14 @@ public class DeviceOperator {
     public DeviceOperator updateRunId(String runId){
         if(!validate)return this;
         deviceBasicInfo.setId(runId);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"id",runId);
+        redisUtils.hset(deviceBasicInfo.getKey(),"id",runId);
         return this;
     }
 
     public DeviceOperator updateStartTime(Date startTime){
         if(!validate)return this;
         deviceBasicInfo.setStartTime(startTime);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"startTime",startTime);
+        redisUtils.hset(deviceBasicInfo.getKey(),"startTime",startTime);
         return this;
     }
 
@@ -82,69 +89,69 @@ public class DeviceOperator {
     public DeviceOperator updateRegisterTime(Date registerTime){
         if(!validate)return this;
         deviceBasicInfo.setRegisterTime(registerTime);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"registerTime",registerTime);
-        return this;
-    }
-
-
-
-    public DeviceOperator updatePatientCode(String patientCode){
-        if(!validate)return this;
-        deviceBasicInfo.setPatientCode(patientCode);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"patientCode",patientCode);
-        return this;
-    }
-
-
-
-    public DeviceOperator updatePatientName(String patientName){
-        if(!validate)return this;
-        deviceBasicInfo.setPatientName(patientName);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"patientName",patientName);
-        return this;
-    }
-
-
-
-    public DeviceOperator updateGender(SexEnum gender){
-        if(!validate)return this;
-        deviceBasicInfo.setGender(gender);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"gender",gender);
-        return this;
-    }
-
-
-
-    public DeviceOperator updateBedNo(String bedNo){
-        if(!validate)return this;
-        deviceBasicInfo.setBedNo(bedNo);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"bedNo",bedNo);
+        redisUtils.hset(deviceBasicInfo.getKey(),"registerTime",registerTime);
         return this;
     }
 
 
-    public DeviceOperator updateWard(String ward){
-        if(!validate)return this;
-        deviceBasicInfo.setWard(ward);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"ward",ward);
-        return this;
-    }
-
-
-
-    public DeviceOperator updateRemark(String remark){
-        if(!validate)return this;
-        deviceBasicInfo.setRemark(remark);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"remark",remark);
-        return this;
-    }
-
-    public DeviceOperator updateClinicId(String clinicId){
-        if(!validate)return this;
-        deviceBasicInfo.setClinicId(clinicId);
-        redisUtils.hset(deviceBasicInfo.getDeviceId(),"clinicId",clinicId);
-        return this;
-    }
+//
+//    public DeviceOperator updatePatientCode(String patientCode){
+//        if(!validate)return this;
+//        deviceBasicInfo.setPatientCode(patientCode);
+//        redisUtils.hset(deviceBasicInfo.getKey(),"patientCode",patientCode);
+//        return this;
+//    }
+//
+//
+//
+//    public DeviceOperator updatePatientName(String patientName){
+//        if(!validate)return this;
+//        deviceBasicInfo.setPatientName(patientName);
+//        redisUtils.hset(deviceBasicInfo.getKey(),"patientName",patientName);
+//        return this;
+//    }
+//
+//
+//
+//    public DeviceOperator updateGender(SexEnum gender){
+//        if(!validate)return this;
+//        deviceBasicInfo.setGender(gender);
+//        redisUtils.hset(deviceBasicInfo.getKey(),"gender",gender);
+//        return this;
+//    }
+//
+//
+//
+//    public DeviceOperator updateBedNo(String bedNo){
+//        if(!validate)return this;
+//        deviceBasicInfo.setBedNo(bedNo);
+//        redisUtils.hset(deviceBasicInfo.getKey(),"bedNo",bedNo);
+//        return this;
+//    }
+//
+//
+//    public DeviceOperator updateWard(String ward){
+//        if(!validate)return this;
+//        deviceBasicInfo.setWard(ward);
+//        redisUtils.hset(deviceBasicInfo.getKey(),"ward",ward);
+//        return this;
+//    }
+//
+//
+//
+//    public DeviceOperator updateRemark(String remark){
+//        if(!validate)return this;
+//        deviceBasicInfo.setRemark(remark);
+//        redisUtils.hset(deviceBasicInfo.getKey(),"remark",remark);
+//        return this;
+//    }
+//
+//    public DeviceOperator updateClinicId(String clinicId){
+//        if(!validate)return this;
+//        deviceBasicInfo.setClinicId(clinicId);
+//        redisUtils.hset(deviceBasicInfo.getKey(),"clinicId",clinicId);
+//        return this;
+//    }
 
     public String getDeviceId(){
         return deviceBasicInfo.getDeviceId();
@@ -174,33 +181,33 @@ public class DeviceOperator {
         return deviceBasicInfo.getRegisterTime();
     }
 
-    public String getPatientCode(){
-        return deviceBasicInfo.getPatientCode();
-    }
-
-    public String getPatientName(){
-        return deviceBasicInfo.getPatientName();
-    }
-
-    public SexEnum getGender(){
-        return deviceBasicInfo.getGender();
-    }
-
-    public String getBedNo(){
-        return deviceBasicInfo.getBedNo();
-    }
-
-    public String getWard(){
-        return deviceBasicInfo.getWard();
-    }
-
-    public String getRemark(){
-        return deviceBasicInfo.getRemark();
-    }
-
-    public String getClinicId(){
-        return deviceBasicInfo.getClinicId();
-    }
+//    public String getPatientCode(){
+//        return deviceBasicInfo.getPatientCode();
+//    }
+//
+//    public String getPatientName(){
+//        return deviceBasicInfo.getPatientName();
+//    }
+//
+//    public SexEnum getGender(){
+//        return deviceBasicInfo.getGender();
+//    }
+//
+//    public String getBedNo(){
+//        return deviceBasicInfo.getBedNo();
+//    }
+//
+//    public String getWard(){
+//        return deviceBasicInfo.getWard();
+//    }
+//
+//    public String getRemark(){
+//        return deviceBasicInfo.getRemark();
+//    }
+//
+//    public String getClinicId(){
+//        return deviceBasicInfo.getClinicId();
+//    }
     /**
      * 判断设备在系统中是否存在
      * @return

+ 3 - 2
coffee-system/src/main/java/com/coffee/bus/registry/device/DeviceRegistry.java

@@ -1,6 +1,7 @@
 package com.coffee.bus.registry.device;
 
-import com.coffee.bus.bean.DeviceBasicInfo;
+import com.coffee.bus.registry.Registry;
+import com.coffee.bus.registry.device.bean.DeviceBasicInfo;
 
 /**
  * @author lifang
@@ -9,7 +10,7 @@ import com.coffee.bus.bean.DeviceBasicInfo;
  * @Description 设备注册中心
  * @createTime 2022年04月01日 17:05:00
  */
-public interface DeviceRegistry {
+public interface DeviceRegistry extends Registry {
     /**
      * 获取设备基础信息
      * @param deviceId

+ 26 - 22
coffee-system/src/main/java/com/coffee/bus/bean/DeviceBasicInfo.java → coffee-system/src/main/java/com/coffee/bus/registry/device/bean/DeviceBasicInfo.java

@@ -1,7 +1,8 @@
-package com.coffee.bus.bean;
+package com.coffee.bus.registry.device.bean;
 
 import com.coffee.bus.entity.BusDeviceRegisteredEntity;
 import com.coffee.bus.entity.BusPumpEntity;
+import com.coffee.bus.registry.CacheInfo;
 import com.coffee.common.enums.SexEnum;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -17,7 +18,8 @@ import java.util.Date;
  */
 @Data
 @NoArgsConstructor
-public class DeviceBasicInfo {
+public class DeviceBasicInfo implements CacheInfo {
+    private String key;
     /*****经销商泵管理状态********/
     /**
      * 设备id
@@ -51,37 +53,39 @@ public class DeviceBasicInfo {
 
     private Date registerTime;
 
-    private String patientCode;
-
-    private String patientName;
-
-    private SexEnum gender;
-
-    private String bedNo;
-
-    private String ward;
-
-    private String remark;
-
-    private String clinicId;
+//    private String patientCode;
+//
+//    private String patientName;
+//
+//    private SexEnum gender;
+//
+//    private String bedNo;
+//
+//    private String ward;
+//
+//    private String remark;
+//
+//    private String clinicId;
     /*****泵正在运行状态********/
 
-    public DeviceBasicInfo(String deviceId, String alias, Integer enable, String tenantId) {
+    public DeviceBasicInfo(String key,String deviceId, String alias, Integer enable, String tenantId) {
         this.deviceId = deviceId;
         this.alias = alias;
         this.enable = enable;
         this.tenantId = tenantId;
+        this.key=key;
     }
 
-    public static DeviceBasicInfo of(String deviceId, String alias, Integer enable, String tenantId) {
-        return new DeviceBasicInfo(deviceId,alias,enable,tenantId);
+    public static DeviceBasicInfo of(String key,String deviceId, String alias, Integer enable, String tenantId) {
+        return new DeviceBasicInfo(key,deviceId,alias,enable,tenantId);
     }
 
-    public static DeviceBasicInfo of(String deviceId) {
-        return new DeviceBasicInfo(deviceId,null,null,null);
+    public static DeviceBasicInfo of(String key,String deviceId) {
+        return new DeviceBasicInfo(key,deviceId,null,null,null);
     }
 
-    public static DeviceBasicInfo of(BusPumpEntity pump, BusDeviceRegisteredEntity deviceRegistered) {
-        return new DeviceBasicInfo(pump.getDeviceId(), pump.getAlias(),deviceRegistered.getEnable(),pump.getTenantId());
+    public static DeviceBasicInfo of(String key,BusPumpEntity pump, BusDeviceRegisteredEntity deviceRegistered) {
+        return new DeviceBasicInfo(key,pump.getDeviceId(), pump.getAlias(),deviceRegistered.getEnable(),pump.getTenantId());
     }
+
 }

+ 42 - 0
coffee-system/src/main/java/com/coffee/bus/registry/patient/ClusterPatientRegistry.java

@@ -1,5 +1,18 @@
 package com.coffee.bus.registry.patient;
 
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONUtil;
+import com.coffee.bus.registry.RegistryConstant;
+import com.coffee.bus.registry.device.DeviceOperator;
+import com.coffee.bus.registry.device.bean.DeviceBasicInfo;
+import com.coffee.bus.registry.patient.bean.PatientCurrentInfo;
+import com.coffee.bus.service.LocalBusPatientService;
+import com.coffee.common.redis.RedisUtils;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+
+import java.util.Map;
+
 /**
  * @author lifang
  * @version 1.0.0
@@ -7,5 +20,34 @@ package com.coffee.bus.registry.patient;
  * @Description 集群缓存
  * @createTime 2022年04月02日 16:17:00
  */
+@AllArgsConstructor
+@Service
 public class ClusterPatientRegistry implements PatientRegistry {
+    private final RedisUtils redisUtils;
+    private final LocalBusPatientService patientService;
+    @Override
+    public PatientOperator getPatient(String hospital, String patientCode) {
+        if(StrUtil.isEmpty(hospital)||StrUtil.isEmpty(patientCode)){
+            return PatientOperator.of(new PatientCurrentInfo(),redisUtils,null);
+        }
+        String key=getId()+hospital+":"+patientCode;
+        Map<Object, Object> result = redisUtils.hmget(key);
+        if(result==null||result.size()==0){
+            //从数据库中获取数据
+        }
+        return PatientOperator.of(JSONUtil.toBean(JSONUtil.toJsonStr(result), PatientCurrentInfo.class),redisUtils,patientCurrentInfo->{
+            //从数据库中刷新数据
+            return patientCurrentInfo;
+        });
+    }
+
+    @Override
+    public void register(PatientCurrentInfo basicInfo) {
+
+    }
+
+    @Override
+    public String getId() {
+        return RegistryConstant.Patient;
+    }
 }

+ 91 - 0
coffee-system/src/main/java/com/coffee/bus/registry/patient/PatientOperator.java

@@ -1,5 +1,16 @@
 package com.coffee.bus.registry.patient;
 
+import cn.hutool.core.util.StrUtil;
+import com.coffee.bus.registry.patient.bean.PatientCurrentInfo;
+import com.coffee.common.enums.SexEnum;
+import com.coffee.common.redis.RedisUtils;
+import lombok.AllArgsConstructor;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+
 /**
  * @author lifang
  * @version 1.0.0
@@ -7,5 +18,85 @@ package com.coffee.bus.registry.patient;
  * @Description 病人信息操作符、
  * @createTime 2022年04月02日 16:16:00
  */
+@AllArgsConstructor(staticName = "of")
 public class PatientOperator {
+    private transient final PatientCurrentInfo patientCurrentInfo;
+
+    private transient final RedisUtils redisUtils;
+
+    private transient final Function<PatientCurrentInfo,PatientCurrentInfo> syncCurrentInfo;
+
+    /**
+     * 清除缓存
+     */
+    public PatientOperator clear(){
+        redisUtils.del(patientCurrentInfo.getKey());
+        return this;
+    }
+    /**
+     * 将自身同步至redis
+     * @param
+     */
+    public PatientOperator syncCache(){
+        redisUtils.hmset(patientCurrentInfo.getKey(),getMap());
+        return this;
+    }
+
+    /**
+     * 异步从his获取临床数据
+     * @param
+     */
+    public PatientOperator asyncClinicHis(){
+        CompletableFuture.runAsync(()->{
+            // todo his
+        });
+        return this;
+    }
+
+
+    /**
+     * 是否存在病人
+     */
+    public boolean existPatient(){
+        return patientCurrentInfo!=null&& StrUtil.isNotEmpty(patientCurrentInfo.getPatientCode());
+    }
+
+    /**
+     * 是否存在临床信息
+     * @return
+     */
+    public boolean existClinic(){
+        return patientCurrentInfo!=null&&StrUtil.isNotEmpty(patientCurrentInfo.getClinicId());
+    }
+
+    public String getPatientName(boolean isNullRefresh){
+        String patientName = patientCurrentInfo.getPatientName();
+        if(StrUtil.isEmpty(patientName)&&isNullRefresh){
+            freshInfo();
+        }
+        return patientCurrentInfo.getPatientName();
+    }
+
+    public SexEnum getPatientGender(boolean isNullRefresh){
+        SexEnum patientGender = patientCurrentInfo.getPatientGender();
+        if(patientGender==null&&isNullRefresh){
+            freshInfo();
+        }
+        return patientCurrentInfo.getPatientGender();
+    }
+
+    private void freshInfo(){
+        if(syncCurrentInfo!=null
+                && StrUtil.isNotEmpty(patientCurrentInfo.getPatientCode())
+                &&StrUtil.isNotEmpty(patientCurrentInfo.getTenantId())){
+            syncCurrentInfo.apply(patientCurrentInfo);
+
+        }
+    }
+
+
+    public Map<String,Object> getMap(){
+        return new HashMap<>();
+    }
+
 }

+ 17 - 1
coffee-system/src/main/java/com/coffee/bus/registry/patient/PatientRegistry.java

@@ -1,5 +1,8 @@
 package com.coffee.bus.registry.patient;
 
+import com.coffee.bus.registry.Registry;
+import com.coffee.bus.registry.patient.bean.PatientCurrentInfo;
+
 /**
  * @author lifang
  * @version 1.0.0
@@ -7,5 +10,18 @@ package com.coffee.bus.registry.patient;
  * @Description 病人信息缓存
  * @createTime 2022年04月02日 16:16:00
  */
-public interface PatientRegistry {
+public interface PatientRegistry extends Registry {
+    /**
+     * 根据医院id和病号获取病人操作符
+     * @param hospital
+     * @param patientCode
+     * @return
+     */
+    PatientOperator getPatient(String hospital,String patientCode);
+
+    /**
+     * 注册病人信息
+     * @param basicInfo
+     */
+    void register(PatientCurrentInfo basicInfo);
 }

+ 41 - 0
coffee-system/src/main/java/com/coffee/bus/registry/patient/bean/PatientCurrentInfo.java

@@ -0,0 +1,41 @@
+package com.coffee.bus.registry.patient.bean;
+
+import com.coffee.bus.registry.CacheInfo;
+import com.coffee.common.enums.SexEnum;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName PatientBasicInfo.java
+ * @Description 病人当前状态
+ * @createTime 2022年04月02日 16:19:00
+ */
+@Data
+public class PatientCurrentInfo implements CacheInfo {
+    private String key;
+    /******病人信息***********/
+    private String patientCode;
+    private SexEnum patientGender;
+    private String patientName;
+    private String tenantId;
+    /******病人信息***********/
+
+
+
+    /******临床信息***********/
+    private String clinicId;
+    private Date clinicStartTime;
+    private Boolean isFinished;
+    /******临床信息***********/
+
+
+    /******泵信息***********/
+    /**
+     * 当前绑定泵id
+     */
+    private String currentDeviceId;
+    /******泵信息***********/
+}

+ 4 - 60
coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceRegisteredService.java

@@ -1,17 +1,14 @@
 package com.coffee.bus.service;
 
-import cn.hutool.core.util.ObjectUtil;
-import com.coffee.bus.bean.DeviceBasicInfo;
-import com.coffee.bus.registry.device.DeviceOperator;
 import com.coffee.bus.registry.device.DeviceRegistry;
 import com.coffee.bus.entity.BusDeviceRegisteredEntity;
 import com.coffee.bus.mapper.BusDeviceRegisteredMapper;
 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 java.util.Collection;
+
+import java.io.Serializable;
 
 /**
  * @author lifang
@@ -38,61 +35,8 @@ public class LocalBusDeviceRegisteredService  extends BaseService<BusDeviceRegis
 
     @Override
     public void validateBeforeDelete(String id) {
-
-    }
-
-    @Override
-    public boolean save(BusDeviceRegisteredEntity entity) {
-        if (super.save(entity)) {
-            deviceRegistry.register(DeviceBasicInfo.of(entity.getDeviceId(),entity.getAlias(),entity.getEnable(),entity.getTenantId()));
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public boolean saveBatch(Collection<BusDeviceRegisteredEntity> entityList) {
-        if(super.saveBatch(entityList)){
-            entityList
-                    .parallelStream()
-                    .forEach(this::saveOrUpdateDeviceRegistered);
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public boolean updateById(BusDeviceRegisteredEntity entity) {
-        if (super.updateById(entity)) {
-            this.saveOrUpdateDeviceRegistered(entity);
-            return true;
-        }
-        return false;
-    }
-
-    @Override
-    public boolean updateBatchById(Collection<BusDeviceRegisteredEntity> entityList) {
-        if (super.updateBatchById(entityList)) {
-            entityList
-                    .parallelStream()
-                    .forEach(this::saveOrUpdateDeviceRegistered);
-            return true;
-        }
-        return false;
-    }
-
-    @Async
-    public void saveOrUpdateDeviceRegistered(BusDeviceRegisteredEntity entity){
-        DeviceOperator operator = deviceRegistry.getDevice(entity.getDeviceId());
-        if (ObjectUtil.isNotNull(entity.getAlias())) {
-            operator.updateAlias(entity.getAlias());
-        }
-        if (ObjectUtil.isNotNull(entity.getEnable())) {
-            operator.updateEnable(entity.getEnable());
-        }
-        if (ObjectUtil.isNotNull(entity.getTenantId())) {
-            operator.updateTenantId(entity.getTenantId());
-        }
+        BusDeviceRegisteredEntity registeredEntity = this.getById(id);
+        deviceRegistry.unRegister(registeredEntity.getDeviceId());
     }
 
 }

+ 66 - 42
coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java

@@ -10,9 +10,13 @@ import com.coffee.bus.entity.BusPumpEntity;
 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.registry.device.bean.DeviceBasicInfo;
+import com.coffee.bus.registry.patient.PatientOperator;
+import com.coffee.bus.registry.patient.PatientRegistry;
 import com.coffee.bus.service.LocalBusPumpService;
 import com.coffee.bus.service.LocalBusPatientService;
 import com.coffee.common.config.websocket.WebSocketConstant;
+import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.event.EventListener;
@@ -35,6 +39,7 @@ import java.util.List;
  */
 @Component
 @Slf4j
+@AllArgsConstructor
 public class DeviceInfoListener {
 
     private final RedisTemplate redisTemplate;
@@ -44,14 +49,9 @@ public class DeviceInfoListener {
     private final LocalBusPatientService patientService;
 
     private final DeviceRegistry deviceRegistry;
-    @Autowired
-    public DeviceInfoListener(RedisTemplate redisTemplate, LocalBusPumpService deviceRunInfoService,
-                              LocalBusPatientService patientService,DeviceRegistry deviceRegistry) {
-        this.redisTemplate = redisTemplate;
-        this.deviceRunInfoService = deviceRunInfoService;
-        this.patientService = patientService;
-        this.deviceRegistry=deviceRegistry;
-    }
+
+    private final PatientRegistry patientRegistry;
+
 
     /**
      * 监听上传的数据信息,
@@ -69,39 +69,29 @@ public class DeviceInfoListener {
             log.warn("设备[{}]暂不可用,数据已丢弃");
             return ;
         }
-        BusPumpEntity exist = deviceRunInfoService.getByDeviceId(device.getDeviceId());
         device.setMonitorType(1);
-        //首次运行需要与病人、语言进行绑定
+        //首次运行需要与病人、医院进行绑定
         if(deviceOperator.isFirst()){
-            //处理无泵状态(即泵首次与医院进行绑定)
-            Date now = new Date();
-
-            //设置注册时间和泵的开始时间
-            device.setId(String.valueOf(IdWorker.getId()));
-
-            device.setRegisterTime(now);
-            device.setStartTime(now);
-            device.setAlias(deviceOperator.getAlias());
-            //设备绑定医院
-            device.setTenantId(deviceOperator.getTenantId());
-
-            //缓存存储泵的开始时间和注册时间
-            deviceOperator.updateRegisterTime(now);
-            deviceOperator.updateStartTime(now);
-
-            //判断是否存在临床信息 ,拉取临床信息
+            initDevice(device,deviceOperator);
+            PatientOperator patientOperator = patientRegistry.getPatient(device.getTenantId(), device.getPatientCode());
+            initPatient(device,patientOperator);
+            /**
+             * 判断是否存在临床信息 ,拉取临床信息 todo
+             * @see  com.coffee.bus.registry.patient.PatientOperator 拉取病人信息
+             */
             deviceRunInfoService.save(device);
         }
         else {
 //            fillDeviceInfoFromCache(device,deviceOperator);
 //            deviceRunInfoService.updateById(device);
         }
+
         //病号是否进行换泵操作
         if (patientService.isChangedDevice(device.getTenantId(),device.getPatientCode(),device.getDeviceId(),device.getStartTime())) {
             patientService.changePump(device.getTenantId(),device.getPatientCode(),device.getDeviceId());
         }
         //发送设备报警
-        if(exist!=null){
+        if(!deviceOperator.isFirst()){
             //非首次注册,则推送设备消息
             String topic = WebSocketConstant.getDeviceInfoDetailTopic(null, device.getId(), device.getTenantId());
             redisTemplate.convertAndSend(topic, device);
@@ -109,6 +99,17 @@ public class DeviceInfoListener {
         SpringUtil.publishEvent(new DeviceAlarmEvent(this,device));
     }
 
+    /**
+     * 初始化病人信息
+     * @param pump
+     * @param patientOperator
+     */
+    private void initPatient(BusPumpEntity pump, PatientOperator patientOperator) {
+        //填充病人名称和病人性别
+        pump.setPatientName(patientOperator.getPatientName(true));
+        pump.setPatientSex(patientOperator.getPatientGender(true));
+    }
+
 
     /**
      * 监听设备的报警信息,
@@ -136,22 +137,45 @@ public class DeviceInfoListener {
 
     }
 
+//    /**
+//     * 从缓存中填充设备信息
+//     */
+//    public void fillDeviceInfoFromCache(BusPumpEntity device,DeviceOperator operator){
+//        device.setStartTime(operator.getStartTime());
+//        device.setRegisterTime(operator.getRegisterTime());
+//        device.setPatientCode(operator.getPatientCode());
+//        device.setPatientName(operator.getPatientName());
+//        device.setPatientSex(operator.getGender());
+//        device.setTenantId(operator.getTenantId());
+//        device.setClinicId(operator.getClinicId());
+//        device.setWard(operator.getWard());
+//        device.setBedNo(operator.getBedNo());
+//        device.setAlias(operator.getAlias());
+//        device.setRemark(operator.getRemark());
+//        device.setId(operator.getRunId());
+//    }
+
     /**
-     * 从缓存中填充设备信息
+     * 初始化设备状态
+     * @param pump
+     * @param deviceOperator
      */
-    public void fillDeviceInfoFromCache(BusPumpEntity device,DeviceOperator operator){
-        device.setStartTime(operator.getStartTime());
-        device.setRegisterTime(operator.getRegisterTime());
-        device.setPatientCode(operator.getPatientCode());
-        device.setPatientName(operator.getPatientName());
-        device.setPatientSex(operator.getGender());
-        device.setTenantId(operator.getTenantId());
-        device.setClinicId(operator.getClinicId());
-        device.setWard(operator.getWard());
-        device.setBedNo(operator.getBedNo());
-        device.setAlias(operator.getAlias());
-        device.setRemark(operator.getRemark());
-        device.setId(operator.getRunId());
+    private void initDevice(BusPumpEntity pump, DeviceOperator deviceOperator){
+        //处理无泵状态(即泵首次与医院进行绑定)
+        Date now = new Date();
+
+        //设置注册时间和泵的开始时间
+        pump.setId(String.valueOf(IdWorker.getId()));
+        pump.setRegisterTime(now);
+        pump.setStartTime(now);
+        pump.setAlias(deviceOperator.getAlias());
+
+        //设备绑定医院
+        pump.setTenantId(deviceOperator.getTenantId());
+
+        //缓存存储泵的开始时间和注册时间
+        deviceOperator.updateRegisterTime(now);
+        deviceOperator.updateStartTime(now);
     }
 
     @Scheduled(cron = "0/3 * * * * ?")