Browse Source

add 病号格式化

A17404李放 3 years ago
parent
commit
b4911a621a

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

@@ -120,6 +120,6 @@ aliyun:
   # iotInstanceId:企业版实例请填写实例ID,公共实例请填空字符串""。
   iotInstanceId: ""
   server-subscription:
-    enable: true  # 是否开启阿里云物联网服务端订阅
+    enable: false  # 是否开启阿里云物联网服务端订阅
   product:
     productKey: a1ALlsBa2ZK

+ 3 - 3
nb-admin/src/main/resources/application.yml

@@ -34,8 +34,8 @@ sa-token:
   token-name: Authorization
   # token有效期,单位s 默认30天, -1代表永不过期
   timeout: 2592000
-  # token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
-  activity-timeout: -1
+  # token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒 一天
+  activity-timeout: 86400
   # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
   is-concurrent: true
   # 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
@@ -50,7 +50,7 @@ sa-token:
 logging:
   level:
     com.coffee: @logging.level@
-    org.springframework: warn
+    org.springframework: debug
   config: classpath:logback.xml
   file:
     path: ./logs

+ 1 - 1
nb-admin/src/main/resources/logback.xml

@@ -47,7 +47,7 @@
         </encoder>
         <filter class="ch.qos.logback.classic.filter.LevelFilter">
             <!-- 过滤的级别 -->
-            <level>INFO</level>
+            <level>DEBUG</level>
             <!-- 匹配时的操作:接收(记录) -->
             <onMatch>ACCEPT</onMatch>
             <!-- 不匹配时的操作:拒绝(不记录) -->

+ 11 - 0
nb-common/src/main/java/com/coffee/common/config/CacheHttpServletRequestWrapper.java

@@ -3,11 +3,14 @@ package com.coffee.common.config;
 import org.springframework.util.StreamUtils;
 
 import javax.servlet.ReadListener;
+import javax.servlet.ServletException;
 import javax.servlet.ServletInputStream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.Part;
 import java.io.*;
 import java.nio.charset.Charset;
+import java.util.Collection;
 import java.util.Map;
 
 public class CacheHttpServletRequestWrapper extends HttpServletRequestWrapper {
@@ -25,6 +28,13 @@ public class CacheHttpServletRequestWrapper extends HttpServletRequestWrapper {
         return this.bodyString;
     }
 
+    @Override
+    public String getParameter(String name) {
+        return super.getParameter(name);
+    }
+
+
+
     @Override
     public BufferedReader getReader() throws IOException {
         return new BufferedReader(new InputStreamReader(getInputStream(),Charset.defaultCharset()));
@@ -63,4 +73,5 @@ public class CacheHttpServletRequestWrapper extends HttpServletRequestWrapper {
             }
         };
     }
+
 }

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

@@ -1,6 +1,7 @@
 package com.coffee.common.config;
 
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import javax.servlet.*;
 import javax.servlet.annotation.WebFilter;

+ 24 - 0
nb-common/src/main/java/com/coffee/common/util/RedissonUtil.java

@@ -1,18 +1,25 @@
 package com.coffee.common.util;
 
 
+import cn.hutool.core.collection.CollUtil;
 import com.coffee.common.entity.AbstractMsgId;
 import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import org.redisson.api.*;
 import org.redisson.client.codec.Codec;
+import org.redisson.client.protocol.ScoredEntry;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
+import java.util.stream.Collectors;
 
 /**
  * @author lifang
@@ -84,4 +91,21 @@ public class RedissonUtil {
             return delayedQueueMap.get(name);
         }
     }
+
+
+    public void addScoreSortSet(String name,Long score,Object obj){
+        this.getRedissonClient().getScoredSortedSet(name)
+                .add(score,obj);
+    }
+
+    public void clearScoreSortSet(String name){
+        this.getRedissonClient().getScoredSortedSet(name).clear();
+    }
+
+    public Collection<ScoredEntry<Object>> getRange(String name, int startIndex, int endIndex){
+        return  this.getRedissonClient()
+                .getScoredSortedSet(name)
+                .entryRange(startIndex, endIndex);
+    }
+
 }

+ 6 - 3
nb-system/src/main/java/com/coffee/bus/controller/BusPatientController.java

@@ -24,6 +24,7 @@ import com.coffee.common.crud.BaseService;
 import com.coffee.common.crud.controller.BaseQueryController;
 import com.coffee.common.exception.CustomException;
 import com.coffee.common.result.R;
+import io.netty.channel.EventLoopGroup;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -266,9 +267,11 @@ public class BusPatientController  implements BaseQueryController<BusPatientEnti
             String clinicId = vo.getClinicId();
             clinic = clinicService.getById(clinicId);
             result.setClinic(clinic);
-            //无泵查看
-            result.setDeviceManual( manualService.getOne(new QueryWrapper<BusDeviceManualEntity>().lambda().eq(BusDeviceManualEntity::getClinicId, clinic.getId())));
-        }
+            if(clinic!=null){
+                //无泵查看
+                result.setDeviceManual( manualService.getOne(new QueryWrapper<BusDeviceManualEntity>().lambda().eq(BusDeviceManualEntity::getClinicId, clinic.getId())));
+            }
+           }
         if(clinic==null){
             throw new CustomException("该临床信息不存在,请刷新后重试");
         }

+ 57 - 11
nb-system/src/main/java/com/coffee/bus/hospital/config/HospitalFunctionAnalConfigHandler.java

@@ -1,6 +1,7 @@
 package com.coffee.bus.hospital.config;
 
 
+import cn.hutool.extra.spring.SpringUtil;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.coffee.bus.entity.BusDeviceAlarmEntity;
 import com.coffee.bus.hospital.config.bean.FunctionAnalConfig;
@@ -12,13 +13,18 @@ import com.coffee.bus.service.LocalBusDeviceAlarmService;
 import com.coffee.bus.service.LocalBusInfusionHistoryService;
 import com.coffee.bus.utils.WsPublishUtils;
 import com.coffee.common.cache.ConfigStorage;
+import com.coffee.common.cache.value.Value;
 import com.coffee.common.entity.AbstractMsgId;
+import com.coffee.common.redis.RedisUtils;
 import com.coffee.common.util.RedissonUtil;
 import lombok.Builder;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.redisson.api.RDelayedQueue;
+import org.redisson.client.protocol.ScoredEntry;
 
+import java.util.Collection;
+import java.util.Comparator;
 import java.util.Date;
 import java.util.Optional;
 import java.util.concurrent.TimeUnit;
@@ -40,6 +46,7 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
     //最后一次取消镇痛不足报警任务对象
     private NoneAnalEntity lastNoneAnal;
 
+
     public HospitalFunctionAnalConfigHandler(ConfigStorage configStorage, String hospitalId, RedissonUtil redissonUtil, LocalBusInfusionHistoryService infusionHistoryService, DeviceRegistry deviceRegistry, WsPublishUtils wsPublishUtils,LocalBusDeviceAlarmService alarmService) {
         super(configStorage, hospitalId, redissonUtil, infusionHistoryService, deviceRegistry, wsPublishUtils);
         this.alarmService=alarmService;
@@ -56,7 +63,6 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
     }
 
 
-
     @Override
     public void handler(BusDeviceRunningEntity source) {
         FunctionAnalConfig config = this.getConfig().as(FunctionAnalConfig.class);
@@ -77,19 +83,16 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
      * @return void
      */
     private void judgeAnalPoor(BusDeviceRunningEntity source, FunctionAnalConfig analConfig){
-        RDelayedQueue<AbstractMsgId>  delayedQueue = redissonUtil.getDelayedQueue(getId().name(), e -> {
-            if(e instanceof AnalEntity){
-                this.handleAnalPoorAndJudgeFinish((AnalEntity) e);
-            }
-        });
+        String analSortKey="anal:sort:" + source.getDeviceId();
         //如果有新的输注产生,则删除该设备镇痛不足任务
         if(source.isNewInfusion()){
             //镇痛不足设置为false
             source.setWarnAnalgesicPoor(false);
-            if(lastAnalWarn!=null){
-                delayedQueue.remove(lastAnalWarn);
-            }
+            //新输注清空缓存记录
+            redissonUtil.clearScoreSortSet(analSortKey);
         }
+        redissonUtil.addScoreSortSet(analSortKey,source.getUploadTime().getTime(),source);
+
         Integer insufficientTime = analConfig.getInsufficientTime();
         Integer insufficientCount = analConfig.getInsufficientCount();
         Boolean valid = analConfig.getValid();
@@ -97,6 +100,8 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
                 (insufficientCount==null||insufficientCount<=0)){
             return;
         }
+        Long endTime = source.getUploadTime().getTime();
+        Long startTime=endTime-TimeUnit.MINUTES.toMillis(insufficientTime);
 
         lastAnalWarn = AnalEntity.builder()
                 .deviceId(source.getDeviceId())
@@ -111,7 +116,48 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
                 .timestamp(new Date())
                 .infusionId(source.getInfusionId())
                 .build();
-        redissonUtil.offerQueue(delayedQueue,lastAnalWarn,lastAnalWarn.getTimeout(),lastAnalWarn.getUnit());
+
+        //获取该次输注过程中,以当前输注上传时间为结束时间,以判定时间区间为区间范围的时间窗口数据
+        Collection<ScoredEntry<Object>> scoreRange = redissonUtil.getRange(analSortKey, startTime.intValue(), endTime.intValue());
+        Optional<ScoredEntry<Object>> min = scoreRange.stream().max(Comparator.comparing(ScoredEntry::getScore));
+        if(!min.isPresent()){
+            return;
+        }
+        //判定时间窗口内的首次输注记录
+        AnalEntity firstAnal = Value.simple(min.get().getValue()).as(AnalEntity.class);
+        if(firstAnal!=null){
+            try {
+                //实时判定PCA差值
+                int subCount=0;
+                if(Boolean.TRUE.equals(analConfig.getValid())){
+                    subCount=Math.subtractExact(source.getPcaValidCount(), Optional.ofNullable(firstAnal.getPcaValidCount()).orElse(0));
+                }else {
+                    subCount=Math.subtractExact(source.getPcaInvalidCount(), Optional.ofNullable(firstAnal.getPcaInvalidCount()).orElse(0));
+                }
+                if(subCount>analConfig.getInsufficientCount()){
+                    log.info("设备:{}镇痛不足--实时判定",source.getDeviceId());
+                    source.setWarnAnalgesicPoor(true);
+                    //镇痛消失延迟队列
+                    RDelayedQueue<AbstractMsgId> noneAnalDelayedQueue = redissonUtil.getDelayedQueue("none-" + getId(), e -> {
+                        if(e instanceof NoneAnalEntity){
+                            handleAnalFinish((NoneAnalEntity) e);
+                        }
+                    });
+                    NoneAnalEntity.builder()
+                            .deviceId(firstAnal.getDeviceId())
+                            .tenantId(firstAnal.getTenantId())
+                            .timeout(analConfig.getDisappearTime())
+                            .unit(TimeUnit.MINUTES)
+                            .infusionId(firstAnal.getInfusionId())
+                            .historyId(firstAnal.getHistoryId())
+                            .timestamp(new Date())
+                            .build();
+                    redissonUtil.offerQueue(noneAnalDelayedQueue,lastNoneAnal,lastNoneAnal.getTimeout(),lastNoneAnal.getUnit());
+                }
+            }catch (Exception e){
+                log.debug("镇痛不足缓存解析失败,设备号【{}】",source.getDeviceId(),e);
+            }
+        }
     }
 
 
@@ -143,7 +189,7 @@ public class HospitalFunctionAnalConfigHandler extends AbstractHospitalConfigHan
             subCount=Math.subtractExact(infusionHistory.getPcaInvalidCount(), Optional.ofNullable(anal.getPcaInvalidCount()).orElse(0));
         }
         if(subCount>anal.getThreshold()){
-            log.info("设备:{}镇痛不足",deviceId);
+            log.info("设备:{}镇痛不足--延迟判定",deviceId);
             //触发阈值,设置为镇痛不足
             if(!Boolean.TRUE.equals(infusionHistory.getWarnAnalgesicPoor())){
                 infusionHistoryService.update(new UpdateWrapper<BusInfusionHistoryEntity>().lambda().eq(BusInfusionHistoryEntity::getId,infusionHistory.getId())

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

@@ -34,7 +34,7 @@ public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper
     @Autowired
     private BusDeviceAlarmMapper busDeviceAlarmMapper;
     @Autowired
-    BusHospitalMapper hospitalMapper;
+    private BusHospitalMapper hospitalMapper;
 
     @Override
     public void validateBeforeSave(BusDeviceAlarmEntity entity) {
@@ -81,7 +81,7 @@ public class LocalBusDeviceAlarmService extends BaseService<BusDeviceAlarmMapper
             busHospitalEntityQueryWrapper.setEntity(hospitalEntity);
         }
         if(query.getHositalName()!=null){
-            busHospitalEntityQueryWrapper.getEntity().setName(query.getHositalName());
+            busHospitalEntityQueryWrapper.lambda().like(BusHospitalEntity::getName,query.getHositalName());
         }
         if(query.getTenantId()!=null){
             busHospitalEntityQueryWrapper.getEntity().setId(query.getTenantId());

+ 8 - 0
nb-system/src/main/java/com/coffee/bus/service/LocalBusDeviceService.java

@@ -226,6 +226,7 @@ public class LocalBusDeviceService extends BaseService<BusDeviceMapper, BusDevic
         HashMap<String, BusDeviceEntity> deviceById = new HashMap<>();
         ArrayList<BusDeviceEntity> devices = new ArrayList<>();
         List<QueryDeviceResponse.DeviceInfo> deviceInfos = aliyunIotSdk.queryDevice();
+        log.info("同步数据数量:【{}】",CollUtil.size(deviceInfos));
         if (CollUtil.isNotEmpty(deviceInfos)) {
             for (QueryDeviceResponse.DeviceInfo deviceInfo : deviceInfos) {
                 BusDeviceEntity device = new BusDeviceEntity();
@@ -250,7 +251,9 @@ public class LocalBusDeviceService extends BaseService<BusDeviceMapper, BusDevic
                             .map(BusDeviceEntity::getDeviceId).collect(Collectors.toSet());
                     List<BusDeviceEntity> insertDevices = devices.stream().filter(info -> !existDeviceIds.contains(info.getDeviceId())).collect(Collectors.toList());
                     this.saveBatch(insertDevices);
+                    log.info("新增设备数量:【{}】",CollUtil.size(insertDevices));
                 }
+                log.info("更新设备数量:【{}】",CollUtil.size(existDevices));
                 this.updateBatchById(existDevices);
 
 
@@ -320,10 +323,15 @@ public class LocalBusDeviceService extends BaseService<BusDeviceMapper, BusDevic
         List<DeviceOperator> operators = deviceIds.stream()
                 .map(deviceRegistry::getOperator)
                 .collect(Collectors.toList());
+        if (CollUtil.isEmpty(operators)) {
+            return;
+        }
         this.update(new UpdateWrapper<BusDeviceEntity>().lambda()
                 .in(BusDeviceEntity::getDeviceId,deviceIds)
                 .set(BusDeviceEntity::getTenantId,afterTenantId));
         operators
+                .stream()
+                .filter(Objects::nonNull)
                 .forEach(deviceOperator -> deviceOperator.setTenantId(afterTenantId));
     }
 }

+ 3 - 0
nb-system/src/main/java/com/coffee/bus/service/dto/CombineQuery.java

@@ -41,6 +41,9 @@ public class CombineQuery {
     @ApiModelProperty("体重区间")
     private List<Integer> weightRange;
 
+    @ApiModelProperty("身高区间")
+    private List<Integer> heightRange;
+
     @ApiModelProperty("asa")
     private String asa;
 

+ 15 - 15
nb-system/src/main/java/com/coffee/system/service/impl/SysRoleServiceImpl.java

@@ -77,17 +77,17 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
         }
         SysRole entity = BeanUtil.copyProperties(req, SysRole.class);
         this.save(entity);
-        // 删除角色和部门关联
-        sysRoleDeptService.remove(Wrappers.lambdaQuery(SysRoleDept.class).eq(SysRoleDept::getRoleId, req.getId()));
-        // 新增角色和菜单关联
-        if (Objects.nonNull(req.getDeptIds())) {
-            req.getDeptIds().forEach(item -> {
-                SysRoleDept sysRoleDept = new SysRoleDept();
-                sysRoleDept.setRoleId(entity.getId());
-                sysRoleDept.setDeptId(item);
-                sysRoleDeptService.save(sysRoleDept);
-            });
-        }
+//        // 删除角色和部门关联
+//        sysRoleDeptService.remove(Wrappers.lambdaQuery(SysRoleDept.class).eq(SysRoleDept::getRoleId, req.getId()));
+//        // 新增角色和菜单关联
+//        if (Objects.nonNull(req.getDeptIds())) {
+//            req.getDeptIds().forEach(item -> {
+//                SysRoleDept sysRoleDept = new SysRoleDept();
+//                sysRoleDept.setRoleId(entity.getId());
+//                sysRoleDept.setDeptId(item);
+//                sysRoleDeptService.save(sysRoleDept);
+//            });
+//        }
     }
 
     @Override
@@ -131,10 +131,10 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
             if (userRoleCount!=0) {
                 throw new CustomException(String.format("角色【%s】存在用户,无法删除", sysRole.getRoleName()));
             }
-            long deptRoleCount = sysRoleDeptService.count(Wrappers.lambdaQuery(SysRoleDept.class).eq(SysRoleDept::getRoleId, item));
-            if (deptRoleCount!=0) {
-                throw new CustomException(String.format("角色【%s】已被使用,无法删除", sysRole.getRoleName()));
-            }
+//            long deptRoleCount = sysRoleDeptService.count(Wrappers.lambdaQuery(SysRoleDept.class).eq(SysRoleDept::getRoleId, item));
+//            if (deptRoleCount!=0) {
+//                throw new CustomException(String.format("角色【%s】已被使用,无法删除", sysRole.getRoleName()));
+//            }
         });
         this.removeByIds(Arrays.asList(ids.split(",")));
     }

+ 2 - 2
nb-system/src/main/resources/mapper/bus/BusDeviceHistoryMapper.xml

@@ -14,8 +14,8 @@
             <if test="query.deviceId !=null">
                 and device_id=#{query.deviceId}
             </if>
-            <if test="query.clinicId !=null">
-                and clinic_id=#{query.clinicId}
+            <if test="query.infusionId !=null">
+                and id=#{query.infusionId}
             </if>
         </where>) as i
         on h.infusion_id=i.id

+ 34 - 6
nb-system/src/main/resources/mapper/bus/BusInfusionHistoryMapper.xml

@@ -274,6 +274,13 @@
                 </if>
             </if>
 
+            <if test="query.heightRange != null and query.heightRange.size > 0">
+                and height &gt;=  #{query.heightRange[0]}
+                <if test="query.heightRange.size >1 ">
+                    and height &lt;=  #{query.heightRange[1]}
+                </if>
+            </if>
+
             <if test="query.asa != null">
                 and asa like concat('%',#{query.asa},'%')
             </if>
@@ -424,16 +431,23 @@
             </if>
 
             <if test="query.ageRange != null and query.ageRange.size > 0">
-                and patient_age &gt;  #{query.ageRange[0]}
+                and patient_age &gt;=  #{query.ageRange[0]}
                 <if test="query.ageRange.size >1 ">
-                    and patient_age &lt;  #{query.ageRange[1]}
+                    and patient_age &lt;=  #{query.ageRange[1]}
                 </if>
             </if>
 
             <if test="query.weightRange != null and query.weightRange.size > 0">
-                and weight &gt;  #{query.weightRange[0]}
+                and weight &gt;=  #{query.weightRange[0]}
                 <if test="query.weightRange.size >1 ">
-                    and weight &lt;  #{query.weightRange[1]}
+                    and weight &lt;=  #{query.weightRange[1]}
+                </if>
+            </if>
+
+            <if test="query.heightRange != null and query.heightRange.size > 0">
+                and height &gt;=  #{query.heightRange[0]}
+                <if test="query.heightRange.size >1 ">
+                    and height &lt;=  #{query.heightRange[1]}
                 </if>
             </if>
 
@@ -509,9 +523,9 @@
             </if>
 
             <if test="query.undoTimeRange != null and query.undoTimeRange.size > 0">
-                and undo_time &gt;  #{query.undoTimeRange[0]}
+                and undo_time &gt;=  #{query.undoTimeRange[0]}
                 <if test="query.startTimeRange.size >1 ">
-                    and undo_time &lt;  #{query.undoTimeRange[1]}
+                    and undo_time &lt;=  #{query.undoTimeRange[1]}
                 </if>
             </if>
 
@@ -588,6 +602,13 @@
                 </if>
             </if>
 
+            <if test="query.heightRange != null and query.heightRange.size > 0">
+                and height &gt;=  #{query.heightRange[0]}
+                <if test="query.heightRange.size >1 ">
+                    and height &lt;=  #{query.heightRange[1]}
+                </if>
+            </if>
+
             <if test="query.asa != null">
                 and asa like concat('%',#{query.asa},'%')
             </if>
@@ -746,6 +767,13 @@
                 </if>
             </if>
 
+            <if test="query.heightRange != null and query.heightRange.size > 0">
+                and height &gt;=  #{query.heightRange[0]}
+                <if test="query.heightRange.size >1 ">
+                    and height &lt;=  #{query.heightRange[1]}
+                </if>
+            </if>
+
             <if test="query.asa != null">
                 and asa like concat('%',#{query.asa},'%')
             </if>