[测评系统]--测评系统核心代码库
wzp
2025-06-17 4ce181bd784aeb873a4751826c227161d35de2b5
src/main/java/com/ots/project/tool/report/LAQ/chart/LAQChart.java
@@ -2,6 +2,8 @@
import com.alibaba.fastjson.JSON;
import com.ots.common.enums.CapabilityEnum;
import com.ots.common.enums.LangTypeEnum;
import com.ots.common.enums.ReportTypeEnum;
import com.ots.common.utils.DateUtils;
import com.ots.common.utils.MapDataUtil;
import com.ots.common.utils.StringUtils;
@@ -10,9 +12,12 @@
import com.ots.framework.config.EssConfig;
import com.ots.project.exam.domain.TReportTemplate;
import com.ots.project.tool.PdfUtil;
import com.ots.project.tool.report.LAQ.LAQReport;
import com.ots.project.tool.report.LAQ.LAQTemplate;
import com.ots.project.tool.report.MAQ.base.RowData;
import com.ots.project.tool.report.MAQ.base.SeriesData;
import com.ots.project.tool.report.MAQNEW.MAQReport_V2;
import com.ots.project.tool.report.ReportResultData;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.ooxml.POIXMLDocumentPart;
@@ -56,15 +61,29 @@
            LAQTemplate laqTemplate = laqTemplateList.get(i);
            //组装报告所用数据
            Map<String, Object> textMap = new HashMap<>();
            textMap.put("sendEmailFileName",laqTemplate.getName());
            textMap.put("nowDate", DateUtils.getDate());
            MapDataUtil.objectToMap(laqTemplate,textMap);
//            textMap.put("sendEmailFileName",laqTemplate.getName());
//            textMap.put("nowDate", DateUtils.getDate());
//            MapDataUtil.objectToMap(laqTemplate,textMap);
            textMap.put("olas","50");
            textMap.put("ca","32");
            textMap.put("bla","34");
            textMap.put("nr","3");
            textMap.put("ar","45");
            textMap.put("open","67");
            textMap.put("cons","12");
            textMap.put("extra","48");
            textMap.put("agree","90");
            textMap.put("emosta","23");
//            textMap.put("perfomance","0");
            LAQReport report = new LAQReport();
//            ReportResultData resultData = report.getTemplateParameters(textMap, ReportTypeEnum.LAQ, LangTypeEnum.codeOf("English"));
//            TReportTemplate template = null;
//            String zipFileName = WordUtil.makeReportFile("D:\\测评系统\\需求\\LAQ\\report\\LAQ英文报告-20230926.docx", template, textMap, new HashMap<>(), deleteStrList);
//            fileNameList.add(zipFileName);
            ZipSecureFile.setMinInflateRatio(0.001);
            try (OutputStream os = new FileOutputStream("D:\\测评系统\\需求\\LAQ\\report\\LAQ.docx");XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage("D:\\测评系统\\需求\\LAQ\\report\\LAQ英文报告-20230926.docx"))){
            try (OutputStream os = new FileOutputStream("D:\\测评系统\\需求\\LAQ\\report\\LAQ英文模板-wzp-修改版-1.docx");XWPFDocument document = new XWPFDocument(POIXMLDocument.openPackage("D:\\测评系统\\需求\\LAQ\\report\\LAQ英文模板-wzp-修改版.docx"))){
                Map<Integer,List<SeriesData>> seriesDatas = initData(textMap);
                changeChart(document,seriesDatas,textMap);
                document.write(os);
@@ -78,6 +97,16 @@
    }
    /**
     * 替换LAQ图表数据
     * @param document 文档对象
     * @param textMap 数据源
     */
    public static void changeChart(XWPFDocument document, Map<String, Object> textMap) {
        Map<Integer,List<SeriesData>> seriesDatas = initData(textMap);
        changeChart(document,seriesDatas,textMap);
    }
    /**
     * 初始化报告数据
     * @param textMap
     * @return
@@ -85,16 +114,23 @@
    public static Map<Integer,List<SeriesData>> initData(Map<String, Object> textMap){
        Map<Integer,List<SeriesData>> seriesDataMap = new HashMap<>();
        //获取命中数值
        BigDecimal olas = (BigDecimal) textMap.get("olas");
        BigDecimal ca = (BigDecimal) textMap.get("ca");
        BigDecimal bla = (BigDecimal) textMap.get("bla");
        BigDecimal nr = (BigDecimal) textMap.get("nr");
        BigDecimal ar = (BigDecimal) textMap.get("ar");
        BigDecimal open = (BigDecimal) textMap.get("open");
        BigDecimal cons = (BigDecimal) textMap.get("cons");
        BigDecimal extra = (BigDecimal) textMap.get("extra");
        BigDecimal agree = (BigDecimal) textMap.get("agree");
        BigDecimal emosta = (BigDecimal) textMap.get("emosta");
        Double olas = Double.valueOf((String)textMap.get("olas"));
        Double ca = Double.valueOf((String)textMap.get("ca"));
        Double bla = Double.valueOf((String)textMap.get("bla"));
        Double nr = Double.valueOf((String)textMap.get("nr"));
        Double ar = Double.valueOf((String)textMap.get("ar"));
        Double open = Double.valueOf((String)textMap.get("open"));
        Double cons = Double.valueOf((String)textMap.get("cons"));
        Double extra = Double.valueOf((String)textMap.get("extra"));
        Double agree = Double.valueOf((String)textMap.get("agree"));
        Double emosta = Double.valueOf((String)textMap.get("emosta"));
        Double perfomance;
        if(textMap.get("perfomance") != null){
            perfomance = Double.valueOf((String)textMap.get("perfomance"));
        }else{
            perfomance = -1D;
        }
        // 图表1
        List<SeriesData> seriesDatas = Arrays.asList(
@@ -250,6 +286,17 @@
        );
        seriesDataMap.put(10,seriesDatas);
        // 图表11
        seriesDatas = Arrays.asList(
                new SeriesData("X 值", Arrays.asList(
                        new RowData("X 值", perfomance.doubleValue() == -1 ? perfomance.doubleValue() : olas.doubleValue())
                )),
                new SeriesData("Y 值", Arrays.asList(
                        new RowData("Y 值", perfomance.doubleValue())
                ))
        );
        seriesDataMap.put(11,seriesDatas);
        return seriesDataMap;
    }
@@ -301,7 +348,7 @@
                    //散点图
                    if (!plot.getScatterChartList().isEmpty()) {
                        List<SeriesData> seriesDatas = seriesDataMap.get(10);
                        List<SeriesData> seriesDatas = seriesDataMap.get(barIndex);
                        CTScatterChart scatterChart = plot.getScatterChartArray(0);
                        //System.out.println("散点图{"+plot.getScatterChartList().size()+"}");
                        //刷新内置excel数据
@@ -318,13 +365,14 @@
                            updateScatterChart(seriesDatas, ser.getXVal(), ser.getYVal());
                            ++i;
                        }
                        barIndex++;
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error("MAQTR替换word图表 散点图图形失败:{}",e);
            log.error("LAQ.替换word图表 散点图图形失败:{}",e);
        }
    }
@@ -404,7 +452,11 @@
                if(StringUtils.isNotEmpty(cellValu.valueStr)){
                    cell.setCellValue(cellValu.valueStr);
                }else{
                    cell.setCellValue(cellValu.value);
                    if(cellValu.value != -1){
                        cell.setCellValue(cellValu.value);
                    }else{
                        cell.setCellValue((String) null);
                    }
                }
            }
@@ -449,7 +501,11 @@
            CTNumVal val = xNumCnt > i ? xDataSource.getNumRef().getNumCache().getPtArray(i)
                    : xDataSource.getNumRef().getNumCache().addNewPt();
            val.setIdx(i);
            val.setV(String.format("%.0f", cellValu.value));
            if(cellValu.value == -1){
                val.setV(null);
            }else {
                val.setV(String.format("%.0f", cellValu.value));
            }
        }
        //更新Y坐标缓存
@@ -458,7 +514,11 @@
            CTNumVal val = yNumCnt > i ? yDataSource.getNumRef().getNumCache().getPtArray(i)
                    : yDataSource.getNumRef().getNumCache().addNewPt();
            val.setIdx(i);
            val.setV(String.format("%.0f", cellValu.value));
            if(cellValu.value == -1){
                val.setV(null);
            }else {
                val.setV(String.format("%.0f", cellValu.value));
            }
        }
        // 更新对应excel的范围