pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/ots/common/utils/poi/WordUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/ots/framework/config/ThreadPoolConfig.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/ots/project/tool/ShellTool.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
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> 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、MAQTR采用新的doc转pdf 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); 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; 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 { //使用文件方式转换成PDF shellTool.documentConverter.convert(new File(sourcePath)).to(new File(targetPath)).execute(); } private static String exec(String command) { String returnString = ""; Runtime runTime = Runtime.getRuntime();