From 40d482669503a7c670fe192ae42f161f0aea01db Mon Sep 17 00:00:00 2001 From: winter <2436197699@qq.com> Date: Thu, 21 Dec 2023 18:28:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E4=B8=AD=E7=9A=84=E6=8E=92=E4=BD=8D=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/teammodel/dao/AppraiseRecordRepository.java | 4 ++-- .../cn/teammodel/service/impl/EvaluationServiceImpl.java | 6 ++++-- .../cn/teammodel/TeamModelExtensionApplicationTests.java | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java index aac3d8a..21beef1 100644 --- a/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java +++ b/src/main/java/cn/teammodel/dao/AppraiseRecordRepository.java @@ -111,8 +111,8 @@ 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); + @Query("SELECT value count(1) FROM Student AS c where c.code = @code and c.academicYearId = @academicYearId and c.classId = @classId and c.praiseCount > @praiseCount") + int findClassRecord(String code, String academicYearId, String classId, int praiseCount); diff --git a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java index 5606573..82f13b4 100644 --- a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java @@ -426,8 +426,8 @@ 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) { throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "当前学生暂未产生评价数据,无法生成报告"); @@ -450,9 +450,11 @@ public class EvaluationServiceImpl implements EvaluationService { Map praiseNodeMap = new HashMap<>(); Map criticalNodeMap = new HashMap<>(); // 计算当前学生排名在全班次位 + int greaterCount = appraiseRecordRepository.findClassRecord(String.format(PK.PK_APPRAISE_RECORD, schoolId), academicYearId, classId, praiseCount); float beyondPercent = 0; - long currentRank = classRecord.stream().filter(item -> item.getPraiseCount() < praiseCount).count(); + long currentRank = stuInClassCount - greaterCount; beyondPercent = (float) currentRank / stuInClassCount; + // 根据全部数据计算结果 for (AppraiseRecordItem record : records) { AppraiseTreeNode appraiseNode = record.getAppraiseNode(); diff --git a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java index 0beb023..b8da321 100644 --- a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java +++ b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java @@ -231,7 +231,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")); + System.out.println(appraiseRecordRepository.findClassRecord("AppraiseRecord-hbcn", "2023-08b81e76-e7d2-4001-8b4c-e7c789ef4bs1", "ae01dc81-1422-4643-bf13-0b38c6d15b1b", 8)); }