From 6e1bfdc6c99a6c31099981c37c11956a1d792b71 Mon Sep 17 00:00:00 2001 From: "hhb@hotmail.com" Date: Wed, 20 Nov 2024 17:08:16 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=AD=A6=E6=AE=B5=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/TeacherServiceImpl.java | 28 +++++++++++-------- .../cn/teammodel/utils/SchoolDateUtil.java | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) 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 {