Просмотр исходного кода

fix 恒邦商业险不能自动续保问题

liub 2 месяцев назад
Родитель
Сommit
80f07d94c8

+ 7 - 2
tenant/insurance/quotation-hengbang/src/main/java/com/jzg/quotation/hengbang/crawler/component/HengBangCrawlerRequestComponent.java

@@ -333,8 +333,13 @@ public class HengBangCrawlerRequestComponent {
                         String time = extractDuplicateEndTime(detail);
                         if (time != null) {
                             String utcTime = DateUtil.toUtcDateTime(time);
-                            calculationRequest.setBegintimeCi(utcTime);
-                            calculationRequest.setBegintimeBi(utcTime);
+                            // 根据重复投保类型分别设置起保时间:交强险只改 begintimeCi,商业险只改 begintimeBi
+                            // 注意:商业险错误信息不含"商业险平台返回",故通过"交强险平台返回"反推
+                            if (detail.contains("交强险平台返回")) {
+                                calculationRequest.setBegintimeCi(utcTime);
+                            } else {
+                                calculationRequest.setBegintimeBi(utcTime);
+                            }
                             calculationRequest.setBegintimeAccident(utcTime);
                             return getCalculationResult(calculationRequest, headers);
                         } else {

+ 45 - 11
tenant/insurance/quotation-hengbang/src/main/java/com/jzg/quotation/hengbang/crawler/service/Impl/HengBangCrawlerRequestImpl.java

@@ -178,18 +178,27 @@ public class HengBangCrawlerRequestImpl implements HengBangCrawlerRequest {
             }
         }
 
-        // 重复投保:循环重试,优先从responseBody.begintimeBi获取建议起保时间
+        // 重复投保:循环重试,优先从responseBody获取建议起保时间
         int maxRetry = 3;
         while (errorMsg.contains("重复投保") && maxRetry-- > 0) {
             String time = getDuplicateBegintime(resJsonObj, errorMsg);
-            log.info("重复投保,重试次数:{}, 建议起保时间:{}", 3 - maxRetry, time);
+            log.info("重复投保,重试次数:{}, 建议起保时间:{}, 错误信息前100字符:{}", 3 - maxRetry, time,
+                    errorMsg.length() > 100 ? errorMsg.substring(0, 100) : errorMsg);
             if (time == null) {
                 break;
             }
             String utcTime = DateUtil.toUtcDateTime(time);
-            calculationRequest.setBegintimeCi(utcTime);
-            calculationRequest.setBegintimeBi(utcTime);
+
+            // 根据重复投保类型分别设置起保时间:交强险只改 begintimeCi,商业险只改 begintimeBi
+            // 注意:商业险错误信息不含"商业险平台返回",故通过"交强险平台返回"反推
+            if (errorMsg.contains("交强险平台返回")) {
+                calculationRequest.setBegintimeCi(utcTime);
+            } else {
+                // 不含交强险标识则为商业险重复投保
+                calculationRequest.setBegintimeBi(utcTime);
+            }
             calculationRequest.setBegintimeAccident(utcTime);
+
             resJsonObj = callCalculation(calculationRequest, headers);
             if (resJsonObj == null) {
                 return buildErrorResult(quoteVo);
@@ -254,19 +263,44 @@ public class HengBangCrawlerRequestImpl implements HengBangCrawlerRequest {
 
     /**
      * 获取重复投保场景的建议起保时间(yyyy-MM-dd HH:mm:ss 格式)
-     * 优先从 responseBody.begintimeBi 获取,兜底从 message 正则提取
+     * 优先从 responseBody.begintimeCi/begintimeBi 获取,兜底从 message 正则提取
      */
     private String getDuplicateBegintime(JSONObject resJsonObj, String errorMsg) {
-        // 优先从 responseBody.begintimeBi 获取
-        JSONObject responseBody = resJsonObj.getJSONObject("responseBody");
+        // 优先从 responseBody 获取建议起保时间(支持顶层和 map.responseBody 嵌套)
+        JSONObject responseBody = getNestedResponseBody(resJsonObj);
         if (responseBody != null) {
+            // 检查 begintimeCi(交强险建议起保时间),保司返回可能带前导空格
+            String begintimeCi = responseBody.getString("begintimeCi");
+            if (StrUtil.isNotBlank(begintimeCi)) {
+                log.info("重复投保,从 responseBody.begintimeCi 获取建议起保时间:{}", begintimeCi);
+                return normalizeTimeFormat(begintimeCi.trim());
+            }
+            // 检查 begintimeBi(商业险建议起保时间)
             String begintimeBi = responseBody.getString("begintimeBi");
-            if (begintimeBi != null) {
-                return normalizeTimeFormat(begintimeBi);
+            if (StrUtil.isNotBlank(begintimeBi)) {
+                log.info("重复投保,从 responseBody.begintimeBi 获取建议起保时间:{}", begintimeBi);
+                return normalizeTimeFormat(begintimeBi.trim());
             }
         }
-        // 兼容:从 message 正则提取终保日期
-        return hbCrawlerRequestComponent.extractDuplicateEndTime(errorMsg);
+        // 兜底:从 message 正则提取终保日期
+        String endTime = hbCrawlerRequestComponent.extractDuplicateEndTime(errorMsg);
+        log.info("重复投保,从 errorMsg 正则提取终保日期:{}", endTime);
+        return endTime;
+    }
+
+    /**
+     * 获取嵌套的 responseBody(保司返回可能在顶层或 map.responseBody 中)
+     */
+    private JSONObject getNestedResponseBody(JSONObject resJsonObj) {
+        JSONObject responseBody = resJsonObj.getJSONObject("responseBody");
+        if (responseBody != null) {
+            return responseBody;
+        }
+        JSONObject map = resJsonObj.getJSONObject("map");
+        if (map != null) {
+            return map.getJSONObject("responseBody");
+        }
+        return null;
     }
 
     /**