diff --git a/src/main/java/cn/teammodel/controller/admin/controller/LaborEducationController.java b/src/main/java/cn/teammodel/controller/admin/controller/LaborEducationController.java index f971677..4bae25d 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/LaborEducationController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/LaborEducationController.java @@ -46,8 +46,8 @@ public class LaborEducationController { @PostMapping("getStudentMonthlyScores") @ApiOperation("按月比对分析") - public R>> getStudentMonthlyScores(@Valid @RequestBody LaborDto laborDto, HttpServletRequest request) { - List> res = laborEducationService.getStudentMonthlyScores(laborDto,request); + public R>>> getStudentMonthlyScores(@Valid @RequestBody LaborDto laborDto, HttpServletRequest request) { + Map>> res = laborEducationService.getStudentMonthlyScores(laborDto,request); return R.success(res); } } diff --git a/src/main/java/cn/teammodel/controller/admin/controller/MoralEducationController.java b/src/main/java/cn/teammodel/controller/admin/controller/MoralEducationController.java index 389cba4..d4962b3 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/MoralEducationController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/MoralEducationController.java @@ -44,8 +44,8 @@ public class MoralEducationController { @PostMapping("getStudentMonthlyScores") @ApiOperation("按月比对分析") - public R>> getStudentMonthlyScores(@Valid @RequestBody LaborDto laborDto, HttpServletRequest request) { - List> res = moralEducationService.getStudentMonthlyScores(laborDto,request); + public R>>> getStudentMonthlyScores(@Valid @RequestBody LaborDto laborDto, HttpServletRequest request) { + Map>> res = moralEducationService.getStudentMonthlyScores(laborDto,request); return R.success(res); } } diff --git a/src/main/java/cn/teammodel/controller/admin/service/LaborEducationService.java b/src/main/java/cn/teammodel/controller/admin/service/LaborEducationService.java index 2a62fd9..e70748f 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/LaborEducationService.java +++ b/src/main/java/cn/teammodel/controller/admin/service/LaborEducationService.java @@ -13,5 +13,5 @@ public interface LaborEducationService { Map getAnalysis(LaborDto laborDto, HttpServletRequest request); Map getDetails(FindDto findDto, HttpServletRequest request); Map getStudentSemesterScores(LaborDto laborDto, HttpServletRequest request); - List> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request); + Map>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request); } diff --git a/src/main/java/cn/teammodel/controller/admin/service/MoralEducationService.java b/src/main/java/cn/teammodel/controller/admin/service/MoralEducationService.java index 6644ee5..44b6c71 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/MoralEducationService.java +++ b/src/main/java/cn/teammodel/controller/admin/service/MoralEducationService.java @@ -11,5 +11,5 @@ public interface MoralEducationService { Map getAnalysis(LaborDto laborDto, HttpServletRequest request); Map getDetails(FindDto findDto, HttpServletRequest request); Map getStudentSemesterScores(LaborDto laborDto, HttpServletRequest request); - List> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request); + Map>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request); } 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 879e112..508c969 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 @@ -702,29 +702,44 @@ public class LaborEducationServiceImpl implements LaborEducationService { if (examResults != null && !examResults.isEmpty()) { // 遍历班级中的每个学生 for (ExamClassResult examResult : examResults) { - if (!examResult.getInfo().getId().equals(classId)) continue; - List statuses = examResult.getStatus(); - for (int i = 0; i < examResult.getStudentIds().size(); i++) { - String studentId = examResult.getStudentIds().get(i); - String name = rMembers.stream() - .filter(member -> member.getId().equals(studentId)) - .findFirst() - .map(RMember::getName) - .orElse("未知"); - int status = statuses.get(i); - if (status == 1) continue; - - // 正确获取已转换的客观分数(无需二次截断) - Map scoreRates = calculateKnowledgeScoreRateForStudent( - studentId, examResults, knowledgeMap, appraise, points - ); - studentScoreRates.put(name, scoreRates); - - // 累加班级整体得分率 - for (Map.Entry entry : scoreRates.entrySet()) { - classScoreRates.put(entry.getKey(), classScoreRates.getOrDefault(entry.getKey(), 0.0) + entry.getValue()); + if (!examResult.getInfo().getId().equals(classId)){ + // 无考试数据时,初始化所有学生的默认分数为60 + if (groupList != null) { + for (RMember member : groupList.members) { + String studentId = member.getId(); + String studentName = studentIdToName.getOrDefault(studentId, "未知学生"); + Map defaultScores = new HashMap<>(); + for (String block : knowledgeBlocks) { + defaultScores.put(block, 84.0); // 初始化为60分 + } + studentScoreRates.put(studentName, defaultScores); + } + } + }else{ + List statuses = examResult.getStatus(); + for (int i = 0; i < examResult.getStudentIds().size(); i++) { + String studentId = examResult.getStudentIds().get(i); + String name = rMembers.stream() + .filter(member -> member.getId().equals(studentId)) + .findFirst() + .map(RMember::getName) + .orElse("未知"); + int status = statuses.get(i); + if (status == 1) continue; + + // 正确获取已转换的客观分数(无需二次截断) + Map scoreRates = calculateKnowledgeScoreRateForStudent( + studentId, examResults, knowledgeMap, appraise, points + ); + studentScoreRates.put(name, scoreRates); + + // 累加班级整体得分率 + for (Map.Entry entry : scoreRates.entrySet()) { + classScoreRates.put(entry.getKey(), classScoreRates.getOrDefault(entry.getKey(), 0.0) + entry.getValue()); + } } } + } }else { // 无考试数据时,初始化所有学生的默认分数为60 @@ -734,7 +749,7 @@ public class LaborEducationServiceImpl implements LaborEducationService { String studentName = studentIdToName.getOrDefault(studentId, "未知学生"); Map defaultScores = new HashMap<>(); for (String block : knowledgeBlocks) { - defaultScores.put(block, 60.0); // 初始化为60分 + defaultScores.put(block, 84.0); // 初始化为60分 } studentScoreRates.put(studentName, defaultScores); } @@ -1376,7 +1391,7 @@ public class LaborEducationServiceImpl implements LaborEducationService { //获取每月各个知识库综合得分以及整体得分内容 -public List> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request) { +public Map>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request) { // 1. 获取基础信息 String schoolId = SecurityUtil.getLoginUser().getSchoolId(); String studentId = laborDto.getStudentId(); @@ -1384,6 +1399,8 @@ public List> getStudentMonthlyScores(LaborDto laborDto,HttpS // 2. 获取相关开课记录 List records = getLessonRecords(laborDto, schoolId); List res; + int rightCount = 0; + int wrongCount = 0; if (laborDto.getClassId() == null) { res = appraiseRecordRepository.getStudentRecords( String.format(PK.PK_APPRAISE_RECORD, schoolId), @@ -1392,6 +1409,10 @@ public List> getStudentMonthlyScores(LaborDto laborDto,HttpS laborDto.getEndTime(), "德育" ); + //表扬的次数 + rightCount = (int) res.stream().filter(RecordVo::isPraise).count(); + //批评的次数 + wrongCount = (int) res.stream().filter(record -> !record.isPraise()).count(); }else { //当班级ID 存在时 获取该班级下所有名单即学生Id List classIds = Collections.singletonList(laborDto.getClassId()); @@ -1428,6 +1449,10 @@ public List> getStudentMonthlyScores(LaborDto laborDto,HttpS "德育", classIds ); + //表扬的次数 + rightCount = (int) res.stream().filter(RecordVo::isPraise).count(); + //批评的次数 + wrongCount = (int) res.stream().filter(record -> !record.isPraise()).count(); } // 3. 获取考试及知识点映射 @@ -1493,7 +1518,7 @@ public List> getStudentMonthlyScores(LaborDto laborDto,HttpS // 6. 处理每月数据,传入主观评价统计结果 - return processMonthlyData( + return processMonthlyData(records,res,rightCount,wrongCount, targetStudents, monthlyResults, knowledgeBlockMap, @@ -1651,14 +1676,24 @@ public List> getStudentMonthlyScores(LaborDto laborDto,HttpS return monthlyResults; } - private List> processMonthlyData( + private Map>> processMonthlyData( + List records,List res,int rightCount,int wrongCount, List targetStudentIds, Map> monthlyResults, Map> knowledgeBlockMap, Set months, Map> blockMonthlyCounts) { - return months.stream().map(month -> { + Map>> detailList = new HashMap<>(); + List> details = new ArrayList<>(); + Map detail = new HashMap<>(); + detail.put("rightCount", rightCount); + detail.put("wrongCount", wrongCount); + detail.put("recordCount", records.size()); + detail.put("resCount", res.size()); + details.add(detail); + detailList.put("detail",details); + List> collect = months.stream().map(month -> { Map monthEntry = new LinkedHashMap<>(); monthEntry.put("month", month); List> scoreList = new ArrayList<>(); @@ -1753,6 +1788,8 @@ public List> getStudentMonthlyScores(LaborDto laborDto,HttpS return monthEntry; }).sorted(Comparator.comparingInt(m -> (Integer) m.get("month"))) .collect(Collectors.toList()); + detailList.put("collect", collect); + return detailList; } // 新增方法:计算主观评分转换后的得分 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 f082b23..eaec92b 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 @@ -1329,7 +1329,7 @@ public class MoralEducationServiceImpl implements MoralEducationService { } //获取每月各个知识库综合得分以及整体得分内容 - public List> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request) { + public Map>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request) { // 1. 获取基础信息 String schoolId = SecurityUtil.getLoginUser().getSchoolId(); String studentId = laborDto.getStudentId(); @@ -1337,6 +1337,8 @@ public class MoralEducationServiceImpl implements MoralEducationService { // 2. 获取相关开课记录 List records = getLessonRecords(laborDto, schoolId); List res; + int rightCount = 0; + int wrongCount = 0; if (laborDto.getClassId() == null) { res = appraiseRecordRepository.getStudentRecords( String.format(PK.PK_APPRAISE_RECORD, schoolId), @@ -1345,6 +1347,10 @@ public class MoralEducationServiceImpl implements MoralEducationService { laborDto.getEndTime(), "劳育" ); + //表扬的次数 + rightCount = (int) res.stream().filter(RecordVo::isPraise).count(); + //批评的次数 + wrongCount = (int) res.stream().filter(record -> !record.isPraise()).count(); }else { //当班级ID 存在时 获取该班级下所有名单即学生Id List classIds = Collections.singletonList(laborDto.getClassId()); @@ -1381,6 +1387,10 @@ public class MoralEducationServiceImpl implements MoralEducationService { "劳育", classIds ); + //表扬的次数 + rightCount = (int) res.stream().filter(RecordVo::isPraise).count(); + //批评的次数 + wrongCount = (int) res.stream().filter(record -> !record.isPraise()).count(); } // 3. 获取考试及知识点映射 @@ -1447,6 +1457,7 @@ public class MoralEducationServiceImpl implements MoralEducationService { // 6. 处理每月数据,传入主观评价统计结果 return processMonthlyData( + records,res, rightCount, wrongCount, targetStudents, monthlyResults, knowledgeBlockMap, @@ -1604,24 +1615,35 @@ public class MoralEducationServiceImpl implements MoralEducationService { return monthlyResults; } - private List> processMonthlyData( + private Map>> processMonthlyData( + List records,List res,int rightCount,int wrongCount, List targetStudentIds, Map> monthlyResults, Map> knowledgeBlockMap, Set months, Map> blockMonthlyCounts) { - return months.stream().map(month -> { + Map>> detailList = new HashMap<>(); + List> details = new ArrayList<>(); + Map detail = new HashMap<>(); + detail.put("rightCount", rightCount); + detail.put("wrongCount", wrongCount); + detail.put("recordCount", records.size()); + detail.put("resCount", res.size()); + details.add(detail); + detailList.put("detail",details); + + List> collect = months.stream().map(month -> { Map monthEntry = new LinkedHashMap<>(); monthEntry.put("month", month); List> scoreList = new ArrayList<>(); // 按学生分组考试结果 - Map> studentResults = monthlyResults + Map> studentResults = monthlyResults .getOrDefault(month, Collections.emptyList()) .stream() .filter(wrapper -> targetStudentIds.contains(wrapper.getStudentId())) - .collect(Collectors.groupingBy(MoralEducationServiceImpl.ExamResultWrapper::getStudentId)); + .collect(Collectors.groupingBy(ExamResultWrapper::getStudentId)); // 初始化知识块总分计数器 Map blockTotalScores = new HashMap<>(); @@ -1629,9 +1651,9 @@ public class MoralEducationServiceImpl implements MoralEducationService { // 遍历所有目标学生 targetStudentIds.forEach(studentId -> { - List wrappers = studentResults.getOrDefault(studentId, Collections.emptyList()); + List wrappers = studentResults.getOrDefault(studentId, Collections.emptyList()); List examResults = wrappers.stream() - .map(MoralEducationServiceImpl.ExamResultWrapper::getResult) + .map(ExamResultWrapper::getResult) .collect(Collectors.toList()); // 1. 计算知识点得分(保留原始逻辑) @@ -1639,11 +1661,11 @@ public class MoralEducationServiceImpl implements MoralEducationService { studentId, examResults, wrappers.stream().collect(Collectors.toMap( - MoralEducationServiceImpl.ExamResultWrapper::getExamId, - MoralEducationServiceImpl.ExamResultWrapper::getKnowledge)), + ExamResultWrapper::getExamId, + ExamResultWrapper::getKnowledge)), wrappers.stream().collect(Collectors.toMap( - MoralEducationServiceImpl.ExamResultWrapper::getExamId, - MoralEducationServiceImpl.ExamResultWrapper::getPoints)) + ExamResultWrapper::getExamId, + ExamResultWrapper::getPoints)) ); // 2. 计算每个知识块的客观得分(新增关键逻辑) @@ -1706,6 +1728,8 @@ public class MoralEducationServiceImpl implements MoralEducationService { return monthEntry; }).sorted(Comparator.comparingInt(m -> (Integer) m.get("month"))) .collect(Collectors.toList()); + detailList.put("collect", collect); + return detailList; } // 新增方法:计算主观评分转换后的得分