diff --git a/src/main/java/club/joylink/rtss/services/ExamService.java b/src/main/java/club/joylink/rtss/services/ExamService.java index cbd2b3f9c..7b32994e4 100644 --- a/src/main/java/club/joylink/rtss/services/ExamService.java +++ b/src/main/java/club/joylink/rtss/services/ExamService.java @@ -444,8 +444,7 @@ public class ExamService implements IExamService { ExamDefinitionVO vo = new ExamDefinitionVO(exam, creatorMap.get(exam.getCreatorId())); vo.setClsIds(examId_orgId_map.get(exam.getId())); return vo; - }) - .collect(Collectors.toList()); + }).collect(Collectors.toList()); return PageVO.convert(page, vos); } diff --git a/src/main/java/club/joylink/rtss/services/UserExamService.java b/src/main/java/club/joylink/rtss/services/UserExamService.java index aa61eeb0e..930181bdf 100644 --- a/src/main/java/club/joylink/rtss/services/UserExamService.java +++ b/src/main/java/club/joylink/rtss/services/UserExamService.java @@ -25,6 +25,7 @@ import java.time.LocalDateTime; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; +import java.util.stream.Stream; @Service @Slf4j @@ -249,8 +250,6 @@ public class UserExamService implements IUserExamService { /** * 删除用户考试 - * - * @param userExam */ @Transactional public void deleteUserExam(UserExam userExam) { @@ -303,44 +302,32 @@ public class UserExamService implements IUserExamService { @Override public PageVO pagedQueryOrgUserExamResult(Long orgId, Long examId, PageQueryVO queryVO) { - List userIds = iOrgUserService.findEntitiesByOrgId(orgId, BusinessConsts.OrgRole.Student) - .stream().map(OrgUser::getUserId).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(userIds)) { - return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), 0, new ArrayList<>()); - } else { - int total = userIds.size(); - userIds = userIds.stream().sorted(Long::compareTo).collect(Collectors.toList()); - if (queryVO.getOffset() >= userIds.size()) { - return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), total, new ArrayList<>()); - } else { - userIds = userIds.subList(queryVO.getOffset(), Math.min(userIds.size(), queryVO.getOffset() + queryVO.getPageSize())); - UserExamExample example = new UserExamExample(); - example.createCriteria() - .andUserIdIn(userIds) - .andExamIdEqualTo(examId); - Map userExamMap = userExamMapper.selectByExample(example).stream() - .collect(Collectors.toMap(UserExam::getUserId, Function.identity())); - - Map userMap = iSysUserService.findEntity(userIds, "id") - .stream().collect(Collectors.toMap(SysUser::getId, Function.identity())); - Org topOrg = iOrgService.getTopOrgEntity(orgId, BusinessConsts.Org.Status.VALID); - List vos = userIds.stream().map(userId -> { - UserExam userExam = userExamMap.get(userId); - UserExamVO vo; - if (userExam != null) { - vo = UserExamVO.buildOrgUserExam(userExam); - } else { - vo = new UserExamVO(); - vo.setUserId(userId.toString()); - } - SysUser sysUser = userMap.get(userId); - vo.setUsername(sysUser.getName()); - vo.setAccount(sysUser.getAccount().substring(0, sysUser.getAccount().indexOf(topOrg.getCode()))); - return vo; - }).collect(Collectors.toList()); - return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), total, vos); - } + Page page = PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); + iOrgUserService.findEntitiesByOrgId(orgId, BusinessConsts.OrgRole.Student); + List studentIds = page.stream().map(OrgUser::getUserId).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(studentIds)) { + return new PageVO<>(queryVO.getPageNum(), queryVO.getPageNum(), 0, new ArrayList<>()); } + UserExamExample example = new UserExamExample(); + example.createCriteria().andUserIdIn(studentIds).andExamIdEqualTo(examId); + List userExams = userExamMapper.selectByExample(example); + Map> user_exam_map = userExams.stream().collect(Collectors.groupingBy(UserExam::getUserId, Collectors.maxBy(Comparator.comparingDouble(UserExam::getScore)))); + List users = iSysUserService.findEntity(studentIds, "account"); + Org topOrg = iOrgService.getTopOrgEntity(orgId, null); + List vos = users.stream().map(user -> { + UserExamVO vo; + Optional userExamOptional = user_exam_map.get(user.getId()); + if (userExamOptional != null) { + vo = userExamOptional.map(UserExamVO::new).orElseGet(UserExamVO::new); + } else { + vo = new UserExamVO(); + } + vo.setUserId(user.getId().toString()); + vo.setAccount(user.getAccount().substring(0, user.getAccount().indexOf(topOrg.getCode()))); + vo.setUsername(user.getName()); + return vo; + }).collect(Collectors.toList()); + return PageVO.convert(page, vos); } @Override diff --git a/src/main/resources/mybatis/mapper/OrgDAO.xml b/src/main/resources/mybatis/mapper/OrgDAO.xml index 159c6d437..123478c87 100644 --- a/src/main/resources/mybatis/mapper/OrgDAO.xml +++ b/src/main/resources/mybatis/mapper/OrgDAO.xml @@ -309,7 +309,7 @@ - +