update 报告相关算法更新

develop
hhb@hotmail.com 1 month ago
parent cb74969301
commit d37286b83e

@ -46,8 +46,8 @@ public class LaborEducationController {
@PostMapping("getStudentMonthlyScores") @PostMapping("getStudentMonthlyScores")
@ApiOperation("按月比对分析") @ApiOperation("按月比对分析")
public R<List<Map<String, Object>>> getStudentMonthlyScores(@Valid @RequestBody LaborDto laborDto, HttpServletRequest request) { public R<Map<String,List<Map<String, Object>>>> getStudentMonthlyScores(@Valid @RequestBody LaborDto laborDto, HttpServletRequest request) {
List<Map<String, Object>> res = laborEducationService.getStudentMonthlyScores(laborDto,request); Map<String,List<Map<String, Object>>> res = laborEducationService.getStudentMonthlyScores(laborDto,request);
return R.success(res); return R.success(res);
} }
} }

@ -44,8 +44,8 @@ public class MoralEducationController {
@PostMapping("getStudentMonthlyScores") @PostMapping("getStudentMonthlyScores")
@ApiOperation("按月比对分析") @ApiOperation("按月比对分析")
public R<List<Map<String, Object>>> getStudentMonthlyScores(@Valid @RequestBody LaborDto laborDto, HttpServletRequest request) { public R<Map<String,List<Map<String, Object>>>> getStudentMonthlyScores(@Valid @RequestBody LaborDto laborDto, HttpServletRequest request) {
List<Map<String, Object>> res = moralEducationService.getStudentMonthlyScores(laborDto,request); Map<String,List<Map<String, Object>>> res = moralEducationService.getStudentMonthlyScores(laborDto,request);
return R.success(res); return R.success(res);
} }
} }

@ -13,5 +13,5 @@ public interface LaborEducationService {
Map<String,Object> getAnalysis(LaborDto laborDto, HttpServletRequest request); Map<String,Object> getAnalysis(LaborDto laborDto, HttpServletRequest request);
Map<String,Object> getDetails(FindDto findDto, HttpServletRequest request); Map<String,Object> getDetails(FindDto findDto, HttpServletRequest request);
Map<String,Object> getStudentSemesterScores(LaborDto laborDto, HttpServletRequest request); Map<String,Object> getStudentSemesterScores(LaborDto laborDto, HttpServletRequest request);
List<Map<String, Object>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request); Map<String,List<Map<String, Object>>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request);
} }

@ -11,5 +11,5 @@ public interface MoralEducationService {
Map<String,Object> getAnalysis(LaborDto laborDto, HttpServletRequest request); Map<String,Object> getAnalysis(LaborDto laborDto, HttpServletRequest request);
Map<String,Object> getDetails(FindDto findDto, HttpServletRequest request); Map<String,Object> getDetails(FindDto findDto, HttpServletRequest request);
Map<String,Object> getStudentSemesterScores(LaborDto laborDto, HttpServletRequest request); Map<String,Object> getStudentSemesterScores(LaborDto laborDto, HttpServletRequest request);
List<Map<String, Object>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request); Map<String,List<Map<String, Object>>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request);
} }

@ -702,29 +702,44 @@ public class LaborEducationServiceImpl implements LaborEducationService {
if (examResults != null && !examResults.isEmpty()) { if (examResults != null && !examResults.isEmpty()) {
// 遍历班级中的每个学生 // 遍历班级中的每个学生
for (ExamClassResult examResult : examResults) { for (ExamClassResult examResult : examResults) {
if (!examResult.getInfo().getId().equals(classId)) continue; if (!examResult.getInfo().getId().equals(classId)){
List<Integer> statuses = examResult.getStatus(); // 无考试数据时初始化所有学生的默认分数为60
for (int i = 0; i < examResult.getStudentIds().size(); i++) { if (groupList != null) {
String studentId = examResult.getStudentIds().get(i); for (RMember member : groupList.members) {
String name = rMembers.stream() String studentId = member.getId();
.filter(member -> member.getId().equals(studentId)) String studentName = studentIdToName.getOrDefault(studentId, "未知学生");
.findFirst() Map<String, Double> defaultScores = new HashMap<>();
.map(RMember::getName) for (String block : knowledgeBlocks) {
.orElse("未知"); defaultScores.put(block, 84.0); // 初始化为60分
int status = statuses.get(i); }
if (status == 1) continue; studentScoreRates.put(studentName, defaultScores);
}
// 正确获取已转换的客观分数(无需二次截断) }
Map<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent( }else{
studentId, examResults, knowledgeMap, appraise, points List<Integer> statuses = examResult.getStatus();
); for (int i = 0; i < examResult.getStudentIds().size(); i++) {
studentScoreRates.put(name, scoreRates); String studentId = examResult.getStudentIds().get(i);
String name = rMembers.stream()
// 累加班级整体得分率 .filter(member -> member.getId().equals(studentId))
for (Map.Entry<String, Double> entry : scoreRates.entrySet()) { .findFirst()
classScoreRates.put(entry.getKey(), classScoreRates.getOrDefault(entry.getKey(), 0.0) + entry.getValue()); .map(RMember::getName)
.orElse("未知");
int status = statuses.get(i);
if (status == 1) continue;
// 正确获取已转换的客观分数(无需二次截断)
Map<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent(
studentId, examResults, knowledgeMap, appraise, points
);
studentScoreRates.put(name, scoreRates);
// 累加班级整体得分率
for (Map.Entry<String, Double> entry : scoreRates.entrySet()) {
classScoreRates.put(entry.getKey(), classScoreRates.getOrDefault(entry.getKey(), 0.0) + entry.getValue());
}
} }
} }
} }
}else { }else {
// 无考试数据时初始化所有学生的默认分数为60 // 无考试数据时初始化所有学生的默认分数为60
@ -734,7 +749,7 @@ public class LaborEducationServiceImpl implements LaborEducationService {
String studentName = studentIdToName.getOrDefault(studentId, "未知学生"); String studentName = studentIdToName.getOrDefault(studentId, "未知学生");
Map<String, Double> defaultScores = new HashMap<>(); Map<String, Double> defaultScores = new HashMap<>();
for (String block : knowledgeBlocks) { for (String block : knowledgeBlocks) {
defaultScores.put(block, 60.0); // 初始化为60分 defaultScores.put(block, 84.0); // 初始化为60分
} }
studentScoreRates.put(studentName, defaultScores); studentScoreRates.put(studentName, defaultScores);
} }
@ -1376,7 +1391,7 @@ public class LaborEducationServiceImpl implements LaborEducationService {
//获取每月各个知识库综合得分以及整体得分内容 //获取每月各个知识库综合得分以及整体得分内容
public List<Map<String, Object>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request) { public Map<String,List<Map<String, Object>>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request) {
// 1. 获取基础信息 // 1. 获取基础信息
String schoolId = SecurityUtil.getLoginUser().getSchoolId(); String schoolId = SecurityUtil.getLoginUser().getSchoolId();
String studentId = laborDto.getStudentId(); String studentId = laborDto.getStudentId();
@ -1384,6 +1399,8 @@ public List<Map<String, Object>> getStudentMonthlyScores(LaborDto laborDto,HttpS
// 2. 获取相关开课记录 // 2. 获取相关开课记录
List<LessonRecord> records = getLessonRecords(laborDto, schoolId); List<LessonRecord> records = getLessonRecords(laborDto, schoolId);
List<RecordVo> res; List<RecordVo> res;
int rightCount = 0;
int wrongCount = 0;
if (laborDto.getClassId() == null) { if (laborDto.getClassId() == null) {
res = appraiseRecordRepository.getStudentRecords( res = appraiseRecordRepository.getStudentRecords(
String.format(PK.PK_APPRAISE_RECORD, schoolId), String.format(PK.PK_APPRAISE_RECORD, schoolId),
@ -1392,6 +1409,10 @@ public List<Map<String, Object>> getStudentMonthlyScores(LaborDto laborDto,HttpS
laborDto.getEndTime(), laborDto.getEndTime(),
"德育" "德育"
); );
//表扬的次数
rightCount = (int) res.stream().filter(RecordVo::isPraise).count();
//批评的次数
wrongCount = (int) res.stream().filter(record -> !record.isPraise()).count();
}else { }else {
//当班级ID 存在时 获取该班级下所有名单即学生Id //当班级ID 存在时 获取该班级下所有名单即学生Id
List<String> classIds = Collections.singletonList(laborDto.getClassId()); List<String> classIds = Collections.singletonList(laborDto.getClassId());
@ -1428,6 +1449,10 @@ public List<Map<String, Object>> getStudentMonthlyScores(LaborDto laborDto,HttpS
"德育", "德育",
classIds classIds
); );
//表扬的次数
rightCount = (int) res.stream().filter(RecordVo::isPraise).count();
//批评的次数
wrongCount = (int) res.stream().filter(record -> !record.isPraise()).count();
} }
// 3. 获取考试及知识点映射 // 3. 获取考试及知识点映射
@ -1493,7 +1518,7 @@ public List<Map<String, Object>> getStudentMonthlyScores(LaborDto laborDto,HttpS
// 6. 处理每月数据,传入主观评价统计结果 // 6. 处理每月数据,传入主观评价统计结果
return processMonthlyData( return processMonthlyData(records,res,rightCount,wrongCount,
targetStudents, targetStudents,
monthlyResults, monthlyResults,
knowledgeBlockMap, knowledgeBlockMap,
@ -1651,14 +1676,24 @@ public List<Map<String, Object>> getStudentMonthlyScores(LaborDto laborDto,HttpS
return monthlyResults; return monthlyResults;
} }
private List<Map<String, Object>> processMonthlyData( private Map<String,List<Map<String, Object>>> processMonthlyData(
List<LessonRecord> records,List<RecordVo> res,int rightCount,int wrongCount,
List<String> targetStudentIds, List<String> targetStudentIds,
Map<Integer, List<ExamResultWrapper>> monthlyResults, Map<Integer, List<ExamResultWrapper>> monthlyResults,
Map<String, List<String>> knowledgeBlockMap, Map<String, List<String>> knowledgeBlockMap,
Set<Integer> months, Set<Integer> months,
Map<String, Map<Integer, Integer>> blockMonthlyCounts) { Map<String, Map<Integer, Integer>> blockMonthlyCounts) {
return months.stream().map(month -> { Map<String,List<Map<String, Object>>> detailList = new HashMap<>();
List<Map<String, Object>> details = new ArrayList<>();
Map<String, Object> 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<Map<String, Object>> collect = months.stream().map(month -> {
Map<String, Object> monthEntry = new LinkedHashMap<>(); Map<String, Object> monthEntry = new LinkedHashMap<>();
monthEntry.put("month", month); monthEntry.put("month", month);
List<Map<String, Object>> scoreList = new ArrayList<>(); List<Map<String, Object>> scoreList = new ArrayList<>();
@ -1753,6 +1788,8 @@ public List<Map<String, Object>> getStudentMonthlyScores(LaborDto laborDto,HttpS
return monthEntry; return monthEntry;
}).sorted(Comparator.comparingInt(m -> (Integer) m.get("month"))) }).sorted(Comparator.comparingInt(m -> (Integer) m.get("month")))
.collect(Collectors.toList()); .collect(Collectors.toList());
detailList.put("collect", collect);
return detailList;
} }
// 新增方法:计算主观评分转换后的得分 // 新增方法:计算主观评分转换后的得分

@ -1329,7 +1329,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
} }
//获取每月各个知识库综合得分以及整体得分内容 //获取每月各个知识库综合得分以及整体得分内容
public List<Map<String, Object>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request) { public Map<String,List<Map<String, Object>>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request) {
// 1. 获取基础信息 // 1. 获取基础信息
String schoolId = SecurityUtil.getLoginUser().getSchoolId(); String schoolId = SecurityUtil.getLoginUser().getSchoolId();
String studentId = laborDto.getStudentId(); String studentId = laborDto.getStudentId();
@ -1337,6 +1337,8 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 2. 获取相关开课记录 // 2. 获取相关开课记录
List<LessonRecord> records = getLessonRecords(laborDto, schoolId); List<LessonRecord> records = getLessonRecords(laborDto, schoolId);
List<RecordVo> res; List<RecordVo> res;
int rightCount = 0;
int wrongCount = 0;
if (laborDto.getClassId() == null) { if (laborDto.getClassId() == null) {
res = appraiseRecordRepository.getStudentRecords( res = appraiseRecordRepository.getStudentRecords(
String.format(PK.PK_APPRAISE_RECORD, schoolId), String.format(PK.PK_APPRAISE_RECORD, schoolId),
@ -1345,6 +1347,10 @@ public class MoralEducationServiceImpl implements MoralEducationService {
laborDto.getEndTime(), laborDto.getEndTime(),
"劳育" "劳育"
); );
//表扬的次数
rightCount = (int) res.stream().filter(RecordVo::isPraise).count();
//批评的次数
wrongCount = (int) res.stream().filter(record -> !record.isPraise()).count();
}else { }else {
//当班级ID 存在时 获取该班级下所有名单即学生Id //当班级ID 存在时 获取该班级下所有名单即学生Id
List<String> classIds = Collections.singletonList(laborDto.getClassId()); List<String> classIds = Collections.singletonList(laborDto.getClassId());
@ -1381,6 +1387,10 @@ public class MoralEducationServiceImpl implements MoralEducationService {
"劳育", "劳育",
classIds classIds
); );
//表扬的次数
rightCount = (int) res.stream().filter(RecordVo::isPraise).count();
//批评的次数
wrongCount = (int) res.stream().filter(record -> !record.isPraise()).count();
} }
// 3. 获取考试及知识点映射 // 3. 获取考试及知识点映射
@ -1447,6 +1457,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 6. 处理每月数据,传入主观评价统计结果 // 6. 处理每月数据,传入主观评价统计结果
return processMonthlyData( return processMonthlyData(
records,res, rightCount, wrongCount,
targetStudents, targetStudents,
monthlyResults, monthlyResults,
knowledgeBlockMap, knowledgeBlockMap,
@ -1604,24 +1615,35 @@ public class MoralEducationServiceImpl implements MoralEducationService {
return monthlyResults; return monthlyResults;
} }
private List<Map<String, Object>> processMonthlyData( private Map<String,List<Map<String, Object>>> processMonthlyData(
List<LessonRecord> records,List<RecordVo> res,int rightCount,int wrongCount,
List<String> targetStudentIds, List<String> targetStudentIds,
Map<Integer, List<MoralEducationServiceImpl.ExamResultWrapper>> monthlyResults, Map<Integer, List<MoralEducationServiceImpl.ExamResultWrapper>> monthlyResults,
Map<String, List<String>> knowledgeBlockMap, Map<String, List<String>> knowledgeBlockMap,
Set<Integer> months, Set<Integer> months,
Map<String, Map<Integer, Integer>> blockMonthlyCounts) { Map<String, Map<Integer, Integer>> blockMonthlyCounts) {
return months.stream().map(month -> { Map<String,List<Map<String, Object>>> detailList = new HashMap<>();
List<Map<String, Object>> details = new ArrayList<>();
Map<String, Object> 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<Map<String, Object>> collect = months.stream().map(month -> {
Map<String, Object> monthEntry = new LinkedHashMap<>(); Map<String, Object> monthEntry = new LinkedHashMap<>();
monthEntry.put("month", month); monthEntry.put("month", month);
List<Map<String, Object>> scoreList = new ArrayList<>(); List<Map<String, Object>> scoreList = new ArrayList<>();
// 按学生分组考试结果 // 按学生分组考试结果
Map<String, List<MoralEducationServiceImpl.ExamResultWrapper>> studentResults = monthlyResults Map<String, List<ExamResultWrapper>> studentResults = monthlyResults
.getOrDefault(month, Collections.emptyList()) .getOrDefault(month, Collections.emptyList())
.stream() .stream()
.filter(wrapper -> targetStudentIds.contains(wrapper.getStudentId())) .filter(wrapper -> targetStudentIds.contains(wrapper.getStudentId()))
.collect(Collectors.groupingBy(MoralEducationServiceImpl.ExamResultWrapper::getStudentId)); .collect(Collectors.groupingBy(ExamResultWrapper::getStudentId));
// 初始化知识块总分计数器 // 初始化知识块总分计数器
Map<String, Double> blockTotalScores = new HashMap<>(); Map<String, Double> blockTotalScores = new HashMap<>();
@ -1629,9 +1651,9 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 遍历所有目标学生 // 遍历所有目标学生
targetStudentIds.forEach(studentId -> { targetStudentIds.forEach(studentId -> {
List<MoralEducationServiceImpl.ExamResultWrapper> wrappers = studentResults.getOrDefault(studentId, Collections.emptyList()); List<ExamResultWrapper> wrappers = studentResults.getOrDefault(studentId, Collections.emptyList());
List<ExamClassResult> examResults = wrappers.stream() List<ExamClassResult> examResults = wrappers.stream()
.map(MoralEducationServiceImpl.ExamResultWrapper::getResult) .map(ExamResultWrapper::getResult)
.collect(Collectors.toList()); .collect(Collectors.toList());
// 1. 计算知识点得分(保留原始逻辑) // 1. 计算知识点得分(保留原始逻辑)
@ -1639,11 +1661,11 @@ public class MoralEducationServiceImpl implements MoralEducationService {
studentId, studentId,
examResults, examResults,
wrappers.stream().collect(Collectors.toMap( wrappers.stream().collect(Collectors.toMap(
MoralEducationServiceImpl.ExamResultWrapper::getExamId, ExamResultWrapper::getExamId,
MoralEducationServiceImpl.ExamResultWrapper::getKnowledge)), ExamResultWrapper::getKnowledge)),
wrappers.stream().collect(Collectors.toMap( wrappers.stream().collect(Collectors.toMap(
MoralEducationServiceImpl.ExamResultWrapper::getExamId, ExamResultWrapper::getExamId,
MoralEducationServiceImpl.ExamResultWrapper::getPoints)) ExamResultWrapper::getPoints))
); );
// 2. 计算每个知识块的客观得分(新增关键逻辑) // 2. 计算每个知识块的客观得分(新增关键逻辑)
@ -1706,6 +1728,8 @@ public class MoralEducationServiceImpl implements MoralEducationService {
return monthEntry; return monthEntry;
}).sorted(Comparator.comparingInt(m -> (Integer) m.get("month"))) }).sorted(Comparator.comparingInt(m -> (Integer) m.get("month")))
.collect(Collectors.toList()); .collect(Collectors.toList());
detailList.put("collect", collect);
return detailList;
} }
// 新增方法:计算主观评分转换后的得分 // 新增方法:计算主观评分转换后的得分

Loading…
Cancel
Save