From e3f8089c830d5c6e7477090cf447bed65e80be9f Mon Sep 17 00:00:00 2001 From: zhijie <1003392067@qq.com> Date: 星期一, 19 九月 2022 00:38:39 +0800 Subject: [PATCH] 优化导出报告 --- src/main/java/com/ots/project/tool/ShellTool.java | 34 ++++++++++++++++ src/main/java/com/ots/framework/config/ThreadPoolConfig.java | 11 +++-- src/main/java/com/ots/common/utils/poi/WordUtil.java | 22 ++++++---- pom.xml | 28 ++++++++++++++ 4 files changed, 81 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 74c7c23..f82a18e 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,34 @@ <optional>true</optional> <!-- 琛ㄧず渚濊禆涓嶄細浼犻�� --> </dependency> + <!--springboot鏀寔鍖咃紝閲岄潰鍖呮嫭浜嗚嚜鍔ㄩ厤缃被 --> + <dependency> + <groupId>org.jodconverter</groupId> + <artifactId>jodconverter-spring-boot-starter</artifactId> + <version>4.4.2</version> + </dependency> + + <!--jodconverter 鏍稿績鍖� --> + <dependency> + <groupId>org.jodconverter</groupId> + <artifactId>jodconverter-core</artifactId> + <version>4.4.2</version> + </dependency> + + <!--jodconverter 鏈湴鏀寔鍖� --> + <dependency> + <groupId>org.jodconverter</groupId> + <artifactId>jodconverter-local</artifactId> + <version>4.4.2</version> + </dependency> + + <!--springboot鏀寔鍖咃紝閲岄潰鍖呮嫭浜嗚嚜鍔ㄩ厤缃被 --> + <dependency> + <groupId>org.libreoffice</groupId> + <artifactId>ridl</artifactId> + <version>7.2.0</version> + </dependency> + <!-- Mysql椹卞姩鍖� --> <dependency> <groupId>mysql</groupId> diff --git a/src/main/java/com/ots/common/utils/poi/WordUtil.java b/src/main/java/com/ots/common/utils/poi/WordUtil.java index 5407cd4..cbb70c2 100644 --- a/src/main/java/com/ots/common/utils/poi/WordUtil.java +++ b/src/main/java/com/ots/common/utils/poi/WordUtil.java @@ -1163,21 +1163,25 @@ reportType = getTypeIfIsSAQ(tReportTemplate, reportType); reportType = getPositionIfJAQ(textMap, reportType); reportName = textMap.get("sendEmailFileName") + "_" + reportType + "_" + ReportTypeNameEnum.valueOf(tReportTemplate.getTemplateType()).getCode() + "_" + ReportTypeNameEnum.valueOf(tReportTemplate.getLangType()).getCode() + ".docx"; - reportName = reportName.replaceAll(" ", "_"); - out = getDownLoadFileOutputStream(reportName); - log.info("reportTemplate:" + fileName); - //String templateType = tReportTemplate.getTemplateType(); - setChageWord(fileName, out, textMap, tReportTemplate.getReportType(),tReportTemplate.getDataPath(), autoTableMap); - out.flush(); - changColorIfJAQ(textMap, out, reportName, tReportTemplate.getReportType()); + //妯℃澘鏂囦欢闇�瑕佸姞閿� + synchronized (reportName.intern()){ + out = getDownLoadFileOutputStream(reportName); + log.info("reportTemplate:" + fileName); + //String templateType = tReportTemplate.getTemplateType(); + setChageWord(fileName, out, textMap, tReportTemplate.getReportType(),tReportTemplate.getDataPath(), autoTableMap); + out.flush(); + changColorIfJAQ(textMap, out, reportName, tReportTemplate.getReportType()); + } + //PAQ銆丮AQTR閲囩敤鏂扮殑doc杞琾df if(ReportTypeEnum.PAQ.getCode().equals(reportType) || ReportTypeEnum.MAQTR.getCode().equals(reportType)){ PdfUtil.convertPDF(EssConfig.getProfile() + "/" + reportName); }else{ - ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/"); - + //ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/"); + ShellTool shellTool = ShellTool.builder(); + shellTool.execNewLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/" + reportName.replace("docx","pdf")); } zipFilePath = getPdfPath(reportName); diff --git a/src/main/java/com/ots/framework/config/ThreadPoolConfig.java b/src/main/java/com/ots/framework/config/ThreadPoolConfig.java index 4293f31..96e9d59 100644 --- a/src/main/java/com/ots/framework/config/ThreadPoolConfig.java +++ b/src/main/java/com/ots/framework/config/ThreadPoolConfig.java @@ -11,13 +11,14 @@ @Configuration public class ThreadPoolConfig { - private int corePoolSize = 50; + private int corePoolSize = 5; - private int maxPoolSize = 200; + private int maxPoolSize = 20; - private int queueCapacity = 1000; + private int queueCapacity = 100; - private int keepAliveSeconds = 300; + private int keepAliveSeconds = 60; + @Bean(name = "threadPoolTaskExecutor") public ThreadPoolTaskExecutor threadPoolTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); @@ -25,6 +26,8 @@ executor.setCorePoolSize(corePoolSize); executor.setQueueCapacity(queueCapacity); executor.setKeepAliveSeconds(keepAliveSeconds); + //绾跨▼鍓嶇紑鍚嶇О + executor.setThreadNamePrefix("thread-pool-%d"); executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); return executor; diff --git a/src/main/java/com/ots/project/tool/ShellTool.java b/src/main/java/com/ots/project/tool/ShellTool.java index 1e2b8b1..2b4c2c8 100644 --- a/src/main/java/com/ots/project/tool/ShellTool.java +++ b/src/main/java/com/ots/project/tool/ShellTool.java @@ -1,10 +1,35 @@ package com.ots.project.tool; +import com.ots.common.utils.spring.SpringUtils; +import com.ots.common.utils.text.CharsetKit; import lombok.extern.slf4j.Slf4j; +import org.jodconverter.core.DocumentConverter; +import org.jodconverter.core.office.OfficeException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; import java.io.*; +import java.util.concurrent.ScheduledExecutorService; @Slf4j +@Component public class ShellTool { - + + @Autowired + private DocumentConverter documentConverter; + private static ShellTool shellTool; + + @PostConstruct + public void init(){ + shellTool = this; + shellTool.documentConverter = documentConverter; + } + + public static ShellTool builder(){ + return shellTool; + } + + public static String execLibreofficeCommand(String type, String sourcePath, String targetPath) { String os = System.getProperty("os.name"); StringBuilder builder = new StringBuilder(); @@ -25,10 +50,17 @@ file.delete(); } } catch (Exception e) { + e.printStackTrace(); } + log.info("鎵ц鍛戒护:{}",builder.toString()); return exec(builder.toString()); } + public static void execNewLibreofficeCommand(String type, String sourcePath, String targetPath) throws OfficeException { + //浣跨敤鏂囦欢鏂瑰紡杞崲鎴怭DF + shellTool.documentConverter.convert(new File(sourcePath)).to(new File(targetPath)).execute(); + } + private static String exec(String command) { String returnString = ""; Runtime runTime = Runtime.getRuntime(); -- Gitblit v1.9.1