use of cn.edu.sdu.qd.oj.common.entity.PageResult in project sduoj-server by SDUOJ.
the class ContestService method listSubmission.
public PageResult<ContestSubmissionListDTO> listSubmission(ContestSubmissionListReqDTO reqDTO, UserSessionDTO userSessionDTO) {
ContestDO contestDO = queryContestAndValidate(reqDTO.getContestId(), userSessionDTO.getUserId());
// 脱敏, 但超级管理员/出题者/权限用户组成员能查所有的提交
ContestFeatureDTO contestFeatureDTO = ContestConvertUtils.featuresTo(contestDO.getFeatures());
ContestFeatureDTO.InfoOpenness infoOpenness = contestDO.getGmtEnd().after(new Date()) ? contestFeatureDTO.getContestRunning() : contestFeatureDTO.getContestEnd();
if (infoOpenness.getDisplayPeerSubmission() == 0 && !(contestCommonService.isContestManager(contestDO, userSessionDTO))) {
reqDTO.setUsername(userSessionDTO.getUsername());
}
// 构造 problemCode To ProblemIndex Map
List<ContestProblemListDTO> contestProblemListDTOList = ContestConvertUtils.problemsTo(contestDO.getProblems());
List<String> problemCodeList = contestProblemListDTOList.stream().map(ContestProblemListDTO::getProblemCode).collect(Collectors.toList());
Map<String, Integer> problemCodeToProblemIndexMap = new HashMap<>(contestProblemListDTOList.size());
for (int i = 0, n = contestProblemListDTOList.size(); i < n; i++) {
problemCodeToProblemIndexMap.put(contestProblemListDTOList.get(i).getProblemCode(), i + 1);
}
// 指定了 problemIndex 的查询
String problemCode = Optional.ofNullable(reqDTO.getProblemIndex()).map(contestDO::getProblemCodeByIndex).map(ContestProblemListDTO::getProblemCode).orElse(null);
// 构造查询
SubmissionListReqDTO submissionListReqDTO = SubmissionListReqDTO.builder().pageNow(reqDTO.getPageNow()).pageSize(reqDTO.getPageSize()).sortBy(reqDTO.getSortBy()).ascending(reqDTO.getAscending()).judgeResult(reqDTO.getJudgeResult()).judgeTemplateId(reqDTO.getJudgeTemplateId()).problemCode(problemCode).username(reqDTO.getUsername()).problemCodeList(problemCodeList).build();
try {
PageResult<SubmissionListDTO> pageResult = submissionClient.page(reqDTO.getContestId(), submissionListReqDTO);
List<ContestSubmissionListDTO> contestSubmissionListDTOList = pageResult.getRows().stream().map(submissionListDTO -> {
Integer problemIndex = problemCodeToProblemIndexMap.get(submissionListDTO.getProblemCode());
ContestSubmissionListDTO contestSubmissionListDTO = new ContestSubmissionListDTO();
BeanUtils.copyProperties(submissionListDTO, contestSubmissionListDTO);
contestSubmissionListDTO.setProblemCode(String.valueOf(problemIndex));
contestSubmissionListDTO.setProblemTitle(contestProblemListDTOList.get(problemIndex - 1).getProblemTitle());
return contestSubmissionListDTO;
}).collect(Collectors.toList());
// 数据脱敏
if (infoOpenness.getDisplayJudgeScore() == 0) {
contestSubmissionListDTOList.forEach(c -> c.setJudgeScore(null));
}
return new PageResult<>(pageResult.getTotalPage(), contestSubmissionListDTOList);
} catch (Exception e) {
throw new ApiException(ApiExceptionEnum.INTERNAL_ERROR, e.getMessage());
}
}
Aggregations