|
@@ -5,6 +5,7 @@ import cn.start.tz.framework.common.pojo.CommonResult;
|
|
|
import cn.start.tz.module.grape.city.api.GrapeCityApi;
|
|
import cn.start.tz.module.grape.city.api.GrapeCityApi;
|
|
|
import cn.start.tz.module.infra.api.file.FileApi;
|
|
import cn.start.tz.module.infra.api.file.FileApi;
|
|
|
import cn.start.tz.module.pressure2.service.standardfile.StandardClassService;
|
|
import cn.start.tz.module.pressure2.service.standardfile.StandardClassService;
|
|
|
|
|
+import cn.start.tz.module.pressure2.util.PdfMergeUtils;
|
|
|
import cn.start.tz.module.pressure2.util.WordToPdfUtils;
|
|
import cn.start.tz.module.pressure2.util.WordToPdfUtils;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.grapecity.documents.excel.*;
|
|
import com.grapecity.documents.excel.*;
|
|
@@ -23,6 +24,8 @@ import java.io.ByteArrayOutputStream;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
|
+import java.util.concurrent.CompletionException;
|
|
|
|
|
|
|
|
import cn.start.tz.framework.common.pojo.PageParam;
|
|
import cn.start.tz.framework.common.pojo.PageParam;
|
|
|
import cn.start.tz.framework.common.pojo.PageResult;
|
|
import cn.start.tz.framework.common.pojo.PageResult;
|
|
@@ -137,40 +140,28 @@ public class StandardFileController {
|
|
|
public void getPDFByInspection(@RequestParam(value = "file", required = true) MultipartFile file,@RequestParam(value = "manualUrl") String manualUrl,
|
|
public void getPDFByInspection(@RequestParam(value = "file", required = true) MultipartFile file,@RequestParam(value = "manualUrl") String manualUrl,
|
|
|
HttpServletResponse response) throws Exception {
|
|
HttpServletResponse response) throws Exception {
|
|
|
|
|
|
|
|
- // 调用另一个服务的 PDF 转换接口
|
|
|
|
|
- String targetUrl = grapecityUrl+
|
|
|
|
|
- "/pdf/getPdf";
|
|
|
|
|
byte[] fileBytes = file.getBytes();
|
|
byte[] fileBytes = file.getBytes();
|
|
|
- List<byte[]> pdfBytesList = new ArrayList<>();
|
|
|
|
|
- pdfBytesList.add(fileBytes);
|
|
|
|
|
- // 发送 POST 请求获取 PDF 字节流
|
|
|
|
|
- byte[] bytes = HttpUtil.createPost(targetUrl)
|
|
|
|
|
- .body(JSONObject.toJSONString(pdfBytesList)).execute().bodyBytes();
|
|
|
|
|
-
|
|
|
|
|
- if (StringUtils.isNotEmpty(manualUrl)){
|
|
|
|
|
-
|
|
|
|
|
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
|
|
- if (manualUrl.endsWith(".doc") || manualUrl.endsWith(".docx")) {
|
|
|
|
|
- byte[] wordBytes = fileApi.getFileByPath(manualUrl).getData();
|
|
|
|
|
- byteArrayOutputStream = WordToPdfUtils.doc2pdfOutStream(wordBytes);
|
|
|
|
|
- } else {
|
|
|
|
|
- byte[] bytes1 = fileApi.getFileByPath(manualUrl).getData();
|
|
|
|
|
- byteArrayOutputStream.write(bytes1);
|
|
|
|
|
|
|
+ // 主模板PDF转换与说明书PDF获取相互独立,并行处理以提升速度
|
|
|
|
|
+ CompletableFuture<byte[]> mainPdfFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String targetUrl = grapecityUrl + "/pdf/getPdf";
|
|
|
|
|
+ List<byte[]> pdfBytesList = new ArrayList<>();
|
|
|
|
|
+ pdfBytesList.add(fileBytes);
|
|
|
|
|
+ return HttpUtil.createPost(targetUrl)
|
|
|
|
|
+ .body(JSONObject.toJSONString(pdfBytesList)).execute().bodyBytes();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new CompletionException(e);
|
|
|
}
|
|
}
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- ByteArrayOutputStream mergeOutputStream = new ByteArrayOutputStream();
|
|
|
|
|
- PDFMergerUtility mergerUtility = new PDFMergerUtility();
|
|
|
|
|
- mergerUtility.addSource(new ByteArrayInputStream(bytes));
|
|
|
|
|
- mergerUtility.addSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
|
|
|
|
|
- // pdf 文件流合并
|
|
|
|
|
- mergerUtility.setDestinationStream(mergeOutputStream);
|
|
|
|
|
- mergerUtility.mergeDocuments(null);
|
|
|
|
|
|
|
+ // 等待模板 PDF 生成完成
|
|
|
|
|
+ byte[] mainPdfBytes = mainPdfFuture.get();
|
|
|
|
|
|
|
|
- response.getOutputStream().write(mergeOutputStream.toByteArray());
|
|
|
|
|
- }else{
|
|
|
|
|
- response.getOutputStream().write(bytes);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 使用公用方法合并附件并添加分割线
|
|
|
|
|
+ byte[] finalPdfBytes = PdfMergeUtils.buildInspectionPlanPdf(mainPdfBytes, manualUrl, fileApi);
|
|
|
|
|
+
|
|
|
|
|
+ response.getOutputStream().write(finalPdfBytes);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|