10 Commits 67c05b317e ... d40ea0e0a4

Author SHA1 Message Date
  FanQun d40ea0e0a4 缓存优化 2 years ago
  FanQun 4cefa36048 增加缓存 2 years ago
  FanQun dc1fbbd09e 身份信息持久化 2 years ago
  FanQun 4a4eb904a8 身份信息持久化 2 years ago
  FanQun a327291fa2 更新证件照接口缓存过期时间 2 years ago
  FanQun 60b6acf54d 更新民族枚举类 2 years ago
  FanQun 31e1f8be07 无核酸信息 也比对其他接口 2 years ago
  FanQun dccf10bfe2 人员劣迹接口 返回增加 xm 字段 2 years ago
  FanQun 809d0ee9e2 人员劣迹接口 返回增加 ryztmc 字段 2 years ago
  FanQun 981bd0d898 处理errCode 2 years ago

+ 141 - 42
src/main/java/com/rshy/project/hy/manager/impl/RshyJkManagerImpl.java

@@ -13,6 +13,7 @@ import com.alibaba.fastjson.JSON;
 import com.rshy.project.hy.manager.RshyJkManager;
 import com.rshy.project.hy.model.constant.ItfwConstant;
 import com.rshy.project.hy.model.dto.NucleicAcidDTO;
+import com.rshy.project.hy.model.entity.Identity;
 import com.rshy.project.hy.model.enums.*;
 import com.rshy.project.hy.server.ItfwServer;
 import com.rshy.project.hy.server.VIIDServer;
@@ -23,13 +24,17 @@ import com.rshy.project.hy.server.param.RshyQuickParam;
 import com.rshy.project.hy.server.vo.RetrievaResultVO;
 import com.rshy.project.hy.server.vo.RetrievalRepositoryVO;
 import com.rshy.project.hy.server.vo.RshyVo;
+import com.rshy.project.hy.service.IdentityService;
 import com.rshy.project.hy.util.ObjectUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.annotation.DependsOn;
+import org.springframework.core.task.support.ExecutorServiceAdapter;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.AsyncResult;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
@@ -37,6 +42,8 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
@@ -50,6 +57,7 @@ import java.util.stream.Collectors;
 @Component
 @Slf4j
 @DependsOn("itfwServer")
+@EnableAsync
 public class RshyJkManagerImpl implements RshyJkManager {
     @Resource
     private YituFaceServer yituFaceServer;
@@ -59,13 +67,17 @@ public class RshyJkManagerImpl implements RshyJkManager {
     private VIIDServer viidServer;
     @Resource
     private StringRedisTemplate stringRedisTemplate;
+    @Resource
+    private ThreadPoolTaskExecutor poolTaskExecutor;
+    @Resource
+    private IdentityService identityService;
 
     @Override
     @Async("hstTaskExecutor")
     public Future<RshyVo> getRshyInfo(RshyParam rshyParam) {
         // timeout 转成毫秒 这里考虑到网络传输延时等原因,减去300ms
-        rshyParam.setTimeout((int) TimeUnit.MILLISECONDS.convert(rshyParam.getTimeout(), TimeUnit.SECONDS) - 300);
-        int jkmTimeout = rshyParam.getTimeout();
+        rshyParam.setTimeout((int) TimeUnit.MILLISECONDS.convert(rshyParam.getTimeout(), TimeUnit.SECONDS));
+        int jkmTimeout = rshyParam.getTimeout() - 300;
         RshyVo rshyVo = new RshyVo();
         PctgkryDTO gkryDTO = new PctgkryDTO();
         ResultDTO resultDTO = new ResultDTO();
@@ -73,34 +85,50 @@ public class RshyJkManagerImpl implements RshyJkManager {
         DateTime beginDate = DateTime.now();
         PctjkmInfoDTO jkmInfo = null;
 
-        if (StringUtils.isNotBlank(rshyParam.getBarCode()) || StringUtils.isNotBlank(rshyParam.getSfzh())) {
+        // 刷健康码或场所码
+        if (StringUtils.isNotBlank(rshyParam.getBarCode()) && StringUtils.isBlank(rshyParam.getSfzh())) {
             try {
                 //查询健康码信息
-                jkmInfo = itfwServer.getPctjkm(rshyParam.getBarCode(), rshyParam.getSfzh(), jkmTimeout);
+                jkmInfo = itfwServer.getPctjkm(rshyParam.getBarCode(), StrUtil.EMPTY, jkmTimeout);
             } catch (Exception e) {
                 log.error("查询健康码信息异常:{}", e.getMessage());
                 //e.printStackTrace();
             }
         }
-        if (jkmInfo == null) {
+        if (jkmInfo == null && StrUtil.isBlank(rshyParam.getSfzh())) {
             return new AsyncResult<>(rshyVo.setPassStatus(PassStatusEnum.NO_HEALTH_CODE).setSfzh(rshyParam.getSfzh()).setXm(rshyParam.getXm()).setWarning(PassStatusEnum.NO_HEALTH_CODE.getDesc())
                     .setNucleic_acid(new NucleicAcidDTO().set(NucleicAcidEnum.NO_DATA)));
         }
 
-        rshyParam.setSfzh(jkmInfo.getId_num());
-        rshyVo.setSfzh(jkmInfo.getId_num()).setXm(jkmInfo.getUser_name()).setHealthCode(jkmInfo.getColor_code_label()).setPhone(jkmInfo.getPn());
+        if (jkmInfo != null) {
+            rshyParam.setSfzh(jkmInfo.getId_num());
+            rshyVo.setSfzh(jkmInfo.getId_num()).setXm(jkmInfo.getUser_name()).setHealthCode(jkmInfo.getColor_code_label()).setPhone(jkmInfo.getPn());
+            saveIdentity(rshyParam.getBarCode(), rshyVo);
+            resultDTO.setPctjkmInfoDTO(jkmInfo);
+        } else {
+            rshyVo.setSfzh(rshyParam.getSfzh());
+            if (rshyParam.getIdentity() != null) {
+                rshyVo.setXm(rshyParam.getIdentity().getName());
+                rshyVo.setPhone(rshyParam.getIdentity().getPhone());
+            }
+        }
         int jkmUsedTime = (int) DateUtil.between(beginDate, DateTime.now(), DateUnit.MS);
         System.out.println("健康码接口用时: " + jkmUsedTime + "毫秒");
 
-        rshyParam.setTimeout(rshyParam.getTimeout() - jkmUsedTime - 300);
-        //剩余时间不到10ms,直接返回
-        if (rshyParam.getTimeout() <= 10) {
+        rshyParam.setTimeout(rshyParam.getTimeout() - jkmUsedTime - 400);
+        //剩余时间不到50ms,直接返回
+        if (rshyParam.getTimeout() <= 50) {
             return new AsyncResult<>(rshyVo);
         }
 
+        log.info(rshyParam.toString());
+
         AtomicReference<RshyVo> quickRshyVo = new AtomicReference<>(new RshyVo());
         List<Runnable> taskList = new ArrayList<Runnable>() {
             {
+                if (resultDTO.getPctjkmInfoDTO() == null) {
+                    add(() -> resultDTO.setPctjkmInfoDTO(itfwServer.getPctjkm("", rshyParam.getSfzh(), rshyParam.getTimeout())));
+                }
                 add(() -> resultDTO.setPctsfzResult(itfwServer.getPctsfz(rshyParam.getSfzh(), rshyParam.getTimeout())));
                 add(() -> resultDTO.setPctymDataDTOS(itfwServer.getPctym(rshyParam.getSfzh(), rshyParam.getTimeout())));
                 add(() -> resultDTO.setPcthsResultDTO(itfwServer.getPcths(rshyParam.getSfzh(), rshyParam.getTimeout())));
@@ -117,29 +145,41 @@ public class RshyJkManagerImpl implements RshyJkManager {
 
         //if (rshyParam.getScreenLocked() == 0 && (barCodes == null || PassStatusEnum.GREEN_CODE.getDesc().equals(barCodes.getCOLOR_CODE_LABEL()))) {
         //绿码人员继续进行七大类管控接口、人车核录接口、杭州市重点人员底库数据查询接口比对
-        if (PassStatusEnum.GREEN_CODE.getDesc().equals(jkmInfo.getColor_code_label())) {
-            taskList.add(() -> resultDTO.getPctgkryDTO().setPctdfkDTO(itfwServer.getPctdfk(rshyParam.getSfzh(), "", rshyParam.getTimeout())));
-            taskList.add(() -> resultDTO.getPctgkryDTO().setPctjsryDTO(itfwServer.getPctjsry(rshyParam.getSfzh(), rshyParam.getTimeout())));
-            taskList.add(() -> resultDTO.getPctgkryDTO().setPctztDTO(itfwServer.getPctzt(rshyParam.getSfzh(), rshyParam.getTimeout())));
-            taskList.add(() -> resultDTO.getPctgkryDTO().setPctzfbaDTO(itfwServer.getPctzfba(rshyParam.getSfzh(), rshyParam.getTimeout())));
-            taskList.add(() -> resultDTO.getPctgkryDTO().setPctqkryDTO(itfwServer.getPctqkry(rshyParam.getSfzh(), rshyParam.getTimeout())));
-            taskList.add(() -> resultDTO.getPctgkryDTO().setPctxdryDTO(itfwServer.getPctxdry(rshyParam.getSfzh(), "", rshyParam.getTimeout())));
-            taskList.add(() -> resultDTO.getPctgkryDTO().setPctzdryDTO(itfwServer.getPctzdry(rshyParam.getSfzh(), rshyParam.getTimeout())));
-            taskList.add(() -> resultDTO.setPctrchlDTO(itfwServer.getPctrchl(rshyParam.getSfzh(), rshyParam.getTimeout())));
-            taskList.add(() -> resultDTO.setPctzdrydkResultDTO(itfwServer.getPctzdrydk(rshyParam.getSfzh(), rshyParam.getTimeout())));
-        }
+        //if (PassStatusEnum.GREEN_CODE.getDesc().equals(jkmInfo.getColor_code_label())) {
+        taskList.add(() -> resultDTO.getPctgkryDTO().setPctdfkDTO(itfwServer.getPctdfk(rshyParam.getSfzh(), "", rshyParam.getTimeout())));
+        taskList.add(() -> resultDTO.getPctgkryDTO().setPctjsryDTO(itfwServer.getPctjsry(rshyParam.getSfzh(), rshyParam.getTimeout())));
+        taskList.add(() -> resultDTO.getPctgkryDTO().setPctztDTO(itfwServer.getPctzt(rshyParam.getSfzh(), rshyParam.getTimeout())));
+        taskList.add(() -> resultDTO.getPctgkryDTO().setPctzfbaDTO(itfwServer.getPctzfba(rshyParam.getSfzh(), rshyParam.getTimeout())));
+        taskList.add(() -> resultDTO.getPctgkryDTO().setPctqkryDTO(itfwServer.getPctqkry(rshyParam.getSfzh(), rshyParam.getTimeout())));
+        taskList.add(() -> resultDTO.getPctgkryDTO().setPctxdryDTO(itfwServer.getPctxdry(rshyParam.getSfzh(), "", rshyParam.getTimeout())));
+        taskList.add(() -> resultDTO.getPctgkryDTO().setPctzdryDTO(itfwServer.getPctzdry(rshyParam.getSfzh(), rshyParam.getTimeout())));
+        taskList.add(() -> resultDTO.setPctrchlDTO(itfwServer.getPctrchl(rshyParam.getSfzh(), rshyParam.getTimeout())));
+        taskList.add(() -> resultDTO.setPctzdrydkResultDTO(itfwServer.getPctzdrydk(rshyParam.getSfzh(), rshyParam.getTimeout())));
+        //}
 
         //异步流并发处理
-        taskList.parallelStream().forEach(v -> {
-            try {
-                v.run();
-            } catch (Exception e) {
-                log.error("异常信息:{}", e.getMessage());
-                e.printStackTrace();
-            }
-        });
+//        taskList.parallelStream().forEach(v -> {
+//            try {
+//                v.run();
+//            } catch (Exception e) {
+//                log.error("异常信息:{}", e.getMessage());
+//                e.printStackTrace();
+//            }
+//        });
+
+        try {
+            log.info("{}个任务, 用时 {}毫秒", taskList.size(), startTaskAllInOnce(taskList, rshyParam.getTimeout() + 100));
+        } catch (InterruptedException e) {
+            log.error("异常信息:{}", e.getMessage());
+            e.printStackTrace();
+        }
 
         log.info("IT服务平台接口调用完成");
+        //用身份证号码获取到健康码信息
+        if (resultDTO.getPctjkmInfoDTO() != null) {
+            jkmInfo = resultDTO.getPctjkmInfoDTO();
+            rshyVo.setXm(resultDTO.getPctjkmInfoDTO().getUser_name()).setHealthCode(resultDTO.getPctjkmInfoDTO().getColor_code_label()).setPhone(resultDTO.getPctjkmInfoDTO().getPn());
+        }
         //今日进站次数
         rshyVo.setTimes(times(rshyVo.getSfzh()));
         //疫苗
@@ -154,10 +194,11 @@ public class RshyJkManagerImpl implements RshyJkManager {
         //出生日期 从身份证号码中获取
         Date date = DateUtil.parse(IdcardUtil.getBirthByIdCard(rshyVo.getSfzh()));
         rshyVo.setBirthday(DateUtil.format(date, "yyyy-M-d"));
-        //不是刷身份证,取地址
+        //不是刷身份证,取地址、姓名、民族
         if (StrUtil.isBlank(rshyParam.getXm())) {
             if (resultDTO.getPctsfzResult() != null) {
-                //有警察叔叔身份证接口返回数据,取地址
+                //有警察叔叔身份证接口返回数据
+                rshyVo.setXm(resultDTO.getPctsfzResult().getCZRKXM());
                 rshyVo.setAddress(resultDTO.getPctsfzResult().getCZRKZZ());
                 rshyVo.setMz(resultDTO.getPctsfzResult().getCZRKMZ());
             } else {
@@ -172,27 +213,36 @@ public class RshyJkManagerImpl implements RshyJkManager {
 //        if (rshyVo.getNucleic_acid().getStatus() == 0) {
 //            rshyVo.setPassStatus(PassStatusEnum.NON_CONFORMANCE).setKind(PassStatusEnum.NON_CONFORMANCE.getDesc()).setWarning(PassStatusEnum.NON_CONFORMANCE.getDesc());
 //        } else
-        if (rshyVo.getTravel_card() != 0) {
-            //行程码到过中高风险地区
-            rshyVo.setPassStatus(PassStatusEnum.ABNORMAL_TRAVEL_CARD).setKind(PassStatusEnum.ABNORMAL_TRAVEL_CARD.getDesc());
-        } else if (PassStatusEnum.RED_CODE.getDesc().equalsIgnoreCase(jkmInfo.getColor_code_label())) {
+//        if (rshyVo.getTravel_card() != 0) {
+//            //行程码到过中高风险地区
+//            rshyVo.setPassStatus(PassStatusEnum.ABNORMAL_TRAVEL_CARD).setKind(PassStatusEnum.ABNORMAL_TRAVEL_CARD.getDesc());
+//        } else
+
+        if (jkmInfo != null && PassStatusEnum.RED_CODE.getDesc().equalsIgnoreCase(jkmInfo.getColor_code_label())) {
             //红码
             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())) {
+        } else if (jkmInfo != null && PassStatusEnum.YELLOW_CODE.getDesc().equalsIgnoreCase(jkmInfo.getColor_code_label())) {
             //黄码
             rshyVo.setPassStatus(PassStatusEnum.YELLOW_CODE).setKind("健康码" + PassStatusEnum.YELLOW_CODE.getDesc()).setWarning(PassStatusEnum.YELLOW_CODE.getDesc());
-        } else if (resultDTO.getPctgkryDTO().getPctztDTO() != null || StrUtil.containsAnyIgnoreCase(hcjg, RchljgEnum.CAPTURE.getDesc()) || StrUtil.containsAnyIgnoreCase(hcjg, RchljgEnum.INTERCEPT.getDesc())) {
-            //在逃 或者 人车核录接口返回 抓捕或者拦截
+        } else if (StrUtil.containsAnyIgnoreCase(hcjg, RchljgEnum.CAPTURE.getDesc()) || StrUtil.containsAnyIgnoreCase(hcjg, RchljgEnum.INTERCEPT.getDesc())) {
+            //人车核录接口返回抓捕或者拦截
+            if (StrUtil.isNotBlank(resultDTO.getPctrchlDTO().getXm())) {
+                rshyVo.setXm(resultDTO.getPctrchlDTO().getXm());
+                rshyVo.setMz(EnumUtil.likeValueOf(Nation.class, resultDTO.getPctrchlDTO().getMz()).getDesc());
+            }
+            rshyVo.setPassStatus(PassStatusEnum.NO_PASSING).setKind(kind(resultDTO)).setWarning(warning(resultDTO));
+        } else if (resultDTO.getPctgkryDTO().getPctztDTO() != null && resultDTO.getPctgkryDTO().getPctztDTO().getRyztmc().equalsIgnoreCase("在逃")) {
+            //在逃接口返回并且ryztmc字段为在逃
+            rshyVo.setXm(resultDTO.getPctgkryDTO().getPctztDTO().getXm());
             rshyVo.setPassStatus(PassStatusEnum.NO_PASSING).setKind(kind(resultDTO)).setWarning(warning(resultDTO));
         } else if (!ObjectUtils.allFieldIsNULL(resultDTO.getPctgkryDTO()) || StrUtil.containsAnyIgnoreCase(hcjg, RchljgEnum.IN_DOUBT.getDesc())) {
-            //七大类管控人员(在逃除外)和人车核录接口返回存疑人员
+            //七大类管控人员和人车核录接口返回存疑人员
             rshyVo.setPassStatus(PassStatusEnum.RIGHT_WAY).setKind(kind(resultDTO)).setWarning(warning(resultDTO));
         } else if (resultDTO.getPctzdrydkResultDTO() != null && resultDTO.getPctzdrydkResultDTO().getTotal() > 0) {
             //杭州市重点人员底库查询接口
             rshyVo.setPassStatus(PassStatusEnum.RIGHT_WAY).setKind(resultDTO.getPctzdrydkResultDTO().getData().get(0).getRyflList()[0]);
         } else if (quickRshyVo.get() != null && StrUtil.isNotEmpty(quickRshyVo.get().getSfzh())) {
             //依图接口
-            //rshyVo = quickRshyVo.get().setTimes(times(rshyParam.getSfzh()));
             rshyVo.copySomeValues(quickRshyVo.get());
         } else {
             //正常通过
@@ -207,9 +257,59 @@ public class RshyJkManagerImpl implements RshyJkManager {
         }
 
         //System.out.println(JSONObject.toJSONString(resultDTO));
+        if (resultDTO.getPctjkmInfoDTO() != null) {
+            saveIdentity(resultDTO.getPctjkmInfoDTO().getBar_code(), rshyVo);
+        }
         return new AsyncResult<>(rshyVo);
     }
 
+
+    /**
+     * 并行执行任务
+     *
+     * @param task 任务列表
+     * @return 用时,毫秒
+     * @throws InterruptedException
+     */
+    protected long startTaskAllInOnce(List<Runnable> task, long timeout) throws InterruptedException {
+        long startTime = System.currentTimeMillis();
+        System.out.println(startTime + " [" + Thread.currentThread() + "] All thread is ready, concurrent going...");
+        final CountDownLatch latch = new CountDownLatch(task.size());
+        ExecutorService executorService = new ExecutorServiceAdapter(poolTaskExecutor);
+        for (Runnable r : task) {
+            executorService.submit(() -> {
+                try {
+                    r.run();
+                } catch (Exception e) {
+                    log.error("异常信息:{}", e.getMessage());
+                } finally {
+                    latch.countDown();
+                }
+            });
+        }
+
+        latch.await(timeout, TimeUnit.MILLISECONDS);
+        long endTime = System.currentTimeMillis();
+        System.out.println(endTime + " [" + Thread.currentThread() + "] All thread is completed.");
+        return endTime - startTime;
+    }
+
+
+    @Async
+    protected void saveIdentity(String barCode, RshyVo rshyVo) {
+        log.info("保存身份信息到数据库, 身份证号码: {}", rshyVo.getSfzh());
+        Identity identity = new Identity();
+        if (StrUtil.isNotBlank(barCode)) {
+            identity.setBarCode(barCode);
+        }
+        identity.setIdNum(rshyVo.getSfzh());
+        identity.setName(rshyVo.getXm());
+        identity.setAddress(rshyVo.getAddress());
+        identity.setPhone(rshyVo.getPhone());
+        identity.setPhoto(rshyVo.getPhoto());
+        identityService.saveOK(identity);
+    }
+
     /**
      * 组装返回的核酸信息
      *
@@ -304,12 +404,11 @@ public class RshyJkManagerImpl implements RshyJkManager {
      */
     private String kind(ResultDTO resultDTO) {
         StringBuilder stringBuilder = new StringBuilder();
-        stringBuilder.append(resultDTO.getPctgkryDTO().getPctztDTO() != null ? resultDTO.getPctgkryDTO().getPctztDTO().getZtrylxmc() + "、" : StrUtil.EMPTY);
+        stringBuilder.append(resultDTO.getPctgkryDTO().getPctztDTO() != null ? resultDTO.getPctgkryDTO().getPctztDTO().getRyztmc() + "、" : StrUtil.EMPTY);
         stringBuilder.append(resultDTO.getPctgkryDTO().getPctdfkDTO() != null ? HyTypeEnum.pctdfk.getDesc() + "、" : StrUtil.EMPTY);
         stringBuilder.append(resultDTO.getPctgkryDTO().getPctjsryDTO() != null ? HyTypeEnum.pctjsry.getDesc() + "、" : StrUtil.EMPTY);
         stringBuilder.append(resultDTO.getPctgkryDTO().getPctxdryDTO() != null ? HyTypeEnum.pctxdry.getDesc() + "、" : StrUtil.EMPTY);
         stringBuilder.append(resultDTO.getPctgkryDTO().getPctqkryDTO() != null ? HyTypeEnum.pctqkry.getDesc() + "、" : StrUtil.EMPTY);
-        //stringBuilder.append(resultDTO.getPctjkmInfoDTO() != null ? HyTypeEnum.pctjkm.getDesc() : StrUtil.EMPTY);
         stringBuilder.append(resultDTO.getPctgkryDTO().getPctzfbaDTO() != null ? HyTypeEnum.pctzfba.getDesc() + "、" : StrUtil.EMPTY);
         stringBuilder.append(resultDTO.getPctgkryDTO().getPctzdryDTO() != null ? HyTypeEnum.pctzdry.getDesc() + "、" : StrUtil.EMPTY);
         stringBuilder.append(resultDTO.getPctrchlDTO() != null ? resultDTO.getPctrchlDTO().getRylb() : StrUtil.EMPTY);

+ 18 - 0
src/main/java/com/rshy/project/hy/mapper/IdentityMapper.java

@@ -0,0 +1,18 @@
+package com.rshy.project.hy.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.rshy.project.hy.model.entity.Identity;
+
+/**
+ * <p>
+ * Mapper 接口
+ * </p>
+ *
+ * @author fanqun
+ * @since 2022-06-11
+ */
+public interface IdentityMapper extends BaseMapper<Identity> {
+
+    String getIdNum(String barCode);
+
+}

+ 5 - 0
src/main/java/com/rshy/project/hy/model/constant/WebConstant.java

@@ -20,4 +20,9 @@ public class WebConstant {
      * 公安接口访问异常次数,达到这个次数后一定时间内不去调用
      */
     public static final Integer TIMEOUT_TIMES = 3;
+
+    /**
+     * 接口响应内容过长时,最长显示的字符长度
+     */
+    public static final Integer DISPLAY_MAX_LENGTH = 80;
 }

+ 48 - 0
src/main/java/com/rshy/project/hy/model/entity/Identity.java

@@ -0,0 +1,48 @@
+package com.rshy.project.hy.model.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 身份信息
+ * </p>
+ *
+ * @author fanqun
+ * @since 2022-06-11
+ */
+@Data
+@Accessors(chain = true)
+public class Identity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private String barCode;
+
+    @TableId(value = "id_num", type = IdType.INPUT)
+    private String idNum;
+
+    private String name;
+
+    private String address;
+
+    private String phone;
+
+    private String photo;
+
+
+    @Override
+    public String toString() {
+        return "Identity{" +
+                "barCode=" + barCode +
+                ", idNum=" + idNum +
+                ", name=" + name +
+                ", address=" + address +
+                ", phone=" + phone +
+                "}";
+    }
+}

+ 78 - 0
src/main/java/com/rshy/project/hy/model/enums/Nation.java

@@ -0,0 +1,78 @@
+package com.rshy.project.hy.model.enums;
+
+import cn.hutool.core.util.EnumUtil;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * 民族代码表
+ * <p>
+ * Created by fanqun on 2022/6/8.
+ */
+@Getter
+@AllArgsConstructor
+public enum Nation {
+    HAN("01", "汉族"),
+    MENGGU("02", "蒙古族"),
+    HUI("03", "回族"),
+    ZANG("04", "藏族"),
+    WEIWUER("05", "维吾尔"),
+    MIAO("06", "苗族"),
+    YI("07", "彝族"),
+    ZUANG("08", "壮族"),
+    BUYI("09", "布依族"),
+    CHAOXIAN("10", "朝鲜族"),
+    MAN("11", "满族"),
+    DONG("12", "侗族"),
+    YAO("13", "瑶族"),
+    BAI("14", "白族"),
+    TUJIA("15", "土家族"),
+    HANI("16", "哈尼族"),
+    HASAKE("17", "哈萨克族"),
+    DAI("18", "傣族"),
+    LI("19", "黎族"),
+    LILI("20", "傈傈族"),
+    WA("21", "佤族"),
+    SHE("22", "畲族"),
+    GAOSHAN("23", "高山族"),
+    LAHU("24", "拉祜族"),
+    SHUI("25", "水族"),
+    DONGXIANG("26", "东乡族"),
+    NAXI("27", "纳西族"),
+    JINGPO("28", "景颇族"),
+    KEERKEZI("29", "柯尔克孜族"),
+    TU("30", "土族"),
+    DAHANER("31", "达翰尔族"),
+    MULAO("32", "仫佬族"),
+    QIANG("33", "羌族"),
+    BULANG("34", "布朗族"),
+    SALA("35", "撒拉族"),
+    MAONAN("36", "毛南族"),
+    GELAO("37", "仡佬族"),
+    XIBO("38", "锡伯族"),
+    ACHANG("39", "阿昌族"),
+    PUMI("40", "普米族"),
+    TAJIKE("41", "塔吉克族"),
+    NU("42", "怒族"),
+    WUZIBIEKE("43", "乌孜别克族"),
+    ELUOSI("44", "俄罗斯族"),
+    EWENKE("45", "鄂温克族"),
+    BENGLONG("46", "崩龙族"),
+    BAOAN("47", "保安族"),
+    YUGU("48", "裕固族"),
+    JING("49", "京族"),
+    TATAER("50", "塔塔尔族"),
+    DULONG("51", "独龙族"),
+    ELUNCHUN("52", "鄂伦春族"),
+    HEZE("53", "赫哲族"),
+    MENGBA("54", "门巴族"),
+    LUOBA("55", "珞巴族"),
+    JINUO("56", "基诺族");
+
+    private String code;
+    private String desc;
+
+    public static void main(String[] args) {
+        System.out.println(EnumUtil.likeValueOf(Nation.class, "03").getDesc());
+    }
+}

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

@@ -645,7 +645,7 @@ public class ItfwServer {
         String cacheKey = idNumber + ':' + ItfwConstant.PCTYM_KEY;
         String cacheValue = stringRedisTemplate.opsForValue().get(cacheKey);
         if (StrUtil.isNotEmpty(cacheValue)) {
-            log.info("浙江省疫苗注射数据服务走缓存读取,响应内容: {}", cacheValue);
+            log.info("浙江省疫苗注射数据服务走缓存读取,响应内容: {}", StrUtil.brief(cacheValue, WebConstant.DISPLAY_MAX_LENGTH));
             return JSON.parseArray(cacheValue, PctymDataDTO.class);
         }
 
@@ -673,7 +673,7 @@ public class ItfwServer {
             return null;
         }
 
-        log.info("浙江省疫苗注射数据服务响应信息:{}", body);
+        log.info("浙江省疫苗注射数据服务响应信息:{}", StrUtil.brief(body, WebConstant.DISPLAY_MAX_LENGTH));
         deleteKeys(cacheStatusKey);
         //Set<String> keys = stringRedisTemplate.keys(cacheStatusKey + "*");
         //stringRedisTemplate.delete(keys);
@@ -719,7 +719,7 @@ public class ItfwServer {
             return null;
         }
 
-        log.info("核酸接口数据服务响应信息:{}", body);
+        log.info("核酸接口数据服务响应信息:{}", StrUtil.brief(body, WebConstant.DISPLAY_MAX_LENGTH));
 
         if (StrUtil.isEmpty(body) || !StrUtil.containsAnyIgnoreCase(body, "data")) {
             return null;
@@ -779,7 +779,7 @@ public class ItfwServer {
 
         log.info("证件照片接口服务响应信息:{}", body);
 
-        if (StrUtil.isEmpty(body)) {
+        if (StrUtil.isEmpty(body) || body.contains("errCode")) {
             return null;
         }
         PctzjzpResultDTO pctzjzpResultDTO = JSON.parseObject(body, PctzjzpResultDTO.class);
@@ -792,7 +792,7 @@ public class ItfwServer {
 
         byte[] bytes = HttpRequest.get(pctzjzpResultDTO.getZjzUrl()).timeout(200).execute().bodyBytes();
         pctzjzpResultDTO.setPhoto(Base64.encode(bytes));
-        stringRedisTemplate.opsForValue().set(cacheKey, JSON.toJSONString(pctzjzpResultDTO), DateUtil.endOfDay(DateUtil.date()).getTime() - DateUtil.date().getTime(), TimeUnit.MILLISECONDS);
+        stringRedisTemplate.opsForValue().set(cacheKey, JSON.toJSONString(pctzjzpResultDTO));//DateUtil.endOfDay(DateUtil.date()).getTime() - DateUtil.date().getTime(), TimeUnit.MILLISECONDS);
         return pctzjzpResultDTO;
     }
 
@@ -843,7 +843,7 @@ public class ItfwServer {
 
         log.info("杭州市重点人员底库数据查询接口服务响应信息:{}", body);
         deleteKeys(cacheStatusKey);
-        if (StrUtil.isEmpty(body)) {
+        if (StrUtil.isEmpty(body) || body.contains("errCode")) {
             return null;
         }
         PctzdrydkResultDTO pctzdrydkResultDTO = JSON.parseObject(body, PctzdrydkResultDTO.class);
@@ -872,7 +872,7 @@ public class ItfwServer {
         String cacheKey = idNumber + ':' + ItfwConstant.PCTXCM_KEY;
         String cacheValue = stringRedisTemplate.opsForValue().get(cacheKey);
         if (StrUtil.isNotEmpty(cacheValue)) {
-            log.info("查询扫行程码记录接口服务走缓存读取,响应内容: {}", cacheValue);
+            log.info("查询扫行程码记录接口服务走缓存读取,响应内容: {}", StrUtil.brief(cacheValue, WebConstant.DISPLAY_MAX_LENGTH));
             return JSON.parseObject(cacheValue, PctxcmResultDTO.class);
         }
 
@@ -900,7 +900,7 @@ public class ItfwServer {
             return null;
         }
 
-        log.info("查询扫行程码记录接口数据服务响应信息:{}", body);
+        log.info("查询扫行程码记录接口数据服务响应信息:{}", StrUtil.brief(body, WebConstant.DISPLAY_MAX_LENGTH));
         deleteKeys(cacheStatusKey);
         if (StrUtil.isEmpty(body) || !StrUtil.containsAnyIgnoreCase(body, "data")) {
             return null;

+ 0 - 1
src/main/java/com/rshy/project/hy/server/dto/PctxcmResultDTO.java

@@ -1,6 +1,5 @@
 package com.rshy.project.hy.server.dto;
 
-import com.alibaba.fastjson.JSON;
 import lombok.Data;
 import lombok.experimental.Accessors;
 

+ 4 - 0
src/main/java/com/rshy/project/hy/server/dto/PctztDTO.java

@@ -9,7 +9,11 @@ import lombok.Data;
  */
 @Data
 public class PctztDTO {
+    private String xm;
+
     private String ztrylxmc;
 
     private String jyaq;
+
+    private String ryztmc;
 }

+ 5 - 0
src/main/java/com/rshy/project/hy/server/param/RshyParam.java

@@ -1,6 +1,8 @@
 package com.rshy.project.hy.server.param;
 
+import com.alibaba.fastjson.annotation.JSONField;
 import com.rshy.project.hy.model.constant.WebConstant;
+import com.rshy.project.hy.model.entity.Identity;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -37,6 +39,9 @@ public class RshyParam {
     @ApiModelProperty("锁屏状态")
     private Integer screenLocked;
 
+    @JSONField(serialize = false, deserialize = false)
+    private Identity identity;
+
     @Override
     public String toString() {
         return "RshyParam{" +

+ 23 - 0
src/main/java/com/rshy/project/hy/service/IdentityService.java

@@ -0,0 +1,23 @@
+package com.rshy.project.hy.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.rshy.project.hy.model.entity.Identity;
+
+/**
+ * <p>
+ * 服务类
+ * </p>
+ *
+ * @author fanqun
+ * @since 2022-06-11
+ */
+public interface IdentityService extends IService<Identity> {
+
+
+    Identity getIdentity(String idNum);
+
+    String getIdNum(String barCode);
+
+    Identity saveOK(Identity identity);
+
+}

+ 57 - 0
src/main/java/com/rshy/project/hy/service/impl/IdentityServiceImpl.java

@@ -0,0 +1,57 @@
+package com.rshy.project.hy.service.impl;
+
+
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.rshy.project.hy.mapper.IdentityMapper;
+import com.rshy.project.hy.model.entity.Identity;
+import com.rshy.project.hy.service.IdentityService;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+/**
+ * <p>
+ * 服务实现类
+ * </p>
+ *
+ * @author fanqun
+ * @since 2022-06-11
+ */
+@Service
+@EnableCaching
+public class IdentityServiceImpl extends ServiceImpl<IdentityMapper, Identity> implements IdentityService {
+
+    @Resource
+    private IdentityMapper identityMapper;
+
+    @Override
+    @Cacheable(value = "identity", key = "#p0", unless = "#result == null")
+    public Identity getIdentity(String idNum) {
+        LambdaQueryWrapper<Identity> wrapper = new LambdaQueryWrapper<>();
+        if (StrUtil.isNotBlank(idNum)) {
+            wrapper.eq(Identity::getIdNum, idNum);
+        } else {
+            return null;
+        }
+        return identityMapper.selectOne(wrapper);
+    }
+
+    @Override
+    @Cacheable(value = "identity", key = "#p0", unless = "#result == null")
+    public String getIdNum(String barCode) {
+        return StrUtil.isBlank(barCode) ? null : identityMapper.getIdNum(barCode);
+    }
+
+    @Override
+    @CachePut(value = "identity", key = "#p0.idNum", unless = "#result == null")
+    public Identity saveOK(Identity identity) {
+        if (super.saveOrUpdate(identity))
+            return identity;
+        return null;
+    }
+}

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

@@ -10,10 +10,12 @@ import com.rshy.project.hy.baseRe.BaseException;
 import com.rshy.project.hy.baseRe.ResultCode;
 import com.rshy.project.hy.baseRe.Ret;
 import com.rshy.project.hy.manager.RshyJkManager;
+import com.rshy.project.hy.model.entity.Identity;
 import com.rshy.project.hy.model.enums.PassStatusEnum;
 import com.rshy.project.hy.server.param.RshyParam;
 import com.rshy.project.hy.server.param.RshyQuickParam;
 import com.rshy.project.hy.server.vo.RshyVo;
+import com.rshy.project.hy.service.IdentityService;
 import com.rshy.project.hy.util.PatternUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -43,10 +45,12 @@ import java.util.concurrent.TimeoutException;
 public class RshyController {
     @Resource
     private RshyJkManager rshyJkManager;
+    @Resource
+    private IdentityService identityService;
 
     @GetMapping(value = "/version")
     public String version() {
-        return "1.2.4.220524";
+        return "1.2.4.220613";
     }
 
     @ApiOperation("普通核验模式")
@@ -70,11 +74,24 @@ public class RshyController {
         DateTime time1 = DateTime.now();
 
         log.info("普通核验接口请求参数:{}", JSON.toJSONString(rshyParam));
+
         RshyVo rshyVo = new RshyVo().setPassStatus(PassStatusEnum.NORMAL_TRAFFIC);
+        String sfz = rshyParam.getSfzh();
+        if (StrUtil.isNotBlank(rshyParam.getBarCode())) {
+            sfz = identityService.getIdNum(rshyParam.getBarCode());
+        }
+        if (StrUtil.isNotBlank(sfz)) {
+            Identity identity = identityService.getIdentity(sfz);
+            if (identity != null) {
+                rshyVo.setXm(identity.getName()).setSfzh(identity.getIdNum()).setPhone(identity.getPhone());
+                rshyParam.setSfzh(identity.getIdNum());
+                rshyParam.setIdentity(identity);
+            }
+        }
         try {
             //RshyVo rshyVo = rshyJkManager.getRshyInfo(rshyParam);
             Future<RshyVo> future = rshyJkManager.getRshyInfo(rshyParam);
-            rshyVo = future.get(rshyParam.getTimeout() * 1000, TimeUnit.MILLISECONDS);
+            rshyVo = future.get(rshyParam.getTimeout() * 1000 - 100, TimeUnit.MILLISECONDS);
         } catch (InterruptedException | ExecutionException e) {
             log.error("普通核验接口异常: {}", e.getMessage());
             //e.printStackTrace();
@@ -84,7 +101,6 @@ public class RshyController {
             throw new BaseException();
         }
         log.info("普通核验响应内容:{}", JSON.toJSONString(rshyVo));
-
         System.out.println("普通核验接口用时: " + DateUtil.between(time1, DateTime.now(), DateUnit.MS) + "毫秒\n");
         return Ret.success(rshyVo);
     }

+ 1 - 1
src/main/resources/application-local.yml

@@ -1,6 +1,6 @@
 spring:
   datasource:
-    url: jdbc:mysql://127.0.0.1:3306/rshy?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&pinGlobalTxToPhysicalConnection=true&serverTimezone=UTC
+    url: jdbc:mysql://127.0.0.1:3306/metro_hy?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&pinGlobalTxToPhysicalConnection=true&serverTimezone=UTC
     username: root
     password: root1234
     driver-class-name: com.mysql.cj.jdbc.Driver

+ 18 - 0
src/main/resources/mapper/IdentityMapper.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.rshy.project.hy.mapper.IdentityMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.rshy.project.hy.model.entity.Identity">
+        <id column="id_num" property="idNum" />
+        <result column="bar_code" property="barCode" />
+        <result column="name" property="name" />
+        <result column="address" property="address" />
+        <result column="phone" property="phone" />
+        <result column="photo" property="photo" />
+    </resultMap>
+
+    <select id="getIdNum" resultType="string">
+        SELECT id_num FROM identity WHERE bar_code = #{barCode}
+    </select>
+</mapper>