diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/LaborEducationServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/LaborEducationServiceImpl.java index 03eea6e..ae37cd0 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/impl/LaborEducationServiceImpl.java +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/LaborEducationServiceImpl.java @@ -1569,12 +1569,14 @@ public Map>> getStudentMonthlyScores(LaborDto la // 3. 获取考试及知识点映射 Map>> examKnowledgeMap = new HashMap<>(); Map> points = new HashMap<>(); + List exams = getExamsWithKnowledge(laborDto, records, examKnowledgeMap, points); // 4. 获取考试结果并按月份分组 List targetStudents = laborDto.getClassId() != null ? classStudentIds : Collections.singletonList(studentId); + //records有可能没有数据 重写monthlyResults Map> monthlyResults = getMonthlyExamResults( schoolId, laborDto.getClassId(), exams, records, examKnowledgeMap, points, targetStudents // 传入目标学生列表 @@ -1697,7 +1699,20 @@ public Map>> getStudentMonthlyScores(LaborDto la private List getExamsWithKnowledge(LaborDto laborDto, List records, Map>> examKnowledgeMap, Map> points) { - List lessonRecordIds = records.stream().map(LessonRecord::getId).collect(Collectors.toList()); + if (records == null || records.isEmpty()) { + return Collections.emptyList(); + } + + List lessonRecordIds = records.stream() + .map(LessonRecord::getId) + .filter(id -> id != null && !id.isEmpty()) + .distinct() + .collect(Collectors.toList()); + + if (lessonRecordIds.isEmpty()) { + return Collections.emptyList(); + } + List exams = examRepository.findExamsByIds(laborDto.getSource(), lessonRecordIds); exams.forEach(exam -> { @@ -1712,13 +1727,16 @@ public Map>> getStudentMonthlyScores(LaborDto la .collect(Collectors.toList()); } + private Map> getMonthlyExamResults( String schoolId, String classId, List exams, List records, Map>> examKnowledgeMap, Map> points, List studentIds) { // 新增studentIds参数 Map> monthlyResults = new HashMap<>(); - + if (exams == null || exams.isEmpty() || records == null || records.isEmpty()) { + return monthlyResults; // 安全退出,返回空 map + } if (classId == null) { exams.forEach(exam -> { List results = examClassResultRepository.findByStudentId( diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/MoralEducationServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/MoralEducationServiceImpl.java index c1c0763..f3bb8af 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/impl/MoralEducationServiceImpl.java +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/MoralEducationServiceImpl.java @@ -11,6 +11,7 @@ import cn.teammodel.model.dto.admin.common.GroupDto; import cn.teammodel.model.dto.admin.common.RGroupList; import cn.teammodel.model.dto.admin.common.RMember; import cn.teammodel.model.dto.admin.labor.FindDto; +import cn.teammodel.model.dto.admin.labor.LaborDto; import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.common.Exam; @@ -1697,7 +1698,20 @@ public class MoralEducationServiceImpl implements MoralEducationService { private List getExamsWithKnowledge(MoralDto moralDto, List records, Map>> examKnowledgeMap, Map> points) { - List lessonRecordIds = records.stream().map(LessonRecord::getId).collect(Collectors.toList()); + if (records == null || records.isEmpty()) { + return Collections.emptyList(); + } + + List lessonRecordIds = records.stream() + .map(LessonRecord::getId) + .filter(id -> id != null && !id.isEmpty()) + .distinct() + .collect(Collectors.toList()); + + if (lessonRecordIds.isEmpty()) { + return Collections.emptyList(); + } + List exams = examRepository.findExamsByIds(moralDto.getSource(), lessonRecordIds); exams.forEach(exam -> { diff --git a/src/main/java/cn/teammodel/test/AsyncTeacherService.java b/src/main/java/cn/teammodel/test/AsyncTeacherService.java index 02b9583..c196128 100644 --- a/src/main/java/cn/teammodel/test/AsyncTeacherService.java +++ b/src/main/java/cn/teammodel/test/AsyncTeacherService.java @@ -64,7 +64,7 @@ public class AsyncTeacherService { .collect(Collectors.toList()); if (!updates.isEmpty()) { - ptTeacherRepository.saveAll(updates); + //ptTeacherRepository.saveAll(updates); // updates.forEach(pt -> PT_TEACHER_CACHE.put(pt.getCode(), pt)); } } catch (Exception e) {