From df19dcb31b846d96e26ab2c161652c51a0ec7de4 Mon Sep 17 00:00:00 2001 From: wzp <2040239371@qq.com> Date: 星期三, 04 九月 2024 08:36:51 +0800 Subject: [PATCH] 优化日志提示文件 --- src/main/java/com/ots/common/utils/poi/WordUtil.java | 180 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 171 insertions(+), 9 deletions(-) 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 e0c6e8c..47f50ec 100644 --- a/src/main/java/com/ots/common/utils/poi/WordUtil.java +++ b/src/main/java/com/ots/common/utils/poi/WordUtil.java @@ -23,6 +23,7 @@ import com.ots.project.tool.report.CIAQ.chart.CIAQChart; import com.ots.project.tool.report.JAQ.condition.JAQTeam; import com.ots.project.tool.report.LAQ.chart.LAQAllChart; +import com.ots.project.tool.report.LAQ.chart.LAQAllPng; import com.ots.project.tool.report.LAQ.chart.LAQChart; import com.ots.project.tool.report.MAQTR.chart.MAQTRChart; import com.ots.project.tool.report.PAQ.chart.PAQChart; @@ -51,6 +52,9 @@ import java.io.*; import java.time.LocalDate; import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -1263,9 +1267,16 @@ out = getDownLoadFileOutputStream(reportName); //synchronized (fileName.intern()){ //String templateType = tReportTemplate.getTemplateType(); - setChageWord(fileName, out, textMap, tReportTemplate.getReportType(),tReportTemplate.getDataPath(), autoTableMap); - out.flush(); - changColorIfJAQ(textMap, out, reportName, tReportTemplate.getReportType()); + long startTime1 = System.currentTimeMillis(); + setChageWord(fileName, out, textMap, tReportTemplate.getReportType(), tReportTemplate.getDataPath(), autoTableMap); + // 鑾峰彇缁撴潫鏃堕棿 + long endTime1 = System.currentTimeMillis(); + // 璁$畻鑰楁椂锛堝崟浣嶏細姣锛� + long duration1 = endTime1 - startTime1; + log.info("setChageWord 绋嬪簭鎵ц鑰楁椂锛�" + duration1 + " 姣锛岀敓鎴愭姤鍛婏細"+reportName); + + out.flush(); + changColorIfJAQ(textMap, out, reportName, tReportTemplate.getReportType()); //} //PAQ銆丮AQTR閲囩敤銆丆IAQ銆丄PIFan鏂扮殑doc杞琾df @@ -1273,7 +1284,26 @@ || ReportTypeEnum.CIAQ.getCode().equals(reportType) ||ReportTypeEnum.API_Fan.getCode().equals(reportType)){ PdfUtil.convertPDF(EssConfig.getProfile() + "/" + reportName); }else if(ReportTypeEnum.LAQ.getCode().equals(reportType)){ + // 鑾峰彇寮�濮嬫椂闂� + long startTime = System.currentTimeMillis(); + +// if(textMap.containsKey("allList")) +// { +// PdfUtil.convertPDF(EssConfig.getProfile() + "/" + reportName); +// } +// else +// { +// +// } + PdfUtil.dockerConvertPDF(EssConfig.getProfile(),EssConfig.getDocx2pdfPath(),reportName); + + // 鑾峰彇缁撴潫鏃堕棿 + long endTime = System.currentTimeMillis(); + // 璁$畻鑰楁椂锛堝崟浣嶏細姣锛� + long duration = endTime - startTime; + log.info("dockerConvertPDF 绋嬪簭鎵ц鑰楁椂锛�" + duration + " 姣锛岀敓鎴愭姤鍛婏細"+reportName); + }else{ ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/"); // ShellTool shellTool = ShellTool.builder(); @@ -1295,6 +1325,128 @@ } return zipFilePath; } + + + /** + * LAQ浣跨敤-----澶參浜嗐�傚お鎱簡 + * @param fileName + * @param tReportTemplate + * @param textMap + * @param autoTableMap + * @param deleteFileStrList + * @return + */ + private static List<String> reportNameList = new ArrayList<>(); +// public static String makeReportFileForLAQ(String fileName, TReportTemplate tReportTemplate, Map<String, Object> textMap, Map<Integer, Map<Integer, List<String[]>>> autoTableMap, List<String> deleteFileStrList,Integer index,Integer totalNum,Boolean cleanFlag) { +// String returnMessage = "瀵煎嚭妯℃澘杞Щ閿欒:"; +// InputStream in = null; +// FileOutputStream out = null; +// String zipFilePath = ""; +// String reportName = ""; +// +// if(cleanFlag) +// { +// reportNameList = new ArrayList<>(); +// } +// +// try { +// +// String reportType = tReportTemplate.getReportType(); +// reportName = textMap.get("sendEmailFileName") + "_" + reportType + "_" + ReportTypeNameEnum.valueOf(tReportTemplate.getTemplateType()).getCode() + "_" + ReportTypeNameEnum.valueOf(tReportTemplate.getLangType()).getCode() + ".docx"; +// reportName = reportName.replaceAll(" ", "_"); +// +// reportNameList.add(reportName); +// +// //妯℃澘鏂囦欢闇�瑕佸姞閿� +// out = getDownLoadFileOutputStream(reportName); +// +// long startTime1 = System.currentTimeMillis(); +// setChageWord(fileName, out, textMap, tReportTemplate.getReportType(), tReportTemplate.getDataPath(), autoTableMap); +// // 鑾峰彇缁撴潫鏃堕棿 +// long endTime1 = System.currentTimeMillis(); +// // 璁$畻鑰楁椂锛堝崟浣嶏細姣锛� +// long duration1 = endTime1 - startTime1; +// log.info("setChageWord 绋嬪簭鎵ц鑰楁椂锛�" + duration1 + " 姣锛岀敓鎴愭姤鍛婏細"+reportName); +// +// out.flush(); +// +//// if(ReportTypeEnum.LAQ.getCode().equals(reportType)){ +//// // 鑾峰彇寮�濮嬫椂闂� +//// long startTime = System.currentTimeMillis(); +//// +//// PdfUtil.dockerConvertPDF(EssConfig.getProfile(),EssConfig.getDocx2pdfPath(),reportName); +//// // 鑾峰彇缁撴潫鏃堕棿 +//// long endTime = System.currentTimeMillis(); +//// // 璁$畻鑰楁椂锛堝崟浣嶏細姣锛� +//// long duration = endTime - startTime; +//// log.info("dockerConvertPDF 绋嬪簭鎵ц鑰楁椂锛�" + duration + " 姣锛岀敓鎴愭姤鍛婏細"+reportName); +//// } +// if(Objects.equals(index, totalNum)) +// { +// //骞惰杞崲 +// execLAQ2PDF(reportNameList); +// } +// +// zipFilePath = getPdfPath(reportName); +// +// deleteFileStrList.add(EssConfig.getProfile() + "/" + reportName); +// } catch (Exception ex) { +// returnMessage = returnMessage + ex.getMessage(); +// deleteFileStrList.add(EssConfig.getProfile() + "/" + reportName); +// log.error("瀵煎嚭妯℃澘杞Щ閿欒锛歿}\n妫�鏌ユ枃浠讹細" + fileName, returnMessage, ex); +// } finally { +// closeChannel(out); +// closeChannel(in); +// } +// return zipFilePath; +// } + + + private static void execLAQ2PDF(List<String> reportNames) + { + // 鑾峰彇寮�濮嬫椂闂� + long startTime = System.currentTimeMillis(); + // 鎺у埗骞惰鎵ц鐨勬渶澶х嚎绋嬫暟 + int parallelism = 2; // 璁剧疆涓轰綘甯屾湜鐨勫苟琛屾暟閲� + + // 鍒涘缓涓�涓浐瀹氬ぇ灏忕殑绾跨▼姹� + ExecutorService executor = Executors.newFixedThreadPool(parallelism); + + // 鍒涘缓涓�涓� CompletableFuture 鍒楄〃锛屾瘡涓� CompletableFuture 琛ㄧず涓�涓紓姝ヤ换鍔� + List<CompletableFuture<Void>> futures = new ArrayList<>(); + + // 鏋勫缓寮傛浠诲姟鍒楄〃 + for (String reportName : reportNames) { + CompletableFuture<Void> future = CompletableFuture.runAsync(() -> { + try { + long oneTime = System.currentTimeMillis(); + PdfUtil.dockerConvertPDF(EssConfig.getProfile(), EssConfig.getDocx2pdfPath(), reportName); + long twoTime = System.currentTimeMillis(); + long dura = twoTime - oneTime; + log.info("杞崲鎴愬姛锛� " + reportName + " successfully.鑰楁椂锛�"+dura); + } catch (Exception e) { + log.info("杞崲澶辫触锛� " + reportName + ": " + e.getMessage()); + } + }, executor); // 浣跨敤鎸囧畾鐨勭嚎绋嬫睜鎵ц浠诲姟 + futures.add(future); + } + + // 绛夊緟鎵�鏈夊紓姝ヤ换鍔″畬鎴� + CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); + + // 鍏抽棴绾跨▼姹� + executor.shutdown(); + // 鑾峰彇缁撴潫鏃堕棿 + long endTime = System.currentTimeMillis(); + // 璁$畻鑰楁椂锛堝崟浣嶏細姣锛� + long duration = endTime - startTime; + log.info("execLAQ2PDF 绋嬪簭鎵ц鑰楁椂锛�" + duration + " 姣"); + log.info("鎵�鏈夌嚎绋嬮兘鎵ц瀹屾垚锛�"); + } + + + + @Nullable private static String getPositionIfJAQ(Map<String, Object> textMap, String reportType) { if (Objects.equals(reportType, "JAQ")) { @@ -1316,10 +1468,14 @@ private static String getPdfPath(String reportName) { return reportName.substring(0, reportName.lastIndexOf(".")) + ".pdf"; } + + + //鍒犻櫎鏂囦欢 public static void deleteFileByStr(List<String> deleteFileStrList) { for (String deleteStr : deleteFileStrList) { File file = new File(deleteStr); + log.info("鍒犻櫎鏂囦欢锛�"+deleteStr); file.delete(); } } @@ -1408,6 +1564,12 @@ //璁剧疆鍥捐〃鎺т欢 changChart(textMap, document, reportType,dataPath); + + //濡傛灉鏄疞AQ鐨勫叏鏅浘锛岃缃浘琛� + if (StringUtils.equals(reportType, ReportTypeEnum.LAQ.getCode())&& textMap.containsKey("allList")){ + LAQAllPng.changeChart(document,textMap); + } + document.write(out); } @@ -1564,16 +1726,16 @@ } else if (StringUtils.equals(reportType, ReportTypeEnum.CIAQ.getCode())) { CIAQChart.changeChart(document, textMap); } else if (StringUtils.equals(reportType, ReportTypeEnum.LAQ.getCode())) { - if(!textMap.containsKey("allList")) + if(textMap.containsKey("allList")) { - System.out.println("涓汉鐢ㄦ埛鎶ュ憡"); - LAQChart.changeChart(document, textMap); + log.info("銆愮敓鎴愬叏鏅浘鎶ュ憡銆�"); + //濡傛灉鍖呭惈allList锛屽垯娓叉煋鍏ㄦ櫙鍥惧浘琛� + LAQAllChart.changeChart(document,textMap); } else { - System.out.println("鍏ㄦ櫙鍥炬姤鍛�"); - //濡傛灉鍖呭惈allList锛屽垯娓叉煋鍏ㄦ櫙鍥惧浘琛� - LAQAllChart.changeChart(document,textMap); + log.info("鐢熸垚鐨勬槸涓汉鐢ㄦ埛鎶ュ憡"); + LAQChart.changeChart(document, textMap); } } else if(StringUtils.equals(reportType, ReportTypeEnum.API_Fan.getCode())) { -- Gitblit v1.9.1