From 8301c973c021642c667b3194c5b9d74d296fcca2 Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Tue, 26 Dec 2023 10:16:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AF=84=E4=BB=B7=E6=8C=87=E6=A0=87?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E6=B7=BB=E5=8A=A0=20path=20=E5=92=8C=20prais?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/IndexController.java | 9 ++--- .../admin/service/AdminAppraiseService.java | 7 ++-- .../impl/AdminAppraiseServiceImpl.java | 36 +++++++++++++------ .../dao/AppraiseRecordRepository.java | 10 +++++- .../model/vo/admin/AppraiseNodeRankVo.java | 14 ++++++++ .../TeamModelExtensionApplicationTests.java | 12 +++---- 6 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 src/main/java/cn/teammodel/model/vo/admin/AppraiseNodeRankVo.java 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 3cf039c..7db0ff2 100644 --- a/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java +++ b/src/main/java/cn/teammodel/controller/admin/controller/IndexController.java @@ -3,10 +3,7 @@ package cn.teammodel.controller.admin.controller; import cn.teammodel.common.R; import cn.teammodel.controller.admin.service.AdminAppraiseService; import cn.teammodel.model.dto.admin.TimeRangeDto; -import cn.teammodel.model.vo.admin.IndexData; -import cn.teammodel.model.vo.admin.RankPo; -import cn.teammodel.model.vo.admin.RankVo; -import cn.teammodel.model.vo.admin.StudentRankVo; +import cn.teammodel.model.vo.admin.*; import cn.teammodel.model.vo.appraise.RecordVo; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; @@ -61,8 +58,8 @@ public class IndexController { } @PostMapping("appraiseNodeRank") @ApiOperation("评价指标活跃排行榜: Top10") - public R> appraiseNodeRank(@Valid @RequestBody TimeRangeDto timeRangeDto) { - List res = adminAppraiseService.appraiseNodeRank(timeRangeDto); + public R> appraiseNodeRank(@Valid @RequestBody TimeRangeDto timeRangeDto) { + List res = adminAppraiseService.appraiseNodeRank(timeRangeDto); return R.success(res); } 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 acf64ac..89ed476 100644 --- a/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java +++ b/src/main/java/cn/teammodel/controller/admin/service/AdminAppraiseService.java @@ -3,10 +3,7 @@ package cn.teammodel.controller.admin.service; import cn.teammodel.model.dto.admin.TimeRangeDto; import cn.teammodel.model.dto.admin.UpdateAchievementRuleDto; import cn.teammodel.model.entity.appraise.AchievementRule; -import cn.teammodel.model.vo.admin.IndexData; -import cn.teammodel.model.vo.admin.RankPo; -import cn.teammodel.model.vo.admin.RankVo; -import cn.teammodel.model.vo.admin.StudentRankVo; +import cn.teammodel.model.vo.admin.*; import cn.teammodel.model.vo.appraise.RecordVo; import java.util.List; @@ -27,7 +24,7 @@ public interface AdminAppraiseService { List teacherRank(TimeRangeDto timeRangeDto); - List appraiseNodeRank(TimeRangeDto timeRangeDto); + List appraiseNodeRank(TimeRangeDto timeRangeDto); List studentRank(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 39aac0c..e550393 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 @@ -10,14 +10,12 @@ import cn.teammodel.model.dto.admin.UpdateAchievementRuleDto; import cn.teammodel.model.entity.User; import cn.teammodel.model.entity.appraise.AchievementRule; import cn.teammodel.model.entity.appraise.Appraise; +import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.school.ClassInfo; import cn.teammodel.model.entity.school.School; import cn.teammodel.model.entity.school.Student; import cn.teammodel.model.entity.school.Teacher; -import cn.teammodel.model.vo.admin.IndexData; -import cn.teammodel.model.vo.admin.RankPo; -import cn.teammodel.model.vo.admin.RankVo; -import cn.teammodel.model.vo.admin.StudentRankVo; +import cn.teammodel.model.vo.admin.*; import cn.teammodel.model.vo.appraise.RecordVo; import cn.teammodel.security.utils.SecurityUtil; import cn.teammodel.utils.RepositoryUtil; @@ -237,25 +235,43 @@ public class AdminAppraiseServiceImpl implements AdminAppraiseService { } @Override - public List appraiseNodeRank(TimeRangeDto timeRangeDto) { + public List appraiseNodeRank(TimeRangeDto timeRangeDto) { Long startTime = timeRangeDto.getStartTime(); Long endTime = timeRangeDto.getEndTime(); String academicYearId = timeRangeDto.getAcademicYearId(); String schoolId = SecurityUtil.getLoginUser().getSchoolId(); - List rankPoList = appraiseRecordRepository.appraiseNodeRank( + List rankVoList = appraiseRecordRepository.appraiseNodeRank( String.format(PK.PK_APPRAISE_RECORD, schoolId), academicYearId, startTime, endTime ); - if (rankPoList == null) return null; - rankPoList = rankPoList.stream() + if (rankVoList == null) return null; + List names = rankVoList.stream().map(AppraiseNodeRankVo::getName).collect(Collectors.toList()); + // 去重后的 nodes + List nodesByName = appraiseRecordRepository.findAppraiseRecordInNames(String.format(PK.PK_APPRAISE_RECORD, schoolId), academicYearId, names); + // 正常情况下 name 一一对应 + Map nameNodeMap = nodesByName.stream().collect(Collectors.toMap(AppraiseTreeNode::getName, item -> item, (existing, replacement) -> { + if (replacement.getPath() != null) { + return replacement; + } + return existing; + })); + + rankVoList = rankVoList.stream() .sorted(Comparator.comparing(RankPo::getCount).reversed()) + // 流中对元素操作但不改变流 + .peek(s -> { + AppraiseTreeNode node = nameNodeMap.get(s.getName()); + if (node != null) { + s.setPath(node.getPath()); + s.setIsPraise(node.isPraise()); + } + }) .collect(Collectors.toList()); - - return rankPoList; + return rankVoList; } @Override diff --git a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java index 21beef1..8c8be2c 100644 --- a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java +++ b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java @@ -1,6 +1,8 @@ package cn.teammodel.dao; import cn.teammodel.model.entity.appraise.AppraiseRecord; +import cn.teammodel.model.entity.appraise.AppraiseTreeNode; +import cn.teammodel.model.vo.admin.AppraiseNodeRankVo; import cn.teammodel.model.vo.admin.RankPo; import cn.teammodel.model.vo.appraise.AppraiseRecordVo; import cn.teammodel.model.vo.appraise.RecordVo; @@ -97,7 +99,13 @@ public interface AppraiseRecordRepository extends CosmosRepository appraiseNodeRank(String code, String academicYearId, Long startTime, Long endTime); + List appraiseNodeRank(String code, String academicYearId, Long startTime, Long endTime); + + @Query("select DISTINCT n.appraiseNode.name, n.appraiseNode.path, n.appraiseNode.isPraise from Student as c join n in c.nodes where " + + " (c.academicYearId = @academicYearId) and " + + " (c.code = @code) and " + + " n.appraiseNode.name in (@names)") + List findAppraiseRecordInNames(String code, String academicYearId, List names); /** * 仅针对学生,不包括班级评价 diff --git a/src/main/java/cn/teammodel/model/vo/admin/AppraiseNodeRankVo.java b/src/main/java/cn/teammodel/model/vo/admin/AppraiseNodeRankVo.java new file mode 100644 index 0000000..41bc07f --- /dev/null +++ b/src/main/java/cn/teammodel/model/vo/admin/AppraiseNodeRankVo.java @@ -0,0 +1,14 @@ +package cn.teammodel.model.vo.admin; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * @author winter + * @create 2023-12-25 17:44 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class AppraiseNodeRankVo extends RankPo { + String[] Path; +} diff --git a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java index b8da321..7b12b5c 100644 --- a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java +++ b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java @@ -8,7 +8,6 @@ import cn.teammodel.model.dto.admin.TimeRangeDto; import cn.teammodel.model.dto.admin.UpdateAchievementRuleDto; import cn.teammodel.model.entity.appraise.*; import cn.teammodel.model.entity.school.School; -import cn.teammodel.model.vo.admin.RankPo; import cn.teammodel.service.EvaluationService; import cn.teammodel.service.impl.EvaluationServiceImpl; import com.azure.cosmos.models.PartitionKey; @@ -20,10 +19,7 @@ import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; import java.time.LocalDateTime; import java.time.temporal.WeekFields; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.UUID; +import java.util.*; @SpringBootTest class TeamModelExtensionApplicationTests { @@ -179,8 +175,8 @@ class TeamModelExtensionApplicationTests { public void testIndexData() { TimeRangeDto timeRangeDto = new TimeRangeDto(); timeRangeDto.setAcademicYearId("2023-71fbd0bd-9a46-0490-f6b3-7d16cba4c017"); - List list = adminAppraiseService.appraiseNodeRank(timeRangeDto); - System.out.println(list); +// List list = adminAppraiseService.appraiseNodeRank(timeRangeDto); +// System.out.println(list); } @Test @@ -231,7 +227,7 @@ class TeamModelExtensionApplicationTests { // System.out.println(chatSessionRepository.save("111e90e5-6afd-413b-ae0f-646d957aedf8", PK.of(PK.CHAT_SESSION), ChatSession.class, options)); // System.out.println(chatSessionRepository.findLatestMessage("111e90e5-6afd-413b-ae0f-646d957aedf8")); - System.out.println(appraiseRecordRepository.findClassRecord("AppraiseRecord-hbcn", "2023-08b81e76-e7d2-4001-8b4c-e7c789ef4bs1", "ae01dc81-1422-4643-bf13-0b38c6d15b1b", 8)); + System.out.println(appraiseRecordRepository.findAppraiseRecordInNames("AppraiseRecord-hbcn", "2023-08b81e76-e7d2-4001-8b4c-e7c789ef4bs1", Arrays.asList("能够感知美"))); }