From 70ffad27a3b4247aff685c397b82fd190250130b Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Tue, 16 Jan 2024 10:41:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E6=9F=A5=E8=AF=A2=E5=80=BC=E5=91=A8=E8=AF=84?= =?UTF-8?q?=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weekduty/AdminFindDutyRecordDto.java | 2 - .../repository/DutyRecordRepository.java | 2 +- .../service/impl/DutyServiceImpl.java | 40 +++++++++++++------ .../cn/teammodel/utils/SchoolDateUtil.java | 14 +++++++ 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/main/java/cn/teammodel/model/dto/admin/weekduty/AdminFindDutyRecordDto.java b/src/main/java/cn/teammodel/model/dto/admin/weekduty/AdminFindDutyRecordDto.java index 2531ceb..e8b82c0 100644 --- a/src/main/java/cn/teammodel/model/dto/admin/weekduty/AdminFindDutyRecordDto.java +++ b/src/main/java/cn/teammodel/model/dto/admin/weekduty/AdminFindDutyRecordDto.java @@ -13,8 +13,6 @@ import javax.validation.constraints.NotNull; public class AdminFindDutyRecordDto { @ApiModelProperty("老师 id") private String teacherId; - @ApiModelProperty("学生 id") - private String studentId; @ApiModelProperty(value = "班级 id", notes = "若不携带默认不指定某个班级") private String classId; @ApiModelProperty(required = true) diff --git a/src/main/java/cn/teammodel/repository/DutyRecordRepository.java b/src/main/java/cn/teammodel/repository/DutyRecordRepository.java index 3224e56..ef3acda 100644 --- a/src/main/java/cn/teammodel/repository/DutyRecordRepository.java +++ b/src/main/java/cn/teammodel/repository/DutyRecordRepository.java @@ -19,7 +19,7 @@ public interface DutyRecordRepository extends CosmosRepository= @startTime) " + diff --git a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java index bc1365c..1799a15 100644 --- a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java @@ -1,5 +1,6 @@ package cn.teammodel.service.impl; +import cn.hutool.core.lang.Pair; import cn.hutool.core.lang.UUID; import cn.teammodel.common.ErrorCode; import cn.teammodel.common.PK; @@ -25,8 +26,8 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.time.*; -import java.time.temporal.TemporalAdjusters; +import java.time.Instant; +import java.time.LocalDate; import java.util.*; import java.util.stream.Collectors; @@ -326,15 +327,9 @@ public class DutyServiceImpl implements DutyService { List semesters = schoolRepository.findSemestersById(schoolId, periodId); String academicYearId = SchoolDateUtil.calculateAcademicYearId(semesters, LocalDate.now()); - if (startTime == null || endTime == null) { - LocalDateTime mondayOfCurWeek = LocalDateTime.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)) - .withHour(0) - .withMinute(0) - .withSecond(0) - .withNano(0); - startTime = mondayOfCurWeek.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli(); - endTime = Instant.now().toEpochMilli(); - } + Pair pair = SchoolDateUtil.adjustTimeRangeToCurrentWeekIfNull(startTime, endTime); + startTime = pair.getKey(); + endTime = pair.getValue(); List records = dutyRecordRepository.findRecordsByConditions( String.format(PK.WEEK_DUTY_RECORD, schoolId), academicYearId, @@ -371,7 +366,28 @@ public class DutyServiceImpl implements DutyService { @Override public List findAdminRecords(AdminFindDutyRecordDto adminFindDutyRecordDto) { - return null; + String teacherId = adminFindDutyRecordDto.getTeacherId(); + String classId = adminFindDutyRecordDto.getClassId(); + String academicYearId = adminFindDutyRecordDto.getAcademicYearId(); + Boolean positive = adminFindDutyRecordDto.getPositive(); + Long startTime = adminFindDutyRecordDto.getStartTime(); + Long endTime = adminFindDutyRecordDto.getEndTime(); + User user = SecurityUtil.getLoginUser(); + String schoolId = user.getSchoolId(); + + Pair pair = SchoolDateUtil.adjustTimeRangeToCurrentWeekIfNull(startTime, endTime); + startTime = pair.getKey(); + endTime = pair.getValue(); + List records = dutyRecordRepository.findRecordsByConditions( + String.format(PK.WEEK_DUTY_RECORD, schoolId), + academicYearId, + teacherId, + classId, + positive, + startTime, + endTime); + records = records.stream().sorted((o1, o2) -> o2.getInfo().getCreateTime().compareTo(o1.getInfo().getCreateTime())).collect(Collectors.toList()); + return records; } /** diff --git a/src/main/java/cn/teammodel/utils/SchoolDateUtil.java b/src/main/java/cn/teammodel/utils/SchoolDateUtil.java index 1bb9280..82cd322 100644 --- a/src/main/java/cn/teammodel/utils/SchoolDateUtil.java +++ b/src/main/java/cn/teammodel/utils/SchoolDateUtil.java @@ -1,5 +1,6 @@ package cn.teammodel.utils; +import cn.hutool.core.lang.Pair; import cn.teammodel.common.CommonConstant; import cn.teammodel.config.exception.ServiceException; import cn.teammodel.model.entity.school.School; @@ -128,6 +129,19 @@ public class SchoolDateUtil { return initialMap; } + public static Pair adjustTimeRangeToCurrentWeekIfNull(Long startTime, Long endTime) { + if (startTime == null || endTime == null) { + LocalDateTime mondayOfCurWeek = LocalDateTime.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)) + .withHour(0) + .withMinute(0) + .withSecond(0) + .withNano(0); + startTime = mondayOfCurWeek.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli(); + endTime = Instant.now().toEpochMilli(); + } + return new Pair<>(startTime, endTime); + } + @Data @AllArgsConstructor