Przeglądaj źródła

华泰-处理核保响应参数转换异常的问题

lixiaolong 3 miesięcy temu
rodzic
commit
54efdb1773

+ 28 - 8
tenant/insurance/quotation-huatai/src/main/java/com/jzg/quotation/huatai/crawler/service/Impl/HuaTaiCrawlerRequestImpl.java

@@ -1,10 +1,13 @@
 package com.jzg.quotation.huatai.crawler.service.Impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.json.JsonReadFeature;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectReader;
 import com.jzg.commons.constants.ProductsType;
 import com.jzg.commons.constants.dict.InsOrderStatusEnum;
 import com.jzg.commons.entity.po.jyxSetting;
@@ -238,17 +241,19 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
     // ====================== 报价主流程 ======================
     @Override
     public QuoteResultsVo quote(QuoteVo quoteVo) throws Exception {
+        // 构造登录参数
         AttributionInformationVo attr = quoteVo.getOrder().getAttributionInformationVo();
         LoginDTO dto = buildLoginDTO(attr);
+        // 获取登录相关信息
         Map<String, Object> mmap = login(dto);
-        //归属信息
+        // 归属信息
         Map<String, Object> gsInfo = parseToMap(mmap.get("gsInfo").toString());
         log.info("gsInfo: {}", JSONObject.toJSONString(mmap));
 
         String cookie = extractCookie(mmap);
         CarInfoVo car = quoteVo.getCarInfoVo();
 
-        //带重试的获取报价编号、车型型号
+        // 带重试的获取报价编号、车型型号
         Map<String, Object> xbResult = retry(() -> {
             try { return xbQuery(dto.getUsername(), cookie, car); }
             catch (Exception e) { refreshLogin(dto); throw new Exception(e); }
@@ -256,14 +261,14 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
 
         String quotationNo = str(xbResult, "quotationNo");
         String modelcodexh = str(xbResult, "modelcodexh");
-        //报价前预处理-保存车辆信息、过滤车型等处理
+        // 报价前预处理-保存车辆信息、过滤车型等处理
         PreResult pre = prepareQuote(attr, mmap, car, modelcodexh, cookie, quotationNo);
-        //报价
+        // 报价
         CoreResult core = executeQuote(quoteVo, quotationNo, dto, cookie, pre, gsInfo, attr);
         if (!core.success()) throw new SystemException("报价失败");
-        //保存订单到MongoDB
+        // 保存订单到MongoDB
         saveOrder(quoteVo, core);
-        //组装费用
+        // 组装费用
         return HuaTaiCrawlerQuoteResultsVoBuild.buildQuoteResultsVo(quoteVo, core.data(), core.fcPrice());
     }
 
@@ -836,12 +841,27 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
 
         Map<String, Object> map = new HashMap<>();
         try {
-            map = MAPPER.readValue(res, Map.class);
+            // 忽略未知字段
+            MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            // 空字符串转null
+            MAPPER.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
+            // 允许单引号、宽松JSON格式(第三方不规范返回必备)
+            MAPPER.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
+            MAPPER.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
+            // 允许换行符、回车符存在于字符串值中
+            // MAPPER.configure(JsonParser.Feature.ALLOW_UNESCAPED_CONTROL_CHARS, true);
+
+            ObjectReader reader = MAPPER.readerFor(Map.class)
+                    .with(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS)
+                    .with(JsonReadFeature.ALLOW_SINGLE_QUOTES)
+                    .with(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES);
+
+            map = reader.readValue(res);
         } catch (JsonProcessingException e) {
             throw new SystemException("核保失败, {}", convertResponseMsg(res));
         }
 
-        if (!"1,2,3,4".contains(order.getCiCategory()) || "Y".equals(str(map, "isOver")) || "Y".equals(str(map, "isOver1"))
+        if (!"1,2,3,4,Y1,Y2,Y3".contains(order.getCiCategory()) || "Y".equals(str(map, "isOver")) || "Y".equals(str(map, "isOver1"))
                 || "重新计算保费".equals(str(map, "MSG")) || (res.contains("下发修改意见") && !res.contains("isPassHB")) || res.contains("转人工意见")) {
             throw new SystemException("核保失败-------" + convertResponseMsg(res));
         }