|
@@ -11,12 +11,13 @@ import com.jzg.quotation.taishan.crawler.properties.TaiShanCrawlerProperties;
|
|
|
import com.jzg.quotation.commons.component.RequestComponent;
|
|
import com.jzg.quotation.commons.component.RequestComponent;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
import org.springframework.util.MultiValueMap;
|
|
|
-import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
|
+import org.springframework.web.reactive.function.client.WebClientResponseException;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
@@ -173,6 +174,55 @@ public class TaiShanCrawlerRequestComponent {
|
|
|
return response;
|
|
return response;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 车型查询(带登录状态检查)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param request
|
|
|
|
|
+ * @param headers
|
|
|
|
|
+ * @return TaiShanCrawlerCarResponse
|
|
|
|
|
+ */
|
|
|
|
|
+ public TaiShanCrawlerCarResponse queryCarModelsWithCheck(TaiShanCrawlerCarRequest request, HttpHeaders headers) {
|
|
|
|
|
+ // 1. 请求体 JSON
|
|
|
|
|
+ String jsonString = com.alibaba.fastjson.JSON.toJSONString(request);
|
|
|
|
|
+ log.info("车型搜索参数:{}", jsonString);
|
|
|
|
|
+ // 2. 执行 POST
|
|
|
|
|
+ ResponseEntity<String> responseEntity;
|
|
|
|
|
+ try {
|
|
|
|
|
+ responseEntity = requestComponent.post(
|
|
|
|
|
+ RequestUrl.CAR.getRequestUrl(taiShanCrawlerProperties.getBaseUrl()),
|
|
|
|
|
+ jsonString,
|
|
|
|
|
+ String.class,
|
|
|
|
|
+ headers);
|
|
|
|
|
+ } catch (WebClientResponseException e) {
|
|
|
|
|
+ // 检查是否是 500 错误且响应体为空(账号掉线)
|
|
|
|
|
+ if (e.getStatusCode().value() == 500 &&
|
|
|
|
|
+ (e.getResponseBodyAsString() == null || e.getResponseBodyAsString().isEmpty())) {
|
|
|
|
|
+ log.error("账号掉线,请重新登录后重新报价");
|
|
|
|
|
+ throw new SystemException("账号掉线,请重新登录后重新报价");
|
|
|
|
|
+ }
|
|
|
|
|
+ throw e;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 3. 获取响应
|
|
|
|
|
+ String responseBody = responseEntity.getBody();
|
|
|
|
|
+
|
|
|
|
|
+ // 3.1 检查500错误且响应体为空(账号掉线)
|
|
|
|
|
+ if (responseEntity.getStatusCode().value() == 500 &&
|
|
|
|
|
+ (responseBody == null || responseBody.isEmpty())) {
|
|
|
|
|
+ log.error("账号掉线,请重新登录后重新报价");
|
|
|
|
|
+ throw new SystemException("账号掉线,请重新登录后重新报价");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("响应内容 {}", responseBody);
|
|
|
|
|
+ // 4. 反序列化
|
|
|
|
|
+ TaiShanCrawlerCarResponse response = com.alibaba.fastjson.JSON.parseObject(responseBody, TaiShanCrawlerCarResponse.class);
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 判断返回码
|
|
|
|
|
+ if ("200".equals(response.getCode())) {
|
|
|
|
|
+ return response;
|
|
|
|
|
+ }
|
|
|
|
|
+ throw new SystemException(response.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取车辆实际价值
|
|
* 获取车辆实际价值
|
|
|
*
|
|
*
|