Преглед изворни кода

Merge remote-tracking branch 'origin/dev' into dev

zsl пре 3 година
родитељ
комит
d0ff5c58b2

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

@@ -101,7 +101,7 @@ spring:
         max-wait: -1ms
 request:
   check:
-    enable: false
+    enable: true
     # 开启请求验签
     sign: true
     # 请求与服务器时间间隔不得超过 10分钟

+ 2 - 0
coffee-common/src/main/java/com/coffee/common/result/R.java

@@ -38,6 +38,7 @@ public class R<T> implements Serializable {
     @ApiModelProperty("返回错误消息")
     private String msg;
 
+
     private Long timestamp;
 
     private R(int code, T data, String msg) {
@@ -47,6 +48,7 @@ public class R<T> implements Serializable {
         this.timestamp=System.currentTimeMillis();
     }
 
+
     private R(IResultCode resultCode) {
         this(resultCode, null, resultCode.getMessage());
     }

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

@@ -36,6 +36,7 @@ public class BusEvaluationEntity extends TenantGenericEntity<String,String> {
     private String infusionId;
 
     @ApiModelProperty(value = "临床号,无泵专用")
+    @NotNull(message = "临床id不能为空")
     @Length(max = 255,message = "临床号长度不得超过255个字节")
     private String clinicId;
 

+ 1 - 1
coffee-system/src/main/java/com/coffee/bus/hospital/HospitalManagerRegister.java

@@ -74,7 +74,7 @@ public class HospitalManagerRegister {
     public void refresh(String hospitalId,boolean info,boolean config,boolean script){
         HospitalManager hospitalManager = this.get(hospitalId);
         if(info){
-            hospitalManager.refreshConfig();
+            hospitalManager.refreshInfo();
         }
         if(config){
             hospitalManager.refreshConfig();

+ 14 - 3
coffee-system/src/main/java/com/coffee/bus/hospital/his/HisScriptSession.java

@@ -26,6 +26,7 @@ import com.coffee.common.cache.ConfigStorage;
 import com.coffee.common.cache.manager.ConfigStorageManager;
 import com.coffee.common.cache.value.Value;
 import com.coffee.common.exception.CustomException;
+import com.coffee.common.exception.ScriptException;
 import com.coffee.common.result.R;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.Getter;
@@ -204,7 +205,11 @@ public class HisScriptSession {
             result = exec.getIfSuccess();
         }catch (Exception e){
             log.error("数据解析后转化为json失败,{},",text,e.getMessage());
-            return null;
+            if(StrUtil.isNotEmpty(text)){
+                throw new ScriptException("脚本解析失败");
+            }else {
+                throw new ScriptException(String.format("病号【[%s]】数据查询为空",patientCode));
+            }
         }finally {
             BusHospitalLogEntity hospitalLog = BusHospitalLogEntity.of(exec, this.getHospitalId(),patientCode);
             try {
@@ -310,8 +315,14 @@ public class HisScriptSession {
                             }
                         }
                         //正常响应
-                        BusClinicEntity clinic = handle(Value.simple(hisResponse.getContext()).asString(), hisResponse.getPatientCode());
-                        result.setResult(R.success(clinic));
+                        try {
+                            BusClinicEntity clinic = handle(Value.simple(hisResponse.getContext()).asString(), hisResponse.getPatientCode());
+                            result.setResult(R.success(clinic));
+                        }catch (ScriptException e){
+                            result.setResult(R.fail(String.format("病号【[%s]】病人数据查询为空",hisResponse.getPatientCode())));
+                        }
+
+
                     });
                 }
 

+ 24 - 6
coffee-system/src/main/java/com/coffee/bus/service/LocalBusHospitalService.java

@@ -25,6 +25,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.PostConstruct;
 import java.util.List;
 import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
 
 /**
  * @author lifang
@@ -39,7 +40,7 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
     @Lazy
     private ConfigStorageManager configStorageManager;
 
-    private ConfigStorage configStorage;
+    private ConfigStorage nameCache;
 
     @Autowired
     @Lazy
@@ -49,7 +50,7 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
     private LocalBusHospitalConfigService configService;
     @PostConstruct
     public void init(){
-        configStorage=configStorageManager.getStorage("hospital_name");
+        nameCache =configStorageManager.getStorage("hospital_name");
     }
 
     @Override
@@ -92,14 +93,31 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
 
     @Override
     public void postSave(BusHospitalEntity entity) {
-        configStorage.setConfig(entity.getId(),entity.getName());
+        CompletableFuture.runAsync(()->{
+            List<BusHospitalConfigEntity> configs =
+                    configService.list(new QueryWrapper<BusHospitalConfigEntity>().lambda()
+                            .or()
+                            .eq(BusHospitalConfigEntity::getTenantId, 1));
+            configs.forEach(config->{
+                config.setId(null);
+                config.setTenantId(entity.getId());
+            });
+            configService.saveBatch(configs);
+        })
+                .whenComplete((i,e)->{
+                    if(e!=null){
+                        log.error("新增医院默认配置失败,",e);
+                    }
+                });
+
+        nameCache.setConfig(entity.getId(),entity.getName());
     }
 
     @Override
     public void postUpdate(BusHospitalEntity entity) {
         hospitalManagerRegister.refresh(entity.getId(),true,null!=entity.getScript());
         if(StrUtil.isNotEmpty(entity.getName())){
-            configStorage.setConfig(entity.getId(),entity.getName());
+            nameCache.setConfig(entity.getId(),entity.getName());
         }
     }
 
@@ -113,7 +131,7 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
         saveDefaultHospital();
         List<BusHospitalEntity> list = list();
         list.forEach(entity -> {
-            configStorage.setConfig(entity.getId(),entity.getName());
+            nameCache.setConfig(entity.getId(),entity.getName());
         });
         configService.saveDefaultConfig();
         list.forEach(hospital->hospitalManagerRegister.refresh(hospital.getId(),true,true,true));
@@ -122,7 +140,7 @@ public class LocalBusHospitalService extends BaseService<BusHospitalMapper, BusH
 
     @Override
     public String getName(String id) {
-        return configStorage.getConfig(id).asString();
+        return nameCache.getConfig(id).asString();
     }
 
 

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

@@ -16,6 +16,7 @@ import com.coffee.bus.enums.DeviceStatusEnum;
 import com.coffee.bus.enums.PatientAlarmEnum;
 import com.coffee.bus.hospital.his.HisScriptSession;
 import com.coffee.bus.hospital.his.HisScriptSessionManager;
+import com.coffee.bus.hospital.his.strategy.HisStrategyEnum;
 import com.coffee.bus.registry.device.DeviceRegistry;
 import com.coffee.bus.service.dto.*;
 import com.coffee.bus.mapper.BusPatientMapper;
@@ -24,6 +25,7 @@ import com.coffee.bus.registry.patient.PatientRegistry;
 import com.coffee.bus.utils.WsPublishUtils;
 import com.coffee.common.crud.BaseService;
 import com.coffee.common.enums.SexEnum;
+import com.coffee.common.exception.CustomException;
 import com.coffee.common.result.R;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -114,6 +116,10 @@ public class LocalBusPatientService extends BaseService<BusPatientMapper, BusPat
      */
     public DeferredResult<R<BusClinicEntity>> getPatientInfoFromHis(String hospitalId, String patientCode, long timeout,boolean sync){
         HisScriptSession hisScriptSession = scriptSessionManager.get(hospitalId);
+        HisStrategyEnum strategy = hisScriptSession.getHospitalInfo().getStrategy();
+        if(null==strategy||HisStrategyEnum.NONE.equals(strategy)){
+            throw new CustomException("医院未对接his,请到【信息维护】->【HIS对接】配置his策略");
+        }
         log.info("医院【{}】,开始拉取病号【{}】信息,拉取方式【{}】",hospitalId,patientCode,sync?"同步":"异步");
         return sync?hisScriptSession.syncGetPatientInfo(patientCode,timeout,TimeUnit.SECONDS):hisScriptSession.asyncGetPatientInfo(patientCode,timeout,TimeUnit.SECONDS,true);
     }

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

@@ -1,60 +0,0 @@
-package com.coffee.bus.web.handler;
-
-import cn.hutool.json.JSONUtil;
-import com.coffee.bus.web.RequestCheckProperties;
-import com.coffee.common.exception.CustomException;
-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;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.annotation.Order;
-import org.springframework.http.HttpMethod;
-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
- * @version 1.0.0
- * @ClassName CheckSignHandler.java
- * @Description 请求重复检验
- * @createTime 2022年04月22日 10:47:00
- */
-@Configuration
-@ConditionalOnProperty(value = "request.check.enable",havingValue = "true",matchIfMissing = false)
-@Order(20)
-@AllArgsConstructor
-public class CheckRepeatHandler implements HandlerInterceptor {
-    private final RedisUtils redisUtils;
-    private final RequestCheckProperties checkProperties;
-    @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");
-            Object result = redisUtils.get(sign);
-            if(result==null){
-                //请求60秒过期
-                redisUtils.set(sign,1,checkProperties.getRepeatInterval());
-                request.setAttribute("repeat-check",true);
-                return true;
-            }else {
-                throw  new RequestRepeatException();
-            }
-        }
-        //get请求
-        return true;
-    }
-}

+ 49 - 4
coffee-system/src/main/java/com/coffee/bus/web/handler/CheckRequestHandler.java

@@ -1,7 +1,14 @@
 package com.coffee.bus.web.handler;
 
+import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.crypto.digest.DigestUtil;
+import cn.hutool.json.JSONObject;
+import com.coffee.bus.web.RequestCheckProperties;
 import com.coffee.common.exception.RequestParmErrorException;
+import com.coffee.common.exception.RequestSignErrorException;
+import com.coffee.common.exception.RequestTimeOutException;
+import com.coffee.common.redis.RedisUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Configuration;
@@ -11,6 +18,8 @@ import org.springframework.web.servlet.HandlerInterceptor;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.nio.charset.Charset;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author lifang
@@ -24,6 +33,8 @@ import javax.servlet.http.HttpServletResponse;
 @Order(10)
 @AllArgsConstructor
 public class CheckRequestHandler  implements HandlerInterceptor {
+    private final RequestCheckProperties properties;
+    private final RedisUtils redisUtils;
     @Override
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
         String method = request.getMethod();
@@ -32,17 +43,51 @@ public class CheckRequestHandler  implements HandlerInterceptor {
             String sign = request.getHeader("Sign");
             String timestamp = request.getHeader("Timestamp");
             String authorization = request.getHeader("Authorization");
+            String body = IoUtil.read(request.getInputStream(), Charset.defaultCharset());
             if(StrUtil.isBlank(sign)
-            ||StrUtil.isBlank(timestamp)
-            ||StrUtil.isBlank(authorization)){
+                    ||StrUtil.isBlank(timestamp)
+                    ||StrUtil.isBlank(authorization)){
                 throw new RequestParmErrorException();
             }
             try {
-                Long.valueOf(timestamp);
-            }catch (Exception e){
+                checkTime( Long.valueOf(timestamp));
+            }catch (NumberFormatException e){
                 throw new RequestParmErrorException();
             }
+            checkSign(sign,timestamp,authorization,body);
+//            checkRepeat(sign);
         }
         return true;
     }
+
+    private void checkTime(Long timestamp){
+        long now = System.currentTimeMillis();
+        //时间间隔不超10分钟
+        long subTime = TimeUnit.MILLISECONDS
+                .toSeconds(Math.abs(Math.subtractExact(timestamp,now)));
+        if(subTime>properties.getExpireInterval()){
+            throw new RequestTimeOutException();
+        }
+    }
+
+    private void checkSign(String sign,String timestamp,String authorization,String body){
+        JSONObject jsonObject = new JSONObject(true);
+        jsonObject.putOpt("body",body);
+        jsonObject.putOpt("timestamp",timestamp);
+        jsonObject.putOpt("token",authorization);
+        String encodeSign = DigestUtil.md5Hex(jsonObject.toString());
+        if (!encodeSign.equals(sign)) {
+            throw new RequestSignErrorException();
+        }
+    }
+
+//    private void checkRepeat(String sign){
+//        Object result = redisUtils.get(sign);
+//        if(result==null){
+//            //请求60秒过期
+//            redisUtils.set(sign,1,properties.getRepeatInterval());
+//        }else {
+//            throw  new RequestRepeatException();
+//        }
+//    }
 }

+ 0 - 56
coffee-system/src/main/java/com/coffee/bus/web/handler/CheckSignHandler.java

@@ -1,56 +0,0 @@
-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.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.annotation.Order;
-import org.springframework.http.HttpMethod;
-import org.springframework.web.servlet.HandlerInterceptor;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.nio.charset.Charset;
-
-/**
- * @author lifang
- * @version 1.0.0
- * @ClassName CheckSignHandler.java
- * @Description 请求验签
- * @createTime 2022年04月22日 10:47:00
- */
-@Configuration
-@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())&&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",body);
-            jsonObject.putOpt("timestamp",timestamp);
-            jsonObject.putOpt("token",authorization);
-            String encodeSign = DigestUtil.md5Hex(jsonObject.toString());
-            if (!encodeSign.equals(sign)) {
-                throw new RequestSignErrorException();
-            }
-        }
-        //get请求
-        return true;
-    }
-}

+ 0 - 54
coffee-system/src/main/java/com/coffee/bus/web/handler/CheckTimeHandler.java

@@ -1,54 +0,0 @@
-package com.coffee.bus.web.handler;
-
-import cn.hutool.json.JSONUtil;
-import com.coffee.bus.web.RequestCheckProperties;
-import com.coffee.common.cache.value.Value;
-import com.coffee.common.exception.RequestTimeOutException;
-import com.coffee.common.result.R;
-import com.coffee.common.result.ResultCode;
-import lombok.AllArgsConstructor;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.annotation.Order;
-import org.springframework.http.HttpMethod;
-import org.springframework.web.servlet.HandlerInterceptor;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author lifang
- * @version 1.0.0
- * @ClassName CheckSignHandler.java
- * @Description 请求时间过期检验
- * @createTime 2022年04月22日 10:47:00
- */
-@Configuration
-@ConditionalOnProperty(value = "request.check.enable",havingValue = "true",matchIfMissing = false)
-@Order(20)
-@AllArgsConstructor
-public class CheckTimeHandler implements HandlerInterceptor {
-
-    private final RequestCheckProperties properties;
-    @Override
-    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
-        String method = request.getMethod();
-        if (method.equals(HttpMethod.POST.name())&&properties.getExpireInterval()!=null) {
-            Long timestamp = Value.simple(request.getHeader("Timestamp")).asLong();
-            long now = System.currentTimeMillis();
-            //时间间隔不超10分钟
-            long subTime = TimeUnit.MILLISECONDS
-                    .toSeconds(Math.abs(Math.subtractExact(timestamp,now)));
-            if(subTime>properties.getExpireInterval()){
-                throw new RequestTimeOutException();
-            }
-            return true;
-
-
-        }
-        //get请求
-        return true;
-    }
-}