From 8c15427ff724ad38c2753d6ef194d731c907f6d9 Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Tue, 9 Jan 2024 14:04:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=92=A4=E5=9B=9E=E5=80=BC=E5=91=A8?= =?UTF-8?q?=E6=8A=95=E7=A5=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/frontend/DutyController.java | 13 ++++-- .../model/dto/weekDuty/RecallDutyVoteDto.java | 20 +++++++++ .../model/dto/weekDuty/UpdateDutyNodeDto.java | 4 +- .../model/vo/weekDuty/DutyRecordVo.java | 16 ++++++++ .../repository/DutyRecordRepository.java | 5 ++- .../cn/teammodel/service/DutyService.java | 6 ++- .../service/impl/DutyServiceImpl.java | 41 +++++++++++++++---- 7 files changed, 88 insertions(+), 17 deletions(-) create mode 100644 src/main/java/cn/teammodel/model/dto/weekDuty/RecallDutyVoteDto.java create mode 100644 src/main/java/cn/teammodel/model/vo/weekDuty/DutyRecordVo.java diff --git a/src/main/java/cn/teammodel/controller/frontend/DutyController.java b/src/main/java/cn/teammodel/controller/frontend/DutyController.java index 7b1f940..0d7ef8c 100644 --- a/src/main/java/cn/teammodel/controller/frontend/DutyController.java +++ b/src/main/java/cn/teammodel/controller/frontend/DutyController.java @@ -4,7 +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.model.vo.weekDuty.DutyRecordVo; import cn.teammodel.service.DutyService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -60,6 +60,13 @@ public class DutyController { return R.success("评价成功"); } + @PostMapping("/recallVote") + @ApiOperation("值周评价投票") + public R recallVote(@RequestBody @Valid RecallDutyVoteDto recallDutyVoteDto) { + dutyService.recallVote(recallDutyVoteDto); + return R.success("撤回评价成功"); + } + @PostMapping("/insertSpot") @ApiOperation("插入值周评价地点") public R> insertSpot(@RequestBody @Valid InsertSpotDto insertSpotDto) { @@ -76,8 +83,8 @@ public class DutyController { @PostMapping("/findRecords") @ApiOperation("多条件查询评价明细") - public R> findRecords(@RequestBody @Valid FindDutyRecordDto findDutyRecordDto) { - List items = dutyService.findRecords(findDutyRecordDto); + 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/RecallDutyVoteDto.java b/src/main/java/cn/teammodel/model/dto/weekDuty/RecallDutyVoteDto.java new file mode 100644 index 0000000..13100e8 --- /dev/null +++ b/src/main/java/cn/teammodel/model/dto/weekDuty/RecallDutyVoteDto.java @@ -0,0 +1,20 @@ +package cn.teammodel.model.dto.weekDuty; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +/** + * @author winter + * @create 2023-11-22 16:16 + */ +@Data +public class RecallDutyVoteDto { + @NotNull + @ApiModelProperty(value = "值周记录的文档id", required = true) + String recordId; + @NotNull + @ApiModelProperty(value = "值周记录的具体节点id", required = true) + String nodeId; +} diff --git a/src/main/java/cn/teammodel/model/dto/weekDuty/UpdateDutyNodeDto.java b/src/main/java/cn/teammodel/model/dto/weekDuty/UpdateDutyNodeDto.java index 2d3190b..3cb6bb2 100644 --- a/src/main/java/cn/teammodel/model/dto/weekDuty/UpdateDutyNodeDto.java +++ b/src/main/java/cn/teammodel/model/dto/weekDuty/UpdateDutyNodeDto.java @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.NotNull; +import javax.validation.constraints.PositiveOrZero; /** * @author winter @@ -18,7 +19,8 @@ public class UpdateDutyNodeDto { private String id; private String name; private String desc; + private Boolean positive = true; private Integer order = 0; + @PositiveOrZero(message = "分数不能为负数") private Integer score = 0; -// boolean positive; } diff --git a/src/main/java/cn/teammodel/model/vo/weekDuty/DutyRecordVo.java b/src/main/java/cn/teammodel/model/vo/weekDuty/DutyRecordVo.java new file mode 100644 index 0000000..dc360e2 --- /dev/null +++ b/src/main/java/cn/teammodel/model/vo/weekDuty/DutyRecordVo.java @@ -0,0 +1,16 @@ +package cn.teammodel.model.vo.weekDuty; + +import cn.teammodel.model.entity.weekDuty.WeekDutyRecord; +import lombok.Data; + +/** + * @author winter + * @create 2023-12-04 15:26 + */ +@Data +public class DutyRecordVo { + private String recordId; + private String classId; + private String className; + private WeekDutyRecord.WeekDutyItem info; +} diff --git a/src/main/java/cn/teammodel/repository/DutyRecordRepository.java b/src/main/java/cn/teammodel/repository/DutyRecordRepository.java index 9a3dd0c..3224e56 100644 --- a/src/main/java/cn/teammodel/repository/DutyRecordRepository.java +++ b/src/main/java/cn/teammodel/repository/DutyRecordRepository.java @@ -1,6 +1,7 @@ package cn.teammodel.repository; import cn.teammodel.model.entity.weekDuty.WeekDutyRecord; +import cn.teammodel.model.vo.weekDuty.DutyRecordVo; import com.azure.spring.data.cosmos.repository.CosmosRepository; import com.azure.spring.data.cosmos.repository.Query; import org.springframework.stereotype.Repository; @@ -15,7 +16,7 @@ import java.util.List; 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 " + + @Query(value = "SELECT c.id as recordId, c.classId, c.className, n as info FROM c join n in c.nodes WHERE " + "c.code = @code " + "AND c.academicYearId = @academicYearId " + "AND n.creatorId = @userId " + @@ -23,6 +24,6 @@ public interface DutyRecordRepository extends CosmosRepository= @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); + 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 b3c0271..19723e9 100644 --- a/src/main/java/cn/teammodel/service/DutyService.java +++ b/src/main/java/cn/teammodel/service/DutyService.java @@ -2,7 +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 cn.teammodel.model.vo.weekDuty.DutyRecordVo; import java.util.List; @@ -25,5 +25,7 @@ public interface DutyService { List deleteSpot(String id); - List findRecords(FindDutyRecordDto findDutyRecordDto); + List findRecords(FindDutyRecordDto findDutyRecordDto); + + void recallVote(RecallDutyVoteDto recallDutyVoteDto); } diff --git a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java index 0006f6e..8c5187b 100644 --- a/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/DutyServiceImpl.java @@ -10,6 +10,7 @@ import cn.teammodel.model.entity.school.ClassInfo; import cn.teammodel.model.entity.school.School; import cn.teammodel.model.entity.weekDuty.WeekDuty; import cn.teammodel.model.entity.weekDuty.WeekDutyRecord; +import cn.teammodel.model.vo.weekDuty.DutyRecordVo; import cn.teammodel.repository.ClassRepository; import cn.teammodel.repository.DutyRecordRepository; import cn.teammodel.repository.DutyRepository; @@ -25,10 +26,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.time.*; import java.time.temporal.TemporalAdjusters; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -158,6 +156,7 @@ public class DutyServiceImpl implements DutyService { String newNodeName = updateDutyNodeDto.getName(); Integer newScore = updateDutyNodeDto.getScore(); String desc = updateDutyNodeDto.getDesc(); + Boolean positive = updateDutyNodeDto.getPositive(); String schoolId = SecurityUtil.getLoginUser().getSchoolId(); WeekDuty duty = dutyRepository.findBySchoolIdAndCode(schoolId, PK.WEEK_DUTY); @@ -173,7 +172,7 @@ public class DutyServiceImpl implements DutyService { nodeToUpdate.setName(newNodeName); nodeToUpdate.setOrder(updateDutyNodeDto.getOrder()); - // 如果是一级,二级需同步更新三级节点的 path + // 一级,二级需同步更新三级节点的 path if (nodeToUpdate.getPath() == null || nodeToUpdate.getPath().length == 0) { int index = StringUtils.isEmpty(nodeToUpdate.getPid()) ? 0 : 1; nodes.forEach(x -> { @@ -188,9 +187,10 @@ public class DutyServiceImpl implements DutyService { } }); } else { - nodeToUpdate.setScore(newScore); + // 三级节点 + nodeToUpdate.setScore(positive ? newScore : -newScore); nodeToUpdate.setDesc(desc); - nodeToUpdate.setPositive(newScore >= 0); + nodeToUpdate.setPositive(newScore.equals(0) || positive); nodeToUpdate.getPath()[2] = newNodeName; } @@ -312,7 +312,7 @@ public class DutyServiceImpl implements DutyService { } @Override - public List findRecords(FindDutyRecordDto findDutyRecordDto) { + public List findRecords(FindDutyRecordDto findDutyRecordDto) { String classId = StringUtils.isEmpty(findDutyRecordDto.getClassId()) ? null : findDutyRecordDto.getClassId(); String academicYearId = findDutyRecordDto.getAcademicYearId(); Boolean positive = findDutyRecordDto.getPositive(); @@ -331,7 +331,7 @@ public class DutyServiceImpl implements DutyService { startTime = mondayOfCurWeek.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli(); endTime = Instant.now().toEpochMilli(); } - List records = dutyRecordRepository.findRecordsByConditions( + List records = dutyRecordRepository.findRecordsByConditions( String.format(PK.WEEK_DUTY_RECORD, schoolId), academicYearId, userId, @@ -339,9 +339,32 @@ public class DutyServiceImpl implements DutyService { positive, startTime, endTime); + records = records.stream().sorted((o1, o2) -> o2.getInfo().getCreateTime().compareTo(o1.getInfo().getCreateTime())).collect(Collectors.toList()); return records; } + @Override + public void recallVote(RecallDutyVoteDto recallDutyVoteDto) { + String recordId = recallDutyVoteDto.getRecordId(); + String nodeId = recallDutyVoteDto.getNodeId(); + User user = SecurityUtil.getLoginUser(); + String schoolId = user.getSchoolId(); + String userId = user.getId(); + + Optional optional = dutyRecordRepository.findById(recordId, PK.of(String.format(PK.WEEK_DUTY_RECORD, schoolId))); + WeekDutyRecord weekDutyRecord = optional.orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "评价记录不存在")); + WeekDutyRecord.WeekDutyItem item = weekDutyRecord.getNodes().stream() + .filter(x -> nodeId.equals(x.getDutyTreeNode().getId())) + .findFirst(). + orElseThrow(() -> new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "评价记录不存在")); + if (!userId.equals(item.getCreatorId())) { + throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "只能撤回自己的评价"); + } + weekDutyRecord.setScore(weekDutyRecord.getScore() - item.getDutyTreeNode().getScore()); + weekDutyRecord.getNodes().remove(item); + dutyRecordRepository.save(weekDutyRecord); + } + /** * 刷新值周树和 spots 的 id */