update 德育 劳育数据校验与新增均分

develop
hhb@hotmail.com 1 week ago
parent 086f63036f
commit 609e32b450

@ -789,7 +789,7 @@ public class LaborEducationServiceImpl implements LaborEducationService {
// 1. 获取班级所有学生的客观分数
Map<String, Map<String, Double>> studentScoreRates = new HashMap<>();
Map<String, Double> classScoreRates = new HashMap<>();
//Map<String, Double> classScoreRates = new HashMap<>();
// 获取班级所有学生的名单(来自 rMembers
Map<String, String> studentIdToName = new HashMap<>();
@ -811,8 +811,12 @@ public class LaborEducationServiceImpl implements LaborEducationService {
}
if (examResults != null && !examResults.isEmpty()) {
//筛选出对应班级的考试结果
List<ExamClassResult> classExamResults = examResults.stream()
.filter(examResult -> examResult.getInfo().getId().equals(classId))
.collect(Collectors.toList());
// 遍历班级中的每个学生
for (ExamClassResult examResult : examResults) {
for (ExamClassResult examResult : classExamResults) {
if (!examResult.getInfo().getId().equals(classId)){
// 无考试数据时初始化所有学生的默认分数为60
if (groupList != null) {
@ -827,27 +831,23 @@ public class LaborEducationServiceImpl implements LaborEducationService {
}
}
}else{
List<Integer> statuses = examResult.getStatus();
for (int i = 0; i < examResult.getStudentIds().size(); i++) {
String studentId = examResult.getStudentIds().get(i);
//<Integer> statuses = examResult.getStatus();
for (String studentId : studentIdToName.keySet()) {
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<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent(
studentId, examResults, knowledgeMap, appraise, points
studentId, classExamResults, 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());
}
// // 累加班级整体得分率
// for (Map.Entry<String, Double> entry : scoreRates.entrySet()) {
// classScoreRates.put(entry.getKey(), classScoreRates.getOrDefault(entry.getKey(), 0.0) + entry.getValue());
// }
}
}
@ -917,7 +917,7 @@ public class LaborEducationServiceImpl implements LaborEducationService {
// 计算综合得分主观60% + 客观40%
double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4);
compositeScore = Math.min(100.0, compositeScore); // 确保不超过100分
compositeScore = Math.max(60.0, Math.min(100.0, compositeScore)); // 确保60-100分
compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
compositeScores.put(block, compositeScore);
@ -928,18 +928,23 @@ public class LaborEducationServiceImpl implements LaborEducationService {
// 5. 计算班级整体得分率
int studentCount = compositeStudentScores.size();
Map<String, Double> compositeClassScoreRates = new HashMap<>();
if (studentCount > 0) {
for (Map<String, Double> studentScores : compositeStudentScores.values()) {
for (String studentId : studentIdToName.keySet()) {
String studentName = studentIdToName.get(studentId);
Map<String, Double> compositeScores = compositeStudentScores.get(studentName);
for (String block : knowledgeBlocks) {
double score = studentScores.getOrDefault(block, 0.0);
compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score);
double score = compositeScores.getOrDefault(block, 60.0);
compositeClassScoreRates.put(block,
compositeClassScoreRates.getOrDefault(block, 0.0) + score);
}
}
compositeClassScoreRates.replaceAll((k, v) -> Double.parseDouble(String.format("%.2f", v / studentCount)));
// 计算平均值
if (studentCount > 0) {
compositeClassScoreRates.replaceAll((k, v) ->
Double.parseDouble(String.format("%.2f", v / studentCount)));
} else {
// 无学生时初始化空值
for (String block : knowledgeBlocks) {
compositeClassScoreRates.put(block, 0.0);
compositeClassScoreRates.put(block, 60.0); // 默认60分
}
}
@ -971,6 +976,10 @@ public class LaborEducationServiceImpl implements LaborEducationService {
classBlocks.add(block);
}
classScore.put("blocks", classBlocks);
double classAverageScore = compositeClassScoreRates.values().stream().mapToDouble(Double::doubleValue).sum() / compositeClassScoreRates.size();
//保留两位小数
classAverageScore = Double.parseDouble(String.format("%.2f", classAverageScore));
classScore.put("average", classAverageScore);
adjustedClassScoreRates.add(classScore);
List<Map<String, Object>> adjustedStudentScoreRates = new ArrayList<>();
@ -989,6 +998,9 @@ public class LaborEducationServiceImpl implements LaborEducationService {
studentBlocks.add(block);
}
studentScore.put("blocks", studentBlocks);
double studentAverageScore = scores.values().stream().mapToDouble(Double::doubleValue).sum() / scores.size();
studentAverageScore = Double.parseDouble(String.format("%.2f", studentAverageScore));
studentScore.put("average", studentAverageScore);
adjustedStudentScoreRates.add(studentScore);
}
@ -1159,6 +1171,27 @@ public class LaborEducationServiceImpl implements LaborEducationService {
// 2. 获取年级所有学生的主观分数(次数)
List<Map<String, Object>> subjectiveScoresList = calculateScoresWithDetails(res, appraise,request);
List<String> classIds = classInfos.stream().map(GradeAndClassVo.CI::getClassId).collect(Collectors.toList());
GroupDto groupDto = new GroupDto();
groupDto.setIds(classIds);
groupDto.setSchoolId(appraise.getSchoolId());
String url = environment.getProperty("ies.server-url-group");
Map<String, Object> groupId = GroupUtil.getGroupId(groupDto, new GroupUtil(environment), request, url);
List<RGroupList> rGroupList = new ArrayList<>();
List<RMember> rMembers = new ArrayList<>();
for (Map.Entry<String, Object> entry : groupId.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (key.equals("groups")) {
String jsonGroups = JSON.toJSONString(value);
rGroupList = JSON.parseObject(jsonGroups, new TypeReference<List<RGroupList>>() {});
}
if (key.equals("members")) {
String jsonGroups = JSON.toJSONString(value);
rMembers = JSON.parseObject(jsonGroups, new TypeReference<List<RMember>>() {});
}
}
// 3. 将主观次数转换为0-100分数并收集学生班级信息
Map<String, Map<String, Double>> subjectiveScores = new HashMap<>();
Map<String, String> studentClassMap = new HashMap<>(); // 学生ID到班级ID的映射
@ -1198,10 +1231,15 @@ public class LaborEducationServiceImpl implements LaborEducationService {
String className = info.getClassName();
Map<String, Double> classScoresInner = new HashMap<>();
// 获取该班级的所有学生ID来自res记录
List<String> studentIdsInClass = studentClassMap.entrySet().stream()
.filter(entry -> entry.getValue().equals(classId))
.map(Map.Entry::getKey)
// 获取该班级的所有学生ID来自res记录 这个地方有问题不一定获取完整的名单 需要调整
// List<String> studentIdsInClass = studentClassMap.entrySet().stream()
// .filter(entry -> entry.getValue().equals(classId))
// .map(Map.Entry::getKey)
// .collect(Collectors.toList());
List<String> studentIdsInClass = rGroupList.stream()
.filter(group -> group.getId().equals(classId))
.flatMap(group -> group.getMembers().stream())
.map(RMember::getId)
.collect(Collectors.toList());
Map<String, Double> classScoreSum = new HashMap<>();
@ -1209,19 +1247,19 @@ public class LaborEducationServiceImpl implements LaborEducationService {
for (String studentId : studentIdsInClass) {
// 获取学生状态(从考试结果中查找,默认为有效)
int status = 0;
for (ExamClassResult examResult : gradeExamResults) {
int index = examResult.getStudentIds().indexOf(studentId);
if (index != -1) {
status = examResult.getStatus().get(index);
break;
}
}
if (status == 1) continue;
// int status = 0;
// for (ExamClassResult examResult : gradeExamResults) {
// int index = examResult.getStudentIds().indexOf(studentId);
// if (index == -1) {
// status = 1;
// break;
// }
// }
// if (status == 1) continue;
// 计算学生的知识点得分(客观分数)
Map<String, Double> studentObjectiveScores = calculateKnowledgeScoreRateForStudent(
studentId, examResults, knowledgeMap, appraise, points
studentId, gradeExamResults, knowledgeMap, appraise, points
);
// 确保客观分数最低为60分
@ -1243,10 +1281,10 @@ public class LaborEducationServiceImpl implements LaborEducationService {
// 计算综合得分主观60%客观40%
for (String block : allBlocks) {
double objectiveScore = studentObjectiveScores.getOrDefault(block, 60.0); // 默认60分
double subjectiveScore = studentSubjectiveScores.getOrDefault(block, 0.0);
double subjectiveScore = studentSubjectiveScores.getOrDefault(block, 60.0);
double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4);
compositeScore = Math.max(60.0, Math.min(100.0, compositeScore)); // 确保60-100分
compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
//compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
// 累加班级得分
classScoreSum.put(block, classScoreSum.getOrDefault(block, 0.0) + compositeScore);
@ -1311,6 +1349,10 @@ public class LaborEducationServiceImpl implements LaborEducationService {
gradeBlocks.add(block);
}
gradeScore.put("blocks", gradeBlocks);
double gradeAverageScore = gradeScores.values().stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
//保留两位小数
gradeAverageScore = Double.parseDouble(String.format("%.2f", gradeAverageScore));
gradeScore.put("averageScore", gradeAverageScore);
adjustedGradeScores.add(gradeScore);
List<Map<String, Object>> adjustedClassScores = new ArrayList<>();
@ -1456,6 +1498,10 @@ public class LaborEducationServiceImpl implements LaborEducationService {
schoolBlocks.add(block);
}
schoolScore.put("blocks", schoolBlocks);
double averageSchoolScore = schoolScores.values().stream().mapToDouble(Double::doubleValue).sum() / schoolScores.size();
//保留两位小数
averageSchoolScore = Double.parseDouble(String.format("%.2f", averageSchoolScore));
schoolScore.put("average", averageSchoolScore);
adjustedSchoolScores.add(schoolScore);
// 9. 返回结果

@ -82,20 +82,20 @@ public class MoralEducationServiceImpl implements MoralEducationService {
MoralEducationServiceImpl.environment = env; // 在初始化时将非静态字段赋值给静态字段
}
@Override
public Map<String, Object> getAnalysis(LaborDto moralDto, HttpServletRequest request) {
public Map<String, Object> getAnalysis(LaborDto laborDto, HttpServletRequest request) {
//根据具体参数查询相关课列内容
List<LessonRecord> records;
LessonRecordQueryService queryService = new LessonRecordQueryService(lessonRecordRepository);
String schoolId = moralDto.getCode();
String lessonRecordKey = String.format(PK.PK_LESSON_RECORD, moralDto.getCode());
Long startTime = moralDto.getStartTime();
Long endTime = moralDto.getEndTime();
String subjectId = moralDto.getSubjectId();
//String tmdId = moralDto.getTmdId();
String grade = moralDto.getGrade();
String periodId = moralDto.getPeriodId();
String academicYearId = moralDto.getAcademicYearId();
String schoolId = laborDto.getCode();
String lessonRecordKey = String.format(PK.PK_LESSON_RECORD, laborDto.getCode());
Long startTime = laborDto.getStartTime();
Long endTime = laborDto.getEndTime();
String subjectId = laborDto.getSubjectId();
//String tmdId = laborDto.getTmdId();
String grade = laborDto.getGrade();
String periodId = laborDto.getPeriodId();
String academicYearId = laborDto.getAcademicYearId();
try {
records = queryService.queryLessonsInParallel(
@ -126,7 +126,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
queryService.shutdown();
}
//总评价数
List<ClassInfo> classes = classRepository.findClassBySchoolIdAndPeriodId(moralDto.getPeriodId(), String.format(PK.CLASS, schoolId));
List<ClassInfo> classes = classRepository.findClassBySchoolIdAndPeriodId(laborDto.getPeriodId(), String.format(PK.CLASS, schoolId));
if (classes.isEmpty()) {
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "暂无班级");
}
@ -158,7 +158,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
//获取所有课程下的课中活动
List<ExamVo> exams = new ArrayList<>();
if (!recordIds.isEmpty()) {
exams = examRepository.findExamsByIds(moralDto.getSource(),recordIds);
exams = examRepository.findExamsByIds(laborDto.getSource(),recordIds);
exams = exams.stream()
.filter(exam -> !exam.getClasses().isEmpty())
.collect(Collectors.toList());
@ -184,9 +184,10 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
}
}
List<ExamClassResult> examResults = new ArrayList<>();
if (!examIds.isEmpty()) {
examResults = examClassResultRepository.findAll(String.format(PK.CLASS_RESULT, moralDto.getCode()),examIds);
examResults = examClassResultRepository.findAll(String.format(PK.CLASS_RESULT, laborDto.getCode()),examIds);
}
//获取学校基础信息
List<School.Period> period = schoolRepository.findPeriodById(schoolId,periodId);
@ -207,11 +208,11 @@ public class MoralEducationServiceImpl implements MoralEducationService {
Map<String, List<String>> knowledgeBlockToPointsMap = getKnowledgeBlockToPointsMap(appraise);
Map<String, Object> classScoreRate = new HashMap<>();
Map<String, Object> gradeScoreRate = new HashMap<>();
if (moralDto.getClassId() != null) {
classScoreRate = calculateKnowledgeScoreRateForClass(moralDto.getClassId(), examResults, knowledgeMap, appraise, point,res,request);
if (laborDto.getClassId() != null) {
classScoreRate = calculateKnowledgeScoreRateForClass(laborDto.getClassId(), examResults, knowledgeMap, appraise, point,res,request);
}
if (moralDto.getGrade() != null) {
gradeScoreRate = calculateKnowledgeScoreForGrade(moralDto.getGrade(), examResults, knowledgeMap,appraise, point,res,gradeAndClassVos,request);
if (laborDto.getGrade() != null) {
gradeScoreRate = calculateKnowledgeScoreForGrade(laborDto.getGrade(), examResults, knowledgeMap,appraise, point,res,gradeAndClassVos,request);
}
Map<String,Object> schoolScoreRate = calculateKnowledgeScoreForSchool(examResults, knowledgeMap,appraise, point,res,period,gradeAndClassVos,request);
resMap.put("gradeScoreRate", gradeScoreRate);
@ -242,16 +243,16 @@ public class MoralEducationServiceImpl implements MoralEducationService {
return resMap;
}
@Override
public Map<String, Object> getExamDetails(LaborDto moralDto, HttpServletRequest request) {
public Map<String, Object> getExamDetails(LaborDto laborDto, HttpServletRequest request) {
Map<String, Object> resMap = new HashMap<>();
try {
List<ExamClassResult> examResults = new ArrayList<>();
if (!moralDto.getExamId().isEmpty()) {
if (!laborDto.getExamId().isEmpty()) {
Map<String, List<List<String>>> knowledgeMap = new HashMap<>();
Map<String, List<Double>> points = new HashMap<>();
// 1. 查询考试信息
Exam exam = examRepository.findExamById(String.format(PK.EXAM, moralDto.getTmdId()), moralDto.getExamId()).get(0);
Exam exam = examRepository.findExamById(String.format(PK.EXAM, laborDto.getTmdId()), laborDto.getExamId()).get(0);
if (exam.getPapers() != null && !exam.getPapers().isEmpty()) {
knowledgeMap.put(exam.getId(), exam.getPapers().get(0).getKnowledge());
points.put(exam.getId(), exam.getPapers().get(0).getPoint());
@ -259,15 +260,15 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 2. 查询考试结果
examResults = examClassResultRepository.findById(
String.format(PK.CLASS_RESULT, moralDto.getCode()),
moralDto.getClassId(),
moralDto.getExamId()
String.format(PK.CLASS_RESULT, laborDto.getCode()),
laborDto.getClassId(),
laborDto.getExamId()
);
// 3. 查询知识块-知识点映射关系
Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(
moralDto.getCode(),
moralDto.getPeriodId(),
laborDto.getCode(),
laborDto.getPeriodId(),
PK.PK_APPRAISE
);
appraise = evaluationService.buildTree(appraise);
@ -277,7 +278,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
Map<String, Double> knowledgeTotalScore = new HashMap<>();
if (!examResults.isEmpty()) {
// 假设计算所有学生的平均分(或指定某个学生)
String studentId = moralDto.getStudentId(); // 如果传入了学生ID
String studentId = laborDto.getStudentId(); // 如果传入了学生ID
calculateStudentScoreRates(studentId, examResults, knowledgeMap, points, knowledgeTotalScore);
} else {
// 如果没有考试数据默认所有知识点60分
@ -641,13 +642,13 @@ public class MoralEducationServiceImpl implements MoralEducationService {
Map<String, Double> knowledgeTotalScore = new HashMap<>();
// 计算学生的知识点得分率
List<MoralEducationServiceImpl.KnowledgeScoreRate> studentScoreRates = calculateStudentScoreRates(studentId, examResults, knowledgeMap, points, knowledgeTotalScore);
List<LaborEducationServiceImpl.KnowledgeScoreRate> studentScoreRates = calculateStudentScoreRates(studentId, examResults, knowledgeMap, points, knowledgeTotalScore);
// 查找知识点对应的节点及其父节点
Map<String, Double> parentNodeScoreRates = new HashMap<>();
Map<String, Integer> parentNodeScoreCount = new HashMap<>(); // 记录每个父节点的知识点数量
for (MoralEducationServiceImpl.KnowledgeScoreRate scoreRate : studentScoreRates) {
for (LaborEducationServiceImpl.KnowledgeScoreRate scoreRate : studentScoreRates) {
String knowledge = scoreRate.getKnowledge();
AppraiseTreeNode node = findKnowledgeNode(appraise.getNodes(), knowledge);
@ -788,7 +789,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 1. 获取班级所有学生的客观分数
Map<String, Map<String, Double>> studentScoreRates = new HashMap<>();
Map<String, Double> classScoreRates = new HashMap<>();
//Map<String, Double> classScoreRates = new HashMap<>();
// 获取班级所有学生的名单(来自 rMembers
Map<String, String> studentIdToName = new HashMap<>();
@ -810,8 +811,12 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
if (examResults != null && !examResults.isEmpty()) {
//筛选出对应班级的考试结果
List<ExamClassResult> classExamResults = examResults.stream()
.filter(examResult -> examResult.getInfo().getId().equals(classId))
.collect(Collectors.toList());
// 遍历班级中的每个学生
for (ExamClassResult examResult : examResults) {
for (ExamClassResult examResult : classExamResults) {
if (!examResult.getInfo().getId().equals(classId)){
// 无考试数据时初始化所有学生的默认分数为60
if (groupList != null) {
@ -826,27 +831,23 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
}
}else{
List<Integer> statuses = examResult.getStatus();
for (int i = 0; i < examResult.getStudentIds().size(); i++) {
String studentId = examResult.getStudentIds().get(i);
//<Integer> statuses = examResult.getStatus();
for (String studentId : studentIdToName.keySet()) {
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<String, Double> scoreRates = calculateKnowledgeScoreRateForStudent(
studentId, examResults, knowledgeMap, appraise, points
studentId, classExamResults, 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());
}
// // 累加班级整体得分率
// for (Map.Entry<String, Double> entry : scoreRates.entrySet()) {
// classScoreRates.put(entry.getKey(), classScoreRates.getOrDefault(entry.getKey(), 0.0) + entry.getValue());
// }
}
}
@ -916,7 +917,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 计算综合得分主观60% + 客观40%
double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4);
compositeScore = Math.min(100.0, compositeScore); // 确保不超过100分
compositeScore = Math.max(60.0, Math.min(100.0, compositeScore)); // 确保60-100分
compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
compositeScores.put(block, compositeScore);
@ -927,18 +928,23 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 5. 计算班级整体得分率
int studentCount = compositeStudentScores.size();
Map<String, Double> compositeClassScoreRates = new HashMap<>();
if (studentCount > 0) {
for (Map<String, Double> studentScores : compositeStudentScores.values()) {
for (String studentId : studentIdToName.keySet()) {
String studentName = studentIdToName.get(studentId);
Map<String, Double> compositeScores = compositeStudentScores.get(studentName);
for (String block : knowledgeBlocks) {
double score = studentScores.getOrDefault(block, 0.0);
compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score);
double score = compositeScores.getOrDefault(block, 60.0);
compositeClassScoreRates.put(block,
compositeClassScoreRates.getOrDefault(block, 0.0) + score);
}
}
compositeClassScoreRates.replaceAll((k, v) -> Double.parseDouble(String.format("%.2f", v / studentCount)));
// 计算平均值
if (studentCount > 0) {
compositeClassScoreRates.replaceAll((k, v) ->
Double.parseDouble(String.format("%.2f", v / studentCount)));
} else {
// 无学生时初始化空值
for (String block : knowledgeBlocks) {
compositeClassScoreRates.put(block, 0.0);
compositeClassScoreRates.put(block, 60.0); // 默认60分
}
}
@ -970,6 +976,10 @@ public class MoralEducationServiceImpl implements MoralEducationService {
classBlocks.add(block);
}
classScore.put("blocks", classBlocks);
double classAverageScore = compositeClassScoreRates.values().stream().mapToDouble(Double::doubleValue).sum() / compositeClassScoreRates.size();
//保留两位小数
classAverageScore = Double.parseDouble(String.format("%.2f", classAverageScore));
classScore.put("average", classAverageScore);
adjustedClassScoreRates.add(classScore);
List<Map<String, Object>> adjustedStudentScoreRates = new ArrayList<>();
@ -988,6 +998,9 @@ public class MoralEducationServiceImpl implements MoralEducationService {
studentBlocks.add(block);
}
studentScore.put("blocks", studentBlocks);
double studentAverageScore = scores.values().stream().mapToDouble(Double::doubleValue).sum() / scores.size();
studentAverageScore = Double.parseDouble(String.format("%.2f", studentAverageScore));
studentScore.put("average", studentAverageScore);
adjustedStudentScoreRates.add(studentScore);
}
@ -999,7 +1012,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
private static List<MoralEducationServiceImpl.KnowledgeScoreRate> calculateStudentScoreRates(
private static List<LaborEducationServiceImpl.KnowledgeScoreRate> calculateStudentScoreRates(
String studentId,
List<ExamClassResult> examResults,
Map<String, List<List<String>>> knowledgeMap,
@ -1017,7 +1030,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
knowledgeTotalScore.put(knowledge, 60.0); // 默认60分
}
return knowledgeTotalScore.entrySet().stream()
.map(entry -> new MoralEducationServiceImpl.KnowledgeScoreRate(entry.getKey(), entry.getValue()))
.map(entry -> new LaborEducationServiceImpl.KnowledgeScoreRate(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
}
@ -1098,7 +1111,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
return knowledgeTotalScore.entrySet().stream()
.map(entry -> new MoralEducationServiceImpl.KnowledgeScoreRate(entry.getKey(), entry.getValue()))
.map(entry -> new LaborEducationServiceImpl.KnowledgeScoreRate(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
}
@ -1158,6 +1171,27 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 2. 获取年级所有学生的主观分数(次数)
List<Map<String, Object>> subjectiveScoresList = calculateScoresWithDetails(res, appraise,request);
List<String> classIds = classInfos.stream().map(GradeAndClassVo.CI::getClassId).collect(Collectors.toList());
GroupDto groupDto = new GroupDto();
groupDto.setIds(classIds);
groupDto.setSchoolId(appraise.getSchoolId());
String url = environment.getProperty("ies.server-url-group");
Map<String, Object> groupId = GroupUtil.getGroupId(groupDto, new GroupUtil(environment), request, url);
List<RGroupList> rGroupList = new ArrayList<>();
List<RMember> rMembers = new ArrayList<>();
for (Map.Entry<String, Object> entry : groupId.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (key.equals("groups")) {
String jsonGroups = JSON.toJSONString(value);
rGroupList = JSON.parseObject(jsonGroups, new TypeReference<List<RGroupList>>() {});
}
if (key.equals("members")) {
String jsonGroups = JSON.toJSONString(value);
rMembers = JSON.parseObject(jsonGroups, new TypeReference<List<RMember>>() {});
}
}
// 3. 将主观次数转换为0-100分数并收集学生班级信息
Map<String, Map<String, Double>> subjectiveScores = new HashMap<>();
Map<String, String> studentClassMap = new HashMap<>(); // 学生ID到班级ID的映射
@ -1197,10 +1231,15 @@ public class MoralEducationServiceImpl implements MoralEducationService {
String className = info.getClassName();
Map<String, Double> classScoresInner = new HashMap<>();
// 获取该班级的所有学生ID来自res记录
List<String> studentIdsInClass = studentClassMap.entrySet().stream()
.filter(entry -> entry.getValue().equals(classId))
.map(Map.Entry::getKey)
// 获取该班级的所有学生ID来自res记录 这个地方有问题不一定获取完整的名单 需要调整
// List<String> studentIdsInClass = studentClassMap.entrySet().stream()
// .filter(entry -> entry.getValue().equals(classId))
// .map(Map.Entry::getKey)
// .collect(Collectors.toList());
List<String> studentIdsInClass = rGroupList.stream()
.filter(group -> group.getId().equals(classId))
.flatMap(group -> group.getMembers().stream())
.map(RMember::getId)
.collect(Collectors.toList());
Map<String, Double> classScoreSum = new HashMap<>();
@ -1208,19 +1247,19 @@ public class MoralEducationServiceImpl implements MoralEducationService {
for (String studentId : studentIdsInClass) {
// 获取学生状态(从考试结果中查找,默认为有效)
int status = 0;
for (ExamClassResult examResult : gradeExamResults) {
int index = examResult.getStudentIds().indexOf(studentId);
if (index != -1) {
status = examResult.getStatus().get(index);
break;
}
}
if (status == 1) continue;
// int status = 0;
// for (ExamClassResult examResult : gradeExamResults) {
// int index = examResult.getStudentIds().indexOf(studentId);
// if (index == -1) {
// status = 1;
// break;
// }
// }
// if (status == 1) continue;
// 计算学生的知识点得分(客观分数)
Map<String, Double> studentObjectiveScores = calculateKnowledgeScoreRateForStudent(
studentId, examResults, knowledgeMap, appraise, points
studentId, gradeExamResults, knowledgeMap, appraise, points
);
// 确保客观分数最低为60分
@ -1242,10 +1281,10 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 计算综合得分主观60%客观40%
for (String block : allBlocks) {
double objectiveScore = studentObjectiveScores.getOrDefault(block, 60.0); // 默认60分
double subjectiveScore = studentSubjectiveScores.getOrDefault(block, 0.0);
double subjectiveScore = studentSubjectiveScores.getOrDefault(block, 60.0);
double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4);
compositeScore = Math.max(60.0, Math.min(100.0, compositeScore)); // 确保60-100分
compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
//compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
// 累加班级得分
classScoreSum.put(block, classScoreSum.getOrDefault(block, 0.0) + compositeScore);
@ -1310,6 +1349,10 @@ public class MoralEducationServiceImpl implements MoralEducationService {
gradeBlocks.add(block);
}
gradeScore.put("blocks", gradeBlocks);
double gradeAverageScore = gradeScores.values().stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
//保留两位小数
gradeAverageScore = Double.parseDouble(String.format("%.2f", gradeAverageScore));
gradeScore.put("averageScore", gradeAverageScore);
adjustedGradeScores.add(gradeScore);
List<Map<String, Object>> adjustedClassScores = new ArrayList<>();
@ -1455,6 +1498,10 @@ public class MoralEducationServiceImpl implements MoralEducationService {
schoolBlocks.add(block);
}
schoolScore.put("blocks", schoolBlocks);
double averageSchoolScore = schoolScores.values().stream().mapToDouble(Double::doubleValue).sum() / schoolScores.size();
//保留两位小数
averageSchoolScore = Double.parseDouble(String.format("%.2f", averageSchoolScore));
schoolScore.put("average", averageSchoolScore);
adjustedSchoolScores.add(schoolScore);
// 9. 返回结果
@ -1502,23 +1549,23 @@ public class MoralEducationServiceImpl implements MoralEducationService {
//获取每月各个知识库综合得分以及整体得分内容
public Map<String,List<Map<String, Object>>> getStudentMonthlyScores(LaborDto moralDto,HttpServletRequest request) {
public Map<String,List<Map<String, Object>>> getStudentMonthlyScores(LaborDto laborDto,HttpServletRequest request) {
// 1. 获取基础信息
String schoolId = SecurityUtil.getLoginUser().getSchoolId();
String studentId = moralDto.getStudentId();
String studentId = laborDto.getStudentId();
List<String> classStudentIds = Collections.emptyList();
// 2. 获取相关开课记录
List<LessonRecord> records = getLessonRecords(moralDto, schoolId);
List<LessonRecord> records = getLessonRecords(laborDto, schoolId);
List<RecordVo> res;
int rightCount = 0;
int wrongCount = 0;
if (moralDto.getClassId() == null) {
if (laborDto.getClassId() == null) {
res = appraiseRecordRepository.getStudentRecords(
String.format(PK.PK_APPRAISE_RECORD, schoolId),
moralDto.getAcademicYearId(),
moralDto.getStudentId(),
moralDto.getStartTime(),
moralDto.getEndTime(),
laborDto.getAcademicYearId(),
laborDto.getStudentId(),
laborDto.getStartTime(),
laborDto.getEndTime(),
"劳育"
);
//表扬的次数
@ -1527,10 +1574,10 @@ public class MoralEducationServiceImpl implements MoralEducationService {
wrongCount = (int) res.stream().filter(record -> !record.isPraise()).count();
}else {
//当班级ID 存在时 获取该班级下所有名单即学生Id
List<String> classIds = Collections.singletonList(moralDto.getClassId());
List<String> classIds = Collections.singletonList(laborDto.getClassId());
GroupDto groupDto = new GroupDto();
groupDto.setIds(classIds);
groupDto.setSchoolId(moralDto.getCode());
groupDto.setSchoolId(laborDto.getCode());
String url = environment.getProperty("ies.server-url-group");
Map<String, Object> groupId = GroupUtil.getGroupId(groupDto, new GroupUtil(environment), request, url);
List<RGroupList> rGroupList = new ArrayList<>();
@ -1545,7 +1592,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
rMembers = rGroupList.stream()
.flatMap(rGroupList1 -> rGroupList1.getMembers().stream())
.filter(rMember -> rMember.getClassId().equals(moralDto.getClassId()))
.filter(rMember -> rMember.getClassId().equals(laborDto.getClassId()))
.collect(Collectors.toList());
classStudentIds = rMembers.stream().map(RMember::getId).collect(Collectors.toList());
/*String className = rGroupList.stream()
@ -1555,9 +1602,9 @@ public class MoralEducationServiceImpl implements MoralEducationService {
.orElse("未知班级"); // 如果未找到则返回默认值 "未知班级"*/
res = appraiseRecordRepository.getRecords(
String.format(PK.PK_APPRAISE_RECORD, schoolId),
moralDto.getAcademicYearId(),
moralDto.getClassId(),
moralDto.getStudentId(),
laborDto.getAcademicYearId(),
laborDto.getClassId(),
laborDto.getStudentId(),
"劳育"
);
//表扬的次数
@ -1569,20 +1616,22 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 3. 获取考试及知识点映射
Map<String, List<List<String>>> examKnowledgeMap = new HashMap<>();
Map<String, List<Double>> points = new HashMap<>();
List<ExamVo> exams = getExamsWithKnowledge(moralDto, records, examKnowledgeMap, points);
List<ExamVo> exams = getExamsWithKnowledge(laborDto, records, examKnowledgeMap, points);
// 4. 获取考试结果并按月份分组
List<String> targetStudents = moralDto.getClassId() != null ?
List<String> targetStudents = laborDto.getClassId() != null ?
classStudentIds : Collections.singletonList(studentId);
//records有可能没有数据 重写monthlyResults
Map<Integer, List<ExamResultWrapper>> monthlyResults = getMonthlyExamResults(
schoolId, moralDto.getClassId(), exams, records,
schoolId, laborDto.getClassId(), exams, records,
examKnowledgeMap, points, targetStudents // 传入目标学生列表
);
// 5. 获取知识块配置
Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(
schoolId, moralDto.getPeriodId(), PK.PK_APPRAISE
schoolId, laborDto.getPeriodId(), PK.PK_APPRAISE
);
appraise = evaluationService.buildTree(appraise);
Map<String, List<String>> knowledgeBlockMap = getKnowledgeBlockToPointsMap(appraise);
@ -1598,7 +1647,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
Map<String, Map<Integer, Integer>> finalBlockMonthlyCounts = blockMonthlyCounts;
res.stream()
.filter(vo -> moralDto.getClassId() != null ?
.filter(vo -> laborDto.getClassId() != null ?
targetStudents.contains(vo.getTargetId()) :
studentId.equals(vo.getTargetId()))
.forEach(vo -> {
@ -1633,7 +1682,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
targetStudents,
monthlyResults,
knowledgeBlockMap,
getMonthsBetween(moralDto.getStartTime(), moralDto.getEndTime()),
getMonthsBetween(laborDto.getStartTime(), laborDto.getEndTime()),
blockMonthlyCounts
);
}
@ -1675,17 +1724,17 @@ public class MoralEducationServiceImpl implements MoralEducationService {
return result;
}
private List<LessonRecord> getLessonRecords(LaborDto moralDto, String schoolId) {
private List<LessonRecord> getLessonRecords(LaborDto laborDto, String schoolId) {
LessonRecordQueryService queryService = new LessonRecordQueryService(lessonRecordRepository);
try {
return queryService.queryLessonsInParallel(
String.format(PK.PK_LESSON_RECORD, schoolId),
moralDto.getStartTime(),
moralDto.getEndTime(),
moralDto.getSubjectId(),
laborDto.getStartTime(),
laborDto.getEndTime(),
laborDto.getSubjectId(),
null,
null,
moralDto.getPeriodId()
laborDto.getPeriodId()
);
} catch (InterruptedException | ExecutionException e) {
throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "课程查询异常");
@ -1694,7 +1743,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
}
private List<ExamVo> getExamsWithKnowledge(LaborDto moralDto, List<LessonRecord> records,
private List<ExamVo> getExamsWithKnowledge(LaborDto laborDto, List<LessonRecord> records,
Map<String, List<List<String>>> examKnowledgeMap,
Map<String, List<Double>> points) {
if (records == null || records.isEmpty()) {
@ -1711,7 +1760,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
return Collections.emptyList();
}
List<ExamVo> exams = examRepository.findExamsByIds(moralDto.getSource(), lessonRecordIds);
List<ExamVo> exams = examRepository.findExamsByIds(laborDto.getSource(), lessonRecordIds);
exams.forEach(exam -> {
if (!exam.getPapers().isEmpty() && exam.getPapers().get(0).getKnowledge() != null) {
@ -1725,13 +1774,16 @@ public class MoralEducationServiceImpl implements MoralEducationService {
.collect(Collectors.toList());
}
private Map<Integer, List<ExamResultWrapper>> getMonthlyExamResults(
String schoolId, String classId, List<ExamVo> exams,
List<LessonRecord> records, Map<String, List<List<String>>> examKnowledgeMap,
Map<String, List<Double>> points, List<String> studentIds) { // 新增studentIds参数
Map<Integer, List<ExamResultWrapper>> monthlyResults = new HashMap<>();
if (exams == null || exams.isEmpty() || records == null || records.isEmpty()) {
return monthlyResults; // 安全退出,返回空 map
}
if (classId == null) {
exams.forEach(exam -> {
List<ExamClassResult> results = examClassResultRepository.findByStudentId(
@ -1907,7 +1959,6 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 按知识块名称排序(可选)
scoreList.sort(Comparator.comparing(m -> (String) m.get("name")));
//所有知识块score求平均
double totalScore = 0.0;
int count = 0;
@ -1923,7 +1974,6 @@ public class MoralEducationServiceImpl implements MoralEducationService {
//保留两位小数
averageScore = Double.parseDouble(String.format("%.2f", averageScore));
monthEntry.put("averageScore", averageScore);
monthEntry.put("types", scoreList);
return monthEntry;
}).sorted(Comparator.comparingInt(m -> (Integer) m.get("month")))
@ -2095,9 +2145,9 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
// 分学期比对,分析 学期数据
public Map<String, Object> getStudentSemesterScores(LaborDto moralDto,HttpServletRequest request) {
public Map<String, Object> getStudentSemesterScores(LaborDto laborDto,HttpServletRequest request) {
// 1. 获取学期配置
List<School.Semester> semesters = schoolRepository.findSemestersById(moralDto.getCode(), moralDto.getPeriodId());
List<School.Semester> semesters = schoolRepository.findSemestersById(laborDto.getCode(), laborDto.getPeriodId());
List<SemesterConfig> configs = new ArrayList<>();
for (School.Semester semester : semesters) {
configs.add(new SemesterConfig(semester.getName(), semester.getStart(), semester.getMonth(), semester.getDay(), semester.getId()));
@ -2109,17 +2159,17 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 学生数据处理
Map<String, Object> studentResult = Collections.emptyMap();
if (StringUtils.isNotBlank(moralDto.getStudentId())) {
studentResult = processIndividual(moralDto, current, last, request);
if (StringUtils.isNotBlank(laborDto.getStudentId())) {
studentResult = processIndividual(laborDto, current, last, request);
}
// 班级数据处理
Map<String, Object> classResult = Collections.emptyMap();
if (StringUtils.isNotBlank(moralDto.getClassId())) {
classResult = processClass(moralDto, current, last, request);
if (StringUtils.isNotBlank(laborDto.getClassId())) {
classResult = processClass(laborDto, current, last, request);
}
// 组合最终结果
return combineAllResults(moralDto, studentResult, classResult);
return combineAllResults(laborDto, studentResult, classResult);
}
private Map<String, Object> combineAllResults(LaborDto dto,
@ -2353,7 +2403,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
// 处理学期数据
private Map<String, Object> processSemesterData(LaborDto moralDto,
private Map<String, Object> processSemesterData(LaborDto laborDto,
SemesterPeriod semester,
HttpServletRequest request,
boolean isCurrent,
@ -2361,11 +2411,11 @@ public class MoralEducationServiceImpl implements MoralEducationService {
Map<String, Object> result = new HashMap<>();
// 1. 设置时间范围查询条件
moralDto.setStartTime(convertToTimestamp(semester.startDate));
moralDto.setEndTime(convertToTimestamp(semester.endDate));
laborDto.setStartTime(convertToTimestamp(semester.startDate));
laborDto.setEndTime(convertToTimestamp(semester.endDate));
// 2. 获取原始分析数据
Map<String, Object> analysisData = getAnalysis(moralDto, request);
Map<String, Object> analysisData = getAnalysis(laborDto, request);
if (isClassMod) {
// 班级知识点统计
@ -2387,7 +2437,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
if (isCurrent) {
List<Map<String, Object>> scores = (List<Map<String, Object>>) analysisData.get("scores");
Map<String, Integer> knowledgeCounts = scores.stream()
.filter(s -> moralDto.getStudentId().equals(s.get("studentId")))
.filter(s -> laborDto.getStudentId().equals(s.get("studentId")))
.findFirst()
.map(s -> (List<Map<String, Object>>) s.get("appraises"))
.map(appraises -> appraises.stream()
@ -2401,7 +2451,7 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
// 4. 提取综合得分
Map<String, Double> blockScores = extractBlockScores(analysisData, moralDto.getStudentId());
Map<String, Double> blockScores = extractBlockScores(analysisData, laborDto.getStudentId());
result.put("blockScores", blockScores);
// 5. 提取班级均分
@ -2454,14 +2504,14 @@ public class MoralEducationServiceImpl implements MoralEducationService {
}
// 结果合并方法
private Map<String, Object> combineResults(LaborDto moralDto,
private Map<String, Object> combineResults(LaborDto laborDto,
Map<String, Object> currentData,
Map<String, Object> lastData) {
Map<String, Object> result = new LinkedHashMap<>();
result.put("studentId", moralDto.getStudentId());
result.put("studentId", laborDto.getStudentId());
Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(moralDto.getCode(), moralDto.getPeriodId(), PK.PK_APPRAISE);
Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(laborDto.getCode(), laborDto.getPeriodId(), PK.PK_APPRAISE);
// 获取知识块配置
appraise = evaluationService.buildTree(appraise);
Set<String> knowledgeBlocks = loadKnowledgeBlocks(appraise);

Loading…
Cancel
Save