|
@@ -0,0 +1,160 @@
|
|
1
|
+package com.xhkjedu.sexam.service.report;
|
|
2
|
+
|
|
3
|
+import com.xhkjedu.sexam.mapper.exam.EBaseMapper;
|
|
4
|
+import com.xhkjedu.sexam.mapper.exam.EClassMapper;
|
|
5
|
+import com.xhkjedu.sexam.mapper.exam.ESubjectMapper;
|
|
6
|
+import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentMapper;
|
|
7
|
+import com.xhkjedu.sexam.mapper.report.ERbaseMapper;
|
|
8
|
+import com.xhkjedu.sexam.mapper.reportstu.ERstudentMapper;
|
|
9
|
+import com.xhkjedu.sexam.model.reportstu.ERstudent;
|
|
10
|
+import org.springframework.stereotype.Service;
|
|
11
|
+
|
|
12
|
+import javax.annotation.Resource;
|
|
13
|
+import java.util.ArrayList;
|
|
14
|
+import java.util.DoubleSummaryStatistics;
|
|
15
|
+import java.util.HashMap;
|
|
16
|
+import java.util.List;
|
|
17
|
+import java.util.Map;
|
|
18
|
+import java.util.stream.Collectors;
|
|
19
|
+
|
|
20
|
+/**
|
|
21
|
+ * @author ywx
|
|
22
|
+ * @classname EReportGenerateService
|
|
23
|
+ * @description 考试报告生成
|
|
24
|
+ * @date 2022/8/8 10:04
|
|
25
|
+ **/
|
|
26
|
+@Service
|
|
27
|
+public class EReportGenerateService {
|
|
28
|
+ @Resource
|
|
29
|
+ private EBaseMapper eBaseMapper;
|
|
30
|
+ @Resource
|
|
31
|
+ private EClassMapper eClassMapper;
|
|
32
|
+ @Resource
|
|
33
|
+ private ESubjectMapper eSubjectMapper;
|
|
34
|
+ @Resource
|
|
35
|
+ private EPaperStudentMapper ePaperStudentMapper;
|
|
36
|
+
|
|
37
|
+ @Resource
|
|
38
|
+ private ERbaseMapper eRbaseMapper;
|
|
39
|
+ @Resource
|
|
40
|
+ private ERstudentMapper eRstudentMapper;
|
|
41
|
+
|
|
42
|
+ //生成考试报告
|
|
43
|
+ public void generateExamReport(Integer examid) {
|
|
44
|
+ List<Map> classes = eClassMapper.listByExamId(examid);
|
|
45
|
+ List<Map> subjects = eSubjectMapper.listSubject(examid);
|
|
46
|
+ int classnum = classes.size();
|
|
47
|
+ int stunum = classes.stream().mapToInt(m -> (int) m.get("classnum")).sum();
|
|
48
|
+ int subjectnum = subjects.size();
|
|
49
|
+ /*ERbase rbase = new ERbase();
|
|
50
|
+ rbase.setExamid(examid);
|
|
51
|
+ rbase.setClassnum(classnum);
|
|
52
|
+ rbase.setStunum(stunum);
|
|
53
|
+ rbase.setSubjectnum(subjectnum);
|
|
54
|
+ eRbaseMapper.insertSelective(rbase);*/
|
|
55
|
+
|
|
56
|
+ String subjectid = "zf";
|
|
57
|
+ String subjectname = "总分";
|
|
58
|
+ Map<String, String> subjectMap = subjects.stream().collect(Collectors.toMap(m -> m.get("subjectid").toString(),
|
|
59
|
+ m -> m.get("subjectname").toString()));
|
|
60
|
+
|
|
61
|
+ List<ERstudent> schoolStudents = new ArrayList<>();//学校学生成绩
|
|
62
|
+ List<ERstudent> classStudents = new ArrayList<>();//班级学生成绩
|
|
63
|
+ List<ERstudent> subjectStudents = new ArrayList<>();//科目学生成绩、
|
|
64
|
+ Map<String, Integer> schoolRank = new HashMap<>();//学校分数排名
|
|
65
|
+ Map<String, Integer> classRank = new HashMap<>();//班级分数排名
|
|
66
|
+ Map<String, Integer> ssubjectRank = new HashMap<>();//学校科目分数排名
|
|
67
|
+ Map<String, Integer> csubjectRank = new HashMap<>();//班级科目分数排名
|
|
68
|
+
|
|
69
|
+ List<ERstudent> students = ePaperStudentMapper.listByExamId(examid);
|
|
70
|
+ Map<Integer, List<ERstudent>> schoolCollect = students.stream().collect(Collectors.groupingBy(s -> s.getStudentid()));
|
|
71
|
+ for (Map.Entry<Integer, List<ERstudent>> entry : schoolCollect.entrySet()) {
|
|
72
|
+ Integer studentid = entry.getKey();
|
|
73
|
+ ERstudent cs = new ERstudent();
|
|
74
|
+ cs.setStudentid(studentid);
|
|
75
|
+ cs.setScore(entry.getValue().stream().mapToDouble(s -> s.getScore()).sum());
|
|
76
|
+ schoolStudents.add(cs);
|
|
77
|
+ }
|
|
78
|
+ setRank(schoolStudents, schoolRank, 1);//学校分数排名
|
|
79
|
+
|
|
80
|
+ Map<Integer, List<ERstudent>> cCollect = students.stream().collect(Collectors.groupingBy(s -> s.getClassid()));
|
|
81
|
+ for (Map.Entry<Integer, List<ERstudent>> entry : cCollect.entrySet()) {
|
|
82
|
+ Integer classid = entry.getKey();
|
|
83
|
+ List<ERstudent> studentList = entry.getValue();
|
|
84
|
+ Map<Integer, List<ERstudent>> sCollect = studentList.stream().collect(Collectors.groupingBy(s -> s.getStudentid()));
|
|
85
|
+ for (Map.Entry<Integer, List<ERstudent>> csEntry : sCollect.entrySet()) {
|
|
86
|
+ ERstudent cs = new ERstudent();
|
|
87
|
+ cs.setClassid(classid);
|
|
88
|
+ cs.setStudentid(csEntry.getKey());
|
|
89
|
+ cs.setSubjectid(subjectid);
|
|
90
|
+ cs.setSubjectname(subjectname);
|
|
91
|
+ cs.setScore(csEntry.getValue().stream().mapToDouble(s -> s.getScore()).sum());
|
|
92
|
+ classStudents.add(cs);
|
|
93
|
+ }
|
|
94
|
+ setRank(classStudents, classRank, 2);//班级分数排名
|
|
95
|
+
|
|
96
|
+ Map<String, List<ERstudent>> subCollect = studentList.stream().collect(Collectors.groupingBy(s -> s.getSubjectid()));
|
|
97
|
+ for (Map.Entry<String, List<ERstudent>> ssEntry : subCollect.entrySet()) {
|
|
98
|
+ subjectid = ssEntry.getKey();
|
|
99
|
+ subjectname = subjectMap.get(subjectid);
|
|
100
|
+ studentList = ssEntry.getValue();
|
|
101
|
+ for (ERstudent cs : studentList) {
|
|
102
|
+ cs.setSubjectname(subjectname);
|
|
103
|
+ subjectStudents.add(cs);
|
|
104
|
+ }
|
|
105
|
+ }
|
|
106
|
+ setRank(subjectStudents, ssubjectRank, 3);//科目分数排名
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ DoubleSummaryStatistics schoolStatistics = schoolStudents.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
|
|
110
|
+ DoubleSummaryStatistics classStatistics = classStudents.stream().mapToDouble(s -> s.getScore()).summaryStatistics();
|
|
111
|
+ for (ERstudent cs : classStudents) {
|
|
112
|
+ Integer studentid = cs.getStudentid();
|
|
113
|
+ cs.setClassrank(classRank.get(cs.getClassid()+"_"+ studentid));
|
|
114
|
+ cs.setClassmaxscore(classStatistics.getMax());
|
|
115
|
+ cs.setClassavgscore(classStatistics.getAverage());
|
|
116
|
+ cs.setSchoolrank(schoolRank.get(studentid));
|
|
117
|
+ cs.setSchoolmaxscore(schoolStatistics.getMax());
|
|
118
|
+ cs.setSchoolavgscore(schoolStatistics.getAverage());
|
|
119
|
+ }
|
|
120
|
+ eRstudentMapper.insertList(classStudents);
|
|
121
|
+
|
|
122
|
+ for (ERstudent cs : subjectStudents) {
|
|
123
|
+ Integer studentid = cs.getStudentid();
|
|
124
|
+ cs.setClassrank(classRank.get(cs.getClassid()+"_"+ studentid));
|
|
125
|
+ cs.setClassmaxscore(classStatistics.getMax());
|
|
126
|
+ cs.setClassavgscore(classStatistics.getAverage());
|
|
127
|
+ cs.setSchoolrank(schoolRank.get(studentid));
|
|
128
|
+ cs.setSchoolmaxscore(schoolStatistics.getMax());
|
|
129
|
+ cs.setSchoolavgscore(schoolStatistics.getAverage());
|
|
130
|
+ }
|
|
131
|
+ eRstudentMapper.insertList(subjectStudents);
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ //分数排名
|
|
135
|
+ private void setRank(List<ERstudent> students, Map<String, Integer> rank, Integer code) {
|
|
136
|
+ students =
|
|
137
|
+ students.stream().sorted((s1, s2) -> -Double.compare(s1.getScore(), s2.getScore())).collect(Collectors.toList());
|
|
138
|
+ List<Map.Entry<Double, List<ERstudent>>> gslist2 = students.stream()
|
|
139
|
+ .collect(Collectors.groupingBy(ERstudent::getScore)).entrySet()
|
|
140
|
+ .stream().sorted((s1, s2) -> -Double.compare(s1.getKey(), s2.getKey())).collect(Collectors.toList());
|
|
141
|
+ Integer index = 1;
|
|
142
|
+ String key;
|
|
143
|
+ for (Map.Entry<Double, List<ERstudent>> entry : gslist2) {
|
|
144
|
+ for (ERstudent cgs : entry.getValue()) {
|
|
145
|
+ Integer studentid = cgs.getStudentid();
|
|
146
|
+ Integer classid = cgs.getClassid();
|
|
147
|
+ String subjectid = cgs.getSubjectid();
|
|
148
|
+ if (code == 1) {//学校
|
|
149
|
+ key = studentid.toString();
|
|
150
|
+ } else if (code == 2) {//班级
|
|
151
|
+ key = classid + "_" + studentid;
|
|
152
|
+ } else {//科目
|
|
153
|
+ key = subjectid + "_" + studentid;
|
|
154
|
+ }
|
|
155
|
+ rank.put(key, index);
|
|
156
|
+ }
|
|
157
|
+ index = index + entry.getValue().size();
|
|
158
|
+ }
|
|
159
|
+ }
|
|
160
|
+}
|