Browse Source

add:普通模式调用依图接口人脸布控

lileilei 2 years ago
parent
commit
2fc29f5f43

+ 34 - 36
src/main/java/com/rshy/project/hy/manager/impl/RshyJkManagerImpl.java

@@ -34,6 +34,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 /**
@@ -84,31 +85,26 @@ public class RshyJkManagerImpl implements RshyJkManager {
         }
 
         rshyParam.setTimeout((int) (rshyParam.getTimeout() - DateUtil.between(beginDate, DateTime.now(), DateUnit.MS)));
-        List<Runnable> taskList = null;
-        if(barCodes == null || PassStatusEnum.GREEN_CODE.getDesc().equals(barCodes.getCOLOR_CODE_LABEL())) {
-            taskList = new ArrayList<Runnable>() {
-                {
-                    add(() -> resultDTO.setPctdfkDTO(itfwServer.getPctdfk(rshyParam.getSfzh(), "", rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPctjsryDTO(itfwServer.getPctjsry(rshyParam.getSfzh(), rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPctztDTO(itfwServer.getPctzt(rshyParam.getSfzh(), rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPctzfbaDTO(itfwServer.getPctzfba(rshyParam.getSfzh(), rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPctqkryDTO(itfwServer.getPctqkry(rshyParam.getSfzh(), rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPctxdryDTO(itfwServer.getPctxdry(rshyParam.getSfzh(), "", rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPctzdryDTO(itfwServer.getPctzdry(rshyParam.getSfzh(), rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPctrchlDTO(itfwServer.getPctrchl(rshyParam.getSfzh(), rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPctymDataDTOS(itfwServer.getPctym(rshyParam.getSfzh(), rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPcthsResultDTO(itfwServer.getPcths(rshyParam.getSfzh(), rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPersonIdentifyDTO(viidServer.personIdentify(rshyParam.getPhoto(), rshyParam.getTimeout())));
-                }
-            };
-        }else{
-            taskList = new ArrayList<Runnable>() {
-                {
-                    add(() -> resultDTO.setPctymDataDTOS(itfwServer.getPctym(rshyParam.getSfzh(), rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPcthsResultDTO(itfwServer.getPcths(rshyParam.getSfzh(), rshyParam.getTimeout())));
-                    add(() -> resultDTO.setPersonIdentifyDTO(viidServer.personIdentify(rshyParam.getPhoto(), rshyParam.getTimeout())));
-                }
-            };
+
+        AtomicReference<RshyVo> quickRshyVo = new AtomicReference<>(new RshyVo());
+        List<Runnable> taskList = new ArrayList<Runnable>() {
+            {
+                add(() -> resultDTO.setPctymDataDTOS(itfwServer.getPctym(rshyParam.getSfzh(), rshyParam.getTimeout())));
+                add(() -> resultDTO.setPcthsResultDTO(itfwServer.getPcths(rshyParam.getSfzh(), rshyParam.getTimeout())));
+                add(() -> resultDTO.setPersonIdentifyDTO(viidServer.personIdentify(rshyParam.getPhoto(), rshyParam.getTimeout())));
+                add(() -> quickRshyVo.set(getQuickRyhyInfo(new RshyQuickParam().setPhoto(rshyParam.getPhoto()).setTimeout(rshyParam.getTimeout()))));
+            }
+        };
+
+        if (barCodes == null || PassStatusEnum.GREEN_CODE.getDesc().equals(barCodes.getCOLOR_CODE_LABEL())) {
+            taskList.add(() -> resultDTO.setPctdfkDTO(itfwServer.getPctdfk(rshyParam.getSfzh(), "", rshyParam.getTimeout())));
+            taskList.add(() -> resultDTO.setPctjsryDTO(itfwServer.getPctjsry(rshyParam.getSfzh(), rshyParam.getTimeout())));
+            taskList.add(() -> resultDTO.setPctztDTO(itfwServer.getPctzt(rshyParam.getSfzh(), rshyParam.getTimeout())));
+            taskList.add(() -> resultDTO.setPctzfbaDTO(itfwServer.getPctzfba(rshyParam.getSfzh(), rshyParam.getTimeout())));
+            taskList.add(() -> resultDTO.setPctqkryDTO(itfwServer.getPctqkry(rshyParam.getSfzh(), rshyParam.getTimeout())));
+            taskList.add(() -> resultDTO.setPctxdryDTO(itfwServer.getPctxdry(rshyParam.getSfzh(), "", rshyParam.getTimeout())));
+            taskList.add(() -> resultDTO.setPctzdryDTO(itfwServer.getPctzdry(rshyParam.getSfzh(), rshyParam.getTimeout())));
+            taskList.add(() -> resultDTO.setPctrchlDTO(itfwServer.getPctrchl(rshyParam.getSfzh(), rshyParam.getTimeout())));
         }
 
         //异步流并发处理
@@ -135,7 +131,7 @@ public class RshyJkManagerImpl implements RshyJkManager {
             hcjg = pctrchlDTO.getHcjg();
         }
 
-        if(resultDTO.getPersonIdentifyDTO() != null && !rshyParam.getSfzh().equals(resultDTO.getPersonIdentifyDTO().getIdNumber())){
+        if (resultDTO.getPersonIdentifyDTO() != null && !rshyParam.getSfzh().equals(resultDTO.getPersonIdentifyDTO().getIdNumber())) {
             rshyVo.setPass(PassStatusEnum.NO_PASSING.getCode()).setTimes(times(rshyParam.getSfzh())).setTts(PassStatusEnum.NO_PASSING.getTts()).setDisplayMsg(PassStatusEnum.NO_PASSING.getDesc()).setWarning(PassStatusEnum.NO_PASSING.getDesc()).setKind("人证不一致");
         } else if (barCodes != null && PassStatusEnum.RED_CODE.getDesc().equalsIgnoreCase(barCodes.getCOLOR_CODE_LABEL())) {
             rshyVo.setPass(PassStatusEnum.RED_CODE.getCode()).setTimes(times(rshyParam.getSfzh())).setTts(PassStatusEnum.RED_CODE.getTts()).setDisplayMsg(PassStatusEnum.RED_CODE.getDesc()).setWarning(PassStatusEnum.RED_CODE.getDesc()).setKind("健康码" + PassStatusEnum.RED_CODE.getDesc());
@@ -145,6 +141,9 @@ public class RshyJkManagerImpl implements RshyJkManager {
             rshyVo.setPass(PassStatusEnum.NO_PASSING.getCode()).setTts(PassStatusEnum.NO_PASSING.getTts()).setDisplayMsg(PassStatusEnum.NO_PASSING.getDesc()).setWarning(new StringBuilder().append("在逃人员:").append(resultDTO.getPctztDTO().getJyaq()).toString()).setKind(resultDTO.getPctztDTO().getZtrylxmc());
         } else if (ObjectUtils.allFieldIsNULL(resultDTO) || StrUtil.containsAnyIgnoreCase(hcjg, "通过")) {
             rshyVo.setPass(PassStatusEnum.NORMAL_TRAFFIC.getCode()).setDisplayMsg(PassStatusEnum.NORMAL_TRAFFIC.getDesc()).setTts(PassStatusEnum.NORMAL_TRAFFIC.getTts());
+        } else if (quickRshyVo.get() != null && StrUtil.isNotEmpty(quickRshyVo.get().getSfzh())) {
+            //快速通行
+            rshyVo = quickRshyVo.get();
         } else {
             rshyVo.setPass(PassStatusEnum.RIGHT_WAY.getCode()).setKind(kind(resultDTO)).setWarning(warning(resultDTO)).setDisplayMsg(PassStatusEnum.RIGHT_WAY.getDesc()).setTts(PassStatusEnum.RIGHT_WAY.getTts());
         }
@@ -157,18 +156,18 @@ public class RshyJkManagerImpl implements RshyJkManager {
         return rshyVo;
     }
 
-    private NucleicAcidDTO nucleicAcid(PcthsResultDTO pcthsResultDTO){
+    private NucleicAcidDTO nucleicAcid(PcthsResultDTO pcthsResultDTO) {
         NucleicAcidDTO nucleicAcidDTO = new NucleicAcidDTO();
-        if(pcthsResultDTO == null){
+        if (pcthsResultDTO == null) {
             nucleicAcidDTO.setStatus(NucleicAcidEnum.NOT_CONFORM.getCode()).setResults("48h内未采集");
             return nucleicAcidDTO;
         }
 
-        if(pcthsResultDTO.getSHE_RQSJ() != null){
+        if (pcthsResultDTO.getSHE_RQSJ() != null) {
             DateTime parse = DateUtil.parse(String.valueOf(Integer.valueOf(pcthsResultDTO.getSHE_RQSJ()) * 1000));
             long betweenMs = DateUtil.betweenMs(parse, DateUtil.date());
             //48h防疫规则
-            if(betweenMs > 48 * 60 * 60 * 1000){
+            if (betweenMs > 48 * 60 * 60 * 1000) {
                 nucleicAcidDTO.setStatus(NucleicAcidEnum.NOT_CONFORM.getCode()).setResults(new StringBuilder("48小时之外已出结果,结果").append(pcthsResultDTO.getJGU_MC()).toString()).setTime(DateUtil.format(parse, "MM-dd HH:mm"));
                 return nucleicAcidDTO;
             }
@@ -180,7 +179,7 @@ public class RshyJkManagerImpl implements RshyJkManager {
         DateTime parse = DateUtil.parse(String.valueOf(Integer.valueOf(pcthsResultDTO.getCJSJ()) * 1000));
         long betweenMs = DateUtil.betweenMs(parse, DateUtil.date());
         //48h防疫规则
-        if(betweenMs > 48 * 60 * 60 * 1000){
+        if (betweenMs > 48 * 60 * 60 * 1000) {
             nucleicAcidDTO.setStatus(NucleicAcidEnum.NOT_CONFORM.getCode()).setResults("48小时之外未出结果");
             return nucleicAcidDTO;
         }
@@ -191,14 +190,13 @@ public class RshyJkManagerImpl implements RshyJkManager {
 
     @Override
     public RshyVo getQuickRyhyInfo(RshyQuickParam rshyQuickParam) {
+        // timeout 转成毫秒
+        rshyQuickParam.setTimeout(rshyQuickParam.getTimeout() * 1000);
         RshyVo rshyVo = new RshyVo();
         RetrievaResultVO retrievaResultVO = faceRetrievaServer.retrieval(rshyQuickParam.getPhoto(), rshyQuickParam.getTimeout());
         List<RetrievalRepositoryVO> voList = Convert.toList(RetrievalRepositoryVO.class, retrievaResultVO.getResults());
         if (CollectionUtil.isEmpty(voList)) {
-            rshyVo.setPass(PassStatusEnum.NORMAL_TRAFFIC.getCode());
-            rshyVo.setDisplayMsg(PassStatusEnum.NORMAL_TRAFFIC.getDesc());
-            rshyVo.setTts(PassStatusEnum.NORMAL_TRAFFIC.getDesc());
-            return rshyVo;
+            return rshyVo.setPass(PassStatusEnum.NORMAL_TRAFFIC.getCode()).setDisplayMsg(PassStatusEnum.NORMAL_TRAFFIC.getDesc()).setTts(PassStatusEnum.NORMAL_TRAFFIC.getTts());
         }
 
         //查询人像库信息
@@ -208,7 +206,7 @@ public class RshyJkManagerImpl implements RshyJkManager {
         RetrievalRepositoryVO repositoryVO = voList.stream().findFirst().get();
         rshyVo.setPass(RepositoryEnum.COUNTRY_LARGE.getId().equals(repositoryVO.getRepository_id()) ? PassStatusEnum.NO_PASSING.getCode() : PassStatusEnum.RIGHT_WAY.getCode()).setKind(StrUtil.EMPTY)
                 .setWarning(stringMap.get(repositoryVO.getRepository_id())).setDisplayMsg(RepositoryEnum.COUNTRY_LARGE.getId().equals(repositoryVO.getRepository_id()) ? PassStatusEnum.NO_PASSING.getDesc() : PassStatusEnum.RIGHT_WAY.getDesc())
-                .setTts(RepositoryEnum.COUNTRY_LARGE.getId().equals(repositoryVO.getRepository_id()) ? PassStatusEnum.NO_PASSING.getDesc() : PassStatusEnum.RIGHT_WAY.getDesc()).setHealthCode(StrUtil.EMPTY).setSfzh(repositoryVO.getPersonId())
+                .setTts(RepositoryEnum.COUNTRY_LARGE.getId().equals(repositoryVO.getRepository_id()) ? PassStatusEnum.NO_PASSING.getTts() : PassStatusEnum.RIGHT_WAY.getTts()).setHealthCode(StrUtil.EMPTY).setSfzh(repositoryVO.getPersonId())
                 .setXm(repositoryVO.getName()).setXb(SexEnum.codeOf(repositoryVO.getGender()).getDesc()).setMz(StrUtil.EMPTY).setPhone(StrUtil.EMPTY).setAddress(StrUtil.EMPTY).setPhoto(rshyQuickParam.getPhoto());
         log.info("快速核验响应内容:{}", JSON.toJSONString(rshyVo));
         return rshyVo;

+ 9 - 9
src/main/java/com/rshy/project/hy/server/FaceRetrievaServer.java

@@ -81,14 +81,14 @@ public class FaceRetrievaServer {
      * 登录接口
      *
      * @param retrievaLoginParam
-     * @param timeout 秒
+     * @param timeout 
      * @return
      */
     public RetrievaResultVO login(RetrievaLoginParam retrievaLoginParam, Integer timeout) {
         String body = timedCache.get(HEADERS_KEY, false);
 
         if (StrUtil.isEmpty(body)) {
-            body = HttpUtil.post(loginUrl, JSON.toJSONString(retrievaLoginParam), timeout * 1000);
+            body = HttpUtil.post(loginUrl, JSON.toJSONString(retrievaLoginParam), timeout);
             timedCache.put(HEADERS_KEY, body);
         }
 
@@ -120,7 +120,7 @@ public class FaceRetrievaServer {
      * @param sessionId 会话标识
      */
     public RetrievaResultVO repository(String sessionId) {
-        return this.repository(sessionId, WebConstant.TIMEOUT);
+        return this.repository(sessionId, WebConstant.TIMEOUT * 1000);
     }
 
     /**
@@ -131,7 +131,7 @@ public class FaceRetrievaServer {
     public RetrievaResultVO repository(String sessionId, Integer timeout) {
         String body = timedCache.get(REPOSITORY_KEY, false);
         if (StrUtil.isEmpty(body)) {
-            body = HttpRequest.get(repositoryUrl).header(HEADERS_KEY, sessionId).timeout(timeout * 1000).execute().body();
+            body = HttpRequest.get(repositoryUrl).header(HEADERS_KEY, sessionId).timeout(timeout).execute().body();
             //缓存一天失效
             timedCache.put(REPOSITORY_KEY, body, 24 * 60 * 60 * 1000);
         }
@@ -146,7 +146,7 @@ public class FaceRetrievaServer {
      *
      */
     public RetrievaResultVO repository() {
-        return this.repository(WebConstant.TIMEOUT);
+        return this.repository(WebConstant.TIMEOUT * 1000);
     }
 
     /**
@@ -160,7 +160,7 @@ public class FaceRetrievaServer {
             throw new BaseException(login.getMessage());
         }
 
-        return this.repository(login.getSession_id());
+        return this.repository(login.getSession_id(), timeout);
     }
 
     /**
@@ -169,7 +169,7 @@ public class FaceRetrievaServer {
      * @param photo base64图片
      */
     public RetrievaResultVO retrieval(String photo) {
-        return this.retrieval(photo, WebConstant.TIMEOUT);
+        return this.retrieval(photo, WebConstant.TIMEOUT * 1000);
     }
 
 
@@ -177,7 +177,7 @@ public class FaceRetrievaServer {
      * 人脸库检索
      *
      * @param photo base64图片
-     * @param timeout 秒
+     * @param timeout 
      */
     public RetrievaResultVO retrieval(String photo, Integer timeout) {
         RetrievaResultVO login = this.login(timeout);
@@ -199,7 +199,7 @@ public class FaceRetrievaServer {
                 .setRetrieval(new RetrievalDTO().setPicture_image_content_base64(photo).setFast(true).setThreshold(threshold)
                         .setRepository_ids(voList.stream().map(RepositoryVO::getId).collect(Collectors.toList())));
         log.info("依图调用参数: {}", JSON.toJSONString(param));
-        String body = HttpRequest.post(retrievalUrl).header(HEADERS_KEY, login.getSession_id()).body(JSON.toJSONString(param)).timeout(timeout * 1000).execute().body();
+        String body = HttpRequest.post(retrievalUrl).header(HEADERS_KEY, login.getSession_id()).body(JSON.toJSONString(param)).timeout(timeout).execute().body();
         log.info("依图返回结果: {}", body);
         return JSON.parseObject(body, RetrievaResultVO.class);
     }

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

@@ -1,5 +1,6 @@
 package com.rshy.project.hy.server.dto;
 
+import com.rshy.project.hy.server.vo.RshyVo;
 import lombok.Data;
 
 import java.util.List;

+ 2 - 0
src/main/java/com/rshy/project/hy/server/param/RshyQuickParam.java

@@ -4,6 +4,7 @@ import com.rshy.project.hy.model.constant.WebConstant;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import lombok.experimental.Accessors;
 
 /**
  * @ProjectName: rshy
@@ -15,6 +16,7 @@ import lombok.Data;
  * @Version: 1.0
  */
 @Data
+@Accessors(chain = true)
 @ApiModel("人脸快速核验请求参数")
 public class RshyQuickParam {
     @ApiModelProperty("人员照片")