From 1a18105096563001f4011d28ed355b9151772d00 Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Mon, 8 Jan 2024 17:19:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=A4=9A=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E6=9F=A5=E8=AF=A2=E8=AF=84=E4=BB=B7=E6=98=8E=E7=BB=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/frontend/DutyController.java | 8 +++- .../model/dto/weekDuty/FindDutyRecordDto.java | 25 +++++++++++ .../model/entity/weekDuty/WeekDutyRecord.java | 2 + .../repository/DutyRecordRepository.java | 14 ++++++ .../cn/teammodel/service/DutyService.java | 3 ++ .../service/impl/DutyServiceImpl.java | 45 +++++++++++++++++-- 6 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/main/java/cn/teammodel/model/dto/weekDuty/FindDutyRecordDto.java diff --git a/src/main/java/cn/teammodel/controller/frontend/DutyController.java b/src/main/java/cn/teammodel/controller/frontend/DutyController.java index 1e9e0bd..7b1f940 100644 --- a/src/main/java/cn/teammodel/controller/frontend/DutyController.java +++ b/src/main/java/cn/teammodel/controller/frontend/DutyController.java @@ -4,6 +4,7 @@ import cn.teammodel.common.IdRequest; import cn.teammodel.common.R; import cn.teammodel.model.dto.weekDuty.*; import cn.teammodel.model.entity.weekDuty.WeekDuty; +import cn.teammodel.model.entity.weekDuty.WeekDutyRecord; import cn.teammodel.service.DutyService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -73,7 +74,12 @@ public class DutyController { return R.success(spots); } - + @PostMapping("/findRecords") + @ApiOperation("多条件查询评价明细") + public R> findRecords(@RequestBody @Valid FindDutyRecordDto findDutyRecordDto) { + List items = dutyService.findRecords(findDutyRecordDto); + return R.success(items); + } diff --git a/src/main/java/cn/teammodel/model/dto/weekDuty/FindDutyRecordDto.java b/src/main/java/cn/teammodel/model/dto/weekDuty/FindDutyRecordDto.java new file mode 100644 index 0000000..93a1634 --- /dev/null +++ b/src/main/java/cn/teammodel/model/dto/weekDuty/FindDutyRecordDto.java @@ -0,0 +1,25 @@ +package cn.teammodel.model.dto.weekDuty; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * @author winter + * @create 2024-01-08 15:31 + */ +@Data +public class FindDutyRecordDto { + @ApiModelProperty(value = "班级 id", notes = "若不携带默认不指定某个班级") + private String classId; + @ApiModelProperty(required = true) + @NotNull(message = "学年 id 不能为空") + private String academicYearId; + @ApiModelProperty(value = "是否加分", notes = "若不携带默认为全部") + private Boolean positive; + @ApiModelProperty(value = "起始时间", notes = "若不携带默认为当前周") + private Long startTime; + @ApiModelProperty(value = "结束时间", notes = "若不携带默认为当前周") + private Long endTime; +} diff --git a/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDutyRecord.java b/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDutyRecord.java index 7ca0e08..64a790e 100644 --- a/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDutyRecord.java +++ b/src/main/java/cn/teammodel/model/entity/weekDuty/WeekDutyRecord.java @@ -43,6 +43,8 @@ public class WeekDutyRecord extends BaseItem { * 备注 */ private String note; + private String creator; + private String creatorId; private Long createTime; } } diff --git a/src/main/java/cn/teammodel/repository/DutyRecordRepository.java b/src/main/java/cn/teammodel/repository/DutyRecordRepository.java index 7395333..9a3dd0c 100644 --- a/src/main/java/cn/teammodel/repository/DutyRecordRepository.java +++ b/src/main/java/cn/teammodel/repository/DutyRecordRepository.java @@ -2,8 +2,11 @@ package cn.teammodel.repository; import cn.teammodel.model.entity.weekDuty.WeekDutyRecord; import com.azure.spring.data.cosmos.repository.CosmosRepository; +import com.azure.spring.data.cosmos.repository.Query; import org.springframework.stereotype.Repository; +import java.util.List; + /** * @author winter * @create 2024-01-04 17:23 @@ -11,4 +14,15 @@ import org.springframework.stereotype.Repository; @Repository public interface DutyRecordRepository extends CosmosRepository { WeekDutyRecord findByClassIdAndAcademicYearIdAndCode(String classId, String academicYearId, String code); + + @Query(value = "SELECT value n FROM c join n in c.nodes WHERE " + + "c.code = @code " + + "AND c.academicYearId = @academicYearId " + + "AND n.creatorId = @userId " + + "AND (IS_NULL(@classId) or c.classId = @classId) " + + "AND (IS_NULL(@positive) or n.dutyTreeNode.positive = @positive) " + + "AND (IS_NULL(@startTime) or n.createTime >= @startTime) " + + "AND (IS_NULL(@endTime) or n.createTime <= @endTime)") + List findRecordsByConditions(String code, String academicYearId, String userId, String classId, Boolean positive, Long startTime, Long endTime); } + diff --git a/src/main/java/cn/teammodel/service/DutyService.java b/src/main/java/cn/teammodel/service/DutyService.java index 57fb084..b3c0271 100644 --- a/src/main/java/cn/teammodel/service/DutyService.java +++ b/src/main/java/cn/teammodel/service/DutyService.java @@ -2,6 +2,7 @@ package cn.teammodel.service; import cn.teammodel.model.dto.weekDuty.*; import cn.teammodel.model.entity.weekDuty.WeekDuty; +import cn.teammodel.model.entity.weekDuty.WeekDutyRecord; import java.util.List; @@ -23,4 +24,6 @@ public interface DutyService { List insertSpot(InsertSpotDto insertSpotDto); List deleteSpot(String id); + + List findRecords(FindDutyRecordDto findDutyRecordDto); } diff --git a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java index 9a86007..0006f6e 100644 --- a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java @@ -23,8 +23,8 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.time.Instant; -import java.time.LocalDate; +import java.time.*; +import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -205,8 +205,9 @@ public class DutyServiceImpl implements DutyService { String note = dutyVoteDto.getNote(); boolean spread = dutyVoteDto.getSpread(); List attachments = dutyVoteDto.getAttachments(); + User user = SecurityUtil.getLoginUser(); + String schoolId = user.getSchoolId(); - String schoolId = SecurityUtil.getLoginUser().getSchoolId(); ClassInfo classInfo = classRepository.findClassByIdAndCode(classId, String.format(PK.CLASS, schoolId)); if (classInfo == null) { throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "目标班级不存在"); @@ -227,6 +228,11 @@ public class DutyServiceImpl implements DutyService { if (dutyNode.getPath() == null || dutyNode.getPath().length == 0) { throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "只能评价三级节点"); } + // dutynode 剪枝 + dutyNode.setCreator(null); + dutyNode.setCreatorId(null); + dutyNode.setCreateTime(null); + WeekDuty.DutySpot spot = duty.getSpots().stream() .filter(x -> spotId.equals(x.getId())) .findFirst() @@ -246,6 +252,8 @@ public class DutyServiceImpl implements DutyService { newItem.setAttachments(attachments); newItem.setNote(note); newItem.setCreateTime(Instant.now().toEpochMilli()); + newItem.setCreator(user.getName()); + newItem.setCreatorId(user.getId()); // 不存在则创建 if (weekDutyRecord == null) { List nodes = Collections.singletonList(newItem); @@ -303,6 +311,37 @@ public class DutyServiceImpl implements DutyService { return duty.getSpots(); } + @Override + public List findRecords(FindDutyRecordDto findDutyRecordDto) { + String classId = StringUtils.isEmpty(findDutyRecordDto.getClassId()) ? null : findDutyRecordDto.getClassId(); + String academicYearId = findDutyRecordDto.getAcademicYearId(); + Boolean positive = findDutyRecordDto.getPositive(); + Long startTime = findDutyRecordDto.getStartTime(); + Long endTime = findDutyRecordDto.getEndTime(); + User user = SecurityUtil.getLoginUser(); + String schoolId = user.getSchoolId(); + String userId = user.getId(); + + 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(); + } + List records = dutyRecordRepository.findRecordsByConditions( + String.format(PK.WEEK_DUTY_RECORD, schoolId), + academicYearId, + userId, + classId, + positive, + startTime, + endTime); + return records; + } + /** * 刷新值周树和 spots 的 id */