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 db565b3..eb10ac1 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 @@ -819,6 +819,10 @@ public class TeacherServiceImpl implements TeacherService { Map degreeCount = new HashMap<>(); Map subjectCount = new HashMap<>(); Map teachingAgeCount = new HashMap<>(); + teachingAgeCount.put("0-5年", 0L); + teachingAgeCount.put("5-10年", 0L); + teachingAgeCount.put("10-15年", 0L); + teachingAgeCount.put("15年以上", 0L); Map averageTeachingAgeCount = new HashMap<>(); if(StringUtils.isNotEmpty(teacherDto.getGrade()) && StringUtils.isNotEmpty(teacherDto.getSubjectId())) { for (PtTeacherInfo teacher : ptTeacherInfos) { @@ -845,22 +849,21 @@ public class TeacherServiceImpl implements TeacherService { //获取教龄分类信息 if (teacher.getTeachingAge() != null) { int age = teacher.getTeachingAge(); - String teachingAge = ""; - if (age >= 0 && age <= 5) { + String teachingAge; + if (age <= 5) { teachingAge = "0-5年"; - } else if (age > 5 && age <= 10) { + } else if (age <= 10) { teachingAge = "5-10年"; - } else if (age > 10 && age <= 15) { + } else if (age <= 15) { teachingAge = "10-15年"; } else { teachingAge = "15年以上"; } - Long count = teachingAgeCount.getOrDefault(teachingAge, 0L); - teachingAgeCount.put(teachingAge, count + 1); + // 直接累加(键已存在) + teachingAgeCount.put(teachingAge, teachingAgeCount.get(teachingAge) + 1); - totalTeachingAge += teacher.getTeachingAge(); + totalTeachingAge += age; validTeachers++; - //计算评价教龄 } // 计算平均教龄(新增逻辑) long averageTeachingAge = validTeachers > 0 ? Math.round((float) totalTeachingAge / validTeachers) : 0; @@ -900,22 +903,21 @@ public class TeacherServiceImpl implements TeacherService { //获取教龄分类信息 if (teacher.getTeachingAge() != null) { int age = teacher.getTeachingAge(); - String teachingAge = ""; - if (age >= 0 && age <= 5) { + String teachingAge; + if (age <= 5) { teachingAge = "0-5年"; - } else if (age > 5 && age <= 10) { + } else if (age <= 10) { teachingAge = "5-10年"; - } else if (age > 10 && age <= 15) { + } else if (age <= 15) { teachingAge = "10-15年"; - } else { + } else { teachingAge = "15年以上"; } - Long count = teachingAgeCount.getOrDefault(teachingAge, 0L); - teachingAgeCount.put(teachingAge, count + 1); + // 直接累加(键已存在) + teachingAgeCount.put(teachingAge, teachingAgeCount.get(teachingAge) + 1); - totalTeachingAge += teacher.getTeachingAge(); + totalTeachingAge += age; validTeachers++; - //计算评价教龄 } // 计算平均教龄(新增逻辑) long averageTeachingAge = validTeachers > 0 ? Math.round((float) totalTeachingAge / validTeachers) : 0; @@ -950,22 +952,21 @@ public class TeacherServiceImpl implements TeacherService { //获取教龄分类信息 if (teacher.getTeachingAge() != null) { int age = teacher.getTeachingAge(); - String teachingAge = ""; - if (age >= 0 && age <= 5) { + String teachingAge; + if (age <= 5) { teachingAge = "0-5年"; - } else if (age > 5 && age <= 10) { + } else if (age <= 10) { teachingAge = "5-10年"; - } else if (age > 10 && age <= 15) { + } else if (age <= 15) { teachingAge = "10-15年"; - } else { + } else { teachingAge = "15年以上"; } - Long count = teachingAgeCount.getOrDefault(teachingAge, 0L); - teachingAgeCount.put(teachingAge, count + 1); + // 直接累加(键已存在) + teachingAgeCount.put(teachingAge, teachingAgeCount.get(teachingAge) + 1); - totalTeachingAge += teacher.getTeachingAge(); + totalTeachingAge += age; validTeachers++; - //计算评价教龄 } // 计算平均教龄(新增逻辑) long averageTeachingAge = validTeachers > 0 ? Math.round((float) totalTeachingAge / validTeachers) : 0; @@ -1001,22 +1002,21 @@ public class TeacherServiceImpl implements TeacherService { //获取教龄分类信息 if (teacher.getTeachingAge() != null) { int age = teacher.getTeachingAge(); - String teachingAge = ""; - if (age >= 0 && age <= 5) { + String teachingAge; + if (age <= 5) { teachingAge = "0-5年"; - } else if (age > 5 && age <= 10) { + } else if (age <= 10) { teachingAge = "5-10年"; - } else if (age > 10 && age <= 15) { + } else if (age <= 15) { teachingAge = "10-15年"; - } else { + } else { teachingAge = "15年以上"; } - Long count = teachingAgeCount.getOrDefault(teachingAge, 0L); - teachingAgeCount.put(teachingAge, count + 1); + // 直接累加(键已存在) + teachingAgeCount.put(teachingAge, teachingAgeCount.get(teachingAge) + 1); - totalTeachingAge += teacher.getTeachingAge(); + totalTeachingAge += age; validTeachers++; - //计算评价教龄 } // 计算平均教龄(新增逻辑) long averageTeachingAge = validTeachers > 0 ? Math.round((float) totalTeachingAge / validTeachers) : 0;