Browse Source

普通核验接口异步处理,提高并发能力

FanQun 2 years ago
parent
commit
5c64c7c6eb

+ 3 - 1
src/main/java/com/rshy/project/hy/config/ThreadPoolTaskConfig.java

@@ -11,6 +11,8 @@ import java.util.concurrent.ThreadPoolExecutor;
 /**
  * 线程池配置文件
  *
+ * @see <a href="https://www.jianshu.com/p/5bf7691c1f1b" />
+ *
  * @author fanqun
  * Created on 2022-05-10 11:17 AM
  **/
@@ -19,7 +21,7 @@ import java.util.concurrent.ThreadPoolExecutor;
 public class ThreadPoolTaskConfig implements AsyncConfigurer {
 
     /* 核心线程数(默认线程数) */
-    private static final int CORE_POOL_SIZE = 10;
+    private static final int CORE_POOL_SIZE = 18;
     /* 最大线程数 */
     private static final int MAX_POOL_SIZE = 20;
     /* 允许线程空闲时间(单位:默认为秒) */

+ 7 - 5
src/main/java/com/rshy/project/hy/manager/impl/RshyJkManagerImpl.java

@@ -61,7 +61,9 @@ public class RshyJkManagerImpl implements RshyJkManager {
     @Async("hstTaskExecutor")
     public Future<RshyVo> getRshyInfo(RshyParam rshyParam) {
         // timeout 转成毫秒
-        rshyParam.setTimeout(rshyParam.getTimeout() * 1000 - 800);
+        rshyParam.setTimeout(rshyParam.getTimeout() * 1000);
+        //健康码最多只能用timeout入参-2秒,不然其他的接口不够
+        int jkmTimeout = rshyParam.getTimeout() - 2000;
         RshyVo rshyVo = new RshyVo();
         PctgkryDTO gkryDTO = new PctgkryDTO();
         ResultDTO resultDTO = new ResultDTO();
@@ -72,21 +74,21 @@ public class RshyJkManagerImpl implements RshyJkManager {
         if (StringUtils.isNotBlank(rshyParam.getBarCode()) || StringUtils.isNotBlank(rshyParam.getSfzh())) {
             try {
                 //查询健康码信息
-                jkmInfo = itfwServer.getPctjkm(rshyParam.getBarCode(), rshyParam.getSfzh(), rshyParam.getTimeout());
+                jkmInfo = itfwServer.getPctjkm(rshyParam.getBarCode(), rshyParam.getSfzh(), jkmTimeout);
             } catch (Exception e) {
                 log.error("查询健康码信息异常:{}", e.getMessage());
                 e.printStackTrace();
             }
         }
         if (jkmInfo == null) {
-            return new AsyncResult<>(rshyVo.setPassStatus(PassStatusEnum.NO_CODE).setSfzh(rshyParam.getSfzh()).setXm(rshyParam.getXm())
+            return new AsyncResult<>(rshyVo.setPassStatus(PassStatusEnum.NO_CODE).setSfzh(rshyParam.getSfzh()).setXm(rshyParam.getXm()).setWarning(PassStatusEnum.NO_CODE.getDesc())
                     .setNucleic_acid(new NucleicAcidDTO().setStatus(NucleicAcidEnum.NO_DATA.getCode()).setResults(NucleicAcidEnum.NO_DATA.getDesc())));
         }
 
         rshyParam.setSfzh(jkmInfo.getId_num());
         rshyVo.setSfzh(jkmInfo.getId_num()).setXm(jkmInfo.getUser_name()).setHealthCode(jkmInfo.getColor_code_label()).setPhone(jkmInfo.getPn());
 
-        rshyParam.setTimeout((int) (rshyParam.getTimeout() - DateUtil.between(beginDate, DateTime.now(), DateUnit.MS)));
+        rshyParam.setTimeout(rshyParam.getTimeout() - (int) DateUtil.between(beginDate, DateTime.now(), DateUnit.MS) - 1000);
 
         AtomicReference<RshyVo> quickRshyVo = new AtomicReference<>(new RshyVo());
         List<Runnable> taskList = new ArrayList<Runnable>() {
@@ -169,7 +171,7 @@ public class RshyJkManagerImpl implements RshyJkManager {
             rshyVo.setPass(PassStatusEnum.RED_CODE.getCode()).setTts(PassStatusEnum.RED_CODE.getTts()).setDisplayMsg(PassStatusEnum.RED_CODE.getDesc()).setWarning(PassStatusEnum.RED_CODE.getDesc()).setKind("健康码" + PassStatusEnum.RED_CODE.getDesc());
         } else if (PassStatusEnum.YELLOW_CODE.getDesc().equalsIgnoreCase(jkmInfo.getColor_code_label())) {
             //黄码
-            rshyVo.setPassStatus(PassStatusEnum.YELLOW_CODE).setKind("健康码" + PassStatusEnum.YELLOW_CODE.getDesc());
+            rshyVo.setPassStatus(PassStatusEnum.YELLOW_CODE).setKind("健康码" + PassStatusEnum.YELLOW_CODE.getDesc()).setWarning(PassStatusEnum.YELLOW_CODE.getDesc());
         } else if (resultDTO.getPctgkryDTO().getPctztDTO() != null || StrUtil.containsAnyIgnoreCase(hcjg, "抓捕") || StrUtil.containsAnyIgnoreCase(hcjg, "拦截")) {
             //在逃 或者 人车核录接口返回 抓捕或者拦截
             rshyVo.setPassStatus(PassStatusEnum.NO_PASSING).setKind(kind(resultDTO)).setWarning(warning(resultDTO));//.setWarning("在逃人员:" + resultDTO.getPctgkryDTO().getPctztDTO().getJyaq()).setKind(resultDTO.getPctgkryDTO().getPctztDTO().getZtrylxmc());

+ 1 - 1
src/main/java/com/rshy/project/hy/server/ItfwServer.java

@@ -113,7 +113,7 @@ public class ItfwServer {
 
         log.info("健康码请求第三方接口入参信息:{}", JSON.toJSONString(properties));
         String body = this.baseAgentApi(properties, timeout);
-        log.info("请求健康码服务响应信息:{}", body);
+        log.info("健康码服务响应信息:{}", body);
         if (StrUtil.isEmpty(body)) {
             return null;
         }

+ 1 - 1
src/main/java/com/rshy/project/hy/web/controller/RshyController.java

@@ -67,7 +67,7 @@ public class RshyController {
         RshyVo rshyVo = new RshyVo().setPassStatus(PassStatusEnum.NORMAL_TRAFFIC);
         try {
             Future<RshyVo> future = rshyJkManager.getRshyInfo(rshyParam);
-            rshyVo = future.get(rshyParam.getTimeout() * 1000 - 150, TimeUnit.MILLISECONDS);
+            rshyVo = future.get(rshyParam.getTimeout() * 1000 - 100, TimeUnit.MILLISECONDS);
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             log.error("普通核验接口异常: {}", e.getMessage());
             e.printStackTrace();