教学管理考试查询bug修改

This commit is contained in:
joylink_zhangsai 2021-03-30 18:27:44 +08:00
parent 06f9914f1a
commit ad506486c0
3 changed files with 29 additions and 43 deletions

View File

@ -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);
}

View File

@ -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<UserExamVO> pagedQueryOrgUserExamResult(Long orgId, Long examId, PageQueryVO queryVO) {
List<Long> 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<Long, UserExam> userExamMap = userExamMapper.selectByExample(example).stream()
.collect(Collectors.toMap(UserExam::getUserId, Function.identity()));
Map<Long, SysUser> userMap = iSysUserService.findEntity(userIds, "id")
.stream().collect(Collectors.toMap(SysUser::getId, Function.identity()));
Org topOrg = iOrgService.getTopOrgEntity(orgId, BusinessConsts.Org.Status.VALID);
List<UserExamVO> 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<OrgUser> page = PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
iOrgUserService.findEntitiesByOrgId(orgId, BusinessConsts.OrgRole.Student);
List<Long> 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<UserExam> userExams = userExamMapper.selectByExample(example);
Map<Long, Optional<UserExam>> user_exam_map = userExams.stream().collect(Collectors.groupingBy(UserExam::getUserId, Collectors.maxBy(Comparator.comparingDouble(UserExam::getScore))));
List<SysUser> users = iSysUserService.findEntity(studentIds, "account");
Org topOrg = iOrgService.getTopOrgEntity(orgId, null);
List<UserExamVO> vos = users.stream().map(user -> {
UserExamVO vo;
Optional<UserExam> 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

View File

@ -309,7 +309,7 @@
<resultMap id="queryByExamIdsResultMap" type="club.joylink.rtss.vo.client.ExamDefinitionVO">
<result column="exam_id" property="id"/>
<collection property="clsIds" ofType="Long" javaType="List">
<result column="org_id"/>
<result column="org.id"/>
</collection>
</resultMap>
<select id="queryByExamIds" resultMap="queryByExamIdsResultMap">
@ -318,7 +318,7 @@
FROM
org
JOIN org_exam ON org.id = org_exam.org_id
where org_exam.exam_id in
and org_exam.exam_id in
<foreach collection="examIds" item="examId" open="(" separator="," close=")">
#{examId}
</foreach>