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