Pārlūkot izejas kodu

update 缓存方式

A17404李放 3 gadi atpakaļ
vecāks
revīzija
79a62de41d

+ 2 - 2
nb-admin/src/main/resources/application-dev.yml

@@ -101,7 +101,7 @@ spring:
         max-wait: -1ms
 request:
   check:
-    enable: false
+    enable: true
     # 开启请求验签
     sign: true
     # 请求与服务器时间间隔不得超过 10分钟
@@ -120,6 +120,6 @@ aliyun:
   # iotInstanceId:企业版实例请填写实例ID,公共实例请填空字符串""。
   iotInstanceId: ""
   server-subscription:
-    enable: false  # 是否开启阿里云物联网服务端订阅
+    enable: true  # 是否开启阿里云物联网服务端订阅
   product:
     productKey: a1ALlsBa2ZK

+ 0 - 10
nb-common/pom.xml

@@ -15,16 +15,6 @@
         <dependency>
             <groupId>org.t-io</groupId>
             <artifactId>tio-websocket-spring-boot-starter</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-data-redis</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>io.undertow</groupId>
-            <artifactId>undertow-servlet</artifactId>
-            <optional>true</optional>
-            <scope>compile</scope>
         </dependency>
          <!--websocket 模块-->
         <!--<dependency>-->

+ 0 - 3
nb-common/src/main/java/com/coffee/common/config/CachingContentFilter.java

@@ -1,14 +1,11 @@
 package com.coffee.common.config;
 
 import cn.hutool.core.text.CharSequenceUtil;
-import io.undertow.servlet.spec.HttpServletRequestImpl;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.RequestParam;
 
 import javax.servlet.*;
 import javax.servlet.annotation.WebFilter;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 
 /**

+ 2 - 0
nb-oss/src/main/java/com/coffee/oss/strategy/impl/MinioStorageStrategy.java

@@ -8,11 +8,13 @@ import com.coffee.common.util.MinioUtil;
 import com.coffee.oss.strategy.storage.LocalSysStorageService;
 import com.coffee.oss.strategy.storage.SysStorage;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.xddf.usermodel.SystemColor;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import java.io.IOException;
+import java.util.ArrayList;
 
 /**
  * MinIO文件存储策略

+ 9 - 3
nb-oss/src/main/java/com/coffee/oss/strategy/storage/SysStorage.java

@@ -49,7 +49,7 @@ public class SysStorage extends GenericEntity<String> implements Serializable {
     private String suffix;
 
     @ApiModelProperty(value = "路径")
-    private String path;
+    private String url;
 
     @ApiModelProperty(value = "类型")
     private String type;
@@ -61,14 +61,20 @@ public class SysStorage extends GenericEntity<String> implements Serializable {
     private String version;
 
     public SysStorage(String realName, String name, String suffix, String path, String type, String size) {
-        new SysStorage(realName,name,suffix,path,type,size,null);
+        this.realName = realName;
+        this.name = name;
+        this.suffix = suffix;
+        this.url = path;
+        this.type = type;
+        this.size = size;
+        this.version=null;
     }
 
     public SysStorage(String realName, String name, String suffix, String path, String type, String size,String version) {
         this.realName = realName;
         this.name = name;
         this.suffix = suffix;
-        this.path = path;
+        this.url = path;
         this.type = type;
         this.size = size;
         this.version=version;

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

@@ -9,6 +9,8 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
+
+import java.math.BigDecimal;
 import java.util.Date;
 
 /**
@@ -26,6 +28,9 @@ import java.util.Date;
 @ApiModel(value="设备历史运行数据", description="设备历史运行数据记录")
 public class BusDeviceHistoryEntity extends CommonDeviceParam<String,String> {
 
+    @ApiModelProperty(value = "公共-此次输注过程中到此为止的总追加量")
+    private BigDecimal totalAppendDose;
+
     @ApiModelProperty(value = "输注记录id")
     @JsonIgnoreProperties
     private String infusionId;
@@ -46,6 +51,7 @@ public class BusDeviceHistoryEntity extends CommonDeviceParam<String,String> {
     public static BusDeviceHistoryEntity parseRunningInfo(BusDeviceRunningEntity running){
         BusDeviceHistoryEntity entity = new BusDeviceHistoryEntity();
         BeanUtil.copyProperties(running,entity);
+        entity.setPatientCode(running.getPatientCode());
         entity.setInfusionId(running.getInfusionId());
         entity.setInfusionModifyId(running.getInfusionModifyId());
         entity.setUploadTime(running.getUploadTime());

+ 3 - 1
nb-system/src/main/java/com/coffee/bus/entity/BusDeviceRunningEntity.java

@@ -32,10 +32,12 @@ import java.util.Optional;
 @Data
 @EqualsAndHashCode(callSuper = true)
 @Accessors(chain = true)
-@TableName(value = "bus_device_running",autoResultMap = true)
 @ApiModel(value="设备运行状态", description="设备运行状态")
 public class BusDeviceRunningEntity extends CommonDeviceParam<String,String> {
 
+    @ApiModelProperty(value = "公共-此次输注过程中到此为止的总追加量")
+    private BigDecimal totalAppendDose;
+
     @ApiModelProperty(value = "输注记录")
     private String infusionId;
 

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

@@ -14,6 +14,7 @@ import lombok.EqualsAndHashCode;
 import lombok.ToString;
 import lombok.experimental.Accessors;
 
+import java.math.BigDecimal;
 import java.util.Date;
 
 /**
@@ -31,6 +32,9 @@ import java.util.Date;
 @ApiModel(value="设备输注历史信息记录", description="设备的classification标识每改变一次,就算一次新的输注记录")
 public class BusInfusionHistoryEntity extends CommonDeviceParam<String,String> {
 
+    @ApiModelProperty(value = "公共-此次输注过程中到此为止的总追加量")
+    private BigDecimal totalAppendDose;
+
     @ApiModelProperty(value = "临床号")
     private String clinicId;
 

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

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

+ 11 - 0
nb-system/src/main/java/com/coffee/bus/registry/Operator.java

@@ -8,6 +8,7 @@ import org.springframework.util.ReflectionUtils;
 
 import java.lang.reflect.Field;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author lifang
@@ -18,6 +19,11 @@ import java.util.*;
  */
 public interface Operator {
 
+    /**
+     * 默认过期时间 24小时
+     */
+    long DEFAULT_TTL=2;
+
     RMapCache<String, Value> getCache();
 
     default Value wrapperValue(Object value){
@@ -34,4 +40,9 @@ public interface Operator {
         }
         return value;
     }
+
+    default void put(String key,Value value){
+        getCache()
+                .put(key,value,DEFAULT_TTL, TimeUnit.HOURS);
+    }
 }

+ 5 - 0
nb-system/src/main/java/com/coffee/bus/registry/constant/DeviceKeyConstant.java

@@ -28,4 +28,9 @@ public class DeviceKeyConstant {
     public static final String CONTINUE_DOSE="continue_dose";
 
     public static final String IS_EXIST="is_exist";
+
+
+    public static final String VALID_PCA="valid_pca";
+
+    public static final String APPEND_DOSE="append_dose";
 }

+ 49 - 14
nb-system/src/main/java/com/coffee/bus/registry/device/ClusterDeviceOperator.java

@@ -11,8 +11,6 @@ import com.coffee.bus.service.LocalBusDeviceService;
 import com.coffee.bus.service.LocalBusInfusionHistoryService;
 import com.coffee.common.cache.value.Value;
 import com.coffee.common.util.RedissonUtil;
-import org.redisson.api.LocalCachedMapOptions;
-import org.redisson.api.RMap;
 import org.redisson.api.RMapCache;
 import java.math.BigDecimal;
 import java.util.Date;
@@ -49,7 +47,7 @@ public class ClusterDeviceOperator implements DeviceOperator {
 
     @Override
     public void setExist(Boolean exist) {
-        mapCache.put(DeviceKeyConstant.IS_EXIST,wrapperValue(exist),DEFAULT_TTL, TimeUnit.HOURS);
+        put(DeviceKeyConstant.IS_EXIST,wrapperValue(exist));
     }
 
     @Override
@@ -70,7 +68,7 @@ public class ClusterDeviceOperator implements DeviceOperator {
 
     @Override
     public void setEnable(Boolean enable) {
-        mapCache.put(DeviceKeyConstant.ENABLE,wrapperValue(enable),DEFAULT_TTL, TimeUnit.HOURS);
+        put(DeviceKeyConstant.ENABLE,wrapperValue(enable) );
     }
 
     @Override
@@ -86,7 +84,7 @@ public class ClusterDeviceOperator implements DeviceOperator {
 
     @Override
     public void setTenantId(String tenantId) {
-        mapCache.put(DeviceKeyConstant.TENANT_ID,wrapperValue(tenantId),DEFAULT_TTL, TimeUnit.HOURS);
+        put(DeviceKeyConstant.TENANT_ID,wrapperValue(tenantId) );
     }
 
     @Override
@@ -103,7 +101,7 @@ public class ClusterDeviceOperator implements DeviceOperator {
 
     @Override
     public void setStartTime(Date startTime) {
-        mapCache.put(DeviceKeyConstant.START_TIME,wrapperValue(startTime),DEFAULT_TTL, TimeUnit.HOURS);
+        put(DeviceKeyConstant.START_TIME,wrapperValue(startTime) );
     }
 
     @Override
@@ -111,15 +109,20 @@ public class ClusterDeviceOperator implements DeviceOperator {
         Value value = getValue(DeviceKeyConstant.START_TIME);
         if(value==null){
             BusInfusionHistoryEntity lastInfusion = getLastInfusion();
-            value=Value.simple(lastInfusion.getStartTime());
-            setStartTime(lastInfusion.getStartTime());
+            if(lastInfusion!=null){
+                value=Value.simple(lastInfusion.getStartTime());
+                setStartTime(lastInfusion.getStartTime());
+            }else {
+                return null;
+            }
+
         }
         return value.asDate();
     }
 
     @Override
     public void setPatientCode(String patientCode) {
-        mapCache.put(DeviceKeyConstant.PATIENT_CODE,wrapperValue(patientCode),DEFAULT_TTL, TimeUnit.HOURS);
+        put(DeviceKeyConstant.PATIENT_CODE,wrapperValue(patientCode) );
     }
 
     @Override
@@ -135,7 +138,7 @@ public class ClusterDeviceOperator implements DeviceOperator {
 
     @Override
     public void setAlarmOrWarn(String alarm) {
-        mapCache.put(DeviceKeyConstant.ALARM,wrapperValue(alarm),DEFAULT_TTL, TimeUnit.HOURS);
+        put(DeviceKeyConstant.ALARM,wrapperValue(alarm) );
     }
 
     @Override
@@ -152,7 +155,7 @@ public class ClusterDeviceOperator implements DeviceOperator {
 
     @Override
     public void setInfusionId(String infusionId) {
-        mapCache.put(DeviceKeyConstant.INFUSION_ID,wrapperValue(infusionId),DEFAULT_TTL, TimeUnit.HOURS);
+        put(DeviceKeyConstant.INFUSION_ID,wrapperValue(infusionId) );
     }
 
     @Override
@@ -168,7 +171,7 @@ public class ClusterDeviceOperator implements DeviceOperator {
 
     @Override
     public void setInfusionParam(String infusionParam) {
-        mapCache.put(DeviceKeyConstant.INFUSION_PARAM,wrapperValue(infusionParam),DEFAULT_TTL, TimeUnit.HOURS);
+        put(DeviceKeyConstant.INFUSION_PARAM,wrapperValue(infusionParam) );
     }
 
     @Override
@@ -191,7 +194,7 @@ public class ClusterDeviceOperator implements DeviceOperator {
 
     @Override
     public void setClassification(String classification) {
-        mapCache.put(DeviceKeyConstant.CLASSIFY,wrapperValue(classification),DEFAULT_TTL, TimeUnit.HOURS);
+        put(DeviceKeyConstant.CLASSIFY,wrapperValue(classification));
     }
 
     @Override
@@ -220,7 +223,39 @@ public class ClusterDeviceOperator implements DeviceOperator {
 
     @Override
     public void setContinueDose(BigDecimal continueDose) {
-        mapCache.put(DeviceKeyConstant.CONTINUE_DOSE,wrapperValue(continueDose),DEFAULT_TTL, TimeUnit.HOURS);
+        put(DeviceKeyConstant.CONTINUE_DOSE,wrapperValue(continueDose) );
+    }
+
+    @Override
+    public void setLastPcaValidCount(Integer pcaValidCount) {
+        put(DeviceKeyConstant.VALID_PCA,wrapperValue(pcaValidCount) );
+    }
+
+    @Override
+    public Integer getLastPcaValidCount() {
+        Value value = getValue(DeviceKeyConstant.VALID_PCA);
+        if(value==null){
+            BusInfusionHistoryEntity lastInfusion = getLastInfusion();
+            value=Value.simple(lastInfusion.getPcaValidCount());
+            setLastPcaValidCount(lastInfusion.getPcaValidCount());
+        }
+        return value.asInt();
+    }
+
+    @Override
+    public void setTotalAppendDose(BigDecimal totalAppendDose) {
+        put(DeviceKeyConstant.APPEND_DOSE,wrapperValue(totalAppendDose) );
+    }
+
+    @Override
+    public BigDecimal getTotalAppendDose() {
+        Value value = getValue(DeviceKeyConstant.APPEND_DOSE);
+        if(value==null){
+            BusInfusionHistoryEntity lastInfusion = getLastInfusion();
+            value=Value.simple(lastInfusion.getTotalAppendDose());
+            setTotalAppendDose(lastInfusion.getTotalAppendDose());
+        }
+        return value.as(BigDecimal.class);
     }
 
     @Override

+ 27 - 4
nb-system/src/main/java/com/coffee/bus/registry/device/DeviceOperator.java

@@ -17,10 +17,7 @@ import java.util.Date;
  */
 public interface DeviceOperator extends Operator {
 
-    /**
-     * 默认过期时间 24小时
-     */
-     long DEFAULT_TTL=2;
+
 
 
 
@@ -159,5 +156,31 @@ public interface DeviceOperator extends Operator {
     void setContinueDose(BigDecimal continueDose);
 
 
+    /**
+     * 设置此次输注过程中的总有效PCA次数
+     * @param pcaValidCount
+     */
+    void setLastPcaValidCount(Integer pcaValidCount);
+
+    /**
+     * 获取此次输注过程中的总有效PCA次数
+     *
+     */
+    Integer getLastPcaValidCount();
+
+
+    /**
+     * 设置此次输注过程中的总追加量
+     * @param totalAppendDose
+     */
+    void setTotalAppendDose(BigDecimal totalAppendDose);
+
+    /**
+     * 获取此次输注过程中的总追加量
+     *
+     */
+    BigDecimal getTotalAppendDose();
+
+
     void clear();
 }

+ 4 - 7
nb-system/src/main/java/com/coffee/bus/registry/patient/ClusterPatientOperator.java

@@ -11,9 +11,6 @@ import com.coffee.bus.service.LocalBusPatientService;
 import com.coffee.common.cache.value.Value;
 import com.coffee.common.util.RedissonUtil;
 import org.redisson.api.RMapCache;
-import java.util.concurrent.TimeUnit;
-
-import static com.coffee.bus.registry.device.DeviceOperator.DEFAULT_TTL;
 
 /**
  * @author lifang
@@ -45,7 +42,7 @@ public class ClusterPatientOperator implements PatientOperator {
 
     @Override
     public void setExist(Boolean exist) {
-        mapCache.put(PatientKeyConstant.IS_EXIST,wrapperValue(exist),DEFAULT_TTL, TimeUnit.HOURS);
+        put(PatientKeyConstant.IS_EXIST,wrapperValue(exist));
     }
 
     @Override
@@ -73,7 +70,7 @@ public class ClusterPatientOperator implements PatientOperator {
 
     @Override
     public void setClinicId(String clinicId) {
-        mapCache.put(PatientKeyConstant.CLINIC_ID,wrapperValue(clinicId),DEFAULT_TTL, TimeUnit.HOURS);
+        put(PatientKeyConstant.CLINIC_ID,wrapperValue(clinicId));
     }
 
     @Override
@@ -89,7 +86,7 @@ public class ClusterPatientOperator implements PatientOperator {
 
     @Override
     public void setBindDeviceId(String deviceId) {
-        mapCache.put(PatientKeyConstant.BIND_DEVICE_ID,wrapperValue(deviceId),DEFAULT_TTL, TimeUnit.HOURS);
+        put(PatientKeyConstant.BIND_DEVICE_ID,wrapperValue(deviceId));
     }
 
     @Override
@@ -120,7 +117,7 @@ public class ClusterPatientOperator implements PatientOperator {
 
     @Override
     public void setPatientId(String patientId) {
-        mapCache.put(PatientKeyConstant.PATIENT_ID,wrapperValue(patientId),DEFAULT_TTL, TimeUnit.HOURS);
+        put(PatientKeyConstant.PATIENT_ID,wrapperValue(patientId));
     }
 
     @Override

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

@@ -26,6 +26,8 @@ import org.springframework.context.event.EventListener;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.DecimalMin;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.List;
@@ -80,7 +82,6 @@ public class DeviceInfoListener {
     public void deviceInfoDetail(DeviceInfoEvent infoEvent){
         //保证统一设备数据顺序处理,若数据发送过快,为防止冲突,请在此加锁处理
         synchronized (infoEvent.getDeviceId()){
-            try {
                 log.info("接收到设备消息:{}",JSONUtil.toJsonStr(infoEvent.getContent()));
                 BusDeviceRunningEntity device = infoEvent.getContent();
                 String classification = device.getClassification();
@@ -149,11 +150,6 @@ public class DeviceInfoListener {
                 cacheOperation.forEach(Supplier::get);
                 log.info("设备数据处理结束:{}",JSONUtil.toJsonStr(infoEvent.getContent()));
                 log.info("设备数据处理耗时:{}",(System.currentTimeMillis()-startTime));
-            }catch (Exception e){
-                e.printStackTrace();
-                throw e;
-            }
-
         }
     }
 
@@ -196,7 +192,6 @@ public class DeviceInfoListener {
         device.setMonitorType(true);
         device.setUploadTime(device.getUploadTime()==null?new Date():device.getUploadTime());
 
-        device.setStartTime(deviceOperator.getStartTime());
         device.setTenantId(deviceOperator.getTenantId());
         //将设备撤泵标志去除
         device.setIsUndo(false);
@@ -287,14 +282,17 @@ public class DeviceInfoListener {
         boolean newInfusion=isNewInFusion(device.getDeviceId(),device.getClassification());
         device.setNewInfusion(newInfusion);
         if(newInfusion){
-//            BusDeviceEntity deviceEntity = deviceService.getByDeviceId(device.getDeviceId());
-            device.setTenantId(deviceOperator.getTenantId());
+            device.setStartTime(device.getUploadTime());
+        }else {
+            device.setStartTime(deviceOperator.getStartTime());
         }
         PatientOperator patientOperator = patientRegistry.getOperator(device.getTenantId(), device.getPatientCode(),MapUtil.of("startTime", device.getStartTime()));
         device.setClinicId(patientOperator.getClinicId());
         device.setPatientId(patientOperator.getPatientId());
-        //智能泵处理
+        //处理智能泵数据
         handleIntelligent(device,deviceOperator);
+        //处理追加量数据
+        handleAppendDose(device,deviceOperator,cacheOperation);
         BusInfusionHistoryEntity infusionHistory = BusInfusionHistoryEntity.parseRunningInfo(device);
         String originInfusionId = deviceOperator.getInfusionId();
         if(ObjectUtil.equal(device.getDeviceId(),patientOperator.getBindDeviceId())){
@@ -334,6 +332,53 @@ public class DeviceInfoListener {
         return infusionHistory;
     }
 
+    /**
+     * 描述: 处理追加量数据
+     * @author lifang
+     * @date 2022/7/1 11:05
+     * @param device
+     * @param deviceOperator
+     * @return void
+     */
+    private void handleAppendDose(BusDeviceRunningEntity device, DeviceOperator deviceOperator, List<Supplier<?>> cacheOperation) {
+        BigDecimal appendDose = device.getAppendDose();
+        device.setTotalAppendDose(BigDecimal.ZERO);
+        if(device.isNewInfusion()){
+            //仅计算此次输注过程中的追加量
+            if(appendDose!=null){
+                device.setTotalAppendDose(appendDose.multiply(BigDecimal.valueOf(Optional.ofNullable(device.getPcaValidCount()).orElse(0))));
+            }
+        }else{
+            if(device.getPcaValidCount()==null||device.getPcaValidCount()==0){
+                device.setTotalAppendDose(BigDecimal.ZERO);
+            }else {
+                Integer lastPcaValidCount = deviceOperator.getLastPcaValidCount();
+                //当pca值变小是则以当前值为准重新计算
+                int compare = CompareUtil.compare(device.getPcaValidCount(),lastPcaValidCount);
+                BigDecimal totalAppendDose = deviceOperator.getTotalAppendDose();
+                if(compare==0){
+                    device.setTotalAppendDose(totalAppendDose);
+                }else if(compare>0){
+                    BigDecimal appendTotalDose=appendDose.multiply(BigDecimal.valueOf(device.getPcaValidCount()-lastPcaValidCount));
+                    totalAppendDose=totalAppendDose.add(appendTotalDose);
+                    device.setTotalAppendDose(totalAppendDose);
+                }else {
+                    device.setTotalAppendDose(appendDose.multiply(BigDecimal.valueOf(Optional.ofNullable(device.getPcaValidCount()).orElse(0))));
+                }
+            }
+
+        }
+
+        cacheOperation.add(()->{
+            if(device.isNewInfusion()){
+                deviceOperator.setLastPcaValidCount(Optional.ofNullable(device.getPcaValidCount()).orElse(0));
+            }
+            deviceOperator.setTotalAppendDose(Optional.ofNullable(device.getTotalAppendDose()).orElse(BigDecimal.ZERO));
+            return null;
+        });
+
+    }
+
     /**
      * 描述: 处理输注参数
      * @author lifang

+ 4 - 1
nb-system/src/main/resources/mapper/bus/BusClinicMapper.xml

@@ -36,8 +36,11 @@
         <if test="query.continueDose!=false">
             h.continue_dose as continue_dose,
         </if>
+        <!--<if test="query.appendDose!=false">-->
+            <!--h.append_dose as append_dose,-->
+        <!--</if>-->
         <if test="query.appendDose!=false">
-            h.append_dose as append_dose,
+            h.total_append_dose as append_dose,
         </if>
         <if test="query.inputDose!=false">
             h.input_dose as input_dose,