From ef1979cbd70b71c040e67218d9c9fdf48748c11a Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Thu, 21 Dec 2023 17:46:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E7=9A=84=E6=8C=87=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dao/AppraiseRecordRepository.java | 5 ++ .../cn/teammodel/dao/StudentRepository.java | 2 + .../model/vo/appraise/StudentReportVo.java | 35 ++++++++++ .../service/impl/EvaluationServiceImpl.java | 70 +++++++++++++++---- .../TeamModelExtensionApplicationTests.java | 3 +- 5 files changed, 100 insertions(+), 15 deletions(-) diff --git a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java index 2b16fb5..aac3d8a 100644 --- a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java +++ b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java @@ -111,6 +111,11 @@ public interface AppraiseRecordRepository extends CosmosRepository studentRank(String code, String academicYearId, Long startTime, Long endTime); + @Query("select c.targetId, c.praiseCount from Student as c where c.code = @code and c.academicYearId = @academicYearId and c.targetType = 'student' and c.classId = @classId") + List findClassRecord(String code, String academicYearId, String classId); + + + // test script @Query("select * from Student as c where c.code = @code") List findByCode(String code); diff --git a/src/main/java/cn/teammodel/dao/StudentRepository.java b/src/main/java/cn/teammodel/dao/StudentRepository.java index 279a9b7..aad5d0b 100644 --- a/src/main/java/cn/teammodel/dao/StudentRepository.java +++ b/src/main/java/cn/teammodel/dao/StudentRepository.java @@ -20,4 +20,6 @@ public interface StudentRepository extends CosmosRepository { @Query("select c.id, c.name, c.classId from Student as c where c.code = @code and c.id in (@ids)") List findAllByCodeAndIdIn(String code, Set ids); + + int countByClassIdAndCode(String classId, String code); } \ No newline at end of file diff --git a/src/main/java/cn/teammodel/model/vo/appraise/StudentReportVo.java b/src/main/java/cn/teammodel/model/vo/appraise/StudentReportVo.java index aeeeb48..601cd50 100644 --- a/src/main/java/cn/teammodel/model/vo/appraise/StudentReportVo.java +++ b/src/main/java/cn/teammodel/model/vo/appraise/StudentReportVo.java @@ -2,10 +2,14 @@ package cn.teammodel.model.vo.appraise; import cn.teammodel.common.FiveEducations; import cn.teammodel.model.entity.appraise.AchievementRule; +import cn.teammodel.model.entity.appraise.AppraiseRecordItem; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -14,18 +18,41 @@ import java.util.Map; * @create 2023-12-04 15:26 */ @Data +@Builder public class StudentReportVo { @ApiModelProperty("学生表扬总数") private Integer praiseCount; + @ApiModelProperty("学生总分") private Integer score; + + @ApiModelProperty("表扬数据超越了全班多少人") + private Float beyondPercent; + + @ApiModelProperty("表扬最多的老师") + private Teacher topPraiseTeacher; + + @ApiModelProperty("批评最多的老师") + private Teacher topCriticalTeacher; + + @ApiModelProperty("最多的表扬指标") + private String topPraiseNode; + + @ApiModelProperty("最多的批评指标") + private String topCriticalNode; + @ApiModelProperty("五育表扬分布图") private Map praiseDistribution; + @ApiModelProperty("五育待改进分布图") private Map criticalDistribution; + @ApiModelProperty("学生当前成就") private AchievementRule curAchievement; + @ApiModelProperty("学生本学期的所有评价数据") + private List records; + public static Map ofFiveEducation() { Map initialMap = new HashMap<>(); FiveEducations.codes().forEach(item -> { @@ -34,4 +61,12 @@ public class StudentReportVo { return initialMap; } + + @Data + @AllArgsConstructor + public static class Teacher { + String id; + String name; + } + } diff --git a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java index 3b7e71c..5606573 100644 --- a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java @@ -426,20 +426,34 @@ public class EvaluationServiceImpl implements EvaluationService { academicYearId, String.format(PK.PK_APPRAISE_RECORD, schoolId) ); + int stuInClassCount = studentRepository.countByClassIdAndCode(classId, String.format(PK.STUDENT, schoolId)); + List classRecord = appraiseRecordRepository.findClassRecord(String.format(PK.PK_APPRAISE_RECORD, schoolId), academicYearId, classId); + if (appraiseRecord == null || appraiseRecord.getNodes() == null) { - return null; + throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "当前学生暂未产生评价数据,无法生成报告"); } + Integer praiseCount = appraiseRecord.getPraiseCount(); List records = appraiseRecord.getNodes(); + records = records.stream().sorted(Comparator.comparing(AppraiseRecordItem::getCreateTime).reversed()).collect(Collectors.toList()); // 查询成就规则 Appraise appraise = RepositoryUtil.findOne(appraiseRepository.findRulesById(schoolId, periodId), "当前成就规则还未创建"); List rules = appraise.getAchievementRules(); if (CollectionUtil.isEmpty(rules)) { throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "当前成就规则为空"); } - StudentReportVo reportVo = new StudentReportVo(); // 计算雷达图 Map praiseDistribution = StudentReportVo.ofFiveEducation(); Map criticalDistribution = StudentReportVo.ofFiveEducation(); + // 计算数据 + Map praiseTeacherMap = new HashMap<>(); + Map criticalTeacherMap = new HashMap<>(); + Map praiseNodeMap = new HashMap<>(); + Map criticalNodeMap = new HashMap<>(); + // 计算当前学生排名在全班次位 + float beyondPercent = 0; + long currentRank = classRecord.stream().filter(item -> item.getPraiseCount() < praiseCount).count(); + beyondPercent = (float) currentRank / stuInClassCount; + // 根据全部数据计算结果 for (AppraiseRecordItem record : records) { AppraiseTreeNode appraiseNode = record.getAppraiseNode(); String[] path = appraiseNode.getPath(); @@ -450,19 +464,28 @@ public class EvaluationServiceImpl implements EvaluationService { String root = path[0]; // 一级评价项不在预期中 String key = FiveEducations.getCodeByName(root); - if (key == null) { - // todo: 这里的数据异常情况是否需要上报一下 - continue; + // 计算雷达图 + if (key != null) { + if (appraiseNode.isPraise()) { + praiseDistribution.put(key, praiseDistribution.getOrDefault(key, 0) + 1); + } else { + criticalDistribution.put(key, criticalDistribution.getOrDefault(key, 0) + 1); + } } + + String teacherId = record.getCreatorId(); + String nodeName = appraiseNode.getName(); + // 根据评价是否为表扬计算数据 if (appraiseNode.isPraise()) { - praiseDistribution.put(key, praiseDistribution.getOrDefault(key, 0) + 1); + praiseTeacherMap.put(teacherId, praiseTeacherMap.getOrDefault(teacherId, 0) + 1); + praiseNodeMap.put(nodeName, praiseNodeMap.getOrDefault(nodeName, 0) + 1); } else { - criticalDistribution.put(key, criticalDistribution.getOrDefault(key, 0) + 1); + criticalTeacherMap.put(teacherId, criticalTeacherMap.getOrDefault(teacherId, 0) + 1); + criticalNodeMap.put(nodeName, criticalNodeMap.getOrDefault(nodeName, 0) + 1); } } // 计算成就项 (排序 rules = rules.stream().sorted(Comparator.comparing(AchievementRule::getLevel).reversed()).collect(Collectors.toList()); - Integer praiseCount = appraiseRecord.getPraiseCount(); AchievementRule curAchievement = rules.get(rules.size() - 1); for (AchievementRule rule : rules) { Integer promotionCount = rule.getPromotionCount(); @@ -473,12 +496,31 @@ public class EvaluationServiceImpl implements EvaluationService { break; } } - reportVo.setPraiseCount(appraiseRecord.getPraiseCount()); - reportVo.setScore(appraiseRecord.getScore()); - reportVo.setPraiseDistribution(praiseDistribution); - reportVo.setCriticalDistribution(criticalDistribution); - reportVo.setCurAchievement(curAchievement); - return reportVo; + // 汇总数据 + String topPraiseTeacherId = praiseTeacherMap.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey).orElse(null); + AppraiseRecordItem tmp1 = records.stream().filter(item -> item.getCreatorId().equals(topPraiseTeacherId)).findFirst().orElse(null); + String topPraiseTeacherName = tmp1 == null ? null : tmp1.getCreator(); + + String topCriticalTeacherId = criticalTeacherMap.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey).orElse(null); + AppraiseRecordItem tmp2 = records.stream().filter(item -> item.getCreatorId().equals(topCriticalTeacherId)).findFirst().orElse(null); + String topCriticalTeacherName = tmp2 == null ? null : tmp2.getCreator(); + + String topPraiseNode = praiseNodeMap.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey).orElse(null); + String topCriticalNode = criticalNodeMap.entrySet().stream().max(Map.Entry.comparingByValue()).map(Map.Entry::getKey).orElse(null); + + return StudentReportVo.builder() + .praiseCount(praiseCount) + .score(appraiseRecord.getScore()) + .beyondPercent(beyondPercent) + .topPraiseTeacher(new StudentReportVo.Teacher(topPraiseTeacherId, topPraiseTeacherName)) + .topCriticalTeacher(new StudentReportVo.Teacher(topCriticalTeacherId, topCriticalTeacherName)) + .topPraiseNode(topPraiseNode) + .topCriticalNode(topCriticalNode) + .praiseDistribution(praiseDistribution) + .criticalDistribution(criticalDistribution) + .curAchievement(curAchievement) + .records(records) + .build(); } /** diff --git a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java index 492bb13..0beb023 100644 --- a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java +++ b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java @@ -230,7 +230,8 @@ class TeamModelExtensionApplicationTests { // CosmosPatchOperations options = CosmosPatchOperations.create().add("/history/-", message); // 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(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")); }