update 教师相关数据

develop
hhb@hotmail.com 1 month ago
parent 7ec8d20ae8
commit 3449d2bcbd

@ -128,8 +128,10 @@ public class TeacherServiceImpl implements TeacherService {
private static @NotNull Map<String, Integer> getPeriodCountMap(List<GroupList> groupLists,List<School.Period> periods) { private static @NotNull Map<String, Integer> getPeriodCountMap(List<GroupList> groupLists,List<School.Period> periods) {
Map<String, String> periodNameMap = new HashMap<>(); Map<String, String> periodNameMap = new HashMap<>();
List<String> periodNames = new ArrayList<>();
for (School.Period period : periods) { for (School.Period period : periods) {
periodNameMap.put(period.getId(), period.getName()); periodNameMap.put(period.getId(), period.getName());
periodNames.add(period.getName());
} }
Map<String, Integer> periodCountMap = getStringIntegerMap(groupLists); Map<String, Integer> periodCountMap = getStringIntegerMap(groupLists);
// 更新 periodCountMap 的 key 为 period 名称 // 更新 periodCountMap 的 key 为 period 名称
@ -142,19 +144,27 @@ public class TeacherServiceImpl implements TeacherService {
updatedPeriodCountMap.put(periodName, count); updatedPeriodCountMap.put(periodName, count);
} }
} }
for(Map.Entry<String, Integer> entry : updatedPeriodCountMap.entrySet()) {
String name = entry.getKey();
for (String periodName : periodNames) {
if(!name.equals(periodName)){
updatedPeriodCountMap.put(periodName, 0);
}
}
}
return updatedPeriodCountMap; return updatedPeriodCountMap;
} }
private static @NotNull Map<String, Integer> getStringIntegerMap(List<GroupList> groupLists) { private static @NotNull Map<String, Integer> getStringIntegerMap(List<GroupList> groupLists) {
Map<String, Integer> periodCountMap = new HashMap<>(); Map<String, Integer> periodCountMap = new HashMap<>();
// 遍历所有 GroupList 对象 // 遍历所有 GroupList 对象
for (GroupList group : groupLists) { for (GroupList group : groupLists) {
// 获取 periodId // 获取 periodId
String periodId = group.getPeriodId(); String periodId = group.getPeriodId();
if (periodId != null) { if (periodId != null) {
// 计算成员数量 // 计算成员数量
int memberCount = group.getMembers().size(); int memberCount = (int) group.getMembers().stream().filter(member -> member.type == 1).count();
// 更新 periodCountMap // 更新 periodCountMap
periodCountMap.put(periodId, periodCountMap.getOrDefault(periodId, 0) + memberCount); periodCountMap.put(periodId, periodCountMap.getOrDefault(periodId, 0) + memberCount);

Loading…
Cancel
Save