|
|
@@ -0,0 +1,309 @@
|
|
|
+package com.jzg.quotation.zhongan.crawler.service;
|
|
|
+
|
|
|
+import com.jzg.quotation.commons.component.RequestComponent;
|
|
|
+import com.jzg.quotation.zhongan.crawler.JsonUtil;
|
|
|
+import com.jzg.quotation.zhongan.crawler.client.ZhongAnAPI;
|
|
|
+import com.jzg.quotation.zhongan.crawler.model.param.ZhongAnCacheCarInfoParam;
|
|
|
+import com.jzg.quotation.zhongan.crawler.model.param.ZhongAnPremiumTrialParamCoverageInfo;
|
|
|
+import com.jzg.quotation.zhongan.crawler.model.param.ZhongAnPremiumTrialParamNonAutoInfo;
|
|
|
+import com.jzg.quotation.zhongan.crawler.model.result.*;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ZhongAnAPIService {
|
|
|
+ @Resource
|
|
|
+ private RequestComponent requestComponent;
|
|
|
+
|
|
|
+ public void setRequestComponent(RequestComponent requestComponent) {
|
|
|
+ this.requestComponent = requestComponent;
|
|
|
+ }
|
|
|
+
|
|
|
+ private <T> T post(ZhongAnAPI api, Object body, Class<T> resultClass, HttpHeaders headers) {
|
|
|
+ String paramString = JsonUtil.toJsonString(body);
|
|
|
+
|
|
|
+ ResponseEntity<String> responseEntity = requestComponent.post(api.url(), paramString, String.class, headers);
|
|
|
+
|
|
|
+ String responseEntityBody = responseEntity.getBody();
|
|
|
+
|
|
|
+ T objcet = JsonUtil.readObjcet(responseEntityBody, resultClass);
|
|
|
+
|
|
|
+ return objcet;
|
|
|
+ }
|
|
|
+
|
|
|
+ private <T> T form(ZhongAnAPI api, MultiValueMap<String, String> formData, Class<T> resultClass, HttpHeaders headers) {
|
|
|
+ ResponseEntity<String> responseEntity = requestComponent.form(api.url(), formData, String.class, headers);
|
|
|
+
|
|
|
+ String responseEntityBody = responseEntity.getBody();
|
|
|
+
|
|
|
+ T objcet = JsonUtil.readObjcet(responseEntityBody, resultClass);
|
|
|
+
|
|
|
+ return objcet;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询保单地址
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ZhongAnQueryCarInfoResult queryCarInfo(String token, String flowId) {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("Cookie", token);
|
|
|
+
|
|
|
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
+ param.set("flowId", flowId);
|
|
|
+ param.set("vehicleFrameNo", "");
|
|
|
+ param.set("passCheck", "");
|
|
|
+ param.set("page", "%2FbaseInfo");
|
|
|
+ param.set("i", "e");
|
|
|
+ param.set("flag", "0");
|
|
|
+
|
|
|
+ ZhongAnQueryCarInfoResult.Response response = form(ZhongAnAPI.QueryCarInfo, param, ZhongAnQueryCarInfoResult.Response.class, headers);
|
|
|
+
|
|
|
+ return response.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 车型查询
|
|
|
+ *
|
|
|
+ * @param token
|
|
|
+ * @param flowId
|
|
|
+ * @param vehicleFrameNo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ZhongAnQueryJyytVehicleModelResult queryJyytVehicleModel(String token, String flowId, String vehicleFrameNo) {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("Cookie", token);
|
|
|
+
|
|
|
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
+ param.set("flowId", flowId);
|
|
|
+ param.set("vehicleFrameNo", vehicleFrameNo);
|
|
|
+ param.set("callVehicleModelLibraryFlag", "0");
|
|
|
+ param.set("vehicleType", "");
|
|
|
+ param.set("page", "/baseInfo");
|
|
|
+ param.set("i", "e");
|
|
|
+ param.set("flag", "0");
|
|
|
+
|
|
|
+ ZhongAnQueryJyytVehicleModelResult.Response response = form(ZhongAnAPI.QueryJyytVehicleModel, param, ZhongAnQueryJyytVehicleModelResult.Response.class, headers);
|
|
|
+
|
|
|
+ return response.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询保单地址
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ZhongAnQueryDocumentInfoResult queryDocumentInfo(String token, String orderNo) {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("Cookie", token);
|
|
|
+
|
|
|
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
+ param.set("orderNo", orderNo);
|
|
|
+
|
|
|
+ ZhongAnQueryDocumentInfoResult.Response response = form(ZhongAnAPI.QueryDocumentInfo, param, ZhongAnQueryDocumentInfoResult.Response.class, headers);
|
|
|
+
|
|
|
+ return response.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ZhongAnQueryPolicyDetailResult queryPolicyDetail(String token, String policyId) {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("Cookie", token);
|
|
|
+
|
|
|
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
+ param.set("policyId", policyId);
|
|
|
+ param.set("appSource", "h5");
|
|
|
+// param.set("page", "%2FpolicyDetail");
|
|
|
+// param.set("flag", "0");
|
|
|
+
|
|
|
+ ZhongAnQueryPolicyDetailResult.Response response = form(ZhongAnAPI.QueryPolicyDetail, param, ZhongAnQueryPolicyDetailResult.Response.class, headers);
|
|
|
+
|
|
|
+ return response.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询保单列表
|
|
|
+ *
|
|
|
+ * @param token
|
|
|
+ * @param flowId
|
|
|
+ * @param status 4:待处理。 2:待支付。 1:已支付
|
|
|
+ * @param chepaihao
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ZhongAnQueryPolicyListResult queryPolicyList(String token, String flowId, String status, String chepaihao) {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("Cookie", token);
|
|
|
+
|
|
|
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
+ param.set("flowId", flowId);
|
|
|
+ param.set("pageIndex", "1");
|
|
|
+ param.set("queryType", "1");
|
|
|
+ param.set("page", "%2Forder%2FmyOrders");
|
|
|
+ param.set("i", " e");
|
|
|
+ param.set("flag", "0");
|
|
|
+ param.set("queryConditon", chepaihao);
|
|
|
+ param.set("status", status);
|
|
|
+
|
|
|
+ ZhongAnQueryPolicyListResult.Response response = form(ZhongAnAPI.QueryPolicyList, param, ZhongAnQueryPolicyListResult.Response.class, headers);
|
|
|
+
|
|
|
+ return response.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 报价
|
|
|
+ * @param token
|
|
|
+ * @param flowId
|
|
|
+ * @param coverageInfo
|
|
|
+ * @param nonAutoInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ZhongAnPremiumTrialResult premiumTrial(String token, String flowId, List<ZhongAnPremiumTrialParamCoverageInfo> coverageInfo, List<ZhongAnPremiumTrialParamNonAutoInfo> nonAutoInfo) {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("Cookie", token);
|
|
|
+
|
|
|
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
+ param.set("flowId", flowId);
|
|
|
+ param.set("page", "/insureProgram");
|
|
|
+ param.set("i", " e");
|
|
|
+ param.set("flag", "0");
|
|
|
+
|
|
|
+ if (coverageInfo != null && coverageInfo.size() > 0) {
|
|
|
+ String jsonString = JsonUtil.toJsonString(coverageInfo);
|
|
|
+ param.set("coverageInfo", jsonString);
|
|
|
+ param.set("addBusi", "1");
|
|
|
+ }
|
|
|
+
|
|
|
+ param.set("addCompel", "0");
|
|
|
+ param.set("addTax", "0");
|
|
|
+ param.set("isTrusted", "true");
|
|
|
+ param.set("effectiveDate", "2025-05-15");
|
|
|
+
|
|
|
+ if (nonAutoInfo != null && nonAutoInfo.size() > 0) {
|
|
|
+ String jsonString = JsonUtil.toJsonString(nonAutoInfo);
|
|
|
+ param.set("nonAutoInfo", jsonString);
|
|
|
+ }
|
|
|
+
|
|
|
+ ZhongAnPremiumTrialResult.Response response = form(ZhongAnAPI.PremiumTrial, param, ZhongAnPremiumTrialResult.Response.class, headers);
|
|
|
+
|
|
|
+ return response.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发起创建保险单
|
|
|
+ *
|
|
|
+ * @param token
|
|
|
+ * @param flowId
|
|
|
+ * @param zhongAnCacheInputQueryParam
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ZhongAnCacheInputQueryResult cacheInputQuery(String token, String flowId, ZhongAnCacheInputQueryParam zhongAnCacheInputQueryParam) {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("Cookie", token);
|
|
|
+
|
|
|
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
+ param.add("insurePlaceCode", zhongAnCacheInputQueryParam.getInsurePlaceCode());
|
|
|
+ param.add("insurePlace", zhongAnCacheInputQueryParam.getInsurePlace());
|
|
|
+ param.add("thirdOrgCode", zhongAnCacheInputQueryParam.getThirdOrgCode());
|
|
|
+ param.add("licenseNo", zhongAnCacheInputQueryParam.getLicenseNo());
|
|
|
+ param.add("branchCode", zhongAnCacheInputQueryParam.getBranchCode());
|
|
|
+ param.add("isOpenRenewalFlag", zhongAnCacheInputQueryParam.getIsOpenRenewalFlag());
|
|
|
+ param.add("flowId", flowId);
|
|
|
+ param.add("page", "%2FinsureEntry");
|
|
|
+ param.add("i", "e");
|
|
|
+ param.add("flag", "0");
|
|
|
+
|
|
|
+ ZhongAnCacheInputQueryResult.Response response = form(ZhongAnAPI.CacheInputQuery, param, ZhongAnCacheInputQueryResult.Response.class, headers);
|
|
|
+
|
|
|
+ return response.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将保单数据缓存起来
|
|
|
+ *
|
|
|
+ * 使用注意:此接口可能不支持并发!
|
|
|
+ * 目前观察到的一次登录会话中, cacheCarInfo 保存的数据是全局共享的,不具备数据隔离性:
|
|
|
+ * 1、会被后续的报价接口 {@link #premiumTrial}、 {@link #queryCarInfo} 使用到。
|
|
|
+ * 2、如果同时对多个车信息保存并报价,最后一次保存的车数据会将之前的其它车的数据覆盖,最终导致 premiumTrial 只会对最后一个车进行报价。
|
|
|
+ * 3、也可能与 flowId 有关系,可以测试一下 flowId 不一样的情况
|
|
|
+ *
|
|
|
+ * @param token
|
|
|
+ * @param zhongAnCacheCarInfoParam
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ZhongAnCacheCarInfoResult cacheCarInfo(String token, ZhongAnCacheCarInfoParam zhongAnCacheCarInfoParam) {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.add("Cookie", token);
|
|
|
+
|
|
|
+ MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
|
|
|
+ param.add("insurePlaceCode", zhongAnCacheCarInfoParam.getInsurePlaceCode());
|
|
|
+ param.add("insurePlace", zhongAnCacheCarInfoParam.getInsurePlace());
|
|
|
+ param.add("thirdOrgCode", zhongAnCacheCarInfoParam.getThirdOrgCode());
|
|
|
+ param.add("vehicleLicencePlateNo", zhongAnCacheCarInfoParam.getVehicleLicencePlateNo());
|
|
|
+ param.add("vehicleFrameNo", zhongAnCacheCarInfoParam.getVehicleFrameNo());
|
|
|
+ param.add("vehicleEngineNo", zhongAnCacheCarInfoParam.getVehicleEngineNo());
|
|
|
+ param.add("vehicleRegisterDate", zhongAnCacheCarInfoParam.getVehicleRegisterDate());
|
|
|
+ param.add("vehicleClass", zhongAnCacheCarInfoParam.getVehicleClass());
|
|
|
+ param.add("vehicleTypeSubclass", zhongAnCacheCarInfoParam.getVehicleTypeSubclass());
|
|
|
+ param.add("paVehicleType", zhongAnCacheCarInfoParam.getPaVehicleType());
|
|
|
+ param.add("vehicleOwnerName", zhongAnCacheCarInfoParam.getVehicleOwnerName());
|
|
|
+ param.add("identifyType", zhongAnCacheCarInfoParam.getIdentifyType());
|
|
|
+ param.add("identifyNo", zhongAnCacheCarInfoParam.getIdentifyNo());
|
|
|
+ param.add("saleCompanyName", zhongAnCacheCarInfoParam.getSaleCompanyName());
|
|
|
+ param.add("sale4SFlag", zhongAnCacheCarInfoParam.getSale4SFlag());
|
|
|
+ param.add("saleCompanyAreaCode", zhongAnCacheCarInfoParam.getSaleCompanyAreaCode());
|
|
|
+ param.add("phone", zhongAnCacheCarInfoParam.getPhone());
|
|
|
+ param.add("applicantName", zhongAnCacheCarInfoParam.getApplicantName());
|
|
|
+ param.add("applicantPhone", zhongAnCacheCarInfoParam.getApplicantPhone());
|
|
|
+ param.add("applicantCertificateNo", zhongAnCacheCarInfoParam.getApplicantCertificateNo());
|
|
|
+ param.add("desVehicleFrameNo", zhongAnCacheCarInfoParam.getDesVehicleFrameNo());
|
|
|
+ param.add("desVehicleEngineNo", zhongAnCacheCarInfoParam.getDesVehicleEngineNo());
|
|
|
+ param.add("modelName", zhongAnCacheCarInfoParam.getModelName());
|
|
|
+ param.add("brandCode", zhongAnCacheCarInfoParam.getBrandCode());
|
|
|
+ param.add("vehicleName", zhongAnCacheCarInfoParam.getVehicleName());
|
|
|
+ param.add("vehicleBrand", zhongAnCacheCarInfoParam.getVehicleBrand());
|
|
|
+ param.add("vehicleModelDesc", zhongAnCacheCarInfoParam.getVehicleModelDesc());
|
|
|
+ param.add("vehicleModelName", zhongAnCacheCarInfoParam.getVehicleModelName());
|
|
|
+ param.add("vehicleModelCode", zhongAnCacheCarInfoParam.getVehicleModelCode());
|
|
|
+ param.add("modelsJy", zhongAnCacheCarInfoParam.getModelsJy());
|
|
|
+ param.add("vehicleCap", zhongAnCacheCarInfoParam.getVehicleCap());
|
|
|
+ param.add("curbWeight", zhongAnCacheCarInfoParam.getCurbWeight());
|
|
|
+ param.add("exhaustMeasure", zhongAnCacheCarInfoParam.getExhaustMeasure());
|
|
|
+ param.add("power", zhongAnCacheCarInfoParam.getPower());
|
|
|
+ param.add("creator", zhongAnCacheCarInfoParam.getCreator());
|
|
|
+ param.add("vehicleAcquisitionPrice", zhongAnCacheCarInfoParam.getVehicleAcquisitionPrice());
|
|
|
+ param.add("vehiclePassengerCap", zhongAnCacheCarInfoParam.getVehiclePassengerCap());
|
|
|
+ param.add("gearBoxType", zhongAnCacheCarInfoParam.getGearBoxType());
|
|
|
+ param.add("configName", zhongAnCacheCarInfoParam.getConfigName());
|
|
|
+ param.add("taxType", zhongAnCacheCarInfoParam.getTaxType());
|
|
|
+ param.add("syxClassid", zhongAnCacheCarInfoParam.getSyxClassid());
|
|
|
+ param.add("vehicleType", zhongAnCacheCarInfoParam.getVehicleType());
|
|
|
+ param.add("modelEnergyType", zhongAnCacheCarInfoParam.getModelEnergyType());
|
|
|
+ param.add("fuelType", zhongAnCacheCarInfoParam.getFuelType());
|
|
|
+ param.add("desVehicleOwnerName", zhongAnCacheCarInfoParam.getDesVehicleOwnerName());
|
|
|
+ param.add("applicantType", zhongAnCacheCarInfoParam.getApplicantType());
|
|
|
+ param.add("applicantUseAttribute", zhongAnCacheCarInfoParam.getApplicantUseAttribute());
|
|
|
+ param.add("useAttribute", zhongAnCacheCarInfoParam.getUseAttribute());
|
|
|
+ param.add("subOwnershipAttribute", zhongAnCacheCarInfoParam.getSubOwnershipAttribute());
|
|
|
+ param.add("ownershipAttribute", zhongAnCacheCarInfoParam.getOwnershipAttribute());
|
|
|
+ param.add("vehicleLicenceType", zhongAnCacheCarInfoParam.getVehicleLicenceType());
|
|
|
+ param.add("callVehicleModelLibraryFlag", zhongAnCacheCarInfoParam.getCallVehicleModelLibraryFlag());
|
|
|
+ param.add("flowId", zhongAnCacheCarInfoParam.getFlowId());
|
|
|
+ param.add("page", zhongAnCacheCarInfoParam.getPage());
|
|
|
+ param.add("i", zhongAnCacheCarInfoParam.getI());
|
|
|
+ param.add("flag", zhongAnCacheCarInfoParam.getFlag());
|
|
|
+
|
|
|
+ ZhongAnCacheCarInfoResult.Response response = form(ZhongAnAPI.CacheCarInfo, param, ZhongAnCacheCarInfoResult.Response.class, headers);
|
|
|
+
|
|
|
+ if (response.getErrorCode().equals("")) {
|
|
|
+ return response.getValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new RuntimeException(response.getErrorMsg());
|
|
|
+ }
|
|
|
+}
|