Sfoglia il codice sorgente

华农保单下载方法修改

wanghao 3 mesi fa
parent
commit
e075c7d764

+ 23 - 2
tenant/insurance/quotation-huanong/src/main/java/com/jzg/quotation/huanong/crawler/component/HuaNongCrawlerRequestComponent.java

@@ -25,9 +25,13 @@ import org.springframework.web.reactive.function.BodyInserters;
 
 import java.io.IOException;
 import java.net.URI;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import static com.jzg.quotation.huanong.crawler.constant.enums.RequestUrl.*;
 
@@ -401,7 +405,14 @@ public class HuaNongCrawlerRequestComponent {
      */
     public String ftpDownload(HuaNongCrawlerFtpDownloadRequestRequest request, HttpHeaders headers) {
         HuaNongCrawlerFtpDownloadResponse response = post(FTP_DOWNLOAD, request, HuaNongCrawlerFtpDownloadResponse.class, headers);
-        return response.getDowloadURL().get(0).getDowloadURL();
+        String fileUrl = response.getDowloadURL().get(0).getDowloadURL();
+        // URL编码 on= 参数值(中文文件名需编码,否则后续下载时报400)
+        Matcher matcher = Pattern.compile("on=(.*?)\\.pdf").matcher(fileUrl);
+        if (matcher.find()) {
+            String matched = matcher.group(1);
+            fileUrl = fileUrl.replace(matched, URLEncoder.encode(matched, StandardCharsets.UTF_8));
+        }
+        return fileUrl;
     }
 
     /**
@@ -414,7 +425,17 @@ public class HuaNongCrawlerRequestComponent {
     public String documentsPrint(HuaNongCrawlerDocumentsPrintRequestRequest request, HttpHeaders headers) {
         HuaNongCrawlerDocumentsPrintResponse response = post(DOCUMENTS_PRINT, request, HuaNongCrawlerDocumentsPrintResponse.class, headers);
         String fileUrl = response.getFileUrl();
-        return fileUrl.replace(properties.getDocumentsPrintUrl(), properties.getFtpDownloadUrl());
+        return fileUrl;
+    }
+
+    /**
+     * CI交强险 DocumentsPrint 前置调用(与Python一致,下载交强保单前需先调用)
+     *
+     * @param request 交强险DocumentsPrint请求
+     * @param headers 请求头
+     */
+    public void documentsPrintForCi(HuaNongCrawlerDocumentsPrintRequestRequest request, HttpHeaders headers) {
+        post(DOCUMENTS_PRINT, request, HuaNongCrawlerDocumentsPrintResponse.class, headers);
     }
 
     /**

+ 7 - 0
tenant/insurance/quotation-huanong/src/main/java/com/jzg/quotation/huanong/crawler/constant/enums/JiaYiXianProduct.java

@@ -44,6 +44,13 @@ public enum JiaYiXianProduct {
             new CoverageConfig("F27047-5", "附加辅助金保险条款", "0094", "家庭辅助金", 0.02, "10", "20000", "2.0万元/座", true),
             new CoverageConfig("F27048-6", "附加救护车车费保险条款", "0095", "救护车费用", 0.1, "10", "2000", "0.2万元/座", true)
     )),
+    ANXIANG_50("091", "好运连连(50)", true, Arrays.asList(
+            new CoverageConfig("Z27096-1", "交通出行团体意外伤害保险C款条款", "0955", "必选责任:意外伤害身故保险责任", 0.06, "30000", "3.0万元/座", " ", false),
+            new CoverageConfig("Z27096-2", "交通出行团体意外伤害保险C款条款", "0956", "可选责任:意外伤害伤残保险责任", 0.04, "30000", "3.0万元/座", " ", false),
+            new CoverageConfig("F27002", "附加团体意外伤害医疗保险条款", "0008", "意外伤害医疗保险责任", 0.24, "1000", "0.1万元/座", "每次事故免赔300后80%比例赔付", false),
+            new CoverageConfig("F27001", "附加团体意外伤害住院津贴保险条款", "0032", "意外伤害住院津贴保险责任", 0.2, "10", "0.001万元/座", "10元/天/座", true)
+
+    )),
     ANXIANG_240("092", "好运连连(240)", true, Arrays.asList(
             new CoverageConfig("Z27096-1", "交通出行团体意外伤害保险C款条款", "0955", "必选责任:意外伤害身故保险责任", 0.06, "30000", "3.0万元/座", " ", false),
             new CoverageConfig("Z27096-2", "交通出行团体意外伤害保险C款条款", "0956", "可选责任:意外伤害伤残保险责任", 0.04, "30000", "3.0万元/座", " ", false),

+ 35 - 1
tenant/insurance/quotation-huanong/src/main/java/com/jzg/quotation/huanong/crawler/entity/request/HuaNongCrawlerDocumentsPrintRequestRequest.java

@@ -79,7 +79,7 @@ public class HuaNongCrawlerDocumentsPrintRequestRequest implements HuaNongHeadRe
         this.printType = "";
         this.returnFlag = "0";
         this.startNo = "";
-        this.visaCode = "";
+        this.visaCode = "BB05550A2019E";
         this.endNo = "";
         this.accountInfo = "";
         this.currency = "RMB";
@@ -91,8 +91,42 @@ public class HuaNongCrawlerDocumentsPrintRequestRequest implements HuaNongHeadRe
         this.ip = "";
         this.visaType = "";
         this.isPreview = "0";
+        this.useNature = "8A";
         this.isMotoDownload = "0";
         this.isImg = 0;
     }
 
+    /**
+     * CI交强险 DocumentsPrint 前置调用构造(与Python hn_bddownload.py get_orderNo 一致)
+     *
+     * @param token         登录token
+     * @param contractNo    交强险保单号
+     * @param username      用户名
+     * @param loginComCode  登录机构代码
+     * @param businessType  业务类型(交强险传 "3")
+     * @param visaCode      签证代码(交强险传 "AB05016A32015A")
+     */
+    public HuaNongCrawlerDocumentsPrintRequestRequest(String token, String contractNo, String username, String loginComCode, String businessType, String visaCode) {
+        this.head = new HuaNongCrawlerRequestBaseHead(token);
+        this.policyType = "1";
+        this.printNoBegin = "";
+        this.printNoEnd = "";
+        this.businessType = businessType;
+        this.contractNo = List.of(contractNo);
+        this.printType = "";
+        this.returnFlag = "0";
+        this.startNo = "";
+        this.visaCode = visaCode;
+        this.endNo = "";
+        this.accountInfo = "";
+        this.currency = "RMB";
+        this.producerCode = "";
+        this.comCode = loginComCode;
+        this.userCode = username;
+        this.loginCom = loginComCode;
+        this.electronicPolicy = false;
+        this.ip = "";
+        this.isPreview = "0";
+    }
+
 }

+ 4 - 3
tenant/insurance/quotation-huanong/src/main/java/com/jzg/quotation/huanong/crawler/entity/request/HuaNongCrawlerFindBusinessesRequestRequest.java

@@ -6,6 +6,7 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import java.io.Serial;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -134,11 +135,11 @@ public class HuaNongCrawlerFindBusinessesRequestRequest implements HuaNongHeadRe
          * 投保单 2
          * 保单 4
          */
-        this.businessType = "2";
+        this.businessType = "4";
         this.policyNo = "";
         this.endorseNo = "";
         this.insuredName = "";
-        this.queryStatus = List.of("0");
+        this.queryStatus = new ArrayList<>();
         this.agreementNo = "";
         this.handlerCode = "";
         this.agentName = "";
@@ -161,7 +162,7 @@ public class HuaNongCrawlerFindBusinessesRequestRequest implements HuaNongHeadRe
                 "0515", "0507", "0520", "0521", "0522", "0523", "0509", "0506", "0510",
                 "0511", "0512", "0513", "2801", "0311", "0301", "1727", "1703", "0109",
                 "2742", "0306", "4001", "2780", "2781", "2784", "2782", "2783", "1980",
-                "1981", "2609", "2785", "2680"
+                "1981", "2609", "2785", "2680","0911"
         );
         this.hasSubFlag = true;
         this.endorType = "";

+ 1 - 0
tenant/insurance/quotation-huanong/src/main/java/com/jzg/quotation/huanong/crawler/entity/request/HuaNongCrawlerFtpDownloadRequestRequest.java

@@ -60,6 +60,7 @@ public class HuaNongCrawlerFtpDownloadRequestRequest implements HuaNongHeadReque
 
         public FtpDowloadListDTO() {
             this.isMotoDownload = "0";
+            this.useNature = "8A";
             this.isVPN = "0";
             this.isBZDown = "0";
             this.isRelate = "0";

+ 4 - 0
tenant/insurance/quotation-huanong/src/main/java/com/jzg/quotation/huanong/crawler/entity/response/HuaNongCrawlerFindBusinessesResponse.java

@@ -53,8 +53,12 @@ public class HuaNongCrawlerFindBusinessesResponse implements HuaNongHeadResponse
         private String comCode;
         @JsonProperty("contractNo1")
         private String contractNo1;
+        @JsonProperty("contractNo2")
+        private String contractNo2;
         @JsonProperty("contractNo3")
         private String contractNo3;
+        @JsonProperty("contractNo4")
+        private String contractNo4;
         @JsonProperty("contractNo5")
         private String contractNo5;
         @JsonProperty("contractNo6")

+ 35 - 8
tenant/insurance/quotation-huanong/src/main/java/com/jzg/quotation/huanong/crawler/service/impl/HuaNongCrawlerRequestImpl.java

@@ -880,37 +880,64 @@ public class HuaNongCrawlerRequestImpl implements HuaNongCrawlerRequest {
         HuaNongCrawlerFtpDownloadRequestRequest huaNongCrawlerFtpDownloadRequest = new HuaNongCrawlerFtpDownloadRequestRequest(loginInfoDto.getToken());
         HuaNongCrawlerFtpDownloadRequestRequest.FtpDowloadListDTO ftpDowloadListDTO = new HuaNongCrawlerFtpDownloadRequestRequest.FtpDowloadListDTO();
         huaNongCrawlerFtpDownloadRequest.setFtpDowloadList(List.of(ftpDowloadListDTO));
+
+        // 投保单号获取保单号
+        String policyNo = StringUtils.hasText(order.getBiPolicyNumber()) ? order.getBiPolicyNumber() : order.getCiPolicyNumber();
+        HuaNongCrawlerFindBusinessesRequestRequest huaNongCrawlerFindBusinessesRequest
+                = new HuaNongCrawlerFindBusinessesRequestRequest(loginInfoDto.getToken(), loginInfoDto.getLoginComCode(), policyNo, order.getRecordingTime());
+        HuaNongCrawlerFindBusinessesResponse businesses = huaNongCrawlerRequestComponent.findBusinesses(huaNongCrawlerFindBusinessesRequest, httpHeaders);
+        // 与Python hn_state.py一致:遍历business按riskCode匹配contractNo字段
+        String ciNo = businesses.getBusiness().get(0).getContractNo6();
+        String biNo = businesses.getBusiness().get(0).getContractNo1();
+
         // 交强保单 标志
-        Optional.ofNullable(order.getCiPolicyNo())
+        Optional.ofNullable(order.getCiPolicyNumber())
                 .filter(s -> !s.isEmpty())
                 .ifPresent(ciPolicyNo -> {
+
+                    // DocumentsPrint 前置调用
+                    HuaNongCrawlerDocumentsPrintRequestRequest ciDocumentsPrintRequest =
+                            new HuaNongCrawlerDocumentsPrintRequestRequest(loginInfoDto.getToken(), ciNo, attributionInformationVo.getUsername(), loginInfoDto.getLoginComCode(), "3", "AB05016A32015A");
+                    huaNongCrawlerRequestComponent.documentsPrintForCi(ciDocumentsPrintRequest, httpHeaders);
+
                     // 交强保单
-                    ftpDowloadListDTO.setBiztype("4");
-                    ftpDowloadListDTO.setBusinessNo(ciPolicyNo);
+                    ftpDowloadListDTO.setBiztype("3");
+                    ftpDowloadListDTO.setBusinessNo(ciNo);
                     ftpDowloadListDTO.setRiskCode(Risk.RISK_0507.getRiskCode());
                     String ciPolicyUrl = huaNongCrawlerRequestComponent.ftpDownload(huaNongCrawlerFtpDownloadRequest, httpHeaders);
                     downloadPolicyResultVo.setJqUrl(ciPolicyUrl);
+                    // 交强险标志
                     ftpDowloadListDTO.setIsBZDown("1");
-                    // 商业标志
                     String ciSignUrl = huaNongCrawlerRequestComponent.ftpDownload(huaNongCrawlerFtpDownloadRequest, httpHeaders);
                     downloadPolicyResultVo.setJqFlagUrl(ciSignUrl);
 
                 });
         // 商业保单
-        Optional.ofNullable(order.getBiPolicyNo())
+        Optional.ofNullable(order.getBiPolicyNumber())
                 .filter(s -> !s.isEmpty())
                 .ifPresent(biPolicyNo -> {
                     // 商业保单
                     ftpDowloadListDTO.setIsBZDown("0");
-                    ftpDowloadListDTO.setBusinessNo(biPolicyNo);
+                    ftpDowloadListDTO.setBiztype("3");
+                    ftpDowloadListDTO.setBusinessNo(biNo);
+                    ftpDowloadListDTO.setRiskCode(Risk.RISK_0515.getRiskCode());
                     String biPolicyUrl = huaNongCrawlerRequestComponent.ftpDownload(huaNongCrawlerFtpDownloadRequest, httpHeaders);
                     downloadPolicyResultVo.setSyUrl(biPolicyUrl);
                 });
 
         // 非车险
         order.getNiInfos().forEach(niInfo -> {
-            Optional.ofNullable(niInfo.getNiPolicyNo()).ifPresent(niPolicyNo -> {
-                HuaNongCrawlerDocumentsPrintRequestRequest huaNongCrawlerDocumentsPrintRequest = new HuaNongCrawlerDocumentsPrintRequestRequest(loginInfoDto.getToken(), niPolicyNo, attributionInformationVo.getUsername(), loginInfoDto.getLoginComCode());
+            Optional.ofNullable(niInfo.getNiPolicyNumber()).ifPresent(niPolicyNo -> {
+                HuaNongCrawlerFindBusinessesRequestRequest niFindBusinessesRequest
+                        = new HuaNongCrawlerFindBusinessesRequestRequest(loginInfoDto.getToken(), loginInfoDto.getLoginComCode(), niPolicyNo, order.getRecordingTime());
+                HuaNongCrawlerFindBusinessesResponse niBusinesses = huaNongCrawlerRequestComponent.findBusinesses(niFindBusinessesRequest, httpHeaders);
+                // 与Python hn_state.py一致:NI(非0507/0510/0515)使用contractNo4
+                String niContractNo = Optional.ofNullable(niBusinesses.getBusiness())
+                        .filter(list -> !list.isEmpty())
+                        .map(list -> list.get(0).getContractNo4())
+                        .orElse(niPolicyNo);
+
+                HuaNongCrawlerDocumentsPrintRequestRequest huaNongCrawlerDocumentsPrintRequest = new HuaNongCrawlerDocumentsPrintRequestRequest(loginInfoDto.getToken(), niContractNo, attributionInformationVo.getUsername(), loginInfoDto.getLoginComCode());
                 String niPolicyUrl = huaNongCrawlerRequestComponent.documentsPrint(huaNongCrawlerDocumentsPrintRequest, httpHeaders);
                 downloadPolicyResultVo.setJyUrl(niPolicyUrl);
             });