From a9687f1dba3b8d4f3973a9de624d12a94208d4ca Mon Sep 17 00:00:00 2001 From: 林致杰 <1003392067@qq.com> Date: 星期四, 19 十月 2023 18:41:28 +0800 Subject: [PATCH] bugfix --- src/main/java/com/ots/common/utils/poi/WordUtil.java | 84 ++++++++++++++++++++++++++++------------- 1 files changed, 57 insertions(+), 27 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 4363b87..dea980f 100644 --- a/src/main/java/com/ots/common/utils/poi/WordUtil.java +++ b/src/main/java/com/ots/common/utils/poi/WordUtil.java @@ -17,11 +17,14 @@ import com.ots.project.tool.exam.ExamUtil; import com.ots.project.tool.exam.ImageUtil; import com.ots.project.tool.exam.ZipUtil; +import com.ots.project.tool.libreoffice.LibreOfficeUtil; +import com.ots.project.tool.report.CIAQ.chart.CIAQChart; import com.ots.project.tool.report.MAQTR.chart.MAQTRChart; import com.ots.project.tool.report.PAQ.chart.PAQChart; import org.apache.commons.collections.map.HashedMap; import org.apache.poi.ooxml.POIXMLDocument; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.openxml4j.util.ZipSecureFile; import org.apache.poi.util.Units; import org.apache.poi.xwpf.usermodel.*; import org.apache.xmlbeans.XmlCursor; @@ -407,6 +410,9 @@ if(tableEnum == TableEnum.table4){ if(tableNum != null && tableNum != 8){ for (int i = tableNum; i <= tableNum + 4; i++) { + if(i+2 > table.getRows().size()){ + continue; + } XWPFTableRow row = table.getRows().get(i+2); List<XWPFTableCell> cells = row.getTableCells(); changeText(cells.get(0).getParagraphs().get(0),"#"+(i+1)+"."); @@ -899,9 +905,8 @@ if (checkText(runValue)) { runValue = runValue.replaceAll("%.*%", ""); - runValue = runValue.replaceAll("N/A NONE", ""); - } + runValue = runValue.replaceAll("N/A NONE", ""); return runValue; } @@ -1119,7 +1124,7 @@ if(StringUtils.contains(keyValue, "%table-line-feed%")){ String[] keyValues = keyValue.split("%table-line-feed%"); runValue = delDynList(keyTemp, Arrays.asList(keyValues), paragraph, document,1); - }else{ + }else if(StringUtils.contains(keyValue, "%line-feed%")){ String[] keyValues = keyValue.split("%line-feed%"); runValue = delDynList(keyTemp, Arrays.asList(keyValues), paragraph, document,0); } @@ -1164,21 +1169,30 @@ 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()); - //PAQ銆丮AQTR閲囩敤鏂扮殑doc杞琾df - if(ReportTypeEnum.PAQ.getCode().equals(reportType) || ReportTypeEnum.MAQTR.getCode().equals(reportType)){ + //妯℃澘鏂囦欢闇�瑕佸姞閿� + 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()); + //} + + //PAQ銆丮AQTR閲囩敤銆丆IAQ鏂扮殑doc杞琾df + if(ReportTypeEnum.PAQ.getCode().equals(reportType) || ReportTypeEnum.MAQTR.getCode().equals(reportType) + || ReportTypeEnum.CIAQ.getCode().equals(reportType)){ PdfUtil.convertPDF(EssConfig.getProfile() + "/" + reportName); + }else if(ReportTypeEnum.LAQ.getCode().equals(reportType)){ + PdfUtil.convertPythonPDF(EssConfig.getDocx2pdfPath(),EssConfig.getProfile() + "/" + reportName); }else{ ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/"); + // ShellTool shellTool = ShellTool.builder(); + // shellTool.execNewLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/" + reportName.replace("docx","pdf")); + //鏂版柟娉曟祴璇� + //LibreOfficeUtil.convertOffice2PDFSyncIsSuccess(new File(EssConfig.getProfile() + "/" + reportName),new File(EssConfig.getProfile() + "/" + reportName.replace("docx","pdf"))); } zipFilePath = getPdfPath(reportName); @@ -1271,6 +1285,7 @@ */ private static void setChageWord(String fileName, OutputStream out, Map<String, Object> textMap, String reportType,String dataPath, Map<Integer, Map<Integer, List<String[]>>> autoTableMap) throws IOException, InvalidFormatException, DocumentException { //String filePath = getTemplateDownLoadPathByUpLoad(fileName); + ZipSecureFile.setMinInflateRatio(0.001); XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(getTemplateDownLoadPathByUpLoad(fileName))); @@ -1325,7 +1340,7 @@ String key = "%" + textSet.getKey() + "%"; if (text.indexOf(key) != -1) { - text = text.replaceAll(key, (String) textMap.get(textSet.getKey())); + text = text.replaceAll(key, String.valueOf(textMap.get(textSet.getKey()))); repText = text; if (checkText(text)) { continue; @@ -1338,9 +1353,9 @@ repText = repText.replaceAll("<BoldText>", ""); repText = repText.replaceAll("</BoldText>", ""); } - if (repText.indexOf("N/A NONE") != -1) { +/* if (repText.indexOf("N/A NONE") != -1) { repText = repText.replaceAll("N/A NONE", ""); - } + }*/ return repText; } public static void changTableColor(String fileName, OutputStream out, List<JAQTableStyle> jaqTableStyleList) throws IOException { @@ -1387,19 +1402,26 @@ if (ExamUtil.isListEmpty(charts)) { return; } - if (StringUtils.equals(reportType, ReportTypeEnum.MAQ.getCode())) { - setMAQCompleteChars(textMap, charts); - } else if (StringUtils.equals(reportType, ReportTypeEnum.MAQV2.getCode()) || StringUtils.equals(reportType, ReportTypeEnum.MAQIAR.getCode())) { - setMAQ_V2CompleteChars(textMap, charts); - } else if (StringUtils.equals(reportType, ReportTypeEnum.RuiLin.getCode())) { - setRuiLinChar(textMap, charts); - } else if (StringUtils.equals(reportType, ReportTypeEnum.PAQ.getCode())) { - PAQChart.changeChart(document, textMap); - } else if (StringUtils.equals(reportType, ReportTypeEnum.MAQTR.getCode())) { - MAQTRChart.changeMAQTRChart(document, dataPath); - } else { - return; + try{ + if (StringUtils.equals(reportType, ReportTypeEnum.MAQ.getCode())) { + setMAQCompleteChars(textMap, charts); + } else if (StringUtils.equals(reportType, ReportTypeEnum.MAQV2.getCode()) || StringUtils.equals(reportType, ReportTypeEnum.MAQIAR.getCode())) { + setMAQ_V2CompleteChars(textMap, charts); + } else if (StringUtils.equals(reportType, ReportTypeEnum.RuiLin.getCode())) { + setRuiLinChar(textMap, charts); + } else if (StringUtils.equals(reportType, ReportTypeEnum.PAQ.getCode())) { + PAQChart.changeChart(document, textMap); + } else if (StringUtils.equals(reportType, ReportTypeEnum.MAQTR.getCode())) { + MAQTRChart.changeMAQTRChart(document, dataPath); + } else if (StringUtils.equals(reportType, ReportTypeEnum.CIAQ.getCode())) { + CIAQChart.changeChart(document, textMap); + } else { + return; + } + }catch (Exception e){ + e.printStackTrace(); } + } private static void setMAQ_V2CompleteChars(Map<String, Object> textMap, List<XWPFChart> charts) { String p_Task31 = textMap.get("P_Task31").toString(); @@ -1773,7 +1795,15 @@ //鏇存敼琛ㄦ牸鐨勫�� textMap.put("sendEmailFileName", "JAQ"); + textMap.put("SelectUsers",8); + //changeTable(document, textMap); + + + changeText(document, textMap); + changeTextBox(document, textMap); + addTableValue(document, null); changeTable(document, textMap); + //changChart(textMap, document, reportType, dataPath); //寤虹珛鏂囦欢瀵硅薄 File file = new File("C:\\Users\\Administrator\\Desktop\\JAQ涓枃鐗�1.docx"); -- Gitblit v1.9.1