浏览代码

修改人员核验接口超时时间
上游超时-返回正常结果

15810770710@163.com 3 年之前
父节点
当前提交
95945c3b87

+ 6 - 2
src/main/java/com/jkcredit/illegal/info/constant/CommonConstant.java

@@ -11,8 +11,6 @@ public class CommonConstant {
     public static String GET_RESULT_SUCCESS = "1";
     // 不良-v2版-上游回调响应码-失败
     public static String GET_RESULT_FAILED = "2";
-    // timeOut
-    public static long TIME_OUT = 5000;
     // contentType-application/json
     public static String MEDIA_TYPE = "application/json;charset=UTF-8";
     // 不良-人员核验-超时redisKey
@@ -25,4 +23,10 @@ public class CommonConstant {
     public static String VEHICLE_ILLEGAL_INFO_QUERY_FAILED = "vehicleIllegalInfoQueryFailed";
 
     public static final String APPLICATION_JSON_UTF8_VALUE = "application/json;charset=UTF-8";
+    // 人员核验超时时间 timeOut
+    public static int PERSON_TIME_OUT = 500;
+    // 车辆核验超时时间 timeOut
+    public static int VEHICLE_TIME_OUT = 5000;
+    // dingding超时时间 timeOut
+    public static int DING_TIME_OUT = 5000;
 }

+ 9 - 0
src/main/java/com/jkcredit/illegal/info/model/IllegalInfoResult.java

@@ -2,6 +2,7 @@ package com.jkcredit.illegal.info.model;
 
 import com.alibaba.fastjson.annotation.JSONField;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
 
@@ -12,6 +13,7 @@ import java.io.Serializable;
  * @version: V1.0
  **/
 @Data
+@NoArgsConstructor
 public class IllegalInfoResult implements Serializable {
 
     private static final long serialVersionUID = -6237336433468586318L;
@@ -26,4 +28,11 @@ public class IllegalInfoResult implements Serializable {
     @JSONField(name = "result3")
     private String isDrugs;
 
+    public IllegalInfoResult normalResult() {
+        this.code = "0";
+        this.isEscape = "0";
+        this.isPedigree = "0";
+        this.isDrugs = "0";
+        return this;
+    }
 }

+ 36 - 7
src/main/java/com/jkcredit/illegal/info/service/impl/IllegalInfoServiceImpl.java

@@ -41,15 +41,29 @@ public class IllegalInfoServiceImpl implements IllegalInfoService {
         String body = JSON.toJSONString(requestParams);
 
         Long startTime = System.currentTimeMillis();
-        String result = OkHttpUtil.doPost(illegalInfoUrl, body);
+        String result = OkHttpUtil.doPost(illegalInfoUrl, body, CommonConstant.PERSON_TIME_OUT);
         log.info("调用上游接口-流水号:{}, 入参:{}, 返回:{}, 时延:{}", requestParams.getTraceId(), body, result, System.currentTimeMillis() - startTime);
         if (StringUtils.isBlank(result)) {
             log.info("调用上游接口-流水号:{}, 入参:{}, 请求上游失败无返回", requestParams.getTraceId(), body);
             stringRedisTemplate.boundValueOps(CommonConstant.PERSON_ILLEGAL_INFO_TIME_OUT).increment();
-            return null;
         }
 
-        IllegalInfoResult illegalInfoResult = JSON.toJavaObject(JSON.parseObject(result), IllegalInfoResult.class);
+        IllegalInfoResult illegalInfoResult;
+        try {
+            if (StringUtils.isBlank(result)) {
+                illegalInfoResult = new IllegalInfoResult().normalResult();
+                CHARGE_LOGGER.info(JSON.toJSONString(new IllegalInfoChargeObject(illegalInfoResult, false, requestParams.getTraceId())));
+                return illegalInfoResult;
+            } else {
+                illegalInfoResult = JSON.toJavaObject(JSON.parseObject(result), IllegalInfoResult.class);
+            }
+        } catch (Exception e) {
+            log.error("调用上游接口-流水号:{}, 入参:{}, 解析上游返回异常:{}", requestParams.getTraceId(), body, e);
+            illegalInfoResult = new IllegalInfoResult().normalResult();
+            CHARGE_LOGGER.info(JSON.toJSONString(new IllegalInfoChargeObject(illegalInfoResult, false, requestParams.getTraceId())));
+            return illegalInfoResult;
+        }
+
         // 返回4个参数,code0表示结果正常,其他表示异常
         if (!illegalInfoResult.getCode().equals("0")
             || illegalInfoResult.getIsDrugs().equals("2")
@@ -77,7 +91,7 @@ public class IllegalInfoServiceImpl implements IllegalInfoService {
         String body = JSON.toJSONString(requestParam);
 
         Long startTime = System.currentTimeMillis();
-        String result = OkHttpUtil.doPost(vehicleIllegalInfoUrl, body);
+        String result = OkHttpUtil.doPost(vehicleIllegalInfoUrl, body, CommonConstant.VEHICLE_TIME_OUT);
         log.info("调用上游接口-流水号:{}, 入参:{}, 返回:{}, 时延:{}", requestParam.getTraceId(), body, result, System.currentTimeMillis() - startTime);
         if (StringUtils.isBlank(result)) {
             log.info("调用上游接口-流水号:{}, 入参:{}, 请求上游失败无返回", requestParam.getTraceId(), body);
@@ -121,14 +135,29 @@ public class IllegalInfoServiceImpl implements IllegalInfoService {
         String body = JSON.toJSONString(requestParams);
 
         Long startTime = System.currentTimeMillis();
-        String result = OkHttpUtil.doPost(illegalInfoUrl, body);
+        String result = OkHttpUtil.doPost(illegalInfoUrl, body, CommonConstant.PERSON_TIME_OUT);
         log.info("调用上游接口-流水号:{}, 入参:{}, 返回:{}, 时延:{}", requestParams.getTraceId(), body, result, System.currentTimeMillis() - startTime);
         if (StringUtils.isBlank(result)) {
             log.info("调用上游接口-流水号:{}, 入参:{}, 请求上游失败无返回", requestParams.getTraceId(), body);
             stringRedisTemplate.boundValueOps(CommonConstant.PERSON_ILLEGAL_INFO_TIME_OUT).increment();
-            return null;
         }
-        IllegalInfoResult illegalInfoResult = JSON.toJavaObject(JSON.parseObject(result), IllegalInfoResult.class);
+
+        IllegalInfoResult illegalInfoResult;
+        try {
+            if (StringUtils.isBlank(result)) {
+                illegalInfoResult = new IllegalInfoResult().normalResult();
+                CHARGE_LOGGER.info(JSON.toJSONString(new IllegalInfoChargeObject(illegalInfoResult, false, requestParams.getTraceId())));
+                return illegalInfoResult;
+            } else {
+                illegalInfoResult = JSON.toJavaObject(JSON.parseObject(result), IllegalInfoResult.class);
+            }
+        } catch (Exception e) {
+            log.error("调用上游接口-流水号:{}, 入参:{}, 解析上游返回异常:{}", requestParams.getTraceId(), body, e);
+            illegalInfoResult = new IllegalInfoResult().normalResult();
+            CHARGE_LOGGER.info(JSON.toJSONString(new IllegalInfoChargeObject(illegalInfoResult, false, requestParams.getTraceId())));
+            return illegalInfoResult;
+        }
+
         // 返回4个参数,code0表示结果正常,其他表示异常
         if (!illegalInfoResult.getCode().equals("0")
                 || illegalInfoResult.getIsDrugs().equals("2")

+ 20 - 4
src/main/java/com/jkcredit/illegal/info/service/impl/IllegalInfoTestServiceImpl.java

@@ -1,6 +1,7 @@
 package com.jkcredit.illegal.info.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.jkcredit.illegal.info.constant.CommonConstant;
 import com.jkcredit.illegal.info.model.*;
 import com.jkcredit.illegal.info.service.IllegalInfoTestService;
 import com.jkcredit.illegal.info.util.OkHttpUtil;
@@ -38,14 +39,29 @@ public class IllegalInfoTestServiceImpl implements IllegalInfoTestService {
         String body = JSON.toJSONString(requestParams);
 
         Long startTime = System.currentTimeMillis();
-        String result = OkHttpUtil.doPost(illegalInfoUrl, body);
+        String result = OkHttpUtil.doPost(illegalInfoUrl, body, CommonConstant.PERSON_TIME_OUT);
         TEST_LOGGER.info("调用上游接口-测试-流水号:" + requestParams.getTraceId() + ", 入参:" + body + ", 返回:" + result
                 + ", 时延:" + (System.currentTimeMillis() - startTime));
         if (StringUtils.isBlank(result)) {
             TEST_LOGGER.info("调用上游接口-测试-流水号:" + requestParams.getTraceId() + ", 入参:" + body);
-            return null;
         }
-        IllegalInfoResult illegalInfoResult = JSON.toJavaObject(JSON.parseObject(result), IllegalInfoResult.class);
+
+        IllegalInfoResult illegalInfoResult;
+        try {
+            if (StringUtils.isBlank(result)) {
+                illegalInfoResult = new IllegalInfoResult().normalResult();
+                CHARGE_LOGGER.info(JSON.toJSONString(new IllegalInfoChargeObject(illegalInfoResult, false, requestParams.getTraceId())));
+                return illegalInfoResult;
+            } else {
+                illegalInfoResult = JSON.toJavaObject(JSON.parseObject(result), IllegalInfoResult.class);
+            }
+        } catch (Exception e) {
+            log.error("调用上游接口-流水号:{}, 入参:{}, 解析上游返回异常:{}", requestParams.getTraceId(), body, e);
+            illegalInfoResult = new IllegalInfoResult().normalResult();
+            CHARGE_LOGGER.info(JSON.toJSONString(new IllegalInfoChargeObject(illegalInfoResult, false, requestParams.getTraceId())));
+            return illegalInfoResult;
+        }
+
         // 返回4个参数,code0表示结果正常,其他表示异常
         if (!illegalInfoResult.getCode().equals("0")
                 || illegalInfoResult.getIsDrugs().equals("2")
@@ -67,7 +83,7 @@ public class IllegalInfoTestServiceImpl implements IllegalInfoTestService {
         String body = JSON.toJSONString(requestParam);
 
         Long startTime = System.currentTimeMillis();
-        String result = OkHttpUtil.doPost(vehicleIllegalInfoUrl, body);
+        String result = OkHttpUtil.doPost(vehicleIllegalInfoUrl, body, CommonConstant.VEHICLE_TIME_OUT);
         TEST_LOGGER.info("调用上游接口-测试-流水号:" + requestParam.getTraceId() + ", 入参:" + body + ", 返回:" + result
                 + ", 时延:" + (System.currentTimeMillis() - startTime));
         if (StringUtils.isBlank(result)) {

+ 8 - 8
src/main/java/com/jkcredit/illegal/info/util/OkHttpUtil.java

@@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
  **/
 @Slf4j
 public class OkHttpUtil {
-    public static String doPost(String url, String body) {
+    public static String doPost(String url, String body, int outTime) {
         OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
         MediaType mediaType = MediaType.parse(CommonConstant.MEDIA_TYPE);
         RequestBody requestBody = RequestBody.create(mediaType, body);
@@ -34,9 +34,9 @@ public class OkHttpUtil {
         OkHttpClient client = okHttpClient.newBuilder()
                 .sslSocketFactory(RxUtil.createSSLSocketFactory(), new RxUtil.TrustAllManager())
                 .hostnameVerifier(new RxUtil.TrustAllHostnameVerifier())
-                .connectTimeout(CommonConstant.TIME_OUT, TimeUnit.MILLISECONDS)
-                .readTimeout(CommonConstant.TIME_OUT, TimeUnit.MILLISECONDS)
-                .writeTimeout(CommonConstant.TIME_OUT, TimeUnit.MILLISECONDS)
+                .connectTimeout(outTime, TimeUnit.MILLISECONDS)
+                .readTimeout(outTime, TimeUnit.MILLISECONDS)
+                .writeTimeout(outTime, TimeUnit.MILLISECONDS)
                 .build();
         String responseContext = "";
         try {
@@ -46,7 +46,7 @@ public class OkHttpUtil {
             }
             response.close();
         } catch (SocketTimeoutException ste) {
-            log.info("doPost, 参数:{}-SocketTimeoutException:{}", body, ste);
+            log.info("doPost, 参数:{}-SocketTimeoutException:", body, ste);
         } catch (IOException ioe) {
             log.info("doPost, 参数:{}-IOException:{}", body, ioe);
         } catch (Exception e) {
@@ -61,9 +61,9 @@ public class OkHttpUtil {
         Request okRequest = new Request.Builder().post(requestBody).url(url).build();
         OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
         OkHttpClient client = okHttpClient.newBuilder()
-                .connectTimeout(CommonConstant.TIME_OUT, TimeUnit.MILLISECONDS)
-                .readTimeout(CommonConstant.TIME_OUT, TimeUnit.MILLISECONDS)
-                .writeTimeout(CommonConstant.TIME_OUT, TimeUnit.MILLISECONDS)
+                .connectTimeout(CommonConstant.DING_TIME_OUT, TimeUnit.MILLISECONDS)
+                .readTimeout(CommonConstant.DING_TIME_OUT, TimeUnit.MILLISECONDS)
+                .writeTimeout(CommonConstant.DING_TIME_OUT, TimeUnit.MILLISECONDS)
                 .build();
 
         try {