xiangpei
2024-05-23 9a1c378ec5566a727efcb85120cdafd52c3ee9f1
src/main/java/com/mindskip/xzs/service/impl/ExamPaperAnswerServiceImpl.java
@@ -10,6 +10,7 @@
import com.mindskip.xzs.domain.other.ExamPaperAnswerUpdate;
import com.mindskip.xzs.domain.other.KeyValue;
import com.mindskip.xzs.domain.task.TaskItemAnswerObject;
import com.mindskip.xzs.domain.vo.ExamPaperStatisticVO;
import com.mindskip.xzs.repository.ExamPaperAnswerMapper;
import com.mindskip.xzs.repository.ExamPaperMapper;
import com.mindskip.xzs.repository.QuestionMapper;
@@ -160,8 +161,8 @@
    }
    @Override
    public Integer selectAllCount() {
        return examPaperAnswerMapper.selectAllCount();
    public Integer selectAllCount(List<Integer> deptIds) {
        return examPaperAnswerMapper.selectAllCount(deptIds);
    }
    @Override
@@ -312,12 +313,40 @@
    }
    @Override
    public Map<String, Object> statistic(String examPaperId, String departmentId) {
    public Map<String, Object> statistic(ExamPaperStatisticVO examPaperStatisticVO) {
        // 获取原始数据
        Map<String, Object> histogram = examPaperAnswerMapper.histogram(examPaperStatisticVO);
        Map<String, Object> pieChart = examPaperAnswerMapper.pieChart(examPaperStatisticVO);
        // 初始化结果容器
        HashMap<String, Object> map = new HashMap<>();
        Map<String, Object> histogram = examPaperAnswerMapper.histogram(examPaperId, departmentId);
        Map<String, Object> pieChart = examPaperAnswerMapper.pieChart(examPaperId, departmentId);
        map.put("histogram", histogram);
        map.put("pieChart", pieChart);
        List<Map<String, Object>> score = new ArrayList<>();
        List<Map<String, Object>> age = new ArrayList<>();
        List<Map<String, Object>> examPeopleNum = new ArrayList<>();
        // 处理成绩与年龄分布
        histogram.forEach((k, v) -> {
            Map<String, Object> hashMap = new HashMap<>();
            hashMap.put(k, v);
            if (k.contains("score")) {
                score.add(hashMap);
            }
            if (k.contains("age")) {
                age.add(hashMap);
            }
        });
        // 处理参考人数(出席与缺席)
        pieChart.forEach((k, v) -> {
            Map<String, Object> hashMap = new HashMap<>();
            hashMap.put(k, v);
            if ("totalAttended".equals(k)) {
                examPeopleNum.add(hashMap);
            }
            if ("totalAbsent".equals(k)) {
                examPeopleNum.add(hashMap);
            }
        });
        map.put("score", score);
        map.put("age", age);
        map.put("examPeopleNum", examPeopleNum);
        return map;
    }
}