Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master'

yzc 2 жил өмнө
parent
commit
23da6eef08

+ 35 - 12
bladex-saas-project/saas-business-tradeerp/src/main/java/com/fjhx/prove/controller/BillProvePdfController.java

@@ -1,26 +1,21 @@
 package com.fjhx.prove.controller;
 
+import cn.hutool.core.io.IoUtil;
 import com.fjhx.prove.entity.BillProve;
 import com.fjhx.prove.entity.BillProvePdfData;
-import com.fjhx.prove.pdf.service.IAfterSaleConfirmPdfService;
-import com.fjhx.prove.pdf.service.IBillProvePdfDataService;
-import com.fjhx.prove.pdf.service.ICIPdfService;
-import com.fjhx.prove.pdf.service.ICommercialInvoicePdfService;
-import com.fjhx.prove.pdf.service.ICustomsDeclareService;
-import com.fjhx.prove.pdf.service.IPIPdfService;
-import com.fjhx.prove.pdf.service.IPackingBillPdfService;
-import com.fjhx.prove.pdf.service.IProxyCustomsPowerAttorneyService;
+import com.fjhx.prove.pdf.service.*;
 import com.fjhx.prove.service.IBillProvePdfService;
 import org.springblade.common.constant.ApiConstant;
 import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.tool.api.R;
 import org.springblade.system.attachment.entity.Attachment;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 /**
@@ -57,6 +52,9 @@ public class BillProvePdfController extends BladeController {
     @Autowired
     private IBillProvePdfDataService iBillProvePdfDataService;
 
+    @Autowired
+    private HttpServletResponse response;
+
     /**
      * 生成单证所有pdf
      *
@@ -155,6 +153,31 @@ public class BillProvePdfController extends BladeController {
     }
 
     /**
+     * 报关单 pdf
+     *
+     * @param billProve
+     * @return
+     */
+    @GetMapping("/customsDeclarePdf")
+    public void customsDeclarePdf(BillProve billProve) {
+        ServletOutputStream outputStream = null;
+        try {
+            response.setContentType("application/pdf");
+            response.setHeader("Content-Disposition", "inline; filename=预览文件.pdf");
+            outputStream = response.getOutputStream();
+            iCustomsDeclareService.customsDeclarePdf(billProve.getId(), outputStream);
+        } catch (Exception e) {
+            try {
+                outputStream.write("生成报关单失败".getBytes(StandardCharsets.UTF_8));
+            } catch (IOException ex) {
+                throw new RuntimeException(ex);
+            }
+        } finally {
+            IoUtil.close(outputStream);
+        }
+    }
+
+    /**
      * 报关单pdf数据详情
      *
      * @param entity

+ 5 - 0
bladex-saas-project/saas-business-tradeerp/src/main/java/com/fjhx/prove/pdf/service/ICustomsDeclareService.java

@@ -3,6 +3,8 @@ package com.fjhx.prove.pdf.service;
 import com.fjhx.prove.entity.BillProvePdfData;
 import org.springblade.system.attachment.entity.Attachment;
 
+import javax.servlet.ServletOutputStream;
+
 /**
  * 报关单 pdf
  */
@@ -24,4 +26,7 @@ public interface ICustomsDeclareService {
      * @return
      */
     BillProvePdfData dataDetails(String billProveId, boolean isLineFeed);
+
+    void customsDeclarePdf(String id, ServletOutputStream outputStream) throws Exception;
+
 }

+ 22 - 0
bladex-saas-project/saas-business-tradeerp/src/main/java/com/fjhx/prove/pdf/service/impl/CustomsDeclareServiceImpl.java

@@ -31,6 +31,7 @@ import org.springblade.system.attachment.entity.Attachment;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.ServletOutputStream;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -438,4 +439,25 @@ public class CustomsDeclareServiceImpl implements ICustomsDeclareService {
 
         return pdfData;
     }
+
+    @Override
+    public void customsDeclarePdf(String proveId, ServletOutputStream outputStream) throws Exception {
+        Map variablesMap = new HashMap();
+        // 获取参数
+        BillProvePdfData pdfData = dataDetails(proveId, true);
+        JSONObject content = JSONObject.parseObject(pdfData.getContent());
+        for (Map.Entry<String, Object> entry : content.entrySet()) {
+            variablesMap.put(entry.getKey(), entry.getValue());
+        }
+
+        // 生成pdf
+        String temp = template_name + "_" + AuthUtil.getTenantId();
+        // 判断租户定制模板是否存在,如果不存在使用默认模板
+        boolean b = ThymeleafPdfUtil.existTemplate(temp);
+        if (!b) {
+            temp = template_name;
+        }
+        ThymeleafPdfUtil.generate(temp, variablesMap, outputStream);
+    }
+
 }

+ 1 - 1
bladex-saas-project/saas-business-tradeerp/src/main/java/com/fjhx/utils/CodeEnum.java

@@ -15,7 +15,7 @@ public enum CodeEnum {
 
     // 供应商
     SERVICE_CONTRACT("S", null, "code", 5, ServiceContractService.class),
-    PRODUCT("P", null, "code", 5, IProductService.class),
+    PRODUCT("PRO-", null, "code", 5, IProductService.class),
     ;
 
     CodeEnum(String prefix, String dateFormat, String codeFieldName, Integer length, Class<? extends IService<?>> serviceCls) {

+ 5 - 3
bladex/blade-common/src/main/java/org/springblade/common/utils/pdf/ThymeleafPdfUtil.java

@@ -3,6 +3,7 @@ package org.springblade.common.utils.pdf;
 import cn.hutool.core.io.IoUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.lowagie.text.pdf.BaseFont;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -31,6 +32,7 @@ import java.util.Optional;
 /**
  * 使用Thymeleaf模板生成pdf
  */
+@Slf4j
 public class ThymeleafPdfUtil {
     // 存放字体路径
     private static final HashSet<String> fontPaths = new HashSet<>();
@@ -139,7 +141,7 @@ public class ThymeleafPdfUtil {
      */
     private static void getFontPaths() {
         try {
-            System.err.println(JSONObject.toJSONString(fontPaths));
+            log.error("加载pdf字体路径:{}", JSONObject.toJSONString(fontPaths));
             if (CollectionUtils.isEmpty(fontPaths)) {
                 //当前运行环境
                 String activeProfile = environment.getActiveProfiles()[0];
@@ -184,15 +186,15 @@ public class ThymeleafPdfUtil {
      */
     private static void readLinuxPdfFont() {
         try {
-            System.err.println(JSONObject.toJSONString(fontPaths));
             if (CollectionUtils.isEmpty(fontPaths)) {
                 // 读取配置
                 String fontPath = environment.getProperty("blade.pdf.fontpath");
+                log.error("fontPath = {}", fontPath);
                 if (StringUtils.isBlank(fontPath)) {
                     return;
                 }
                 getFiles(fontPath);
-                System.err.println("加载到字体路径==" + JSONObject.toJSONString(fontPaths));
+                log.error("加载到字体路径:" + JSONObject.toJSONString(fontPaths));
             }
         } catch (Exception e) {
             e.printStackTrace();