From 4efefb9ada923a7a0480b49b292c498ff88ed15a Mon Sep 17 00:00:00 2001 From: wzp <2040239371@qq.com> Date: 星期三, 31 七月 2024 14:22:53 +0800 Subject: [PATCH] 优化图表里的标签显示,设置一定的偏移量,确保标签都在图表内 --- src/main/java/com/ots/common/utils/poi/WordUtil.java | 151 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 148 insertions(+), 3 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..53c83c4 100644 --- a/src/main/java/com/ots/common/utils/poi/WordUtil.java +++ b/src/main/java/com/ots/common/utils/poi/WordUtil.java @@ -51,6 +51,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 +1266,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 +1283,16 @@ || 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(); + 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 +1314,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 +1457,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(); } } -- Gitblit v1.9.1