[测评系统]--测评系统核心代码库
wzp
2025-06-17 4ce181bd784aeb873a4751826c227161d35de2b5
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;
@@ -1257,15 +1261,23 @@
            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.replace("\t","");
            reportName = reportName.replaceAll(" ", "_");
            //模板文件需要加锁
            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、MAQTR采用、CIAQ、APIFan新的doc转pdf
@@ -1273,7 +1285,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 +1316,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 +1459,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 +1555,12 @@
        //设置图表控件
        changChart(textMap, document, reportType,dataPath);
        //如果是LAQ的全景图,设置图表
        if (StringUtils.equals(reportType, ReportTypeEnum.LAQ.getCode())&& textMap.containsKey("allList")){
            LAQAllPng.changeChart(document,textMap);
        }
        document.write(out);
    }
@@ -1564,16 +1717,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()))
            {