|
|
@@ -2,19 +2,24 @@ package com.jzg.quotation.guoren.crawler.component;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.TypeReference;
|
|
|
import com.jzg.commons.constants.quote.enums.base.InsuranceEnum;
|
|
|
import com.jzg.commons.entity.po.SysUploadFiles;
|
|
|
import com.jzg.commons.entity.quote.vo.CarInfoVo;
|
|
|
import com.jzg.commons.entity.quote.vo.QuoteVo;
|
|
|
import com.jzg.commons.entity.quote.vo.image.InsuranceImageVo;
|
|
|
import com.jzg.commons.exception.SystemException;
|
|
|
+import com.jzg.commons.exception.TokenExpireException;
|
|
|
import com.jzg.commons.util.MinioUtils;
|
|
|
import com.jzg.commons.util.StringUtils;
|
|
|
import com.jzg.quotation.commons.client.PlatformClient;
|
|
|
import com.jzg.quotation.commons.component.RequestComponent;
|
|
|
import com.jzg.quotation.commons.filter.CarModelsFilterUtils;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
import com.jzg.quotation.commons.utils.HttpUtil;
|
|
|
import com.jzg.quotation.commons.utils.InsuranceLog;
|
|
|
+import com.jzg.quotation.guoren.api.entity.Response.IdentifyCodeDataResponse;
|
|
|
import com.jzg.quotation.guoren.crawler.constant.enums.RequestUrl;
|
|
|
import com.jzg.quotation.guoren.crawler.entity.dto.GuoRenPrpTitemCarDTO;
|
|
|
import com.jzg.quotation.guoren.crawler.entity.dto.PrpTMainDTO;
|
|
|
@@ -124,9 +129,11 @@ public class GuoRenCrawlerRequestComponent {
|
|
|
* @param username 用户名称
|
|
|
* @return 验证码编号
|
|
|
*/
|
|
|
- public GuoRenCrawlerIdentifyCodeData identifyCode(String username) {
|
|
|
+ public IdentifyCodeDataResponse identifyCode(String username) {
|
|
|
GuoRenCrawlerIdentifyCodeRequest identifyCodeRequest = new GuoRenCrawlerIdentifyCodeRequest(username);
|
|
|
- return request(RequestUrl.IDENTIFY_CODE, identifyCodeRequest, new HttpHeaders());
|
|
|
+ IdentifyCodeDataResponse request = request(RequestUrl.IDENTIFY_CODE, identifyCodeRequest, IdentifyCodeDataResponse.class, new HttpHeaders());
|
|
|
+// JSONObject.parseObject(request, IdentifyCodeDataResponse.class);
|
|
|
+ return request;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -140,7 +147,12 @@ public class GuoRenCrawlerRequestComponent {
|
|
|
*/
|
|
|
public GuoRenCrawlerTokenData getToken(String username, String password, String identifyId, String identifyCode) {
|
|
|
GuoRenCrawlerTokenRequest tokenRequest = new GuoRenCrawlerTokenRequest(username, password, identifyId, identifyCode);
|
|
|
- return request(RequestUrl.LOGIN, tokenRequest, new HttpHeaders());
|
|
|
+ GuoRenCrawlerBaseResponse<GuoRenCrawlerTokenData> response = request(RequestUrl.LOGIN, tokenRequest, new ParameterizedTypeReference<>() {
|
|
|
+ }, new HttpHeaders());
|
|
|
+ if (response.getResultCode() == 40102 || response.getResultCode() == 40104) {
|
|
|
+ throw new SystemException(response.getResultMsg());
|
|
|
+ }
|
|
|
+ return response.getData();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -149,12 +161,29 @@ public class GuoRenCrawlerRequestComponent {
|
|
|
* @param username 用户名
|
|
|
* @param comCode 归属机构编码
|
|
|
* @param httpHeaders 请求头
|
|
|
- * @return 归属机构
|
|
|
+ * @return 归属机构(登录失效时resultCode为40301)
|
|
|
*/
|
|
|
public GuoRenCrawlerGetLoginComInfoResponse getLoginComInfo(String username, String comCode, HttpHeaders httpHeaders) {
|
|
|
+ String url = guoRenCrawlerProperties.getBaseUrl() + RequestUrl.GET_LOGIN_COM_INFO.getUri();
|
|
|
GuoRenCrawlerGetLoginComInfoRequest guoRenCrawlerGetLoginComInfoRequest = new GuoRenCrawlerGetLoginComInfoRequest(username);
|
|
|
- List<GuoRenCrawlerGetLoginComInfoResponse> getLoginComInfoResponseList = request(RequestUrl.GET_LOGIN_COM_INFO, guoRenCrawlerGetLoginComInfoRequest, new ParameterizedTypeReference<>() {
|
|
|
- }, httpHeaders);
|
|
|
+ HttpRequest request = HttpRequest.post(url)
|
|
|
+ .header(httpHeaders)
|
|
|
+ .body(JSON.toJSONString(guoRenCrawlerGetLoginComInfoRequest));
|
|
|
+ HttpResponse httpResponse = request.execute();
|
|
|
+ String body = httpResponse.body();
|
|
|
+
|
|
|
+ List<GuoRenCrawlerGetLoginComInfoResponse> getLoginComInfoResponseList;
|
|
|
+ // 判断返回是数组还是对象(登录失效可能返回对象)
|
|
|
+ if (body.trim().startsWith("[")) {
|
|
|
+ getLoginComInfoResponseList = JSON.parseArray(body, GuoRenCrawlerGetLoginComInfoResponse.class);
|
|
|
+ } else {
|
|
|
+ GuoRenCrawlerBaseResponse<List<GuoRenCrawlerGetLoginComInfoResponse>> response = JSON.parseObject(body, new TypeReference<>() {});
|
|
|
+ // 检查登录失效,返回特殊code码
|
|
|
+ if (response != null && response.getResultCode() == 40301) {
|
|
|
+ throw new TokenExpireException();
|
|
|
+ }
|
|
|
+ getLoginComInfoResponseList = response.getData();
|
|
|
+ }
|
|
|
|
|
|
if (CollectionUtils.isEmpty(getLoginComInfoResponseList)) {
|
|
|
throw new SystemException("归属机构查询失败, 列表为空");
|