From b808c220a835e0efdabee9341f01b0ba03373c61 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Mon, 18 Apr 2022 19:01:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=99=E5=AD=A6=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/user/UserExamController.java | 7 ++-- .../rtss/services/IUserExamService.java | 5 +-- .../rtss/services/UserExamService.java | 37 +++---------------- .../joylink/rtss/vo/client/UserExamVO.java | 19 ++-------- 4 files changed, 14 insertions(+), 54 deletions(-) diff --git a/src/main/java/club/joylink/rtss/controller/user/UserExamController.java b/src/main/java/club/joylink/rtss/controller/user/UserExamController.java index d6f40ee75..8d1b90a00 100644 --- a/src/main/java/club/joylink/rtss/controller/user/UserExamController.java +++ b/src/main/java/club/joylink/rtss/controller/user/UserExamController.java @@ -5,7 +5,6 @@ import club.joylink.rtss.controller.advice.Role; import club.joylink.rtss.services.IUserExamService; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.client.*; -import club.joylink.rtss.vo.client.userExam.PersonalUserExamResultCurveQueryVO; import club.joylink.rtss.vo.client.userExam.WholeOrgUserExamResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; @@ -101,9 +100,9 @@ public class UserExamController { /** * 查询个人考试成绩曲线 */ - @GetMapping("/curve/personal") - public List getPersonalUserExamResults(PersonalUserExamResultCurveQueryVO queryVO) { - return iUserExamService.getPersonalUserExamResults(queryVO); + @GetMapping("/curve/{userId}") + public List getPersonalUserExamResults(@PathVariable Long userId) { + return iUserExamService.getPersonalUserExamResults(userId); } /** diff --git a/src/main/java/club/joylink/rtss/services/IUserExamService.java b/src/main/java/club/joylink/rtss/services/IUserExamService.java index 1e3db2fa4..909cd1d50 100644 --- a/src/main/java/club/joylink/rtss/services/IUserExamService.java +++ b/src/main/java/club/joylink/rtss/services/IUserExamService.java @@ -3,7 +3,6 @@ package club.joylink.rtss.services; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.client.*; -import club.joylink.rtss.vo.client.userExam.PersonalUserExamResultCurveQueryVO; import club.joylink.rtss.vo.client.userExam.WholeOrgUserExamResult; import java.util.List; @@ -83,9 +82,9 @@ public interface IUserExamService { /*** * 获取组织中一个人的考试成绩 - * @param queryVO + * @param userId */ - List getPersonalUserExamResults(PersonalUserExamResultCurveQueryVO queryVO); + List getPersonalUserExamResults(Long userId); /** * 获取某一次考试的全组织的用户考试成绩 diff --git a/src/main/java/club/joylink/rtss/services/UserExamService.java b/src/main/java/club/joylink/rtss/services/UserExamService.java index 3847cb95b..6f50203bc 100644 --- a/src/main/java/club/joylink/rtss/services/UserExamService.java +++ b/src/main/java/club/joylink/rtss/services/UserExamService.java @@ -1,7 +1,6 @@ package club.joylink.rtss.services; import club.joylink.rtss.constants.BusinessConsts; -import club.joylink.rtss.constants.StatusEnum; import club.joylink.rtss.dao.*; import club.joylink.rtss.entity.*; import club.joylink.rtss.event.UserExamRecordEvent; @@ -14,7 +13,6 @@ import club.joylink.rtss.simulation.cbtc.GroupSimulationService; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.client.*; import club.joylink.rtss.vo.client.training.TrainingResultVO; -import club.joylink.rtss.vo.client.userExam.PersonalUserExamResultCurveQueryVO; import club.joylink.rtss.vo.client.userExam.WholeOrgUserExamResult; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; @@ -360,38 +358,15 @@ public class UserExamService implements IUserExamService { } @Override - public List getPersonalUserExamResults(PersonalUserExamResultCurveQueryVO queryVO) { - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(queryVO.getOrgId()); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(queryVO.getUserId()); - List orgExams = iOrgExamService.findEntities(queryVO.getOrgId(), queryVO.getCreatorId()); - //该组织下由指定用户创建的所有考试 - List examIds = orgExams.stream().map(OrgExam::getExamId).collect(Collectors.toList()); - List exams = iExamService.findEntities(examIds, StatusEnum.Valid.getCode()); - //该用户对这些考试的成绩 + public List getPersonalUserExamResults(Long userId) { UserExamExample example = new UserExamExample(); - example.createCriteria() - .andUserIdEqualTo(queryVO.getUserId()) - .andExamIdIn(examIds); + example.createCriteria().andUserIdEqualTo(userId); List userExams = userExamMapper.selectByExample(example); - - Map examId_userExam_map = userExams.stream() - .collect(Collectors.toMap(UserExam::getExamId, + Collection maxScoreUserExams = userExams.stream().collect(Collectors.toMap(UserExam::getExamId, Function.identity(), - BinaryOperator.maxBy(Comparator.comparing(UserExam::getScore)))); - return exams.stream().map(exam -> { - UserExam userExam = examId_userExam_map.get(exam.getId()); - UserExamVO vo; - if (userExam != null) { - vo = new UserExamVO(userExam); - } else { //该用户没有考这门试的记录 - vo = new UserExamVO(); - vo.setUserId(queryVO.getUserId().toString()); - vo.setExamId(exam.getId().toString()); - vo.setExamName(exam.getName()); - vo.setScore(0f); - } - return vo; - }).collect(Collectors.toList()); + BinaryOperator.maxBy(Comparator.comparing(UserExam::getScore)))) + .values(); + return UserExamVO.convert(maxScoreUserExams); } @Override diff --git a/src/main/java/club/joylink/rtss/vo/client/UserExamVO.java b/src/main/java/club/joylink/rtss/vo/client/UserExamVO.java index 967dac883..3a77578cb 100644 --- a/src/main/java/club/joylink/rtss/vo/client/UserExamVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/UserExamVO.java @@ -1,6 +1,5 @@ package club.joylink.rtss.vo.client; -import club.joylink.rtss.entity.SysAccount; import club.joylink.rtss.entity.UserExam; import lombok.Getter; import lombok.NoArgsConstructor; @@ -8,9 +7,8 @@ import lombok.Setter; import org.springframework.util.CollectionUtils; import java.util.ArrayList; -import java.util.HashMap; +import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; /** @@ -83,21 +81,10 @@ public class UserExamVO { this.id = id.toString(); } - public static List convert(List entities, List accounts) { + public static List convert(Collection entities) { if (CollectionUtils.isEmpty(entities)) return new ArrayList<>(); - Map userId_userName_map; - if (CollectionUtils.isEmpty(accounts)) { - userId_userName_map = new HashMap<>(); - } else { - userId_userName_map = accounts.stream() - .collect(Collectors.toMap(SysAccount::getId, SysAccount::getName)); - } - return entities.stream().map(userExam -> { - UserExamVO vo = new UserExamVO(userExam); - vo.setUsername(userId_userName_map.get(userExam.getUserId())); - return vo; - }).collect(Collectors.toList()); + return entities.stream().map(UserExamVO::new).collect(Collectors.toList()); } }