Browse Source

当姓名为1个字时, 不调用上游,返回身份证号与姓名不匹配并增加500-700ms延时

15810770710@163.com 3 years ago
parent
commit
e85791fc50

+ 56 - 5
src/main/java/info/aspirecn/rdc/iov/sjjh/servicenode/supplier/yh/service/impl/FaceCheckServiceImpl.java

@@ -14,6 +14,7 @@ import info.aspirecn.iov.sjjh.service.sms.action.SmsActionInterface;
 import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
 import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.constant.SjjhConstant;
 import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.service.FaceCheckService;
+import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.task.AsyncDelayTask;
 import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.utils.*;
 import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.vo.CommonRequestObject;
 import info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.vo.FaceCheckResObject;
@@ -36,7 +37,10 @@ import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Timer;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 /**
  * @author jianggang
@@ -77,6 +81,11 @@ public class FaceCheckServiceImpl implements FaceCheckService {
     private ObjectMapper objectMapper;
     DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
 
+    @Autowired
+    AsyncDelayTask asyncDelayTask;
+
+    @Value("${thread.delayedTime}")
+    private Long delayedTime;
     @Override
     public ChannelTypeHandleResponseObject callFaceCheck(HttpServletRequest request,
                                                          String channelId,
@@ -383,14 +392,21 @@ public class FaceCheckServiceImpl implements FaceCheckService {
             JSONObject paramObject = JSON.parseObject(customBody);
             paramObject.put("photo", "base64");
             log.info("supplier10000003.faceCheckWZDecode---customBody={},outTime={}", paramObject.toJSONString(), outTime);
+
+            if (StringUtils.isNotBlank((String)map.get("name")) && ((String) map.get("name")).length() == 1) {
+                // 姓名1个字, 增加500-700ms延时,返回身份证号与姓名不匹配
+                delay();
+                setErrorNameResponse(res, ifJkCode);
+                reduceVisitCount(hashKey,key);
+                map = null;
+                request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, "-1");
+                log.info("supplier10000003.faceCheckWZDecode---姓名格式错误");
+                return res;
+            }
+
             request.setAttribute(Constant.CHANNEL_LOG_QUERY,
                     Base64.encodeBase64String(paramObject.toJSONString().getBytes("utf-8")));
 
-            OkHttpClient okHttpClient = client.newBuilder()
-                    .connectTimeout(outTime, TimeUnit.MILLISECONDS)
-                    .writeTimeout(outTime, TimeUnit.MILLISECONDS)
-                    .readTimeout(outTime, TimeUnit.MILLISECONDS)
-                    .build();
             if(StringUtils.isBlank((String)map.get("name"))
                     ||StringUtils.isBlank((String)map.get("idCode"))
                     ||StringUtils.isBlank((String)map.get("photo"))){
@@ -453,6 +469,11 @@ public class FaceCheckServiceImpl implements FaceCheckService {
                     .url(yhProperties.getFaceCheckUri())
                     .post(requestBody)
                     .build();
+            OkHttpClient okHttpClient = client.newBuilder()
+                    .connectTimeout(outTime, TimeUnit.MILLISECONDS)
+                    .writeTimeout(outTime, TimeUnit.MILLISECONDS)
+                    .readTimeout(outTime, TimeUnit.MILLISECONDS)
+                    .build();
             Response response = okHttpClient.newCall(okRequest).execute();
             String responseJson = response.body().string();
 
@@ -588,5 +609,35 @@ public class FaceCheckServiceImpl implements FaceCheckService {
         log.info("test..................,notify:{},traceId:{}",notifySms);
         timer.schedule(new NotifyThread(notifySms),1*60*1000);
     }
+    private void delay() {
+        Long startTime = System.currentTimeMillis();
+        try {
+            Future<String> delayTask = asyncDelayTask.doDelay();
+            delayTask.get(delayedTime*2, TimeUnit.MILLISECONDS);
+        } catch (InterruptedException ie) {
+            log.info("InterruptedException, 强制结束子线程,子线程耗时:{}, {}", System.currentTimeMillis() - startTime, ie);
+            ErrorUtils.captureException(ie);
+        } catch (ExecutionException ee) {
+            log.info("ExecutionException, 强制结束子线程,子线程耗时:{}, {}", System.currentTimeMillis() - startTime, ee);
+            ErrorUtils.captureException(ee);
+        } catch (TimeoutException te) {
+            log.info("TimeoutException, 强制结束子线程,子线程耗时:{}, {}", System.currentTimeMillis() - startTime, te);
+            ErrorUtils.captureException(te);
+        }
+    }
+
+    private void setErrorNameResponse(ChannelTypeHandleResponseObject res, String ifJkCode) {
+        if (ifJkCode.equals(Constant.CUSTOMER_RETURN_ZW)) {
+            res.setResultCode(Constant.ZW_RETURN_CODE_71);
+        } else {
+            res.setResultCode(Constant.JK_RETURN_CODE_1146);
+        }
+        res.setIsCharge(Constant.IS_CHARGE);
+        res.setResultDesc(Constant.RETURN_MESSAGE_71);
 
+        JSONObject resultBody = new JSONObject();
+        resultBody.put("verificationScore", "");
+        resultBody.put("message", Constant.RETURN_MESSAGE_71);
+        res.setResultBody(JSON.toJSONString(resultBody));
+    }
 }

+ 24 - 0
src/main/java/info/aspirecn/rdc/iov/sjjh/servicenode/supplier/yh/task/AsyncDelayTask.java

@@ -0,0 +1,24 @@
+package info.aspirecn.rdc.iov.sjjh.servicenode.supplier.yh.task;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.AsyncResult;
+import org.springframework.stereotype.Component;
+
+import java.util.concurrent.Future;
+
+/**
+ * @author xusonglin
+ * @version V1.0
+ **/
+@Component
+public class AsyncDelayTask {
+    @Value("${thread.delayedTime}")
+    private Long delayedTime;
+    @Async
+    public Future<String> doDelay() throws InterruptedException {
+        int random=(int)(Math.random()*200);
+        Thread.sleep(delayedTime + random);
+        return new AsyncResult<>("延时任务完成");
+    }
+}

+ 7 - 1
src/main/resources/config/application-test.yml

@@ -46,7 +46,7 @@ HOSTNAME: 127.0.0.1
 
 #logging
 logging:
-  path: /apps/var/jakarta/logs
+  path: /Users/jkxy/root-logs/apps/var/jakarta/logs
   level:
     root: INFO
     red:
@@ -132,3 +132,9 @@ yh:
 wz:
   decryptKey: JK568FG2823
   aesDecryptKey: C1AA8eh0116128nn
+thread:
+  pool:
+    coreSize: 20
+    maximumPoolSize: 40
+    queueSize: 100
+  delayedTime: 500