Bladeren bron

update 表名修改 devicepump 改为deviceusing
fix 缓存存储null错误修改

18339543638 3 jaren geleden
bovenliggende
commit
4853152881
25 gewijzigde bestanden met toevoegingen van 141 en 123 verwijderingen
  1. 1 1
      coffee-admin/src/main/resources/application.yml
  2. 2 4
      coffee-admin/src/test/java/com/coffee/admin/AliyunTest.java
  3. 5 5
      coffee-admin/src/test/java/com/coffee/admin/BusNetpumpTest.java
  4. 1 1
      coffee-common/src/main/java/com/coffee/common/cache/ClusterConfigStorage.java
  5. 5 0
      coffee-common/src/main/java/com/coffee/common/cache/value/Value.java
  6. 5 6
      coffee-system/src/main/java/com/coffee/bus/controller/BusPumpController.java
  7. 2 2
      coffee-system/src/main/java/com/coffee/bus/controller/vo/NoPumpConfig.java
  8. 2 2
      coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceUsingEntity.java
  9. 1 1
      coffee-system/src/main/java/com/coffee/bus/entity/BusPumpHistoryEntity.java
  10. 4 4
      coffee-system/src/main/java/com/coffee/bus/listener/event/bean/DeviceAlarmEvent.java
  11. 5 5
      coffee-system/src/main/java/com/coffee/bus/listener/event/bean/DeviceInfoEvent.java
  12. 2 2
      coffee-system/src/main/java/com/coffee/bus/mapper/BusDeviceUsingMapper.java
  13. 3 0
      coffee-system/src/main/java/com/coffee/bus/registry/device/ClusterDeviceOperator.java
  14. 6 6
      coffee-system/src/main/java/com/coffee/bus/registry/device/ClusterDeviceRegistry.java
  15. 2 1
      coffee-system/src/main/java/com/coffee/bus/registry/device/DeviceOperator.java
  16. 2 4
      coffee-system/src/main/java/com/coffee/bus/registry/device/bean/DeviceCacheInfo.java
  17. 3 0
      coffee-system/src/main/java/com/coffee/bus/registry/patient/ClusterPatientOperator.java
  18. 1 1
      coffee-system/src/main/java/com/coffee/bus/registry/patient/ClusterPatientRegistry.java
  19. 1 1
      coffee-system/src/main/java/com/coffee/bus/registry/patient/PatientRegistry.java
  20. 2 0
      coffee-system/src/main/java/com/coffee/bus/registry/patient/bean/DeviceTimeSmallInfo.java
  21. 1 4
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusClinicService.java
  22. 11 11
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceUsingService.java
  23. 7 7
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusPatientService.java
  24. 55 40
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java
  25. 12 15
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/HistoryInfoListener.java

+ 1 - 1
coffee-admin/src/main/resources/application.yml

@@ -61,4 +61,4 @@ mybatis-plus:
     dbConfig:
       idType: ASSIGN_ID
   configuration:
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl

+ 2 - 4
coffee-admin/src/test/java/com/coffee/admin/AliyunTest.java

@@ -1,8 +1,6 @@
 package com.coffee.admin;
 
-import com.coffee.admin.AdminApplication;
-import com.coffee.bus.entity.BusDeviceEntity;
-import com.coffee.bus.entity.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import com.coffee.bus.listener.event.bean.DeviceInfoEvent;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -26,7 +24,7 @@ public class AliyunTest {
 
     @Test
     public void test001(){
-        BusPumpEntity pump = new BusPumpEntity();
+        BusDeviceUsingEntity pump = new BusDeviceUsingEntity();
         pump.setAlias("123456777");
         DeviceInfoEvent event = new DeviceInfoEvent(this,pump,"123");
         applicationContext.publishEvent(event);

+ 5 - 5
coffee-admin/src/test/java/com/coffee/admin/BusNetpumpTest.java

@@ -1,9 +1,9 @@
 package com.coffee.admin;
 
 import com.coffee.bus.controller.BusPumpController;
-import com.coffee.bus.entity.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import com.coffee.bus.enums.NetPumpWarnEnum;
-import com.coffee.bus.service.LocalBusPumpService;
+import com.coffee.bus.service.LocalBusDeviceUsingService;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -24,14 +24,14 @@ import java.util.List;
 @SpringBootTest(classes = AdminApplication.class)
 public class BusNetpumpTest {
     @Autowired
-    private LocalBusPumpService netPumpService;
+    private LocalBusDeviceUsingService netPumpService;
 
     @Autowired
     private BusPumpController netPumpController;
     @Test
     public void save(){
 //        StpUtil.login();
-        BusPumpEntity netPumpEntity = new BusPumpEntity();
+        BusDeviceUsingEntity netPumpEntity = new BusDeviceUsingEntity();
         netPumpEntity.setWarn(NetPumpWarnEnum.ComingEnd);
         netPumpEntity.setId("1507903748141658113");
         netPumpEntity.setAlias("1");
@@ -44,7 +44,7 @@ public class BusNetpumpTest {
 
     @Test
     public void query(){
-        List<BusPumpEntity> list = netPumpService.list();
+        List<BusDeviceUsingEntity> list = netPumpService.list();
         System.out.println(list);
     }
 

+ 1 - 1
coffee-common/src/main/java/com/coffee/common/cache/ClusterConfigStorage.java

@@ -39,7 +39,7 @@ public class ClusterConfigStorage implements ConfigStorage {
 
     @Override
     public Boolean setConfig(String key, Object value) {
-        if (key == null) {
+        if (key == null||value==null) {
             return true;
         }
         cache.put(key, value);

+ 5 - 0
coffee-common/src/main/java/com/coffee/common/cache/value/Value.java

@@ -1,9 +1,14 @@
 package com.coffee.common.cache.value;
 
+import cn.hutool.core.util.ObjectUtil;
+
 import java.util.Date;
 
 public interface Value {
     default String asString() {
+        if(ObjectUtil.isNull(get())){
+            return null;
+        }
         return String.valueOf(get());
     }
 

+ 5 - 6
coffee-system/src/main/java/com/coffee/bus/controller/BusPumpController.java

@@ -6,12 +6,11 @@ import cn.dev33.satoken.stp.StpLogic;
 import com.baomidou.mybatisplus.core.mapper.Mapper;
 import com.coffee.bus.controller.vo.NoPumpConfig;
 import com.coffee.bus.controller.vo.UndoConfig;
-import com.coffee.bus.entity.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import com.coffee.bus.enums.NetPumpWarnEnum;
 import com.coffee.bus.enums.NetPumpStatusEnum;
-import com.coffee.bus.service.LocalBusPumpService;
+import com.coffee.bus.service.LocalBusDeviceUsingService;
 import com.coffee.common.crud.BaseService;
-import com.coffee.common.crud.controller.BaseCrudController;
 import com.coffee.common.crud.controller.BaseQueryController;
 import com.coffee.common.result.R;
 import io.swagger.annotations.Api;
@@ -30,8 +29,8 @@ import org.springframework.web.bind.annotation.*;
 @AllArgsConstructor
 @RequestMapping("/bus/netpump")
 @Api(tags = "网络泵管理",description = "统一权限前缀(bus:pump),例如新增bus:pump:add")
-public class BusPumpController implements BaseQueryController<BusPumpEntity, String> {
-    private final LocalBusPumpService netPumpService;
+public class BusPumpController implements BaseQueryController<BusDeviceUsingEntity, String> {
+    private final LocalBusDeviceUsingService netPumpService;
 
     @GetMapping("/warn/dict")
     @Operation(summary = "网络泵提醒信息枚举,无权限配置")
@@ -77,7 +76,7 @@ public class BusPumpController implements BaseQueryController<BusPumpEntity, Str
     }
 
     @Override
-    public BaseService<? extends Mapper<BusPumpEntity>, BusPumpEntity, String> getService() {
+    public BaseService<? extends Mapper<BusDeviceUsingEntity>, BusDeviceUsingEntity, String> getService() {
         return netPumpService;
     }
 }

+ 2 - 2
coffee-system/src/main/java/com/coffee/bus/controller/vo/NoPumpConfig.java

@@ -1,7 +1,7 @@
 package com.coffee.bus.controller.vo;
 
 import com.coffee.bus.entity.BusClinicEntity;
-import com.coffee.bus.entity.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -17,7 +17,7 @@ import lombok.Data;
 @ApiModel("新增无泵监护配置")
 public class NoPumpConfig {
     @ApiModelProperty("泵数据")
-    private BusPumpEntity pump;
+    private BusDeviceUsingEntity pump;
     @ApiModelProperty("手术信息")
     private BusClinicEntity clinic;
     @ApiModelProperty("医院号")

+ 2 - 2
coffee-system/src/main/java/com/coffee/bus/entity/BusPumpEntity.java → coffee-system/src/main/java/com/coffee/bus/entity/BusDeviceUsingEntity.java

@@ -31,9 +31,9 @@ import java.util.Date;
 @Data
 @EqualsAndHashCode(callSuper = false)
 @Accessors(chain = true)
-@TableName(value = "bus_pump",autoResultMap = true)
+@TableName(value = "bus_device_using",autoResultMap = true)
 @ApiModel(value="设备运行状态", description="")
-public class BusPumpEntity extends TenantGenericEntity<String,String> {
+public class BusDeviceUsingEntity extends TenantGenericEntity<String,String> {
 
     @ApiModelProperty(value = "网络泵id")
     private String deviceId;

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

@@ -154,7 +154,7 @@ public class BusPumpHistoryEntity extends TenantGenericEntity<String,String> {
         this.bedNo=clinic.getBedNo();
     }
 
-    public static BusPumpHistoryEntity of(BusPumpEntity pump, BusClinicEntity clinic){
+    public static BusPumpHistoryEntity of(BusDeviceUsingEntity pump, BusClinicEntity clinic){
         BusPumpHistoryEntity history = new BusPumpHistoryEntity();
 
         //临床信息

+ 4 - 4
coffee-system/src/main/java/com/coffee/bus/listener/event/bean/DeviceAlarmEvent.java

@@ -1,6 +1,6 @@
 package com.coffee.bus.listener.event.bean;
 
-import com.coffee.bus.entity.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import lombok.Data;
 import org.springframework.context.ApplicationEvent;
 
@@ -16,13 +16,13 @@ import java.time.Clock;
 @Data
 public class DeviceAlarmEvent extends ApplicationEvent {
 
-    private final BusPumpEntity content;
-    public DeviceAlarmEvent(Object source, BusPumpEntity content) {
+    private final BusDeviceUsingEntity content;
+    public DeviceAlarmEvent(Object source, BusDeviceUsingEntity content) {
         super(source);
         this.content=content;
     }
 
-    public DeviceAlarmEvent(Object source, BusPumpEntity content, Clock clock) {
+    public DeviceAlarmEvent(Object source, BusDeviceUsingEntity content, Clock clock) {
         super(source, clock);
         this.content=content;
     }

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

@@ -1,6 +1,6 @@
 package com.coffee.bus.listener.event.bean;
 
-import com.coffee.bus.entity.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import lombok.Getter;
 import org.springframework.context.ApplicationEvent;
 
@@ -13,7 +13,7 @@ import java.time.Clock;
  * @ClassName DeviceInfoEvent.java
  * @Description 所有通过第三方传过来的数据,请先解析成netpump格式类型,然后分发到系统中
  *
- * @see  BusPumpEntity
+ * @see  BusDeviceUsingEntity
  * @createTime 2022年03月21日 16:21:00
  */
 @Getter
@@ -22,7 +22,7 @@ public class DeviceInfoEvent extends ApplicationEvent {
     /**
      * 设备属性值
      */
-    private final BusPumpEntity content;
+    private final BusDeviceUsingEntity content;
 
     /**
      * 设备id,即泵设备号
@@ -30,13 +30,13 @@ public class DeviceInfoEvent extends ApplicationEvent {
     private final String deviceId;
 
 
-    public DeviceInfoEvent(Object source, @NotNull BusPumpEntity content, @NotNull String deviceId) {
+    public DeviceInfoEvent(Object source, @NotNull BusDeviceUsingEntity content, @NotNull String deviceId) {
         super(source);
         this.content=content;
         this.deviceId=deviceId;
     }
 
-    public DeviceInfoEvent(Object source, Clock clock, @NotNull BusPumpEntity content, @NotNull String deviceId) {
+    public DeviceInfoEvent(Object source, Clock clock, @NotNull BusDeviceUsingEntity content, @NotNull String deviceId) {
         super(source, clock);
         this.content=content;
         this.deviceId=deviceId;

+ 2 - 2
coffee-system/src/main/java/com/coffee/bus/mapper/BusPumpMapper.java → coffee-system/src/main/java/com/coffee/bus/mapper/BusDeviceUsingMapper.java

@@ -1,7 +1,7 @@
 package com.coffee.bus.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.coffee.bus.entity.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import org.apache.ibatis.annotations.Mapper;
 
 /**
@@ -12,5 +12,5 @@ import org.apache.ibatis.annotations.Mapper;
  * @createTime 2022年03月19日 09:15:00
  */
 @Mapper
-public interface BusPumpMapper extends BaseMapper<BusPumpEntity> {
+public interface BusDeviceUsingMapper extends BaseMapper<BusDeviceUsingEntity> {
 }

+ 3 - 0
coffee-system/src/main/java/com/coffee/bus/registry/device/ClusterDeviceOperator.java

@@ -186,6 +186,9 @@ public class ClusterDeviceOperator implements DeviceOperator<DeviceCacheInfo> {
 
     @Override
     public void setStatus(NetPumpStatusEnum status) {
+        if(status==null){
+            return;
+        }
         configStorage.setConfig("status",status.ordinal());
     }
 

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

@@ -4,11 +4,11 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.coffee.bus.entity.BusDeviceEntity;
-import com.coffee.bus.entity.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import com.coffee.bus.registry.RegistryConstant;
 import com.coffee.bus.registry.device.bean.DeviceCacheInfo;
 import com.coffee.bus.service.LocalBusDeviceService;
-import com.coffee.bus.service.LocalBusPumpService;
+import com.coffee.bus.service.LocalBusDeviceUsingService;
 import com.coffee.common.cache.manager.ClusterConfigStorageManager;
 import com.coffee.common.cache.value.Value;
 import lombok.AllArgsConstructor;
@@ -26,7 +26,7 @@ import java.util.Map;
 @AllArgsConstructor
 @Service
 public class ClusterDeviceRegistry implements DeviceRegistry {
-    private final LocalBusPumpService pumpService;
+    private final LocalBusDeviceUsingService pumpService;
     private final LocalBusDeviceService deviceService;
     private final ClusterConfigStorageManager configStorageManager;
 
@@ -40,7 +40,7 @@ public class ClusterDeviceRegistry implements DeviceRegistry {
         Map<String, Value> result = deviceOperator.getAll();
         if(result==null||result.size()==0){
             //从数据库中获取数据
-            BusPumpEntity pump = pumpService.getOne(new QueryWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getDeviceId, deviceId));
+            BusDeviceUsingEntity pump = pumpService.getOne(new QueryWrapper<BusDeviceUsingEntity>().lambda().eq(BusDeviceUsingEntity::getDeviceId, deviceId));
             BusDeviceEntity device = deviceService.getOne(new QueryWrapper<BusDeviceEntity>().lambda()
                     .eq(BusDeviceEntity::getDeviceId, deviceId));
             if(device==null){
@@ -56,8 +56,8 @@ public class ClusterDeviceRegistry implements DeviceRegistry {
                 deviceOperator.setUsingId(pump.getId());
                 //判断泵是否医院绑定发生变化
                 if(device.getTenantId().equals(pump.getTenantId())){
-                    pumpService.update(new UpdateWrapper<BusPumpEntity>().lambda()
-                            .eq(BusPumpEntity::getDeviceId,deviceId).set(BusPumpEntity::getTenantId,device.getTenantId()));
+                    pumpService.update(new UpdateWrapper<BusDeviceUsingEntity>().lambda()
+                            .eq(BusDeviceUsingEntity::getDeviceId,deviceId).set(BusDeviceUsingEntity::getTenantId,device.getTenantId()));
                 }
 
             }

+ 2 - 1
coffee-system/src/main/java/com/coffee/bus/registry/device/DeviceOperator.java

@@ -1,5 +1,6 @@
 package com.coffee.bus.registry.device;
 
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import com.coffee.bus.enums.NetPumpStatusEnum;
 import com.coffee.bus.registry.Operator;
 
@@ -65,7 +66,7 @@ public interface DeviceOperator<T> extends Operator<T> {
 
     /**
      * 设置设备运行id
-     * @see com.coffee.bus.entity.BusPumpEntity
+     * @see BusDeviceUsingEntity
      * @param usingId
      */
     void setUsingId(String usingId);

+ 2 - 4
coffee-system/src/main/java/com/coffee/bus/registry/device/bean/DeviceCacheInfo.java

@@ -1,13 +1,11 @@
 package com.coffee.bus.registry.device.bean;
 
-import com.coffee.bus.entity.BusDeviceEntity;
-import com.coffee.bus.entity.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import com.coffee.bus.enums.NetPumpStatusEnum;
 import com.coffee.bus.registry.CacheInfo;
 import com.coffee.bus.registry.RegistryConstant;
 import lombok.Builder;
 import lombok.Data;
-import lombok.NoArgsConstructor;
 //import com.coffee.common.cache.*;
 import java.util.Date;
 
@@ -50,7 +48,7 @@ public class DeviceCacheInfo implements CacheInfo {
 
     /**
      * 运行泵主键id
-     * @see com.coffee.bus.entity.BusPumpEntity
+     * @see BusDeviceUsingEntity
      */
     private String usingId;
 

+ 3 - 0
coffee-system/src/main/java/com/coffee/bus/registry/patient/ClusterPatientOperator.java

@@ -117,6 +117,9 @@ public class ClusterPatientOperator implements PatientOperator<PatientCacheInfo>
 
     @Override
     public void setGender(SexEnum gender) {
+        if(gender==null){
+            return;
+        }
         configStorage.setConfig("gender",gender.ordinal());
     }
 

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

@@ -34,7 +34,7 @@ public class ClusterPatientRegistry implements PatientRegistry {
     private final ClusterConfigStorageManager configStorageManager;
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public PatientOperator getPatient(String hospitalId, String patientCode) {
+    public PatientOperator<PatientCacheInfo> getPatient(String hospitalId, String patientCode) {
         if(StrUtil.isEmpty(hospitalId)||StrUtil.isEmpty(patientCode)){
             return null;
         }

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

@@ -17,7 +17,7 @@ public interface PatientRegistry extends Registry {
      * @param patientCode
      * @return
      */
-    PatientOperator getPatient(String hospital,String patientCode);
+    PatientOperator<PatientCacheInfo> getPatient(String hospital,String patientCode);
 
     /**
      * 注册病人信息

+ 2 - 0
coffee-system/src/main/java/com/coffee/bus/registry/patient/bean/DeviceTimeSmallInfo.java

@@ -2,6 +2,7 @@ package com.coffee.bus.registry.patient.bean;
 
 import lombok.AllArgsConstructor;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
 import java.util.Date;
@@ -16,6 +17,7 @@ import java.util.Objects;
  */
 @Data
 @AllArgsConstructor(staticName = "of")
+@NoArgsConstructor
 public class DeviceTimeSmallInfo implements Serializable {
     private String deviceId;
     private Date startTime;

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

@@ -4,14 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.coffee.bus.entity.BusClinicEntity;
 import com.coffee.bus.mapper.BusClinicMapper;
 import com.coffee.common.crud.BaseService;
-import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
-import javax.annotation.Resource;
-
 /**
  * @author lifang
  * @version 1.0.0
@@ -24,7 +21,7 @@ import javax.annotation.Resource;
 public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClinicEntity,String> {
     @Autowired
     @Lazy
-    private LocalBusPumpService netPumpService;
+    private LocalBusDeviceUsingService netPumpService;
     @Override
     public void validateBeforeSave(BusClinicEntity entity) {
 

+ 11 - 11
coffee-system/src/main/java/com/coffee/bus/service/LocalBusPumpService.java → coffee-system/src/main/java/com/coffee/bus/service/LocalBusDeviceUsingService.java

@@ -4,9 +4,9 @@ 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.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import com.coffee.bus.entity.BusPumpHistoryEntity;
-import com.coffee.bus.mapper.BusPumpMapper;
+import com.coffee.bus.mapper.BusDeviceUsingMapper;
 import com.coffee.common.crud.BaseService;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
@@ -27,16 +27,16 @@ import java.util.stream.Collectors;
  */
 @Service
 @AllArgsConstructor
-public class LocalBusPumpService extends BaseService<BusPumpMapper, BusPumpEntity,String> {
+public class LocalBusDeviceUsingService extends BaseService<BusDeviceUsingMapper, BusDeviceUsingEntity,String> {
     private final LocalBusClinicService clinicService;
     private final LocalBusPumpHistoryService historyService;
     @Override
-    public void validateBeforeSave(BusPumpEntity entity) {
+    public void validateBeforeSave(BusDeviceUsingEntity entity) {
 
     }
 
     @Override
-    public void validateBeforeUpdate(BusPumpEntity entity) {
+    public void validateBeforeUpdate(BusDeviceUsingEntity entity) {
 
     }
 
@@ -46,12 +46,12 @@ public class LocalBusPumpService extends BaseService<BusPumpMapper, BusPumpEntit
     }
 
     public boolean firstRegister(String deviceId){
-        return this.getOne(new QueryWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getDeviceId,deviceId))!=null;
+        return this.getOne(new QueryWrapper<BusDeviceUsingEntity>().lambda().eq(BusDeviceUsingEntity::getDeviceId,deviceId))!=null;
     }
 
 
-    public BusPumpEntity getByDeviceId(String deviceId){
-        return this.getOne(new QueryWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getDeviceId,deviceId));
+    public BusDeviceUsingEntity getByDeviceId(String deviceId){
+        return this.getOne(new QueryWrapper<BusDeviceUsingEntity>().lambda().eq(BusDeviceUsingEntity::getDeviceId,deviceId));
     }
     /**
      * 撤泵操作
@@ -64,9 +64,9 @@ public class LocalBusPumpService extends BaseService<BusPumpMapper, BusPumpEntit
             return;
         }
         /****************将撤泵记录存入到泵的使用历史记录中***************/
-        List<BusPumpEntity> pumps = this.listByIds(ids);
+        List<BusDeviceUsingEntity> pumps = this.listByIds(ids);
         //获取有泵监护的临床信息
-        Set<String> clinicIds = pumps.stream().map(BusPumpEntity::getClinicId).collect(Collectors.toSet());
+        Set<String> clinicIds = pumps.stream().map(BusDeviceUsingEntity::getClinicId).collect(Collectors.toSet());
         List<BusClinicEntity> clinics = clinicService.listByIds(clinicIds);
         Map<String, List<BusClinicEntity>> clinicMap = clinics.stream().collect(Collectors.groupingBy(BusClinicEntity::getId));
         //泵的撤泵数据插入到历史数据中
@@ -84,7 +84,7 @@ public class LocalBusPumpService extends BaseService<BusPumpMapper, BusPumpEntit
 
         /****************将泵改为撤泵状态***************/
         this.updateBatchById(ids.stream().map(id->{
-            BusPumpEntity pump = new BusPumpEntity();
+            BusDeviceUsingEntity pump = new BusDeviceUsingEntity();
             pump.setId(id);
             pump.setIsUndo(true);
             return pump;

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

@@ -2,7 +2,7 @@ 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.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import com.coffee.bus.entity.BusPatientEntity;
 import com.coffee.bus.mapper.BusPatientMapper;
 import com.coffee.common.crud.BaseService;
@@ -25,7 +25,7 @@ import java.util.Date;
 @AllArgsConstructor
 @Slf4j
 public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPatientEntity,String> {
-    private final LocalBusPumpService netPumpService;
+    private final LocalBusDeviceUsingService netPumpService;
     @Override
     public void validateBeforeSave(BusPatientEntity entity) {
 
@@ -60,9 +60,9 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
      * @return
      */
     public boolean isChangedDevice(String hospitalId, String patientCode, String checkDeviceId, Date checkStartTime){
-        BusPumpEntity existDevice = netPumpService
-                .getOne(new QueryWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getTenantId, hospitalId)
-                        .eq(BusPumpEntity::getPatientCode, patientCode));
+        BusDeviceUsingEntity existDevice = netPumpService
+                .getOne(new QueryWrapper<BusDeviceUsingEntity>().lambda().eq(BusDeviceUsingEntity::getTenantId, hospitalId)
+                        .eq(BusDeviceUsingEntity::getPatientCode, patientCode));
         if(existDevice==null){
             return true;
         }
@@ -82,8 +82,8 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
     @Transactional(rollbackFor = Exception.class)
     public void changePump(String hospitalId,String patientCode,String newDeviceId){
         log.info("医院id:[{}],病号:[{}],进行换泵操作,现设备id:[{}]",patientCode,hospitalId,newDeviceId);
-        netPumpService.update(new UpdateWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getPatientCode,patientCode).set(BusPumpEntity::getMaster,0));
-        netPumpService.update(new UpdateWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getDeviceId,newDeviceId).set(BusPumpEntity::getMaster,1));
+        netPumpService.update(new UpdateWrapper<BusDeviceUsingEntity>().lambda().eq(BusDeviceUsingEntity::getPatientCode,patientCode).set(BusDeviceUsingEntity::getMaster,0));
+        netPumpService.update(new UpdateWrapper<BusDeviceUsingEntity>().lambda().eq(BusDeviceUsingEntity::getDeviceId,newDeviceId).set(BusDeviceUsingEntity::getMaster,1));
     }
 
 

+ 55 - 40
coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java

@@ -1,15 +1,14 @@
 package com.coffee.bus.websocket.listener;
 
 import cn.hutool.core.collection.CollectionUtil;
-import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 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.IdWorker;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import com.coffee.bus.registry.device.DeviceRegistry;
-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;
@@ -19,7 +18,7 @@ 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.LocalBusPumpService;
+import com.coffee.bus.service.LocalBusDeviceUsingService;
 import com.coffee.bus.service.LocalBusPatientService;
 import com.coffee.common.config.websocket.WebSocketConstant;
 import lombok.AllArgsConstructor;
@@ -27,12 +26,12 @@ 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.function.Supplier;
 import java.util.stream.Collectors;
 
 /**
@@ -49,7 +48,7 @@ public class DeviceInfoListener {
 
     private final RedisTemplate redisTemplate;
 
-    private final LocalBusPumpService deviceUsingService;
+    private final LocalBusDeviceUsingService deviceUsingService;
 
     private final LocalBusPatientService patientService;
 
@@ -70,7 +69,7 @@ public class DeviceInfoListener {
         //若数据发送过快,为防止冲突,请在此加锁处理 todo
         synchronized (infoEvent.getDeviceId()){
             /****************处理泵数据****************/
-            BusPumpEntity device = infoEvent.getContent();
+            BusDeviceUsingEntity device = infoEvent.getContent();
             //1、判断该设备是否已和医院绑定并开启使用
             String deviceId = device.getDeviceId();
             DeviceOperator<DeviceCacheInfo> deviceOperator = deviceRegistry.getDevice(deviceId);
@@ -79,20 +78,23 @@ public class DeviceInfoListener {
                 return ;
             }
             log.info("接收到设备数据:[{}]",infoEvent.getContent().toString());
+//            deviceOperator.setStartTime(new Date());
             String tenantId = deviceOperator.getTenantId();
             PatientOperator<PatientCacheInfo> patientOperator =patientRegistry.getPatient(tenantId, device.getPatientCode());
             device.setTenantId(tenantId);
             device.setMonitorType(1);
+            //默认为主泵
+            device.setMaster(1);
+            device.setStartTime(deviceOperator.getStartTime());
+            device.setAlias(deviceOperator.getAlias());
             String usingId = deviceOperator.getUsingId();
             if(StrUtil.isNullOrUndefined(usingId)){
                 //不存在运行id,即首次运行,需要与病人、医院进行绑定
                 initDevice(device,deviceOperator);
                 initPatient(device,patientOperator);
-                deviceUsingService.save(device);
             }
             else {
                 device.setId(usingId);
-                deviceUsingService.updateById(device);
             }
             /****************处理泵数据****************/
 
@@ -100,13 +102,15 @@ public class DeviceInfoListener {
             //泵绑定重复判定
             //获取病号当前绑定的泵号
             String bindDeviceId = patientOperator.getBindDeviceId();
-            if(StrUtil.isNullOrUndefined(bindDeviceId)&&deviceId.equals(bindDeviceId)){
+            if(!StrUtil.isNullOrUndefined(bindDeviceId)&&!deviceId.equals(bindDeviceId)){
                 //泵号发生改变,判断泵的开始时间,将开始时间稍后的泵设置为主泵再与设备绑定
                 DeviceOperator currentBindDevice = deviceRegistry.getDevice(bindDeviceId);
                 if (currentBindDevice.getStartTime().before(device.getStartTime())) {
                     //设置当前上传信息的泵为主泵,将旧泵设置为副泵吗,并更新病人绑定泵的信息, todo 发生泵重复报警
-                    deviceUsingService.update(new UpdateWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getDeviceId,deviceId).set(BusPumpEntity::getMaster,1));
-                    deviceUsingService.update(new UpdateWrapper<BusPumpEntity>().lambda().eq(BusPumpEntity::getDeviceId,bindDeviceId).set(BusPumpEntity::getMaster,0));
+                    deviceUsingService.update(new UpdateWrapper<BusDeviceUsingEntity>().lambda().eq(BusDeviceUsingEntity::getDeviceId,deviceId).set(BusDeviceUsingEntity::getMaster,1));
+                    deviceUsingService.update(new UpdateWrapper<BusDeviceUsingEntity>().lambda().eq(BusDeviceUsingEntity::getDeviceId,bindDeviceId).set(BusDeviceUsingEntity::getMaster,0));
+                }else {
+                    device.setMaster(0);
                 }
             }
             if (StrUtil.isNullOrUndefined(bindDeviceId)) {
@@ -117,10 +121,11 @@ public class DeviceInfoListener {
             //上条记录所绑定的病号
             String originPatientCode=deviceOperator.getPatientCode();
             //当泵所绑定的病号发生变化时,进行原先泵号无泵判定
-            if(!device.getPatientCode().equals(originPatientCode)){
+            if(!StrUtil.isNullOrUndefined(originPatientCode)&&!device.getPatientCode().equals(originPatientCode)){
                 //检查是原先的病号是否发生了无泵异常
-                PatientOperator originPatientOperator =patientRegistry.getPatient(tenantId, originPatientCode);
+                PatientOperator<PatientCacheInfo> originPatientOperator =patientRegistry.getPatient(tenantId, originPatientCode);
                 Set<DeviceTimeSmallInfo> originPatientBindDevices = originPatientOperator.getAllDevice();
+
                 Set<DeviceTimeSmallInfo> originRemainPatientBindDevices = originPatientBindDevices.stream().filter(bindDevice -> !bindDevice.getDeviceId().equals(deviceId)).collect(Collectors.toSet());
                 //临床无泵绑定时,查看是否存在副泵,若存在将开始时间稍后的泵设置为副泵,若不存在,则报无泵异常
                 if(CollectionUtil.isEmpty(originRemainPatientBindDevices)){
@@ -133,9 +138,9 @@ public class DeviceInfoListener {
                     Optional<DeviceTimeSmallInfo> master = originRemainPatientBindDevices.stream().max((o1,o2)->o1.getStartTime().before(o2.getStartTime()) ? 1 : 0);
                     if(master.isPresent()){
                         deviceUsingService
-                                .update(new UpdateWrapper<BusPumpEntity>().lambda()
-                                        .eq(BusPumpEntity::getDeviceId,master.get().getDeviceId())
-                                        .set(BusPumpEntity::getMaster,1));
+                                .update(new UpdateWrapper<BusDeviceUsingEntity>().lambda()
+                                        .eq(BusDeviceUsingEntity::getDeviceId,master.get().getDeviceId())
+                                        .set(BusDeviceUsingEntity::getMaster,1));
                         //更新泵原来绑定病人缓存信息
                         originPatientOperator.setBindDeviceId(master.get().getDeviceId());
                     }
@@ -143,7 +148,7 @@ public class DeviceInfoListener {
                 //更新泵原来绑定病人缓存信息
                 originPatientOperator.setAllDevice(originRemainPatientBindDevices);
             }
-
+            deviceUsingService.saveOrUpdate(device);
             /****************处理泵与患者关系****************/
 
             //则推送设备上报消息
@@ -156,13 +161,13 @@ public class DeviceInfoListener {
                     .usingId(device.getId())
                     .status(device.getRunState())
                     .startTime(device.getStartTime())
-                    .master(device.getMaster() == 1)
+                    .master(device.getMaster()!=null&&device.getMaster() == 1)
                     .patientCode(device.getPatientCode())
                     .mark(device.getMark())
                     .build();
             deviceOperator.set(deviceCacheInfo);
             //更新病人缓存信息
-            Set allDevice = patientOperator.getAllDevice();
+            Set<DeviceTimeSmallInfo> allDevice = Optional.ofNullable(patientOperator.getAllDevice()).orElse(new HashSet<>());
             allDevice.add(DeviceTimeSmallInfo.of(deviceId,device.getStartTime()));
             PatientCacheInfo patientCacheInfo = PatientCacheInfo.builder()
                     .bindDeviceId(deviceId)
@@ -185,7 +190,7 @@ public class DeviceInfoListener {
      * @param pump
      * @param patientOperator
      */
-    private void initPatient(BusPumpEntity pump, PatientOperator patientOperator) {
+    private void initPatient(BusDeviceUsingEntity pump, PatientOperator patientOperator) {
         //填充病人名称和病人性别
         pump.setPatientName(patientOperator.getName());
         pump.setPatientSex(patientOperator.getGender());
@@ -199,7 +204,7 @@ public class DeviceInfoListener {
     @EventListener
     @Async
     public void deviceAlarm(DeviceAlarmEvent alarmEvent){
-        BusPumpEntity pump = alarmEvent.getContent();
+        BusDeviceUsingEntity pump = alarmEvent.getContent();
         //获取医院配置,对医院功能配置进行过滤筛选
         NetPumpStatusEnum runState = pump.getRunState();
         //是否解除报警状态
@@ -208,10 +213,10 @@ public class DeviceInfoListener {
             //存储报警信息 todo
             String topic = WebSocketConstant.getDeviceStateCount(null, runState.name(), pump.getTenantId());
             //获取报警设备数量
-            List<BusPumpEntity> alarmList = deviceUsingService.list(new QueryWrapper<BusPumpEntity>()
+            List<BusDeviceUsingEntity> alarmList = deviceUsingService.list(new QueryWrapper<BusDeviceUsingEntity>()
                     .lambda()
-                    .select(BusPumpEntity::getId)
-                    .eq(BusPumpEntity::getRunState, runState));
+                    .select(BusDeviceUsingEntity::getId)
+                    .eq(BusDeviceUsingEntity::getRunState, runState));
             //发送告警通知,获取报警设备数量, 下标为0是报警设备总数量,下标为1是设备所属医院的报警设备总数量
             List<? extends Number> result = Arrays.asList(alarmList.size(), alarmList.stream().filter(alarm -> alarm.getTenantId().equals(pump.getTenantId())).count());
             redisTemplate.convertAndSend(topic, result);
@@ -224,7 +229,7 @@ public class DeviceInfoListener {
      * @param pump
      * @param deviceOperator
      */
-    private void initDevice(BusPumpEntity pump, DeviceOperator deviceOperator){
+    private void initDevice(BusDeviceUsingEntity pump, DeviceOperator deviceOperator){
         //处理无泵状态(即泵首次与医院进行绑定)
         Date now = new Date();
         //设置注册时间和泵的开始时间
@@ -234,23 +239,33 @@ public class DeviceInfoListener {
         pump.setAlias(deviceOperator.getAlias());
     }
 
-    //    @Scheduled(cron = "0/10 * * * * ?")
-    public void send(){
-//        List<BusPumpEntity> list = deviceUsingService.list();
+    @Scheduled(cron = "0/20 * * * * ?")
+    public void send() throws InterruptedException {
+//        List<BusDeviceUsingEntity> list = deviceUsingService.list();
 //        list.forEach(pump->{
+        BusDeviceUsingEntity pump = new BusDeviceUsingEntity();
+        pump.setDeviceId("123");
+        pump.setPatientCode("456");
+        pump.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+        pump.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+        pump.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+        pump.setValidTime(RandomUtil.randomInt(100));
+        pump.setInvalidTime(RandomUtil.randomInt(100));
+        pump.setTotalCount(RandomUtil.randomInt(100));
+        SpringUtil.publishEvent(new DeviceInfoEvent(this,pump,pump.getDeviceId()));
+
+        Thread.sleep(5000);
 
-        ThreadUtil.concurrencyTest(1,()->  {
-            BusPumpEntity pump = new BusPumpEntity();
-            pump.setDeviceId("123");
-            pump.setPatientCode("456");
-            pump.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-            pump.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-            pump.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
-            pump.setValidTime(RandomUtil.randomInt(100));
-            pump.setInvalidTime(RandomUtil.randomInt(100));
-            pump.setTotalCount(RandomUtil.randomInt(100));
-            SpringUtil.publishEvent(new DeviceInfoEvent(this,pump,pump.getDeviceId()));
-        });
+        BusDeviceUsingEntity pump1 = new BusDeviceUsingEntity();
+        pump1.setDeviceId("567");
+        pump1.setPatientCode("456");
+        pump1.setRemainDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+        pump1.setContinueDose(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+        pump1.setSelfControlLockTime(BigDecimal.valueOf(RandomUtil.randomInt(100)));
+        pump1.setValidTime(RandomUtil.randomInt(100));
+        pump1.setInvalidTime(RandomUtil.randomInt(100));
+        pump1.setTotalCount(RandomUtil.randomInt(100));
+        SpringUtil.publishEvent(new DeviceInfoEvent(this,pump1,pump1.getDeviceId()));
 //        });
     }
 }

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

@@ -9,7 +9,7 @@ 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.BusPumpEntity;
+import com.coffee.bus.entity.BusDeviceUsingEntity;
 import com.coffee.bus.entity.BusPumpHistoryEntity;
 import com.coffee.bus.entity.BusPatientEntity;
 import com.coffee.bus.listener.event.bean.HistoryInfoEvent;
@@ -17,11 +17,8 @@ import com.coffee.bus.script.ExecuteResult;
 import com.coffee.bus.script.ScriptManager;
 import com.coffee.bus.service.*;
 import com.coffee.common.config.websocket.WebSocketConstant;
-import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Lazy;
 import org.springframework.context.event.EventListener;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
@@ -53,10 +50,10 @@ public class HistoryInfoListener {
 
     private final RedisTemplate redisTemplate;
 
-    private final LocalBusPumpService pumpService;
+    private final LocalBusDeviceUsingService pumpService;
 
     @Autowired
-    public HistoryInfoListener(ScriptManager scriptManager, LocalBusPatientService patientService, LocalBusClinicService clinicService, LocalBusPumpHistoryService historyService, RedisTemplate redisTemplate, LocalBusPumpService pumpService) {
+    public HistoryInfoListener(ScriptManager scriptManager, LocalBusPatientService patientService, LocalBusClinicService clinicService, LocalBusPumpHistoryService historyService, RedisTemplate redisTemplate, LocalBusDeviceUsingService pumpService) {
         this.scriptManager = scriptManager;
         this.patientService = patientService;
         this.clinicService = clinicService;
@@ -155,16 +152,16 @@ public class HistoryInfoListener {
             clinic.setDeviceCodes(historyList.stream().map(BusPumpHistoryEntity::getDeviceId).collect(Collectors.toSet()));
         }
 
-        pumpService.update(new UpdateWrapper<BusPumpEntity>()
+        pumpService.update(new UpdateWrapper<BusDeviceUsingEntity>()
                 .lambda()
-                .eq(BusPumpEntity::getPatientCode,clinic.getPatientCode())
-                .eq(BusPumpEntity::getTenantId,clinic.getTenantId())
-                .isNull(BusPumpEntity::getClinicId)
-                .set(BusPumpEntity::getClinicId,clinic.getId())
-                .set(BusPumpEntity::getPatientSex,clinic.getPatientGender())
-                .set(BusPumpEntity::getWard,clinic.getWard())
-                .set(BusPumpEntity::getBedNo,clinic.getBedNo())
-                .set(BusPumpEntity::getPatientName,clinic.getPatientName()));
+                .eq(BusDeviceUsingEntity::getPatientCode,clinic.getPatientCode())
+                .eq(BusDeviceUsingEntity::getTenantId,clinic.getTenantId())
+                .isNull(BusDeviceUsingEntity::getClinicId)
+                .set(BusDeviceUsingEntity::getClinicId,clinic.getId())
+                .set(BusDeviceUsingEntity::getPatientSex,clinic.getPatientGender())
+                .set(BusDeviceUsingEntity::getWard,clinic.getWard())
+                .set(BusDeviceUsingEntity::getBedNo,clinic.getBedNo())
+                .set(BusDeviceUsingEntity::getPatientName,clinic.getPatientName()));
 
         clinicService.save(clinic);
         log.info("新增临床信息,[{}]",clinic);