Search in sources :

Example 1 with PageResult

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());
    }
}
Also used : LambdaQueryChainWrapper(com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper) java.util(java.util) ProblemListDTO(cn.edu.sdu.qd.oj.problem.dto.ProblemListDTO) Cacheable(org.springframework.cache.annotation.Cacheable) Autowired(org.springframework.beans.factory.annotation.Autowired) PermissionEnum(cn.edu.sdu.qd.oj.auth.enums.PermissionEnum) ContestDO(cn.edu.sdu.qd.oj.contest.entity.ContestDO) CacheEvict(org.springframework.cache.annotation.CacheEvict) ApiExceptionEnum(cn.edu.sdu.qd.oj.common.enums.ApiExceptionEnum) PageResult(cn.edu.sdu.qd.oj.common.entity.PageResult) ContestModeEnum(cn.edu.sdu.qd.oj.contest.enums.ContestModeEnum) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) SubmissionClient(cn.edu.sdu.qd.oj.contest.client.SubmissionClient) RedisUtils(cn.edu.sdu.qd.oj.common.util.RedisUtils) SubmissionJudgeResult(cn.edu.sdu.qd.oj.submit.enums.SubmissionJudgeResult) ContestOpennessEnum(cn.edu.sdu.qd.oj.contest.enums.ContestOpennessEnum) ContestCacheTypeManager(cn.edu.sdu.qd.oj.contest.cache.ContestCacheTypeManager) ContestConvertUtils(cn.edu.sdu.qd.oj.contest.converter.ContestConvertUtils) Service(org.springframework.stereotype.Service) ProblemClient(cn.edu.sdu.qd.oj.contest.client.ProblemClient) InternalApiException(cn.edu.sdu.qd.oj.common.exception.InternalApiException) RedisConstants(cn.edu.sdu.qd.oj.common.util.RedisConstants) AssertUtils(cn.edu.sdu.qd.oj.common.util.AssertUtils) cn.edu.sdu.qd.oj.contest.dto(cn.edu.sdu.qd.oj.contest.dto) ProblemDTO(cn.edu.sdu.qd.oj.problem.dto.ProblemDTO) ProblemDescriptionDTO(cn.edu.sdu.qd.oj.problem.dto.ProblemDescriptionDTO) cn.edu.sdu.qd.oj.submit.dto(cn.edu.sdu.qd.oj.submit.dto) ContestDao(cn.edu.sdu.qd.oj.contest.dao.ContestDao) NotNull(javax.validation.constraints.NotNull) ContestListDao(cn.edu.sdu.qd.oj.contest.dao.ContestListDao) Collectors(java.util.stream.Collectors) UserSessionDTO(cn.edu.sdu.qd.oj.common.entity.UserSessionDTO) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) SubmissionListReqDTO(cn.edu.sdu.qd.oj.submit.dto.SubmissionListReqDTO) Slf4j(lombok.extern.slf4j.Slf4j) ApiException(cn.edu.sdu.qd.oj.common.exception.ApiException) ContestListDO(cn.edu.sdu.qd.oj.contest.entity.ContestListDO) UserClient(cn.edu.sdu.qd.oj.contest.client.UserClient) Lists(org.assertj.core.util.Lists) SubmissionDTO(cn.edu.sdu.qd.oj.submit.dto.SubmissionDTO) SubmissionListDTO(cn.edu.sdu.qd.oj.submit.dto.SubmissionListDTO) SubmissionCreateReqDTO(cn.edu.sdu.qd.oj.submit.dto.SubmissionCreateReqDTO) ContestListConverter(cn.edu.sdu.qd.oj.contest.converter.ContestListConverter) ContestConverter(cn.edu.sdu.qd.oj.contest.converter.ContestConverter) BeanUtils(org.springframework.beans.BeanUtils) Transactional(org.springframework.transaction.annotation.Transactional) PageResult(cn.edu.sdu.qd.oj.common.entity.PageResult) InternalApiException(cn.edu.sdu.qd.oj.common.exception.InternalApiException) ApiException(cn.edu.sdu.qd.oj.common.exception.ApiException) ContestDO(cn.edu.sdu.qd.oj.contest.entity.ContestDO) SubmissionListReqDTO(cn.edu.sdu.qd.oj.submit.dto.SubmissionListReqDTO) SubmissionListDTO(cn.edu.sdu.qd.oj.submit.dto.SubmissionListDTO) InternalApiException(cn.edu.sdu.qd.oj.common.exception.InternalApiException) ApiException(cn.edu.sdu.qd.oj.common.exception.ApiException)

Aggregations

PermissionEnum (cn.edu.sdu.qd.oj.auth.enums.PermissionEnum)1 PageResult (cn.edu.sdu.qd.oj.common.entity.PageResult)1 UserSessionDTO (cn.edu.sdu.qd.oj.common.entity.UserSessionDTO)1 ApiExceptionEnum (cn.edu.sdu.qd.oj.common.enums.ApiExceptionEnum)1 ApiException (cn.edu.sdu.qd.oj.common.exception.ApiException)1 InternalApiException (cn.edu.sdu.qd.oj.common.exception.InternalApiException)1 AssertUtils (cn.edu.sdu.qd.oj.common.util.AssertUtils)1 RedisConstants (cn.edu.sdu.qd.oj.common.util.RedisConstants)1 RedisUtils (cn.edu.sdu.qd.oj.common.util.RedisUtils)1 ContestCacheTypeManager (cn.edu.sdu.qd.oj.contest.cache.ContestCacheTypeManager)1 ProblemClient (cn.edu.sdu.qd.oj.contest.client.ProblemClient)1 SubmissionClient (cn.edu.sdu.qd.oj.contest.client.SubmissionClient)1 UserClient (cn.edu.sdu.qd.oj.contest.client.UserClient)1 ContestConvertUtils (cn.edu.sdu.qd.oj.contest.converter.ContestConvertUtils)1 ContestConverter (cn.edu.sdu.qd.oj.contest.converter.ContestConverter)1 ContestListConverter (cn.edu.sdu.qd.oj.contest.converter.ContestListConverter)1 ContestDao (cn.edu.sdu.qd.oj.contest.dao.ContestDao)1 ContestListDao (cn.edu.sdu.qd.oj.contest.dao.ContestListDao)1 cn.edu.sdu.qd.oj.contest.dto (cn.edu.sdu.qd.oj.contest.dto)1 ContestDO (cn.edu.sdu.qd.oj.contest.entity.ContestDO)1