优化对比多学院接口

This commit is contained in:
xbx 2024-04-24 15:45:03 +08:00
parent 2ee73def1c
commit 8eacfd52dc
1 changed files with 8 additions and 15 deletions

View File

@ -299,32 +299,25 @@ public class Cet_4ServiceImpl extends ServiceImpl<Cet_4Mapper, Cet_4> implements
} }
} }
} }
//学院/专业的全部在籍学生
long allStudent;
//查某个入学年级的所有学院 //查某个入学年级的所有学院
LambdaQueryWrapper<Cet4_major> cet4MajorQW = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Cet4_major> cet4MajorQW = new LambdaQueryWrapper<>();
cet4MajorQW.select(Cet4_major::getCollege).eq(Cet4_major::getEntrydate, entryDate).groupBy(Cet4_major::getCollege); cet4MajorQW.select(Cet4_major::getCollege).eq(Cet4_major::getEntrydate, entryDate).groupBy(Cet4_major::getCollege);
//若无该学院则剔除 //若无该学院则剔除
List<Object> collegeSet = cet4_MajorMapper.selectObjs(cet4MajorQW); List<Object> collegeSet = cet4_MajorMapper.selectObjs(cet4MajorQW);
// 在循环开始之前获取所有学院的在籍学生数量 // 在循环开始之前获取该学院该年级的学生数量
LambdaQueryWrapper<Cet4_major> allStudentQW = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Cet4_major> allStudentQW = new LambdaQueryWrapper<>();
allStudentQW.select(Cet4_major::getCollege, Cet4_major::getId).eq(Cet4_major::getState, "在校").eq(Cet4_major::getEntrydate, entryDate); allStudentQW.select(Cet4_major::getId).eq(Cet4_major::getState, "在校").eq(Cet4_major::getEntrydate, entryDate).eq(Cet4_major::getCollege, collegeName);
List<Map<String, Object>> allStudentList = cet4_majorMapper.selectMaps(allStudentQW); //获取该学院在籍学生数量
Map<String, Long> allStudentMap = allStudentList.stream().collect(Collectors.groupingBy(map -> (String) map.get("college"), Collectors.counting())); long allStudent = cet4_majorMapper.selectCount(allStudentQW);
// 在循环开始之前获取该年级学院所有批次的数据
// 在循环开始之前获取所有批次的数据
LambdaQueryWrapper<Cet_4> allBatchQW = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Cet_4> allBatchQW = new LambdaQueryWrapper<>();
allBatchQW.select(Cet_4::getCollege, Cet_4::getId, Cet_4::getResult).eq(Cet_4::getEntrydate, entryDate).in(Cet_4::getBatch, batchList); allBatchQW.select(Cet_4::getCollege, Cet_4::getId, Cet_4::getResult).eq(Cet_4::getEntrydate, entryDate).eq(Cet_4::getCollege, collegeName).in(Cet_4::getBatch, batchList);
List<Map<String, Object>> allBatchList = cet4Mapper.selectMaps(allBatchQW); //获取该学院该年级所有批次的数据
Map<String, List<Map<String, Object>>> allBatchMap = allBatchList.stream().collect(Collectors.groupingBy(map -> (String) map.get("college"))); List<Map<String, Object>> Cet_4eEntrydate = cet4Mapper.selectMaps(allBatchQW);
if (collegeSet.contains(collegeName)) { if (collegeSet.contains(collegeName)) {
//所有参加过四级考试的学生 //所有参加过四级考试的学生
Map<String, Integer> attendMap4 = new HashMap<>(); Map<String, Integer> attendMap4 = new HashMap<>();
//获取该学院在籍学生数量
allStudent = allStudentMap.getOrDefault(collegeName, 0L);
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
//一次性获取所有批次的数据
List<Map<String, Object>> Cet_4eEntrydate = allBatchMap.get(collegeName);
for (Map<String, Object> map : Cet_4eEntrydate) { for (Map<String, Object> map : Cet_4eEntrydate) {
String str = (String) map.get("id"); String str = (String) map.get("id");
if ((int) map.get("result") >= 425) { if ((int) map.get("result") >= 425) {