ccj 1 rok temu
rodzic
commit
9c55b18c02

BIN
templates/tmp.pdf


+ 2 - 2
winsea-haixin-platform-backend/src/main/resources/application.yml

@@ -14,7 +14,7 @@ spring:
     serialization:
       write_dates_as_timestamps: false
   profiles:
-    active: test
+    active: prod
   resources:
     static-locations: file:///winsea/static/
   thymeleaf:
@@ -27,7 +27,7 @@ spring:
 #运行环境 1.开发环境 2.测试环境 3.生产环境
 com:
   changyuntong:
-    env: 1
+    env: 3
 
 auth:
   anon-methods:

+ 3 - 3
winsea-haixin-plugin-wangluohuoyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/OrderInfoServiceImpl.java

@@ -1128,7 +1128,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String batchSubmission(OrderInfo orderInfo) throws IOException {
-//        if ("3".equals(ENV)) {
+        if ("3".equals(ENV)) {
             //获取token
             String token = EntityAnalyse.GetJTToken(ENV);
             if (CollectionUtils.isNotEmpty(orderInfo.getOrderInfoList())) {
@@ -1249,8 +1249,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
                 }
             }
             return "ok";
-//        }
-//        return "NG";
+        }
+        return "NG";
     }
 
     /**

+ 88 - 22
winsea-haixin-plugin-wangluohuoyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/util/EntityAnalyse.java

@@ -138,6 +138,63 @@ public class EntityAnalyse {
             image.delete();
         }
     }
+    /**
+     * 批量上传文件
+     *
+     * @param list
+     * @return
+     * @throws IOException
+     */
+    public static String[] uploadImageList(List<File> list, String token, String ENV) throws IOException {
+        String[] dataResult = new String[list.size()];
+        for(int i=0;i<list.size();i++){
+            File image = list.get(i);
+            String url = "";
+            if ("3".equals(ENV)) {
+                url = "http://116.182.4.67:50033/platform/file/uploadImage";
+            } else {
+                url = "http://116.182.4.67:50065/platform/file/uploadImage";
+            }
+            CloseableHttpClient httpClient = HttpClients.createDefault();
+            // 模拟登陆,按实际服务器端要求选用 Post 或 Get 请求方式
+            HttpPost httpPost = new HttpPost(url);
+            // 设置请求头 boundary边界不可重复,重复会导致提交失败
+            String boundary = "-------------------------" + UUID.randomUUID().toString();
+            httpPost.setHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
+            // 创建MultipartEntityBuilder
+            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+            // 设置字符编码
+            builder.setCharset(StandardCharsets.UTF_8);
+            // 模拟浏览器
+            builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
+            // 设置边界
+            builder.setBoundary(boundary);
+            // 设置multipart/form-data流文件
+            builder.addPart("multipartFile", new FileBody(image));
+            // application/octet-stream代表不知道是什么格式的文件
+            builder.addBinaryBody("image", image, ContentType.create("application/octet-stream"), "tmp.jpg");
+            HttpEntity entity = builder.build();
+            httpPost.setEntity(entity);
+            // 设置header信息
+            httpPost.setHeader("token", token);
+            CloseableHttpResponse response = null;
+            try {
+                // 执行请求操作,并拿到结果(同步阻塞)
+                String body = EntityUtils.toString(httpClient.execute(httpPost).getEntity());
+                JSONObject jsonObject = JSONObject.parseObject(body);
+                String result = jsonObject.getString("result");
+                System.out.println("result = " + result);
+                dataResult[i] = result;
+            } catch (Exception e) {
+                throw e;
+            } finally {
+                // 释放链接
+                httpClient.close();
+                image.delete();
+            }
+        }
+        return dataResult;
+    }
 
     /**
      * 上报驾驶员信息
@@ -511,9 +568,9 @@ public class EntityAnalyse {
         params.put("insuranceInformation", insuranceInformation);
 
         params.put("remark", orderInfo.getRemark() != null ? orderInfo.getRemark() : "");
-//        String[] file1 = {EntityAnalyse.uploadImage(EntityAnalyse.urlToPdfFile(new URL(orderInfo.getDriverContractUrl())), orderInfo.getToken(), ENV)};
-//        params.put("file", file1);
-        String[] ownersContractFile = {EntityAnalyse.uploadImage(EntityAnalyse.urlToPdfFile(new URL(orderInfo.getContractUrl())), orderInfo.getToken(), ENV)};
+        String[] file1 = EntityAnalyse.uploadImageList(EntityAnalyse.urlToPdfFile(new URL(orderInfo.getDriverContractUrl())), orderInfo.getToken(), ENV);
+        params.put("file", file1);
+        String[] ownersContractFile = EntityAnalyse.uploadImageList(EntityAnalyse.urlToPdfFile(new URL(orderInfo.getContractUrl())), orderInfo.getToken(), ENV);
         params.put("ownersContractFile", ownersContractFile);
         String[] backDocumentImages = {EntityAnalyse.uploadImage(EntityAnalyse.urlToFile(new URL(orderInfo.getReceiptImg())), orderInfo.getToken(), ENV)};
         params.put("backDocumentImages", backDocumentImages);
@@ -1347,37 +1404,46 @@ public class EntityAnalyse {
      * @param url
      * @return
      */
-    public static File urlToPdfFile(URL url) {
+    public static List<File> urlToPdfFile(URL url) {
         byte[] bytes = getImageFromNetByUrl(url);
         File file = writePDFToDisk(bytes);
+        List<File> list = new ArrayList<>();
         try {
             PDDocument doc = PDDocument.load(file);
             PDFRenderer renderer = new PDFRenderer(doc);
             int pageCount = doc.getNumberOfPages();
-            BufferedImage image = null;
-            for (int i = 0; i < pageCount; i++) {
-                if(i == 0){
-                    image = renderer.renderImageWithDPI(i, 72); // Windows native DPI
+
+            //pdf转图片后分块
+            int number = pageCount/6 + 1;
+            //保存文件标识
+            boolean flag = true;
+            //管局最多上传6张图片
+            for (int i = 0; i < 6; i++) {
+                BufferedImage image = null;
+                for(int j=i*number;j<(i+1)*number;j++){
+                    if(j>=pageCount){
+                        flag = false;
+                        break;
+                    }
+                    if(j == 0){
+                        image = renderer.renderImageWithDPI(j, 72);
+                    }
+                    else{
+                        BufferedImage tmpImage = renderer.renderImageWithDPI(j, 72);
+                        image = mergeImage(image,tmpImage,true,true,true,0,null);
+                    }
                 }
-                else{
-                    BufferedImage tmpImage = renderer.renderImageWithDPI(i, 72);
-                    image = mergeImage(image,tmpImage,false,true,true,0,null);
+                if(flag){
+                    file = new File("templates" + File.separator + "tmpPdf"+i+".png");
+                    ImageIO.write(image, "png", file);
+                    list.add(file);
                 }
-                // BufferedImage srcImage = resize(image, 240, 240);//产生缩略图
             }
-            file = new File("templates" + File.separator + "tmpPdf.png");
-            ImageIO.write(image, "png", file);
-//            Thumbnails.of(file) //原图片
-//                    .scale(0.4) //分辨率比例
-//                    .outputQuality(1) //图片质量
-//                    .outputFormat("JPEG") //目标文件格式
-//                    .toFile(file); //目标图片
+
         } catch (IOException e) {
             e.printStackTrace();
         }
-//        bytes = ImgCompressUtil.compressPicForScale(getImageStream(file),2000);
-//        file = readBin2Image(bytes,file);
-        return file;
+        return list;
     }
     public static byte[] getImageStream(File file) {
         byte[] buffer = null;