|
|
@@ -123,6 +123,13 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
|
|
|
private final PlatformClient platformClient;
|
|
|
private final CookieUtils cookieUtils;
|
|
|
private static final ObjectMapper MAPPER = new ObjectMapper();
|
|
|
+ static {
|
|
|
+ // 初始化时统一配置所有 Feature,避免运行时多线程并发配置导致不稳定
|
|
|
+ MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
+ MAPPER.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
|
|
|
+ MAPPER.configure(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
|
|
|
+ MAPPER.configure(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
|
|
|
+ }
|
|
|
|
|
|
// ====================== 登录 ======================
|
|
|
@Override public void login(LoginBase loginBase) { }
|
|
|
@@ -239,7 +246,7 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
|
|
|
// 报价前预处理-保存车辆信息、过滤车型等处理
|
|
|
PreResult pre = null;
|
|
|
try {
|
|
|
- pre = prepareQuote(attr, mmap, car, modelcodexh, cookie, quotationNo, xbResult);
|
|
|
+ pre = prepareQuote(attr, mmap, car, modelcodexh, cache.getCookie(), quotationNo, xbResult);
|
|
|
} catch (Exception e) {
|
|
|
log.error("报价失败:保存车辆信息、过滤车型异常,{}",e.getMessage());
|
|
|
throw new SystemException(e.getMessage());
|
|
|
@@ -247,7 +254,7 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
|
|
|
// 报价
|
|
|
CoreResult core = null;
|
|
|
try {
|
|
|
- core = executeQuote(quoteVo, quotationNo, dto, cookie, pre, gsInfo, attr);
|
|
|
+ core = executeQuote(quoteVo, quotationNo, dto, cache.getCookie(), pre, gsInfo, attr);
|
|
|
} catch (Exception e) {
|
|
|
log.error("报价失败,{}",e.getMessage());
|
|
|
throw new SystemException(e.getMessage());
|
|
|
@@ -341,9 +348,9 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
|
|
|
//车型查询 -- renewCarInfo
|
|
|
String carData = executeCarModelCodexhQuery(carDTO, car, cookie, quotationNo);
|
|
|
// 核心:关闭「未知字段抛出异常」,优先级 > 类注解
|
|
|
- MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
+ //MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
// 可选:兼容空字符串、大小写字段(对接第三方接口常用)
|
|
|
- MAPPER.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
|
|
|
+ //MAPPER.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
|
|
|
Map<String, Object> rootMap = MAPPER.readValue(carData, new TypeReference<Map<String, Object>>() {});
|
|
|
String datalistStr = (String) rootMap.get("datalist");
|
|
|
String datalist2Str = (String) rootMap.get("datalist2");
|
|
|
@@ -371,6 +378,9 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
|
|
|
|
|
|
private void executeSaveCarQuery(HtCrawlerCarQueryResponse.DataDTO.DataListDTO carDTO,
|
|
|
HtCrawlerCarQueryResponse.DataDTO dataDTO, CarInfoVo car, String cookie) throws JsonProcessingException {
|
|
|
+ if (dataDTO.getDatalist2() == null || dataDTO.getDatalist2().isEmpty()) {
|
|
|
+ throw new SystemException("车辆信息不完整");
|
|
|
+ }
|
|
|
String aa = URLEncoder.encode(MAPPER.writeValueAsString(carDTO), StandardCharsets.UTF_8);
|
|
|
String bb = URLEncoder.encode(MAPPER.writeValueAsString(dataDTO.getDatalist2().get(0)), StandardCharsets.UTF_8);
|
|
|
|
|
|
@@ -796,10 +806,6 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
|
|
|
//cookie还在,但服务器已断开连接,需重新连接
|
|
|
if(res.contains("<html>")) {
|
|
|
refreshLogin(buildLoginDTO(attr));
|
|
|
- Map<String, Object> m = login(buildLoginDTO(attr));
|
|
|
- String cookie = (String) m.get("cookie");
|
|
|
- req.getHeaders().remove(HtRequestConstant.COOKIE);
|
|
|
- req.getHeaders().add(HtRequestConstant.COOKIE, cookie);
|
|
|
return underwriting(vo);
|
|
|
}
|
|
|
if (res.contains("起保时间不正确")) {
|
|
|
@@ -809,12 +815,12 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
try {
|
|
|
// 忽略未知字段
|
|
|
- MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
+ // MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
// 空字符串转null
|
|
|
- MAPPER.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
|
|
|
+ // 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_SINGLE_QUOTES, true);
|
|
|
+ // MAPPER.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
|
|
|
// 允许换行符、回车符存在于字符串值中
|
|
|
// MAPPER.configure(JsonParser.Feature.ALLOW_UNESCAPED_CONTROL_CHARS, true);
|
|
|
|
|
|
@@ -927,7 +933,7 @@ public class HuaTaiCrawlerRequestImpl implements HuaTaiCrawlerRequest {
|
|
|
private void doLoginCookie(AttributionInformationVo attr) {
|
|
|
if (StringUtils.isBlank(req.getCookie())) {
|
|
|
Map<String, Object> m = login(buildLoginDTO(attr));
|
|
|
- String cookie = (String) m.get("cookie");
|
|
|
+ String cookie = (String) m.get("cookies");
|
|
|
req.getHeaders().remove(HtRequestConstant.COOKIE);
|
|
|
req.getHeaders().add(HtRequestConstant.COOKIE, cookie);
|
|
|
}
|