[测评系统]--测评系统核心代码库
林致杰
2022-06-26 99f7f9adac08f3a3fa3211f7a6062c26d62fa224
src/main/java/com/ots/common/utils/poi/WordUtil.java
@@ -17,6 +17,7 @@
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;
@@ -1168,15 +1169,16 @@
            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);
            
@@ -1255,8 +1257,20 @@
        }
        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)));
@@ -1266,11 +1280,6 @@
        //设置文本框
        changeTextBox(document, textMap);
        //设置图表
        if (Objects.equals(reportType, ReportTypeEnum.PAQ.getCode())) {
            PAQChart.changeChart(document, textMap);
        }
        //插入表格
        addTableValue(document, autoTableMap);
@@ -1278,7 +1287,7 @@
        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 {
@@ -1365,13 +1374,13 @@
    /**
     * 设置图标控件
     * @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();
@@ -1384,6 +1393,10 @@
            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;
        }
@@ -1600,7 +1613,7 @@
        }
    }
    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();