浏览代码

华泰二次查询车型逻辑调整;华泰预报价流程逻辑调整

lixiaolong 1 月之前
父节点
当前提交
a4733d6499

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

@@ -1,6 +1,7 @@
 package com.jzg.quotation.huatai.crawler.service.Impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSON;
 import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.json.JsonReadFeature;
@@ -46,6 +47,7 @@ import com.jzg.quotation.huatai.crawler.service.HtCrawlerOrderService;
 import com.jzg.quotation.huatai.crawler.service.HuaTaiCrawlerRequest;
 import com.jzg.quotation.huatai.crawler.util.CookieUtils;
 import com.jzg.quotation.huatai.crawler.util.CryptoUtil;
+import com.jzg.quotation.huatai.crawler.util.HuaTaiCryptUtil;
 import com.jzg.quotation.huatai.crawler.util.UploadUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -201,7 +203,7 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
         m.put("engineno", "");
         m.put("liceenseplatetype", "02 小型汽车号牌");//
         m.put("ecdemicvehicleflag", "0");
-        fillVehicleTypeCodes(car, m);
+        fillVehicleTypeCodes(car, m, "motortypecode", "motorusagetypecode");
         m.put("xbcomcode", XBCOM_CODE);
         m.put("quotationNo", quotationNo);
         m.put("riskCode", RISK_CODE);
@@ -244,7 +246,7 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
         // 报价前预处理-保存车辆信息、过滤车型等处理
         PreResult pre = null;
         try {
-            pre = prepareQuote(attr, mmap, car, modelcodexh, cache.getCookie(), quotationNo, xbResult);
+            pre = prepareQuote(attr, mmap, car, modelcodexh, cache.getCookie(), quotationNo, xbResult, "");
         } catch (Exception e) {
             log.error("报价失败:保存车辆信息、过滤车型异常,{}",e.getMessage());
             throw new SystemException(e.getMessage());
@@ -317,14 +319,57 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
 
     // ====================== 报价预处理 ======================
     private PreResult prepareQuote(AttributionInformationVo attr, Map<String, Object> mmap,
-                                   CarInfoVo car, String modelcodexh, String cookie, String quotationNo, Map<String, Object> xbResult) throws Exception {
+                                   CarInfoVo car, String modelcodexh, String cookie, String quotationNo, Map<String, Object> xbResult, String carChange) throws Exception {
         HtCrawlerConfigureParameters params = ConfigureParametersConversion.conversionEntity(
                 HtCrawlerConfigureParameters.class, attr.getConfigInfo());
         params.setFullComCode(params.getComCode());
         //参数格式保持一致--方便过滤
         car.setPurchasePrice(car.getPurchasePrice().replace(".00", ""));
+        HtCrawlerCarQueryResponse.DataDTO dataDTO = null;
         //车辆查询
-        HtCrawlerCarQueryResponse.DataDTO dataDTO = req.carQuery(new HtCrawlerCarQueryRequest(car, modelcodexh, xbResult), req.getHeaders1(), car);
+        if (StringUtils.isBlank(carChange)) {
+            dataDTO = req.carQuery(new HtCrawlerCarQueryRequest(car, modelcodexh, xbResult), req.getHeaders1(), car);
+        } else {
+            HttpHeaders headers = buildReCarQueryHeaders(req.getCookie());
+            Map<String, Object> dataDTOMap = new HashMap<>();
+            dataDTOMap.put("vehiclemodel", car.getBrandName());
+            fillVehicleTypeCodes(car, dataDTOMap, "motortypecode", "motorusagetypecode");
+            dataDTOMap.put("EACSP_MODEL_CODE_QUERY_new", System.currentTimeMillis() + "");
+            dataDTOMap.put("EACSP_MODEL_CODE_QUERY_old", "");
+            dataDTOMap.put("pageno", "1");
+            dataDTOMap.put("rowsperpage", "10");
+            dataDTOMap.put("reformRisk", "1251");
+            dataDTOMap.put("vin", car.getVinNo());
+            dataDTOMap.put("licenseplateno", car.getLicenseNo());
+            dataDTOMap.put("engineno", car.getEngineNo());
+            dataDTOMap.put("vehicleregisterdate", car.getRegisterDate());
+            dataDTOMap.put("fueltype", "0");
+            dataDTOMap.put("purerange", "");
+            dataDTOMap.put("modelcodexh", modelcodexh);
+
+            String rawData = JSON.toJSONString(dataDTOMap);
+            String key = HuaTaiCryptUtil.generateKey(16);         // 生成16位AES密钥
+            String accessToken = HuaTaiCryptUtil.RSAEncrypt(key);  // RSA 加密密钥
+            String encryptData = HuaTaiCryptUtil.AESEncrypt(rawData, key);  // AES 加密数据
+
+            MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
+            requestBody.add("sourceCode", "8");
+            requestBody.add("accessToken", accessToken);
+            requestBody.add("data", encryptData);
+            requestBody.add("cmd", "carquery");
+
+            String url = "https://cspxp.pc.ehuatai.com/htcsp/VehicleInfoEntryAction.do";
+            String response = cookieUtils.getRestTemplate().postForEntity(url, new HttpEntity<>(requestBody, headers), String.class).getBody();
+            log.info("carChange车辆查询,response,{}",response);
+
+            HtCrawlerCarQueryResponse encryptedResponse =
+                    JSON.parseObject(response, HtCrawlerCarQueryResponse.class);
+            String decryptKey = CryptoUtil.rsaDecrypt(encryptedResponse.getAccessToken());
+            String decryptData = CryptoUtil.aesDecrypt(encryptedResponse.getData(), decryptKey);
+
+            dataDTO = JSON.parseObject(decryptData, HtCrawlerCarQueryResponse.DataDTO.class);
+
+        }
         //过滤车辆
         HtCrawlerCarQueryResponse.DataDTO.DataListDTO carDTO = null;
         if(dataDTO.getDatalist() != null && !dataDTO.getDatalist().isEmpty()) {
@@ -341,9 +386,9 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
             log.info("未匹配则第二次车辆查询,carDTO,{}",JSONObject.toJSONString(carDTO));
         }
         log.info("过滤后的车型carDTO: {}", JSONObject.toJSONString(carDTO));
-        //保存车辆信息
+        //保存车辆信息 -- renewCarInfo
         executeSaveCarQuery(carDTO, dataDTO, car, cookie);
-        //车型查询 -- renewCarInfo
+        //车型查询 -- get_peopleinfo
         String carData = executeCarModelCodexhQuery(carDTO, car, cookie, quotationNo);
         // 核心:关闭「未知字段抛出异常」,优先级 > 类注解
         //MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@@ -399,11 +444,12 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
         MultiValueMap<String, String> fd = new LinkedMultiValueMap<>();
         fd.add("modelCode", carDTO.getModelcode());
         fd.add("licenseNo", car.getLicenseNo());
-        fd.add("licenseKindCode", "02 小型汽车号牌");
+        fd.add("licenseKindCode", car.getLicenseKindCode() + " " + car.getLicenseKindName()); // "02 小型汽车号牌"
         fd.add("engineNo", car.getEngineNo());
         fd.add("frameNo", car.getVinNo());
-        fd.add("useNatureCode", "8A 家庭自用");
-        fd.add("carKindCode", "A0 客车");
+        // fd.add("useNatureCode", "8A 家庭自用");
+        // fd.add("carKindCode", "A0 客车");
+        fillVehicleTypeCodes2(car, fd, "carKindCode", "useNatureCode");
         fd.add("enrollDate", car.getRegisterDate());
         fd.add("completeKerbMass", "1250");
         fd.add("seatCount", carDTO.getLimitloadperson());
@@ -557,7 +603,7 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
             AttributionInformationVo attr = q.getOrder().getAttributionInformationVo();
             log.info(map.get("unMatchVehicleFrameMessage") + "已重新执行prepareQuote,新modelcodexh:{}", newModelCodexh);
             return prepareQuote(attr, gsInfo, q.getCarInfoVo(),
-                    newModelCodexh, cookie, quotationNo, map);
+                    newModelCodexh, cookie, quotationNo, map, "carChange");
         } catch (Exception e) {
             log.error("重新构建PreResult失败", e);
             throw new SystemException("重新获取车型信息失败", e.getMessage());
@@ -1303,6 +1349,22 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
         });
     }
 
+    private HttpHeaders buildReCarQueryHeaders(String cookie) {
+        return header(h -> {
+            h.add(HtRequestConstant.COOKIE, cookie);
+            h.add("Accept", ACCEPT_JSON);
+            h.add("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
+            h.add("Cache-Control", "no-cache");
+            h.add("Connection", "keep-alive");
+            h.add("Content-Type", CONTENT_TYPE_FORM);
+            h.add("Origin", ORIGIN);
+            h.add("Pragma", "no-cache");
+            h.add("Referer", ORIGIN + "/htcsp/VehicleInfoEntryAction.do?cmd=startProcess");
+            h.add("User-Agent", UA);
+            h.add("X-Requested-With", XHR);
+        });
+    }
+
     private HttpHeaders buildCarModelCodexhHeaders(String cookie) {
         return header(h -> {
             h.add("Accept", ACCEPT_JSON);
@@ -1404,20 +1466,37 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
         return m;
     }
 
-    private static void fillVehicleTypeCodes(CarInfoVo car, Map<String, Object> data) {
+    private static void fillVehicleTypeCodes(CarInfoVo car, Map<String, Object> data, String motorTypeKey, String motorUsageKey) {
+        String use = car.getVehicleUseCode(), kind = car.getCarKindCode();
+        switch (use) {
+            case "04" -> data.putAll(Map.of(motorTypeKey, "H0", motorUsageKey, "9D"));
+            case "05" -> data.putAll(Map.of(motorTypeKey, "A0", motorUsageKey, "8A"));
+            case "06" -> {
+                if ("A0".equals(kind)) data.putAll(Map.of(motorTypeKey, "A0", motorUsageKey, "8C"));
+                else if ("A1".equals(kind)) data.putAll(Map.of(motorTypeKey, "H0", motorUsageKey, "8D"));
+            }
+            case "07" -> {
+                if ("A0".equals(kind)) data.putAll(Map.of(motorTypeKey, "A0", motorUsageKey, "8B"));
+                else if ("A1".equals(kind)) data.putAll(Map.of(motorTypeKey, "H0", motorUsageKey, "8D"));
+            }
+            case "08" -> data.putAll(Map.of(motorTypeKey, "H0", motorUsageKey, "8D"));
+        }
+    }
+
+    private static void fillVehicleTypeCodes2(CarInfoVo car, MultiValueMap<String, String> data, String motorTypeKey, String motorUsageKey) {
         String use = car.getVehicleUseCode(), kind = car.getCarKindCode();
         switch (use) {
-            case "04" -> data.putAll(Map.of("motortypecode", "H0", "motorusagetypecode", "9D"));
-            case "05" -> data.putAll(Map.of("motortypecode", "A0", "motorusagetypecode", "8A"));
+            case "04" -> { data.add(motorTypeKey, "H0"); data.add(motorUsageKey, "9D"); }
+            case "05" -> { data.add(motorTypeKey, "A0"); data.add(motorUsageKey, "8A"); }
             case "06" -> {
-                if ("A0".equals(kind)) data.putAll(Map.of("motortypecode", "A0", "motorusagetypecode", "8C"));
-                else if ("A1".equals(kind)) data.putAll(Map.of("motortypecode", "H0", "motorusagetypecode", "8D"));
+                if ("A0".equals(kind)) { data.add(motorTypeKey, "A0"); data.add(motorUsageKey, "8C"); }
+                else if ("A1".equals(kind)) { data.add(motorTypeKey, "H0"); data.add(motorUsageKey, "8D"); }
             }
             case "07" -> {
-                if ("A0".equals(kind)) data.putAll(Map.of("motortypecode", "A0", "motorusagetypecode", "8B"));
-                else if ("A1".equals(kind)) data.putAll(Map.of("motortypecode", "H0", "motorusagetypecode", "8D"));
+                if ("A0".equals(kind)) { data.add(motorTypeKey, "A0"); data.add(motorUsageKey, "8B"); }
+                else if ("A1".equals(kind)) { data.add(motorTypeKey, "H0"); data.add(motorUsageKey, "8D"); }
             }
-            case "08" -> data.putAll(Map.of("motortypecode", "H0", "motorusagetypecode", "8D"));
+            case "08" -> { data.add(motorTypeKey, "H0"); data.add(motorUsageKey, "8D"); }
         }
     }