ソースを参照

1. 永诚处理车险保单文件名。

ligang134 3 年 前
コミット
7be3a45605

+ 39 - 8
src/main/java/com/ydtech/modules/ins/service/impl/InsAlltrustApiServiceImpl.java

@@ -23,6 +23,7 @@ import com.ydtech.modules.esm.model.*;
 import com.ydtech.modules.esm.service.*;
 import com.ydtech.modules.esm.service.*;
 import com.ydtech.modules.ins.dao.InsAlltrustRegionMapper;
 import com.ydtech.modules.ins.dao.InsAlltrustRegionMapper;
 import com.ydtech.modules.ins.model.InsApiLog;
 import com.ydtech.modules.ins.model.InsApiLog;
+import com.ydtech.modules.ins.model.InsOrder;
 import com.ydtech.modules.ins.model.vo.CarInfoVo;
 import com.ydtech.modules.ins.model.vo.CarInfoVo;
 import com.ydtech.modules.ins.model.vo.CustomerInfoVo;
 import com.ydtech.modules.ins.model.vo.CustomerInfoVo;
 import com.ydtech.modules.ins.model.vo.QuoteRespVo;
 import com.ydtech.modules.ins.model.vo.QuoteRespVo;
@@ -56,11 +57,14 @@ import com.ydtech.modules.order.entity.InsOrders;
 import com.ydtech.modules.order.entity.vo.*;
 import com.ydtech.modules.order.entity.vo.*;
 import com.ydtech.modules.order.service.InsAreaCompanyService;
 import com.ydtech.modules.order.service.InsAreaCompanyService;
 import com.ydtech.modules.order.service.InsOrdersService;
 import com.ydtech.modules.order.service.InsOrdersService;
+import com.ydtech.modules.protocol.utils.AssertionUtils;
 import com.ydtech.utils.*;
 import com.ydtech.utils.*;
+import com.ydtech.utils.baidu.FileUtil;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
@@ -98,6 +102,13 @@ public class InsAlltrustApiServiceImpl implements InsAlltrustApiService {
     List<String> requestInfoList = new ArrayList<>();
     List<String> requestInfoList = new ArrayList<>();
 
 
 
 
+    @Value("${upload.file.path}")
+    private String uploadFilePath;
+
+    @Value("${upload.file.url}")
+    private String showFileUrl;
+
+
     @Autowired
     @Autowired
     private YcBuildData ycBuildData;
     private YcBuildData ycBuildData;
     @Autowired
     @Autowired
@@ -885,10 +896,8 @@ public class InsAlltrustApiServiceImpl implements InsAlltrustApiService {
         HttpResult httpResult = new HttpResult();
         HttpResult httpResult = new HttpResult();
         try {
         try {
             InsAreaCompany iac = insAreaCompanyService.getById(policyPrintVo.getCompanyId());
             InsAreaCompany iac = insAreaCompanyService.getById(policyPrintVo.getCompanyId());
-//            InsOrder order = insOrderService.selectByPk(orderno);
-            if (iac == null) {
-                return HttpResult.error("报价订单不存在");
-            }
+            AssertionUtils.isEmpty(iac,"报价订单不存在");
+            InsOrders order = insOrdersService.getById(iac.getOrderno());
 
 
             // 获取协议配置信息
             // 获取协议配置信息
             YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId());
             YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId());
@@ -913,15 +922,25 @@ public class InsAlltrustApiServiceImpl implements InsAlltrustApiService {
 
 
             if (pResp.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) {
             if (pResp.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) {
                 Map m = new HashMap();
                 Map m = new HashMap();
+
+                String bzInsUrl = StringUtils.isNotEmpty(pResp.getPolicyBZUrl())?pResp.getPolicyBZUrl().replaceAll(";pkid", "&pkid"):"";
+                String licensePlate = order.getLicenseno();
+                String jqFlagUrl = gainCarInsPolicy(bzInsUrl,licensePlate + "-交强险标志.pdf");
                 if (policyPrintVo.getType().equals("1")) {
                 if (policyPrintVo.getType().equals("1")) {
-                    m.put("jqFlagUrl", pResp.getPolicyBZUrl());
+                    m.put("jqFlagUrl", jqFlagUrl);
                     m.put("jqUrl", "");
                     m.put("jqUrl", "");
                     m.put("syUrl", "");
                     m.put("syUrl", "");
                 }
                 }
                 if (policyPrintVo.getType().equals("2")) {
                 if (policyPrintVo.getType().equals("2")) {
-                    m.put("jqFlagUrl", pResp.getPolicyBZUrl().replaceAll(";pkid", "&pkid"));
-                    m.put("jqUrl", pResp.getJqpolicyUrl().replaceAll(";pkid", "&pkid"));
-                    m.put("syUrl", pResp.getSypolicyUrl().replaceAll(";pkid", "&pkid"));
+                    String jqInsUrl = StringUtils.isNotEmpty(pResp.getJqpolicyUrl())?pResp.getJqpolicyUrl().replaceAll(";pkid", "&pkid"):"";
+                    String syInsUrl = StringUtils.isNotEmpty(pResp.getSypolicyUrl())?pResp.getSypolicyUrl().replaceAll(";pkid", "&pkid"):"";
+
+                    String jqUrl = gainCarInsPolicy(jqInsUrl,licensePlate + "-交强险保单.pdf");
+                    String syUrl = gainCarInsPolicy(syInsUrl,licensePlate + "-商业险保单.pdf");
+
+                    m.put("jqFlagUrl", jqFlagUrl);
+                    m.put("jqUrl", jqUrl);
+                    m.put("syUrl", syUrl);
 
 
                 }
                 }
 //                httpResult.setData(m);
 //                httpResult.setData(m);
@@ -1971,4 +1990,16 @@ public class InsAlltrustApiServiceImpl implements InsAlltrustApiService {
     }
     }
 
 
 
 
+    /**
+     *  获取车险保单
+     *
+     * @author: lig
+     * @date: 2023年09月21日 0021
+     */
+    public String gainCarInsPolicy(String url,String fileName){
+        String dir = "carInsPolicy/";
+        return FileUtil.netUrlToFile(url,dir,fileName,uploadFilePath,showFileUrl);
+    }
+
+
 }
 }

+ 68 - 2
src/main/java/com/ydtech/utils/baidu/FileUtil.java

@@ -1,6 +1,10 @@
 package com.ydtech.utils.baidu;
 package com.ydtech.utils.baidu;
 
 
+import com.ydtech.utils.StringUtils;
+
 import java.io.*;
 import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URI;
 
 
 /**
 /**
  * 文件读取工具类
  * 文件读取工具类
@@ -21,11 +25,11 @@ public class FileUtil {
         }
         }
 
 
         StringBuilder sb = new StringBuilder((int) (file.length()));
         StringBuilder sb = new StringBuilder((int) (file.length()));
-        // 创建字节输入流  
+        // 创建字节输入流
         FileInputStream fis = new FileInputStream(filePath);
         FileInputStream fis = new FileInputStream(filePath);
         // 创建一个长度为10240的Buffer
         // 创建一个长度为10240的Buffer
         byte[] bbuf = new byte[10240];
         byte[] bbuf = new byte[10240];
-        // 用于保存实际读取的字节数  
+        // 用于保存实际读取的字节数
         int hasRead = 0;
         int hasRead = 0;
         while ((hasRead = fis.read(bbuf)) > 0) {
         while ((hasRead = fis.read(bbuf)) > 0) {
             sb.append(new String(bbuf, 0, hasRead));
             sb.append(new String(bbuf, 0, hasRead));
@@ -69,4 +73,66 @@ public class FileUtil {
             }
             }
         }
         }
     }
     }
+
+
+
+
+    /**
+     *  网络url转文件
+     * @param dir   目录 杠结束  carInsPolicy/
+     *
+     * @author: lig
+     * @date: 2023年09月21日 0021
+     */
+    public static String netUrlToFile(String url, String dir,String fileName,String path,String showUrl) {
+//        String s = "http://eserviceinterface.ciitc.com.cn/ePolicyServices/insurancePolicy.do?downFiles=key&amp&pkid=a7370fea493945868b8ca847d3ef9d9e";
+//        String path = "D:/upload/";
+//        String dir = "carInsPolicy/";
+        if(StringUtils.isEmpty(url)) return "";
+        String showPath = String.format("%s%s%s",showUrl,dir,fileName);
+        String uploadPath = path + dir;
+
+        try {
+
+            File folder = new File(uploadPath);
+            if (!folder.isDirectory()) {
+                folder.mkdirs();
+            }
+
+            URI u = URI.create(url);
+            InputStream inputStream = u.toURL().openStream();
+            File file = new File(uploadPath + fileName);
+            copyInputStreamToFile(inputStream, file);
+
+            System.err.println("文件路径:"+file.getPath());
+            return showPath;
+
+        } catch (MalformedURLException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+
+    // InputStream -> File
+    private static void copyInputStreamToFile(InputStream inputStream, File file)
+            throws IOException {
+
+        try (FileOutputStream outputStream = new FileOutputStream(file)) {
+
+            int read;
+            byte[] bytes = new byte[1024];
+
+            while ((read = inputStream.read(bytes)) != -1) {
+                outputStream.write(bytes, 0, read);
+            }
+
+            // commons-io
+            //IOUtils.copy(inputStream, outputStream);
+
+        }
+
+    }
 }
 }