From 5933e2daeeefba81cc653a14ffd64f44cfa95b29 Mon Sep 17 00:00:00 2001 From: "hhb@hotmail.com" Date: Fri, 15 Nov 2024 10:38:56 +0800 Subject: [PATCH] update --- .../service/impl/TeacherServiceImpl.java | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 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 baf6a1b..e831d31 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 @@ -9,7 +9,6 @@ import cn.teammodel.model.entity.common.GroupList; import cn.teammodel.model.entity.school.LessonRecord; import cn.teammodel.model.entity.school.School; import cn.teammodel.model.entity.school.SchoolTeacher; -import cn.teammodel.model.vo.appraise.RecordVo; import cn.teammodel.repository.LessonRecordRepository; import cn.teammodel.repository.SchoolGroupListRepository; import cn.teammodel.repository.SchoolRepository; @@ -115,8 +114,8 @@ public class TeacherServiceImpl implements TeacherService { // 获取学期起止时间 List semesters = schoolRepository.findSemestersById(teacherDto.getCode(), teacherDto.getPeriodId()); SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now()); - LocalDateTime startDatetime = null; - LocalDateTime endDatetime = null; + LocalDateTime startDatetime; + LocalDateTime endDatetime; if(teacherDto.getStartTime() != null) { startDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getStartTime()), ZoneId.systemDefault()); endDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getEndTime()), ZoneId.systemDefault()); @@ -162,8 +161,8 @@ public class TeacherServiceImpl implements TeacherService { // 获取学期起止时间 List semesters = schoolRepository.findSemestersById(teacherDto.getCode(), teacherDto.getPeriodId()); SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now()); - LocalDateTime startDatetime = null; - LocalDateTime endDatetime = null; + LocalDateTime startDatetime; + LocalDateTime endDatetime; if(teacherDto.getStartTime() != null) { startDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getStartTime()), ZoneId.systemDefault()); endDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(teacherDto.getEndTime()), ZoneId.systemDefault()); @@ -178,26 +177,22 @@ public class TeacherServiceImpl implements TeacherService { long endTimestamp = endDatetime.toInstant(ZoneOffset.UTC).toEpochMilli(); List lessonRecords = lessonRecordRepository.getLessonsByConditions(String.format(PK.PK_LESSON_RECORD, teacherDto.getCode()), startTimestamp, endTimestamp, teacherDto.getTmdId()); - int cooperationCount = 0; - int internetCount = 0; - int taskCount = 0; - int examCount = 0; - int diffentialCount = 0; + int[] counts = {0, 0, 0, 0, 0}; + String[] keys = {"cooperation", "internet", "task", "exam", "diffential"}; for (LessonRecord record : lessonRecords) { if (record.getLearningCategory() != null) { - cooperationCount += record.getLearningCategory().getCooperation(); - internetCount += record.getLearningCategory().getInteraction(); - taskCount += record.getLearningCategory().getTask(); - examCount += record.getLearningCategory().getExam(); - diffentialCount += record.getLearningCategory().getDiffential(); + counts[0] += record.getLearningCategory().getCooperation(); + counts[1] += record.getLearningCategory().getInteraction(); + counts[2] += record.getLearningCategory().getTask(); + counts[3] += record.getLearningCategory().getExam(); + counts[4] += record.getLearningCategory().getDiffential(); } } - LearningCategory.put("cooperation", cooperationCount); - LearningCategory.put("internet", internetCount); - LearningCategory.put("task", taskCount); - LearningCategory.put("exam", examCount); - LearningCategory.put("diffential", diffentialCount); + + for (int i = 0; i < keys.length; i++) { + LearningCategory.put(keys[i], counts[i]); + } }catch (Exception e) { throw new ServiceException(ErrorCode.SYSTEM_ERROR.getCode(), "数据转换错误");