From 2f8bb75d6f4fbf2182dfc3f45622ea98ff67efd4 Mon Sep 17 00:00:00 2001 From: "hhb@hotmail.com" Date: Mon, 23 Sep 2024 17:37:07 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=9F=A5=E8=AF=A2=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/AdminDutyController.java | 6 ++--- .../admin/controller/IndexController.java | 8 +++---- .../admin/service/AdminAppraiseService.java | 2 +- .../admin/service/AdminIndexDutyService.java | 2 +- .../impl/AdminAppraiseServiceImpl.java | 22 ++++++++++++----- .../impl/AdminIndexDutyServiceImpl.java | 24 ++++++++++++++----- .../dto/admin/appraise/TimeRangeDto.java | 1 + 7 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/main/java/cn/teammodel/controller/admin/controller/AdminDutyController.java b/src/main/java/cn/teammodel/controller/admin/controller/AdminDutyController.java index b240877..0411b3b 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/AdminDutyController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/AdminDutyController.java @@ -45,10 +45,10 @@ public class AdminDutyController { return R.success(res); } - @GetMapping("index/{periodId}") + @PostMapping("index") @ApiOperation("获取首页数据") - public R index(@PathVariable String periodId){ - DutyIndexData dutyIndexData = adminIndexDutyService.getIndexData(periodId); + public R index(@Valid @RequestBody TimeRangeDto timeRangeDto){ + DutyIndexData dutyIndexData = adminIndexDutyService.getIndexData(timeRangeDto); return R.success(dutyIndexData); } diff --git a/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java b/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java index 9943c19..fb9e9a9 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java @@ -16,7 +16,7 @@ import java.util.List; /** * 管理员首页 * @author winter - * @create 2023-12-06 14:37 + * @create 2023-12-06 14:37 */ @RestController @RequestMapping("admin/index") @@ -26,10 +26,10 @@ public class IndexController { private AdminAppraiseService adminAppraiseService; - @GetMapping("/{periodId}") + @PostMapping("/") @ApiOperation("获取首页数据") - public R index(@PathVariable String periodId){ - AppraiseIndexData appraiseIndexData = adminAppraiseService.getIndexData(periodId); + public R index(@Valid @RequestBody TimeRangeDto timeRangeDto){ + AppraiseIndexData appraiseIndexData = adminAppraiseService.getIndexData(timeRangeDto); return R.success(appraiseIndexData); } diff --git a/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java b/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java index 60895c5..20492c7 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java +++ b/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java @@ -13,7 +13,7 @@ import java.util.List; * @create 2023-12-06 14:45 */ public interface AdminAppraiseService { - AppraiseIndexData getIndexData(String periodId); + AppraiseIndexData getIndexData(TimeRangeDto timeRangeDto); /** * 按时期分页获取最新的评价数据 diff --git a/src/main/java/cn/teammodel/controller/admin/service/AdminIndexDutyService.java b/src/main/java/cn/teammodel/controller/admin/service/AdminIndexDutyService.java index 05959b8..c83bf11 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/AdminIndexDutyService.java +++ b/src/main/java/cn/teammodel/controller/admin/service/AdminIndexDutyService.java @@ -16,7 +16,7 @@ import java.util.Map; * @create 2024-02-28 15:07 */ public interface AdminIndexDutyService { - DutyIndexData getIndexData(String periodId); + DutyIndexData getIndexData(TimeRangeDto timeRangeDto); List classRank(TimeRangeDto timeRangeDto); diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java index 246d393..a89aed1 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/AdminAppraiseServiceImpl.java @@ -57,9 +57,9 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService { private AppraiseRecordRepository appraiseRecordRepository; @Override - public AppraiseIndexData getIndexData(String periodId) { + public AppraiseIndexData getIndexData(TimeRangeDto timeRangeDto) { final int SLICE_SIZE = 100; - if (StringUtils.isBlank(periodId)) { + if (StringUtils.isBlank(timeRangeDto.getPeriodId())) { throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "不能为空"); } @@ -72,11 +72,21 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService { String schoolId = loginUser.getSchoolId(); // 获取学期起止时间 - List semesters = schoolRepository.findSemestersById(schoolId, periodId); + List semesters = schoolRepository.findSemestersById(schoolId, timeRangeDto.getPeriodId()); SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now()); - String academicYearId = semesterModel.getAcademicYearId(); - LocalDateTime startDatetime = semesterModel.getStartDatetime(); - LocalDateTime endDatetime = semesterModel.getEndDatetime(); + LocalDateTime startDatetime = null; + LocalDateTime endDatetime = null; + String academicYearId = null; + if(timeRangeDto.getStartTime() != null) { + startDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timeRangeDto.getStartTime()), ZoneId.systemDefault()); + endDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timeRangeDto.getEndTime()), ZoneId.systemDefault()); + academicYearId = timeRangeDto.getAcademicYearId(); + }else { + academicYearId = semesterModel.getAcademicYearId(); + startDatetime = semesterModel.getStartDatetime(); + endDatetime = semesterModel.getEndDatetime(); + + } if (startDatetime == null || endDatetime == null) throw new ServiceException(ErrorCode.PARAMS_ERROR); long totalWeek = calculateWeekNum(startDatetime, endDatetime, null); diff --git a/src/main/java/cn/teammodel/controller/admin/service/impl/AdminIndexDutyServiceImpl.java b/src/main/java/cn/teammodel/controller/admin/service/impl/AdminIndexDutyServiceImpl.java index 6d2b270..6ad0942 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/impl/AdminIndexDutyServiceImpl.java +++ b/src/main/java/cn/teammodel/controller/admin/service/impl/AdminIndexDutyServiceImpl.java @@ -33,8 +33,10 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.*; import java.util.stream.Collectors; @@ -67,12 +69,12 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService { }*/ @Override - public DutyIndexData getIndexData(String periodId) { + public DutyIndexData getIndexData(TimeRangeDto timeRangeDto) { User loginUser = SecurityUtil.getLoginUser(); String schoolId = loginUser.getSchoolId(); final int SLICE_SIZE = 100; - if (StringUtils.isBlank(periodId)) { + if (StringUtils.isBlank(timeRangeDto.getPeriodId())) { throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "不能为空"); } final DutyIndexData DutyIndexData = new DutyIndexData(); @@ -83,11 +85,21 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService { Set classIdSet = new HashSet<>(); // 获取学期起止时间 - List semesters = schoolRepository.findSemestersById(schoolId, periodId); + List semesters = schoolRepository.findSemestersById(schoolId, timeRangeDto.getPeriodId()); SchoolDateUtil.semesterModel semesterModel = SchoolDateUtil.getSemesterByNow(semesters, LocalDate.now()); - String academicYearId = semesterModel.getAcademicYearId(); - LocalDateTime startDatetime = semesterModel.getStartDatetime(); - LocalDateTime endDatetime = semesterModel.getEndDatetime(); + LocalDateTime startDatetime = null; + LocalDateTime endDatetime = null; + String academicYearId = null; + if(timeRangeDto.getStartTime() != null) { + startDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timeRangeDto.getStartTime()), ZoneId.systemDefault()); + endDatetime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timeRangeDto.getEndTime()), ZoneId.systemDefault()); + academicYearId = timeRangeDto.getAcademicYearId(); + }else { + academicYearId = semesterModel.getAcademicYearId(); + startDatetime = semesterModel.getStartDatetime(); + endDatetime = semesterModel.getEndDatetime(); + + } if (startDatetime == null || endDatetime == null) throw new ServiceException(ErrorCode.PARAMS_ERROR); long totalWeek = calculateWeekNum(startDatetime, endDatetime, null); diff --git a/src/main/java/cn/teammodel/model/dto/admin/appraise/TimeRangeDto.java b/src/main/java/cn/teammodel/model/dto/admin/appraise/TimeRangeDto.java index 51c1219..ab4ecc5 100644 --- a/src/main/java/cn/teammodel/model/dto/admin/appraise/TimeRangeDto.java +++ b/src/main/java/cn/teammodel/model/dto/admin/appraise/TimeRangeDto.java @@ -12,6 +12,7 @@ public class TimeRangeDto { private Long startTime; private Long endTime; @NotNull + private String periodId; // todo: 似乎不需要(有时间范围就不需要这个字段来划分时间,如果不传时间那就需要) private String academicYearId; }