| | |
| | | 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.ExamPaperDataExportVO; |
| | | import com.mindskip.xzs.domain.vo.ExamPaperDataVO; |
| | | 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; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Integer selectAllCount() { |
| | | return examPaperAnswerMapper.selectAllCount(); |
| | | public Integer selectAllCount(List<Integer> deptIds) { |
| | | return examPaperAnswerMapper.selectAllCount(deptIds); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> statistic(String examPaperId, String departmentId) { |
| | | public Map<String, Object> statistic(ExamPaperStatisticVO 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<>(); |
| | | Map<String, Object> histogram = examPaperAnswerMapper.histogram(examPaperId, departmentId); |
| | | Map<String, Object> pieChart = examPaperAnswerMapper.pieChart(examPaperId, departmentId); |
| | | ArrayList<Double> histograms = new ArrayList<>(); |
| | | ArrayList<Double> pieCharts = new ArrayList<>(); |
| | | histogram.forEach((k, v) -> histograms.add(Double.valueOf(v.toString()))); |
| | | pieChart.forEach((k, v) -> pieCharts.add(Double.valueOf(v.toString()))); |
| | | map.put("histogram", histograms); |
| | | map.put("pieChart", pieCharts); |
| | | 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); |
| | | map.put("total", examPaperDataExportVO); |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> data(ExamPaperDataVO examPaperDataVO) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | // 随机试卷 |
| | | if (Objects.equals(examPaperDataVO.getType(), 7)) { |
| | | map.put("data", examPaperAnswerMapper.dataByTemplate(examPaperDataVO)); |
| | | map.put("total", examPaperAnswerMapper.totalByTemplate(examPaperDataVO)); |
| | | } else { |
| | | map.put("data", examPaperAnswerMapper.dataByPaper(examPaperDataVO)); |
| | | map.put("total", examPaperAnswerMapper.totalByPaper(examPaperDataVO)); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public List<ExamPaperDataExportVO> dataExport(ExamPaperDataVO examPaperDataVO) { |
| | | // 随机试卷 |
| | | if (Objects.equals(examPaperDataVO.getType(), 7)) { |
| | | List<ExamPaperDataExportVO > dataByTemplate = examPaperAnswerMapper.dataByTemplate(examPaperDataVO); |
| | | ExamPaperDataExportVO totalByTemplate = examPaperAnswerMapper.totalByTemplate(examPaperDataVO); |
| | | dataByTemplate.add(0, totalByTemplate.setName("所有部门")); |
| | | return dataByTemplate; |
| | | } else { |
| | | List<ExamPaperDataExportVO > dataByPaper = examPaperAnswerMapper.dataByPaper(examPaperDataVO); |
| | | ExamPaperDataExportVO totalByPaper = examPaperAnswerMapper.totalByPaper(examPaperDataVO); |
| | | dataByPaper.add(0, totalByPaper.setName("所有部门")); |
| | | return dataByPaper; |
| | | } |
| | | } |
| | | } |