diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/TeacherServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/TeacherServiceImpl.java index e831d31..e23cb0a 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/impl/TeacherServiceImpl.java +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/TeacherServiceImpl.java @@ -82,7 +82,7 @@ public class TeacherServiceImpl implements TeacherService { } } jobCountMap.entrySet().removeIf(entry -> entry.getKey().isEmpty()); - Map periodCountMap = getPeriodCountMap(groupLists, periods); + Map periodCountMap = getPeriodCountMap(periods,schoolTeachers); periodCountMap.entrySet().removeIf(entry -> entry.getKey().isEmpty()); updatedSubjectCountMap.entrySet().removeIf(entry -> entry.getKey().isEmpty()); @@ -230,15 +230,25 @@ public class TeacherServiceImpl implements TeacherService { return updatedSubjectCountMap; } - private static @NotNull Map getPeriodCountMap(List groupLists,List periods) { + private static @NotNull Map getPeriodCountMap(List periods,List schoolTeachers) { + Map periodCountMap = new HashMap<>(); + for (School.Period period : periods) { + for ( School.Subject subject : period.getSubjects()) { + for (SchoolTeacher schoolTeacher : schoolTeachers) { + if (schoolTeacher.getSubjectIds().contains(subject.getId())) { + periodCountMap.put(period.getId(), periodCountMap.getOrDefault(period.getId(), 0) + 1); + } + } + } + } Map periodNameMap = new HashMap<>(); List periodNames = new ArrayList<>(); for (School.Period period : periods) { periodNameMap.put(period.getId(), period.getName()); periodNames.add(period.getName()); } - Map periodCountMap = getStringIntegerMap(groupLists); + //Map periodCountMap = getStringIntegerMap(groupLists); // 更新 periodCountMap 的 key 为 period 名称 Map updatedPeriodCountMap = new HashMap<>(); for (Map.Entry entry : periodCountMap.entrySet()) { @@ -249,14 +259,10 @@ public class TeacherServiceImpl implements TeacherService { updatedPeriodCountMap.put(periodName, count); } } - for(Map.Entry entry : updatedPeriodCountMap.entrySet()) { - String name = entry.getKey(); - for (String periodName : periodNames) { - if(!name.equals(periodName)){ - updatedPeriodCountMap.put(periodName, 0); - } - } - + for (String periodName : periodNames) { + if(!updatedPeriodCountMap.containsKey(periodName)) { + updatedPeriodCountMap.put(periodName, 0); + } } return updatedPeriodCountMap; } diff --git a/src/main/java/cn/teammodel/utils/SchoolDateUtil.java b/src/main/java/cn/teammodel/utils/SchoolDateUtil.java index cb05eb7..7c606aa 100644 --- a/src/main/java/cn/teammodel/utils/SchoolDateUtil.java +++ b/src/main/java/cn/teammodel/utils/SchoolDateUtil.java @@ -18,7 +18,7 @@ import java.util.Map; /** * 学校中年级,学年,日期相关的工具类 * @author winter - * @create 2023-11-28 10:15 + * @create 2023-11-28 10:15 */ public class SchoolDateUtil {