Parcourir la source

add ws心跳检测
fix 修复一些小bug
update 字段与前端统一

A17404李放 il y a 3 ans
Parent
commit
2646bd572b
24 fichiers modifiés avec 217 ajouts et 73 suppressions
  1. 5 4
      coffee-admin/Dockerfile
  2. 2 2
      coffee-admin/src/main/resources/application.yml
  3. 1 1
      coffee-common/src/main/java/com/coffee/common/config/CacheHttpServletRequestWrapper.java
  4. 3 0
      coffee-common/src/main/java/com/coffee/common/config/websocket/DefaultMessageListener.java
  5. 3 2
      coffee-common/src/main/java/com/coffee/common/config/websocket/handler/Subscribe.java
  6. 1 1
      coffee-system/src/main/java/com/coffee/bus/controller/BusHospitalController.java
  7. 3 0
      coffee-system/src/main/java/com/coffee/bus/controller/BusPatientController.java
  8. 1 1
      coffee-system/src/main/java/com/coffee/bus/entity/BusEvaluationEntity.java
  9. 16 0
      coffee-system/src/main/java/com/coffee/bus/entity/BusInfusionHistoryEntity.java
  10. 1 1
      coffee-system/src/main/java/com/coffee/bus/hospital/config/bean/FunctionEvalConfig.java
  11. 2 1
      coffee-system/src/main/java/com/coffee/bus/service/LocalBusHospitalService.java
  12. 1 1
      coffee-system/src/main/java/com/coffee/bus/service/dto/CombineEvalResult.java
  13. 1 1
      coffee-system/src/main/java/com/coffee/bus/stats/CommonStats.java
  14. 2 2
      coffee-system/src/main/java/com/coffee/bus/stats/analyse/AlarmStatsAnalyse.java
  15. 7 7
      coffee-system/src/main/java/com/coffee/bus/stats/analyse/EvalStatsAnalyse.java
  16. 5 5
      coffee-system/src/main/java/com/coffee/bus/stats/entity/EvalTableResult.java
  17. 9 9
      coffee-system/src/main/java/com/coffee/bus/stats/report/AgeAndGenderStatsReport.java
  18. 6 0
      coffee-system/src/main/java/com/coffee/bus/web/handler/CheckRepeatHandler.java
  19. 10 3
      coffee-system/src/main/java/com/coffee/bus/web/handler/CheckSignHandler.java
  20. 12 12
      coffee-system/src/main/java/com/coffee/bus/websocket/DefaultWebSocketMsgHandler.java
  21. 62 0
      coffee-system/src/main/java/com/coffee/bus/websocket/DefaultWsServerAioListener.java
  22. 33 0
      coffee-system/src/main/java/com/coffee/bus/websocket/HeartBeatConfig.java
  23. 29 18
      coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java
  24. 2 2
      coffee-system/src/main/resources/mapper/bus/BusInfusionHistoryMapper.xml

+ 5 - 4
coffee-admin/Dockerfile

@@ -3,10 +3,11 @@ FROM docker.io/java:8
 ADD target/coffee-admin.jar /pump.jar
 ADD src/main/resources/python/jython-standalone-2.7.1.jar /jython-standalone-2.7.1.jar
 RUN bash -c "touch /pump.jar"
-ENV TZ 'Asia/Shanghai'
-ENV LANG en_US.UTF-8
-ENV LANGUAGE en_US:en
-ENV LC_ALL en_US.UTF-8
+RUN echo "Asia/shanghai" > /etc/timezone
+ENV LANG C.UTF-8
+ENV LANGUAGE zh_CN.UTF-8
+ENV LC_ALL C.UTF-8
+ENV TZ Asia/Shanghai
 
 ENTRYPOINT ["java", "-jar", "/pump.jar"]
 EXPOSE 9090

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

@@ -23,8 +23,8 @@ tio:
   websocket:
     server:
       port: 9000
-      #心跳检测在业务层面自定义进行
-      heartbeat-timeout: -1
+      #心跳检测在业务层面自定义进行 ms 毫秒级 按照最后一次接受数据包算 30s
+      heartbeat-timeout: 30000
       #是否支持集群,集群开启需要redis
     cluster:
       enabled: false

+ 1 - 1
coffee-common/src/main/java/com/coffee/common/config/CacheHttpServletRequestWrapper.java

@@ -28,7 +28,7 @@ public class CacheHttpServletRequestWrapper extends HttpServletRequestWrapper {
 
     @Override
     public BufferedReader getReader() throws IOException {
-        return new BufferedReader(new InputStreamReader(getInputStream()));
+        return new BufferedReader(new InputStreamReader(getInputStream(),CHARSET_UTF8));
     }
 
     @Override

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

@@ -45,6 +45,9 @@ public class DefaultMessageListener implements PatternMessageListener<TopicMessa
         }else {
             channelContext.setClosed(true);
             rPatternTopic.removeListener(this);
+            if(log.isDebugEnabled()){
+                Tio.remove(channelContext,"通道已关闭,移除该通道");
+            }
         }
     }
 }

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

@@ -76,8 +76,9 @@ public abstract class Subscribe implements WsHandler {
             //取消订阅主题
             subScribeTopic.forEach(topicWrapper->this.unsubscribe(channelContext,topicWrapper.getTopic()));
         }
-        log.error("订阅成功{}",subScribeTopic.stream().map(TopicWrapper::getTopic).collect(Collectors.toList()));
-
+        if(log.isDebugEnabled()){
+            log.debug("订阅成功{}",subScribeTopic.stream().map(TopicWrapper::getTopic).collect(Collectors.toList()));
+        }
     }
 
     /**

+ 1 - 1
coffee-system/src/main/java/com/coffee/bus/controller/BusHospitalController.java

@@ -93,7 +93,7 @@ public class BusHospitalController extends BaseCrudController<BusHospitalEntity,
     @ApiOperation(value = "发布脚本",notes = "医院必选,发布脚本,发布后即用该脚本解析his数据,权限【bus:hospital:script:pub】")
     public R publishScript(@RequestAttribute("tenantId")@ApiParam(hidden = true) String tenantId){
         BusHospitalEntity hospital = hospitalService.getById(tenantId);
-        if (ObjectUtil.isNull(hospital.getScript())||StrUtil.isEmpty(hospital.getScript().getContent())) {
+        if (ObjectUtil.isNull(hospital.getDraftScript())||StrUtil.isEmpty(hospital.getDraftScript().getContent())) {
             throw new CustomException("草稿脚本内容为空,发布失败");
         }
         hospitalService.update(new UpdateWrapper<BusHospitalEntity>().lambda().eq(BusHospitalEntity::getId,tenantId)

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

@@ -237,6 +237,9 @@ public class BusPatientController  implements BaseQueryController<BusPatientEnti
         if(Boolean.TRUE.equals(monitorType)){
             String patientCode = vo.getPatientCode();
             BusPatientEntity patient = patientService.getOne(new QueryWrapper<BusPatientEntity>().lambda().eq(BusPatientEntity::getCode, patientCode));
+            if(patient==null){
+                throw new CustomException("该病号信息不存在,请刷新后重试");
+            }
             clinic = clinicService.getById(patient.getClinicId());
             BusInfusionHistoryEntity infusion =infusionService.getById(patient.getInfusionId());
             result.setInfusion(infusion);

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

@@ -110,7 +110,7 @@ public class BusEvaluationEntity extends TenantGenericEntity<String,String> {
 
 
     @ApiModelProperty(value = "舒张压")
-    private BigDecimal  diastolicPressure;
+    private BigDecimal diastensPressure;
 
     @ApiModelProperty(value = "心率")
     private BigDecimal heartRate;

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

@@ -92,6 +92,22 @@ public class BusInfusionHistoryEntity extends CommonDeviceParam<String,String> {
         return entity;
     }
 
+    public String getUndoBy() {
+        return Boolean.TRUE.equals(getIsUndo())?this.undoBy:null;
+    }
+
+    public String getDestroyer() {
+        return Boolean.TRUE.equals(getIsUndo())?this.destroyer:null;
+    }
+
+    public String getWitnesses() {
+        return Boolean.TRUE.equals(getIsUndo())?this.witnesses:null;
+    }
+
+    public Date getUndoTime() {
+        return Boolean.TRUE.equals(getIsUndo())?this.undoTime:null;
+    }
+
     public static Date defaultClinicStartTime(){
         return new Date(32503654861L);
     }

+ 1 - 1
coffee-system/src/main/java/com/coffee/bus/hospital/config/bean/FunctionEvalConfig.java

@@ -68,7 +68,7 @@ public class FunctionEvalConfig {
 
 
     @ApiModelProperty(value = "舒张压")
-    private Boolean  diastolicPressure;
+    private Boolean diastensPressure;
 
     @ApiModelProperty(value = "心率")
     private Boolean heartRate;

+ 2 - 1
coffee-system/src/main/java/com/coffee/bus/service/LocalBusHospitalService.java

@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.coffee.bus.bean.GeoPoint;
+import com.coffee.bus.entity.BusHospitalConfigEntity;
 import com.coffee.bus.entity.BusHospitalEntity;
 import com.coffee.bus.hospital.HospitalManagerRegister;
 import com.coffee.bus.hospital.his.strategy.HisStrategyEnum;
@@ -59,7 +60,7 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
             throw new CustomException(String.format("医院名称[%s]不可重复",entity.getName()));
         }
         if(entity.getStrategy()==null){
-            entity.setStrategy(HisStrategyEnum.ALL);
+            entity.setStrategy(HisStrategyEnum.NONE);
         }
         entity.setScriptOnline(false);
         entity.setCode(CodeUtils.genInviteCode(id));

+ 1 - 1
coffee-system/src/main/java/com/coffee/bus/service/dto/CombineEvalResult.java

@@ -74,7 +74,7 @@ public class CombineEvalResult extends CombineResult {
 
 
     @ApiModelProperty(value = "舒张压")
-    private BigDecimal  diastolicPressure;
+    private BigDecimal diastensPressure;
 
     @ApiModelProperty(value = "心率")
     private BigDecimal heartRate;

+ 1 - 1
coffee-system/src/main/java/com/coffee/bus/stats/CommonStats.java

@@ -92,7 +92,7 @@ public interface CommonStats<T extends CombineResult> {
             return BigDecimal.valueOf(0);
         }
         return count
-                .divide(total,2, RoundingMode.HALF_UP)
+                .divide(total,4, RoundingMode.HALF_UP)
                 .multiply(BigDecimal.valueOf(100));
     }
 

+ 2 - 2
coffee-system/src/main/java/com/coffee/bus/stats/analyse/AlarmStatsAnalyse.java

@@ -182,7 +182,7 @@ public class AlarmStatsAnalyse implements CommonStats<CombineAlarmResult> {
             contentValues.put("电量耗尽",totalResult.getLowBattery().getValue());
             contentValues.put("气泡无液",totalResult.getBubble().getValue());
             contentValues.put("低输注",totalResult.getLowInfusion().getValue());
-
+            contentValues.put("返厂维护",totalResult.getInfusionMax().getValue());
             contentValues.put("堵塞比率",computeRatio(BigDecimal.valueOf(totalResult.getJam().getValue()),total));
             contentValues.put("极限比率",computeRatio(BigDecimal.valueOf(totalResult.getLimit().getValue()),total));
             contentValues.put("未装药盒比率",computeRatio(BigDecimal.valueOf(totalResult.getNoBox().getValue()),total));
@@ -193,7 +193,7 @@ public class AlarmStatsAnalyse implements CommonStats<CombineAlarmResult> {
             contentValues.put("电量耗尽比率",computeRatio(BigDecimal.valueOf(totalResult.getLowBattery().getValue()),total));
             contentValues.put("气泡无液比率",computeRatio(BigDecimal.valueOf(totalResult.getBubble().getValue()),total));
             contentValues.put("低输注比率",computeRatio(BigDecimal.valueOf(totalResult.getLowInfusion().getValue()),total));
-
+            contentValues.put("返厂维护比率",computeRatio(BigDecimal.valueOf(totalResult.getInfusionMax().getValue()),total));
             contents.add(contentValues);
         });
         return Arrays.asList(result);

+ 7 - 7
coffee-system/src/main/java/com/coffee/bus/stats/analyse/EvalStatsAnalyse.java

@@ -113,7 +113,7 @@ public class EvalStatsAnalyse implements CommonStats<CombineEvalResult> {
             if(null!=result.getShrinkPressure()){
                 resultMap.computeIfPresent("收缩压",(k,v)->v+1);
             }
-            if(null!=result.getDiastolicPressure()){
+            if(null!=result.getDiastensPressure()){
                 resultMap.computeIfPresent("舒张压",(k,v)->v+1);
             }
             if(null!=result.getHeartRate()){
@@ -180,7 +180,7 @@ public class EvalStatsAnalyse implements CommonStats<CombineEvalResult> {
         if(Boolean.TRUE.equals(evalConfig.getShrinkPressure())){
             resultMap.put("收缩压",0L);
         }
-        if(Boolean.TRUE.equals(evalConfig.getDiastolicPressure())){
+        if(Boolean.TRUE.equals(evalConfig.getDiastensPressure())){
             resultMap.put("舒张压",0L);
         }
         if(Boolean.TRUE.equals(evalConfig.getHeartRate())){
@@ -262,7 +262,7 @@ public class EvalStatsAnalyse implements CommonStats<CombineEvalResult> {
         result.add(StatsColumn.of("时间","time"));
         result.add(StatsColumn.of("输注次数","infusionCount"));
         result.add(StatsColumn.of("评价次数","evalCount"));
-        result.add(StatsColumn.of("评价","evalRatio",true));
+        result.add(StatsColumn.of("评价","评价",true));
         if(Boolean.TRUE.equals(config.getStatics())){
             result.add(StatsColumn.of("静息疼痛","静息疼痛"));
         }
@@ -311,7 +311,7 @@ public class EvalStatsAnalyse implements CommonStats<CombineEvalResult> {
         if(Boolean.TRUE.equals(config.getShrinkPressure())){
             result.add(StatsColumn.of("收缩压","收缩压"));
         }
-        if(Boolean.TRUE.equals(config.getDiastolicPressure())){
+        if(Boolean.TRUE.equals(config.getDiastensPressure())){
             result.add(StatsColumn.of("舒张压","舒张压"));
         }
         if(Boolean.TRUE.equals(config.getHeartRate())){
@@ -498,11 +498,11 @@ public class EvalStatsAnalyse implements CommonStats<CombineEvalResult> {
         }
 
 
-        if (Boolean.TRUE.equals(evalConfig.getDiastolicPressure())) {
+        if (Boolean.TRUE.equals(evalConfig.getDiastensPressure())) {
             LineResult<BigDecimal> diastolicPressureLine =  LineResult.of("diastolicPressureLine",false,false,"舒张压走势图");
             handleMixPolyLines(groupByTime,diastolicPressureLine,
-                    evalResult -> evalResult.getDiastolicPressure()!=null,
-                    CombineEvalResult::getDiastolicPressure);
+                    evalResult -> evalResult.getDiastensPressure()!=null,
+                    CombineEvalResult::getDiastensPressure);
             result.add(diastolicPressureLine);
         }
 

+ 5 - 5
coffee-system/src/main/java/com/coffee/bus/stats/entity/EvalTableResult.java

@@ -72,7 +72,7 @@ public class EvalTableResult extends HashMap<String,Long> {
         return this.computeIfAbsent("收缩压",k->0L);
     }
 
-    public Long getDiastolicPressure(){
+    public Long getDiastensPressure(){
         return this.computeIfAbsent("舒张压",k->0L);
     }
 
@@ -156,7 +156,7 @@ public class EvalTableResult extends HashMap<String,Long> {
         incrementValue("收缩压");
     }
 
-    public void incrementDiastolicPressure() {
+    public void incrementDiastensPressure() {
         incrementValue("舒张压");
     }
 
@@ -193,7 +193,7 @@ public class EvalTableResult extends HashMap<String,Long> {
         getHoarseness();
         getCognitionObstacle();
         getShrinkPressure();
-        getDiastolicPressure();
+        getDiastensPressure();
         getHeartRate();
         getFetalHeartRate();
         getBreathRate();
@@ -253,8 +253,8 @@ public class EvalTableResult extends HashMap<String,Long> {
         if(evalResult.getShrinkPressure()!=null){
             incrementShrinkPressure();
         }
-        if(evalResult.getDiastolicPressure()!=null){
-            incrementDiastolicPressure();
+        if(evalResult.getDiastensPressure()!=null){
+            incrementDiastensPressure();
         }
         if(evalResult.getHeartRate()!=null){
             incrementHeartRate();

+ 9 - 9
coffee-system/src/main/java/com/coffee/bus/stats/report/AgeAndGenderStatsReport.java

@@ -116,23 +116,23 @@ public class AgeAndGenderStatsReport implements CommonStats<CombineResult> {
                 StatsColumn.of("时间","time"),
                 StatsColumn.of("总人数","total"),
                 StatsColumn.of(AgeStatsEnum.infant.getName(),AgeStatsEnum.infant.getName()),
-                StatsColumn.of("婴幼儿","婴幼儿比率",true),
+                StatsColumn.of("婴幼儿","婴幼儿",true),
                 StatsColumn.of(AgeStatsEnum.child.getName(),AgeStatsEnum.child.getName()),
-                StatsColumn.of("儿童","儿童比率",true),
+                StatsColumn.of("儿童","儿童",true),
                 StatsColumn.of(AgeStatsEnum.juvenile.getName(),AgeStatsEnum.juvenile.getName()),
-                StatsColumn.of("少年","少年比率",true),
+                StatsColumn.of("少年","少年",true),
                 StatsColumn.of(AgeStatsEnum.youth.getName(),AgeStatsEnum.youth.getName()),
-                StatsColumn.of("青年","青年比率",true),
+                StatsColumn.of("青年","青年",true),
                 StatsColumn.of(AgeStatsEnum.midlife.getName(),AgeStatsEnum.midlife.getName()),
-                StatsColumn.of("中年","中年比率",true),
+                StatsColumn.of("中年","中年",true),
                 StatsColumn.of(AgeStatsEnum.fewOld.getName(),AgeStatsEnum.fewOld.getName()),
-                StatsColumn.of("年轻的老人","年轻的老人比率",true),
+                StatsColumn.of("年轻的老人","年轻的老人",true),
                 StatsColumn.of(AgeStatsEnum.old.getName(),AgeStatsEnum.old.getName()),
-                StatsColumn.of("老年人","老年人比率",true),
+                StatsColumn.of("老年人","老年人",true),
                 StatsColumn.of(AgeStatsEnum.longevity.getName(),AgeStatsEnum.longevity.getName()),
-                StatsColumn.of("长寿的老年人","长寿的老年人比率",true),
+                StatsColumn.of("长寿的老年人","长寿的老年人",true),
                 StatsColumn.of(AgeStatsEnum.unkown.getName(),AgeStatsEnum.unkown.getName()),
-                StatsColumn.of("未填写","未填写比率",true)
+                StatsColumn.of("未填写","未填写",true)
 
         );
         List<Map<String, Object>> contents = new ArrayList<>();

+ 6 - 0
coffee-system/src/main/java/com/coffee/bus/web/handler/CheckRepeatHandler.java

@@ -7,6 +7,7 @@ import com.coffee.common.exception.RequestRepeatException;
 import com.coffee.common.redis.RedisUtils;
 import com.coffee.common.result.R;
 import com.coffee.common.result.ResultCode;
+import jodd.util.ObjectUtil;
 import lombok.AllArgsConstructor;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -18,6 +19,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.Objects;
 
 /**
  * @author lifang
@@ -36,6 +38,9 @@ public class CheckRepeatHandler implements HandlerInterceptor {
     @Override
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
         String method = request.getMethod();
+        if(Objects.nonNull(request.getAttribute("repeat-check"))){
+            return true;
+        }
         if (method.equals(HttpMethod.POST.name())&&checkProperties.getRepeatInterval()!=null) {
             //post 请求验证参数
             String sign = request.getHeader("Sign");
@@ -43,6 +48,7 @@ public class CheckRepeatHandler implements HandlerInterceptor {
             if(result==null){
                 //请求60秒过期
                 redisUtils.set(sign,1,checkProperties.getRepeatInterval());
+                request.setAttribute("repeat-check",true);
                 return true;
             }else {
                 throw  new RequestRepeatException();

+ 10 - 3
coffee-system/src/main/java/com/coffee/bus/web/handler/CheckSignHandler.java

@@ -3,7 +3,11 @@ package com.coffee.bus.web.handler;
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.crypto.digest.DigestUtil;
 import cn.hutool.json.JSONObject;
+import com.coffee.bus.web.RequestCheckProperties;
 import com.coffee.common.exception.RequestSignErrorException;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.annotation.Order;
@@ -23,20 +27,23 @@ import java.nio.charset.Charset;
  * @createTime 2022年04月22日 10:47:00
  */
 @Configuration
-@ConditionalOnProperty(value = "request.check.sign",havingValue = "true",matchIfMissing = false)
+@ConditionalOnProperty(value = "request.check.enable",havingValue = "true",matchIfMissing = false)
 @Order(30)
+@Slf4j
+@AllArgsConstructor
 public class CheckSignHandler implements HandlerInterceptor {
+    private final RequestCheckProperties checkProperties;
     @Override
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
         String method = request.getMethod();
-        if (method.equals(HttpMethod.POST.name())) {
+        if (method.equals(HttpMethod.POST.name())&&checkProperties.isSign()) {
             //post 请求验证参数
             String sign = request.getHeader("Sign");
             String timestamp = request.getHeader("Timestamp");
             String authorization = request.getHeader("Authorization");
             String body = IoUtil.read(request.getInputStream(), Charset.defaultCharset());
             JSONObject jsonObject = new JSONObject(true);
-            jsonObject.putOpt("body",String.valueOf(body));
+            jsonObject.putOpt("body",body);
             jsonObject.putOpt("timestamp",timestamp);
             jsonObject.putOpt("token",authorization);
             String encodeSign = DigestUtil.md5Hex(jsonObject.toString());

+ 12 - 12
coffee-system/src/main/java/com/coffee/bus/websocket/DefaultWebSocketMsgHandler.java

@@ -38,6 +38,7 @@ public class DefaultWebSocketMsgHandler implements IWsMsgHandler {
     private final List<WsHandler> messageHandlers;
     private final HisScriptSessionManager scriptSessionManager;
     private final HospitalCodeCheck codeCheck;
+
     @Override
     public HttpResponse handshake(HttpRequest httpRequest, HttpResponse httpResponse, ChannelContext channelContext) {
         return httpResponse;
@@ -52,8 +53,10 @@ public class DefaultWebSocketMsgHandler implements IWsMsgHandler {
         }
         if(StrUtil.isNullOrUndefined(authorization)){
             Tio.send(channelContext,WsResponse.fromText(JSONUtil.toJsonStr(R.fail("授权失败")),"utf-8"));
-            //给返回信息一些时间 todo1
+            //给返回信息一些时间
+            Thread.sleep(50);
             channelContext.setClosed(true);
+            Tio.remove(channelContext,  "接受数据不符合业务规范");
             return;
         }
         if (StrUtil.isNotEmpty(authorization)) {
@@ -68,13 +71,15 @@ public class DefaultWebSocketMsgHandler implements IWsMsgHandler {
                     hisScriptSession.bindChannel(channelContext);
                     log.info("医院脚本连接成功,医院编码【{}】",authorization);
                 }else {
-                    unbind(channelContext);
                     Thread.sleep(50);
                     channelContext.setClosed(true);
                     if(log.isDebugEnabled()){
                         log.debug("Authorization:{},鉴权失败",authorization);
                     }
                     Tio.send(channelContext,WsResponse.fromText(JSONUtil.toJsonStr(R.fail("授权失败")),"utf-8"));
+                    Thread.sleep(50);
+                    channelContext.setClosed(true);
+                    Tio.remove(channelContext,  "接受数据不符合业务规范");
                 }
                 return;
             }else {
@@ -100,11 +105,11 @@ public class DefaultWebSocketMsgHandler implements IWsMsgHandler {
     @Override
     public Object onText(WsRequest wsRequest, String message, ChannelContext channelContext) {
         if (StrUtil.isEmpty(message)) {
-            unbind(channelContext);
             channelContext.setClosed(true);
+            Tio.remove(channelContext,  "接受数据不符合业务规范");
             return null;
         }
-        //心跳请求 todo
+        //心跳请求
         if("ping".equals(message.trim().toLowerCase())){
             Tio.send(channelContext,WsResponse.fromText("pong","utf-8"));
             return null;
@@ -123,18 +128,13 @@ public class DefaultWebSocketMsgHandler implements IWsMsgHandler {
             }
         }catch (Exception e){
             log.warn("websocket 接收到异常请求,token:{},message:{},userId:{}",channelContext.getToken(),message,JSONUtil.toJsonStr(channelContext.get(Constants.LOGIN_USER_KEY)));
-            unbind(channelContext);
-            channelContext.setClosed(true);
+            channelContext.setCloseCode(ChannelContext.CloseCode.HEARTBEAT_TIMEOUT);
+            Tio.remove(channelContext,  "接受数据不符合业务规范");
         }
 
         return null;
     }
 
-    private void unbind(ChannelContext channelContext){
-        Tio.unbindToken(channelContext);
-        Tio.unbindUser(channelContext);
-    }
-
 
     /**
      * 描述: 处理用户请求
@@ -154,8 +154,8 @@ public class DefaultWebSocketMsgHandler implements IWsMsgHandler {
                 .collect(Collectors.toList());
         //传入格式错误,不支持该订阅id
         if(CollectionUtil.isEmpty(collect)){
-            unbind(channelContext);
             channelContext.setClosed(true);
+            Tio.remove(channelContext,  "接受数据不符合业务规范");
             return;
         }
         collect.forEach(handler->handler.onMessage(messagingRequest,channelContext));

+ 62 - 0
coffee-system/src/main/java/com/coffee/bus/websocket/DefaultWsServerAioListener.java

@@ -0,0 +1,62 @@
+package com.coffee.bus.websocket;
+
+import com.coffee.common.config.websocket.handler.WsHandler;
+import lombok.extern.slf4j.Slf4j;
+import org.tio.core.ChannelContext;
+import org.tio.core.intf.Packet;
+import org.tio.server.intf.ServerAioListener;
+import org.tio.websocket.common.WsSessionContext;
+import org.tio.websocket.server.WsServerAioListener;
+
+import java.util.*;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName ChannelHeartBeatCheck.java
+ * @Description 检查通道是否存活心跳
+ * @createTime 2022年06月10日 20:13:00
+ */
+@Slf4j
+public class DefaultWsServerAioListener extends WsServerAioListener {
+
+
+    private List<WsHandler> wsHandlers;
+
+    public DefaultWsServerAioListener( List<WsHandler> wsHandlers) {
+        this.wsHandlers = wsHandlers;
+    }
+
+    @Override
+    public boolean onHeartbeatTimeout(ChannelContext channelContext, Long interval, int heartbeatTimeoutCount) {
+        //连接关闭时进行业务处理
+        log.info("{},心跳超时,通道关闭", channelContext);
+        wsHandlers.forEach(wsHandler -> wsHandler.close(channelContext));
+        return false;
+    }
+
+
+    @Override
+    public void onAfterDecoded(ChannelContext channelContext, Packet packet, int packetSize) throws Exception {
+    }
+
+    @Override
+    public void onAfterReceivedBytes(ChannelContext channelContext, int receivedBytes) throws Exception {
+
+    }
+
+    @Override
+    public void onAfterSent(ChannelContext channelContext, Packet packet, boolean isSentSuccess) throws Exception {
+
+    }
+
+    @Override
+    public void onAfterHandled(ChannelContext channelContext, Packet packet, long cost) throws Exception {
+
+    }
+
+    @Override
+    public void onBeforeClose(ChannelContext channelContext, Throwable throwable, String remark, boolean isRemove) throws Exception {
+
+    }
+}

+ 33 - 0
coffee-system/src/main/java/com/coffee/bus/websocket/HeartBeatConfig.java

@@ -0,0 +1,33 @@
+package com.coffee.bus.websocket;
+
+import com.coffee.common.config.websocket.handler.WsHandler;
+import lombok.AllArgsConstructor;
+import lombok.SneakyThrows;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.tio.websocket.starter.TioWebSocketServerBootstrap;
+import org.tio.websocket.starter.TioWebSocketServerInitializerConfiguration;
+
+import java.util.List;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName HeartBeatConfig.java
+ * @Description ws心跳业务配置
+ * @createTime 2022年06月10日 22:47:00
+ */
+@Configuration
+@AllArgsConstructor
+public class HeartBeatConfig implements CommandLineRunner {
+    private final TioWebSocketServerBootstrap serverTioConfig;
+    private final List<WsHandler> wsHandlers;
+
+    @Override
+    public void run(String... args) {
+        serverTioConfig.getServerTioConfig().setServerAioListener(new DefaultWsServerAioListener(wsHandlers));
+    }
+}

+ 29 - 18
coffee-system/src/main/java/com/coffee/bus/websocket/listener/DeviceInfoListener.java

@@ -148,6 +148,8 @@ public class DeviceInfoListener {
 
         device.setStartTime(deviceOperator.getStartTime());
         device.setTenantId(deviceOperator.getTenantId());
+        //将设备撤泵标志去除
+        device.setIsUndo(false);
 
     }
 
@@ -230,23 +232,16 @@ public class DeviceInfoListener {
             device.setMaster(true);
         }
         if (isNewInFusion(device.getDeviceId(),device.getClassification())) {
-//            BusInfusionHistoryEntity exist=infusionHistoryService.findInfusion(device.getDeviceId(),device.getClassification());
-//            if(exist==null){
-                infusionHistory.setId(IdWorker.getIdStr());
-                infusionHistory.setFinished(false);
-                infusionHistory.setStartTime(device.getUploadTime());
-                device.setNewInfusion(true);
-                //结束其余输注信息
-                infusionHistoryService.update(new UpdateWrapper<BusInfusionHistoryEntity>().lambda()
-                        .eq(BusInfusionHistoryEntity::getDeviceId,device.getDeviceId())
-                        .eq(BusInfusionHistoryEntity::getTenantId,device.getTenantId())
-                        .eq(BusInfusionHistoryEntity::getFinished,false)
-                        .set(BusInfusionHistoryEntity::getFinished,true));
-//            }else {
-//                device.setNewInfusion(false);
-//                infusionHistory.setStartTime(device.getStartTime());
-//                infusionHistory.setId(exist.getId());
-//            }
+            infusionHistory.setId(IdWorker.getIdStr());
+            infusionHistory.setFinished(false);
+            infusionHistory.setStartTime(device.getUploadTime());
+            device.setNewInfusion(true);
+            //结束其余输注信息
+            infusionHistoryService.update(new UpdateWrapper<BusInfusionHistoryEntity>().lambda()
+                    .eq(BusInfusionHistoryEntity::getDeviceId,device.getDeviceId())
+                    .eq(BusInfusionHistoryEntity::getTenantId,device.getTenantId())
+                    .eq(BusInfusionHistoryEntity::getFinished,false)
+                    .set(BusInfusionHistoryEntity::getFinished,true));
         }else {
             device.setNewInfusion(false);
             infusionHistory.setStartTime(device.getStartTime());
@@ -277,9 +272,9 @@ public class DeviceInfoListener {
 
         String signHex = busInfusionModify.signParam();
         String infusionParam = deviceOperator.getInfusionParam();
+        boolean clinicFinished = clinicService.isFinished(device.getClinicId());
         if(ObjectUtil.notEqual(signHex,infusionParam)){
             device.setInfusionModify(true);
-            boolean clinicFinished = clinicService.isFinished(device.getClinicId());
             infusionModifyService.save(busInfusionModify);
             device.setInfusionModifyId(busInfusionModify.getId());
             device.setModifyTime(busInfusionModify.getModifyTime());
@@ -291,6 +286,22 @@ public class DeviceInfoListener {
             });
             device.setIsUndo(false);
         }else {
+            //判断临床是否已结束,若临床已结束,则采用当前输注作为主输注开启临床
+            if(clinicFinished){
+                clinicService.resetClinic(device.getClinicId());
+                patientService.update(new UpdateWrapper<BusPatientEntity>()
+                        .lambda()
+                        .eq(BusPatientEntity::getCode,device.getPatientCode())
+                        .eq(BusPatientEntity::getTenantId,device.getTenantId())
+                        .set(BusPatientEntity::getInfusionId,device.getInfusionId()));
+                PatientOperator patientOperator = patientRegistry.getOperator(device.getTenantId(), device.getPatientCode());
+                device.setMaster(true);
+                device.setResetClinic(true);
+                cacheOperation.add(()->{
+                    patientOperator.setBindDeviceId(device.getDeviceId());
+                    return null;
+                });
+            }
             //填充当前参数修改记录id
             BusInfusionModifyEntity modify =infusionModifyService.recentModify(device.getClinicId(),device.getTenantId());
             if(modify==null){

+ 2 - 2
coffee-system/src/main/resources/mapper/bus/BusInfusionHistoryMapper.xml

@@ -103,7 +103,7 @@
         <result column="cognition_obstacle" property="cognitionObstacle"/>
         <result column="satisfaction" property="satisfaction"/>
         <result column="shrink_pressure" property="shrinkPressure"/>
-        <result column="diastolic_pressure" property="diastolicPressure"/>
+        <result column="diastens_pressure" property="diastensPressure"/>
         <result column="heart_rate" property="heartRate"/>
         <result column="fetal_heart_rate" property="fetalHeartRate"/>
         <result column="breath_rate" property="breathRate"/>
@@ -629,7 +629,7 @@
         e.cognition_obstacle as cognition_obstacle,
         e.satisfaction as satisfaction,
         e.shrink_pressure as shrink_pressure,
-        e.diastolic_pressure as diastolic_pressure,
+        e.diastens_pressure as diastens_pressure,
         e.heart_rate as heart_rate,
         e.fetal_heart_rate as fetal_heart_rate,
         e.breath_rate as breath_rate,