龚焕茏
2024-07-03 3ec909b27b3eba956aa9d00cc7a94c179bd04bbf
src/main/java/com/mindskip/xzs/service/impl/ExamPaperAnswerServiceImpl.java
@@ -32,6 +32,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@@ -317,7 +318,25 @@
    @Override
    public Map<String, Object> statistic(ExamPaperStatisticVO examPaperStatisticVO) {
        // 获取原始数据
        Map<String, Object> histogram = examPaperAnswerMapper.histogram(examPaperStatisticVO);
        Map<String, Object> histogram;
        ExamPaperDataExportVO examPaperDataExportVO;
        if (Objects.equals(examPaperStatisticVO.getExamPaperType(), 7)) {
            histogram = examPaperAnswerMapper.histogramByTemplate(examPaperStatisticVO);
            examPaperDataExportVO = examPaperAnswerMapper.totalByTemplate(new ExamPaperDataVO().setId(examPaperStatisticVO.getExamPaperId()).setDeptIds(examPaperStatisticVO.getDepartmentId()));
        } else {
            histogram = examPaperAnswerMapper.histogram(examPaperStatisticVO);
            examPaperDataExportVO = examPaperAnswerMapper.totalByPaper(new ExamPaperDataVO().setId(examPaperStatisticVO.getExamPaperId()).setDeptIds(examPaperStatisticVO.getDepartmentId()));
        }
        // 不存在时填充0
        if (Objects.isNull(examPaperDataExportVO)) {
            examPaperDataExportVO = new ExamPaperDataExportVO()
                    .setExamTotal(examPaperAnswerMapper.getExamTotal(examPaperStatisticVO))
                    .setFactPeopleTotal(0)
                    .setAverageScore(BigDecimal.ZERO)
                    .setReferencePercentage(BigDecimal.ZERO);
        }
        Map<String, Object> pieChart = examPaperAnswerMapper.pieChart(examPaperStatisticVO);
        // 初始化结果容器
        HashMap<String, Object> map = new HashMap<>();
@@ -349,6 +368,7 @@
        map.put("score", score);
        map.put("age", age);
        map.put("examPeopleNum", examPeopleNum);
        map.put("total", examPaperDataExportVO);
        return map;
    }