update 调整无数据时 初始化结构返回

develop
hhb@hotmail.com 2 months ago
parent fb2e273060
commit 0523d7c774

@ -575,6 +575,26 @@ public class LaborEducationServiceImpl implements LaborEducationService {
Map<String, Map<String, Double>> studentScoreRates = new HashMap<>(); 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<>();
RGroupList groupList = rGroupList.stream().filter(rGroupList1 -> rGroupList1.getId().equals(classId)).findFirst().orElse(null);
if (groupList != null) {
for (RMember member : groupList.members) {
studentIdToName.put(member.getId(), member.getName());
}
}
// 初始化知识块列表(从 appraise 配置中提取)
Set<String> knowledgeBlocks = new HashSet<>();
for (AppraiseTreeNode node : appraise.getNodes()) {
if (node.getName().equals("劳育")) {
for (AppraiseTreeNode child : node.getChildren()) {
knowledgeBlocks.add(child.getName());
}
}
}
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)) continue; // 过滤出该班级的考试
@ -601,6 +621,24 @@ public class LaborEducationServiceImpl implements LaborEducationService {
} }
} }
} }
}else {
// 无考试数据时初始化所有学生的默认分数为0
if (groupList != null) {
for (RMember member : groupList.members) {
String studentId = member.getId();
String studentName = studentIdToName.getOrDefault(studentId, "未知学生");
Map<String, Double> defaultScores = new HashMap<>();
for (String block : knowledgeBlocks) {
defaultScores.put(block, 0.0);
}
studentScoreRates.put(studentName, defaultScores);
// 初始化班级得分率
for (String block : knowledgeBlocks) {
classScoreRates.put(block, 0.0);
}
}
}
}
// 2. 获取班级所有学生的主观分数(次数) // 2. 获取班级所有学生的主观分数(次数)
List<Map<String, Object>> subjectiveScoresList = calculateScoresWithDetails(res, appraise); List<Map<String, Object>> subjectiveScoresList = calculateScoresWithDetails(res, appraise);
@ -632,42 +670,43 @@ public class LaborEducationServiceImpl implements LaborEducationService {
// 4. 融合主观和客观分数 // 4. 融合主观和客观分数
Map<String, Map<String, Double>> compositeStudentScores = new HashMap<>(); Map<String, Map<String, Double>> compositeStudentScores = new HashMap<>();
for (Map.Entry<String, Map<String, Double>> entry : studentScoreRates.entrySet()) { for (String studentId : studentIdToName.keySet()) {
String studentId = entry.getKey(); String studentName = studentIdToName.get(studentId);
Map<String, Double> objective = entry.getValue(); Map<String, Double> objective = studentScoreRates.getOrDefault(studentName, new HashMap<>());
Map<String, Double> subjective = subjectiveScores.getOrDefault(studentId, new HashMap<>()); Map<String, Double> subjective = subjectiveScores.getOrDefault(studentId, new HashMap<>());
// 计算综合得分
Map<String, Double> compositeScores = new HashMap<>(); Map<String, Double> compositeScores = new HashMap<>();
for (Map.Entry<String, Double> objectiveEntry : objective.entrySet()) { for (String block : knowledgeBlocks) {
String block = objectiveEntry.getKey(); double objectiveScore = objective.getOrDefault(block, 0.0);
double objectiveScore = objectiveEntry.getValue();
double subjectiveScore = subjective.getOrDefault(block, 0.0); double subjectiveScore = subjective.getOrDefault(block, 0.0);
// 按6:4比例计算综合得分
double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4); double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4);
compositeScore = Double.parseDouble(String.format("%.2f", compositeScore)); compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
compositeScores.put(block, compositeScore); compositeScores.put(block, compositeScore);
} }
compositeStudentScores.put(studentName, compositeScores);
compositeStudentScores.put(studentId, compositeScores);
} }
// 5. 计算班级整体得分率 // 5. 计算班级整体得分率
int studentCount = compositeStudentScores.size(); int studentCount = compositeStudentScores.size();
Map<String, Double> compositeClassScoreRates = new HashMap<>(); Map<String, Double> compositeClassScoreRates = new HashMap<>();
if (studentCount > 0) {
for (Map<String, Double> studentScores : compositeStudentScores.values()) { for (Map<String, Double> studentScores : compositeStudentScores.values()) {
for (Map.Entry<String, Double> entry : studentScores.entrySet()) { for (String block : knowledgeBlocks) {
String block = entry.getKey(); double score = studentScores.getOrDefault(block, 0.0);
double score = entry.getValue();
compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score); compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score);
} }
} }
compositeClassScoreRates.replaceAll((k, v) -> Double.parseDouble(String.format("%.2f", v / studentCount))); // 保留小数点后两位 compositeClassScoreRates.replaceAll((k, v) -> Double.parseDouble(String.format("%.2f", v / studentCount)));
} else {
// 无学生时初始化空值
for (String block : knowledgeBlocks) {
compositeClassScoreRates.put(block, 0.0);
}
}
// 6. 初始化所有同层的父节点 // 6. 初始化所有同层的父节点
for (AppraiseTreeNode node : appraise.getNodes()) { for (AppraiseTreeNode node : appraise.getNodes()) {
if (node.getName().equals("德育")) { if (node.getName().equals("育")) {
for (AppraiseTreeNode child : node.getChildren()) { for (AppraiseTreeNode child : node.getChildren()) {
if (!compositeClassScoreRates.containsKey(child.getName())) { if (!compositeClassScoreRates.containsKey(child.getName())) {
compositeClassScoreRates.put(child.getName(), 0.0); compositeClassScoreRates.put(child.getName(), 0.0);
@ -677,6 +716,10 @@ public class LaborEducationServiceImpl implements LaborEducationService {
} }
// 7. 转换 classScoreRates 和 studentScoreRates 为新的数据结构 // 7. 转换 classScoreRates 和 studentScoreRates 为新的数据结构
return getResult(className, compositeClassScoreRates, compositeStudentScores);
}
private static @NotNull Map<String, Object> getResult(String className, Map<String, Double> compositeClassScoreRates, Map<String, Map<String, Double>> compositeStudentScores) {
List<Map<String, Object>> adjustedClassScoreRates = new ArrayList<>(); List<Map<String, Object>> adjustedClassScoreRates = new ArrayList<>();
Map<String, Object> classScore = new HashMap<>(); Map<String, Object> classScore = new HashMap<>();
classScore.put("className", className); // 设置班级名称 classScore.put("className", className); // 设置班级名称
@ -718,8 +761,6 @@ public class LaborEducationServiceImpl implements LaborEducationService {
} }
private static List<KnowledgeScoreRate> calculateStudentScoreRates( private static List<KnowledgeScoreRate> calculateStudentScoreRates(
String studentId, String studentId,
List<ExamClassResult> examResults, List<ExamClassResult> examResults,

@ -576,6 +576,26 @@ public class MoralEducationServiceImpl implements MoralEducationService {
Map<String, Map<String, Double>> studentScoreRates = new HashMap<>(); 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<>();
RGroupList groupList = rGroupList.stream().filter(rGroupList1 -> rGroupList1.getId().equals(classId)).findFirst().orElse(null);
if (groupList != null) {
for (RMember member : groupList.members) {
studentIdToName.put(member.getId(), member.getName());
}
}
// 初始化知识块列表(从 appraise 配置中提取)
Set<String> knowledgeBlocks = new HashSet<>();
for (AppraiseTreeNode node : appraise.getNodes()) {
if (node.getName().equals("劳育")) {
for (AppraiseTreeNode child : node.getChildren()) {
knowledgeBlocks.add(child.getName());
}
}
}
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)) continue; // 过滤出该班级的考试
@ -602,6 +622,24 @@ public class MoralEducationServiceImpl implements MoralEducationService {
} }
} }
} }
}else {
// 无考试数据时初始化所有学生的默认分数为0
if (groupList != null) {
for (RMember member : groupList.members) {
String studentId = member.getId();
String studentName = studentIdToName.getOrDefault(studentId, "未知学生");
Map<String, Double> defaultScores = new HashMap<>();
for (String block : knowledgeBlocks) {
defaultScores.put(block, 0.0);
}
studentScoreRates.put(studentName, defaultScores);
// 初始化班级得分率
for (String block : knowledgeBlocks) {
classScoreRates.put(block, 0.0);
}
}
}
}
// 2. 获取班级所有学生的主观分数(次数) // 2. 获取班级所有学生的主观分数(次数)
List<Map<String, Object>> subjectiveScoresList = calculateScoresWithDetails(res, appraise); List<Map<String, Object>> subjectiveScoresList = calculateScoresWithDetails(res, appraise);
@ -633,38 +671,39 @@ public class MoralEducationServiceImpl implements MoralEducationService {
// 4. 融合主观和客观分数 // 4. 融合主观和客观分数
Map<String, Map<String, Double>> compositeStudentScores = new HashMap<>(); Map<String, Map<String, Double>> compositeStudentScores = new HashMap<>();
for (Map.Entry<String, Map<String, Double>> entry : studentScoreRates.entrySet()) { for (String studentId : studentIdToName.keySet()) {
String studentId = entry.getKey(); String studentName = studentIdToName.get(studentId);
Map<String, Double> objective = entry.getValue(); Map<String, Double> objective = studentScoreRates.getOrDefault(studentName, new HashMap<>());
Map<String, Double> subjective = subjectiveScores.getOrDefault(studentId, new HashMap<>()); Map<String, Double> subjective = subjectiveScores.getOrDefault(studentId, new HashMap<>());
// 计算综合得分
Map<String, Double> compositeScores = new HashMap<>(); Map<String, Double> compositeScores = new HashMap<>();
for (Map.Entry<String, Double> objectiveEntry : objective.entrySet()) { for (String block : knowledgeBlocks) {
String block = objectiveEntry.getKey(); double objectiveScore = objective.getOrDefault(block, 0.0);
double objectiveScore = objectiveEntry.getValue();
double subjectiveScore = subjective.getOrDefault(block, 0.0); double subjectiveScore = subjective.getOrDefault(block, 0.0);
// 按6:4比例计算综合得分
double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4); double compositeScore = (subjectiveScore * 0.6) + (objectiveScore * 0.4);
compositeScore = Double.parseDouble(String.format("%.2f", compositeScore)); compositeScore = Double.parseDouble(String.format("%.2f", compositeScore));
compositeScores.put(block, compositeScore); compositeScores.put(block, compositeScore);
} }
compositeStudentScores.put(studentName, compositeScores);
compositeStudentScores.put(studentId, compositeScores);
} }
// 5. 计算班级整体得分率 // 5. 计算班级整体得分率
int studentCount = compositeStudentScores.size(); int studentCount = compositeStudentScores.size();
Map<String, Double> compositeClassScoreRates = new HashMap<>(); Map<String, Double> compositeClassScoreRates = new HashMap<>();
if (studentCount > 0) {
for (Map<String, Double> studentScores : compositeStudentScores.values()) { for (Map<String, Double> studentScores : compositeStudentScores.values()) {
for (Map.Entry<String, Double> entry : studentScores.entrySet()) { for (String block : knowledgeBlocks) {
String block = entry.getKey(); double score = studentScores.getOrDefault(block, 0.0);
double score = entry.getValue();
compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score); compositeClassScoreRates.put(block, compositeClassScoreRates.getOrDefault(block, 0.0) + score);
} }
} }
compositeClassScoreRates.replaceAll((k, v) -> Double.parseDouble(String.format("%.2f", v / studentCount))); // 保留小数点后两位 compositeClassScoreRates.replaceAll((k, v) -> Double.parseDouble(String.format("%.2f", v / studentCount)));
} else {
// 无学生时初始化空值
for (String block : knowledgeBlocks) {
compositeClassScoreRates.put(block, 0.0);
}
}
// 6. 初始化所有同层的父节点 // 6. 初始化所有同层的父节点
for (AppraiseTreeNode node : appraise.getNodes()) { for (AppraiseTreeNode node : appraise.getNodes()) {
@ -678,6 +717,10 @@ public class MoralEducationServiceImpl implements MoralEducationService {
} }
// 7. 转换 classScoreRates 和 studentScoreRates 为新的数据结构 // 7. 转换 classScoreRates 和 studentScoreRates 为新的数据结构
return getResult(className, compositeClassScoreRates, compositeStudentScores);
}
private static @NotNull Map<String, Object> getResult(String className, Map<String, Double> compositeClassScoreRates, Map<String, Map<String, Double>> compositeStudentScores) {
List<Map<String, Object>> adjustedClassScoreRates = new ArrayList<>(); List<Map<String, Object>> adjustedClassScoreRates = new ArrayList<>();
Map<String, Object> classScore = new HashMap<>(); Map<String, Object> classScore = new HashMap<>();
classScore.put("className", className); // 设置班级名称 classScore.put("className", className); // 设置班级名称
@ -719,8 +762,6 @@ public class MoralEducationServiceImpl implements MoralEducationService {
} }
private static List<KnowledgeScoreRate> calculateStudentScoreRates( private static List<KnowledgeScoreRate> calculateStudentScoreRates(
String studentId, String studentId,
List<ExamClassResult> examResults, List<ExamClassResult> examResults,

Loading…
Cancel
Save