| | |
| | | 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.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; |
| | |
| | | out = getDownLoadFileOutputStream(reportName); |
| | | |
| | | log.info("reportTemplate:" + fileName); |
| | | String templateType = tReportTemplate.getTemplateType(); |
| | | setChageWord(fileName, out, textMap, tReportTemplate.getReportType(), templateType, autoTableMap); |
| | | //String templateType = tReportTemplate.getTemplateType(); |
| | | setChageWord(fileName, out, textMap, tReportTemplate.getReportType(),tReportTemplate.getDataPath(), autoTableMap); |
| | | out.flush(); |
| | | changColorIfJAQ(textMap, out, reportName, tReportTemplate.getReportType()); |
| | | //PAQ采用新的doc转pdf |
| | | if(!ReportTypeEnum.PAQ.getCode().equals(reportType)){ |
| | | ShellTool.execLibreofficeCommand("pdf", EssConfig.getProfile() + "/" + reportName, EssConfig.getProfile() + "/"); |
| | | }else{ |
| | | //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() + "/"); |
| | | |
| | | } |
| | | zipFilePath = getPdfPath(reportName); |
| | | |
| | |
| | | } |
| | | return new FileOutputStream(outFile); |
| | | } |
| | | private static void setChageWord(String fileName, OutputStream out, Map<String, Object> textMap, String reportType, String templateType, Map<Integer, Map<Integer, List<String[]>>> autoTableMap) throws IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException, DocumentException { |
| | | String filePath = getTemplateDownLoadPathByUpLoad(fileName); |
| | | |
| | | /** |
| | | * 内容变更 |
| | | * @param fileName |
| | | * @param out |
| | | * @param textMap |
| | | * @param reportType |
| | | * @param autoTableMap |
| | | * @throws IOException |
| | | * @throws InvalidFormatException |
| | | * @throws DocumentException |
| | | */ |
| | | 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); |
| | | |
| | | XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage(getTemplateDownLoadPathByUpLoad(fileName))); |
| | | |
| | |
| | | //设置文本框 |
| | | changeTextBox(document, textMap); |
| | | |
| | | //设置图表 |
| | | if (Objects.equals(reportType, ReportTypeEnum.PAQ.getCode())) { |
| | | PAQChart.changeChart(document, textMap); |
| | | } |
| | | |
| | | //插入表格 |
| | | addTableValue(document, autoTableMap); |
| | | |
| | |
| | | changeTable(document, textMap); |
| | | |
| | | //设置图表控件 |
| | | changChar(textMap, document, reportType, templateType); |
| | | changChart(textMap, document, reportType,dataPath); |
| | | document.write(out); |
| | | } |
| | | private static void changeTextBox(XWPFDocument document, Map<String, Object> textMap) throws DocumentException { |
| | |
| | | |
| | | /** |
| | | * 设置图标控件 |
| | | * @param textMap |
| | | * @param document |
| | | * @param reportType |
| | | * @param templateType |
| | | * @param textMap 替换text |
| | | * @param document 报告文件 |
| | | * @param reportType 报告类型 |
| | | * @param dataPath MAQTR数据路径 |
| | | */ |
| | | private static void changChar(Map<String, Object> textMap, XWPFDocument document, String reportType, String templateType) { |
| | | if (StringUtils.isEmpty(reportType) || StringUtils.isEmpty(templateType)) { |
| | | private static void changChart(Map<String, Object> textMap, XWPFDocument document, String reportType,String dataPath) { |
| | | if (StringUtils.isEmpty(reportType)) { |
| | | return; |
| | | } |
| | | List<XWPFChart> charts = document.getCharts(); |
| | |
| | | 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; |
| | | } |
| | |
| | | } |
| | | } |
| | | public File getAbsoluteFileZipByName(String filename) { |
| | | String downloadPath = EssConfig.getDownloadPath() + filename; |
| | | String downloadPath = EssConfig.getDownloadPath() + "/" + filename; |
| | | File desc = new File(downloadPath); |
| | | if (!desc.getParentFile().exists()) { |
| | | desc.getParentFile().mkdirs(); |