Search in sources :

Example 1 with ProblemDescriptionDO

use of cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO in project sduoj-server by SDUOJ.

the class ProblemManageService method updateDescription.

public void updateDescription(ProblemDescriptionDTO problemDescriptionDTO, UserSessionDTO userSessionDTO) {
    ProblemDescriptionDO descriptionDO = problemDescriptionDao.lambdaQuery().select(ProblemDescriptionDO::getProblemId, ProblemDescriptionDO::getUserId, ProblemDescriptionDO::getVersion).eq(ProblemDescriptionDO::getId, problemDescriptionDTO.getId()).one();
    AssertUtils.notNull(descriptionDO, ApiExceptionEnum.DESCRIPTION_NOT_FOUND);
    // 鉴权
    AssertUtils.isTrue(problemCommonService.isProblemManager(descriptionDO.getProblemId(), userSessionDTO) || userSessionDTO.userIdEquals(descriptionDO.getUserId()), ApiExceptionEnum.USER_NOT_MATCHING);
    // 更新
    ProblemDescriptionDO update = problemDescriptionConverter.from(problemDescriptionDTO);
    update.setVersion(descriptionDO.getVersion());
    AssertUtils.isTrue(problemDescriptionDao.updateById(update), ApiExceptionEnum.UNKNOWN_ERROR, "或 修改他人题面出错");
}
Also used : ProblemDescriptionDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO)

Example 2 with ProblemDescriptionDO

use of cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO in project sduoj-server by SDUOJ.

the class ProblemManageService method createDescription.

public long createDescription(ProblemDescriptionDTO problemDescriptionDTO) {
    problemDescriptionDTO.setProblemId(problemService.problemCodeToProblemId(problemDescriptionDTO.getProblemCode()));
    ProblemDescriptionDO problemDescriptionDO = problemDescriptionConverter.from(problemDescriptionDTO);
    AssertUtils.isTrue(problemDescriptionDao.save(problemDescriptionDO), ApiExceptionEnum.UNKNOWN_ERROR);
    return problemDescriptionDO.getId();
}
Also used : ProblemDescriptionDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO)

Example 3 with ProblemDescriptionDO

use of cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO in project sduoj-server by SDUOJ.

the class ProblemManageService method queryDescription.

public ProblemDescriptionDTO queryDescription(long id, UserSessionDTO userSessionDTO) {
    ProblemDescriptionDO descriptionDO = problemDescriptionDao.lambdaQuery().eq(ProblemDescriptionDO::getId, id).one();
    AssertUtils.notNull(descriptionDO, ApiExceptionEnum.DESCRIPTION_NOT_FOUND);
    ProblemDO problemDO = problemDao.lambdaQuery().select(ProblemDO::getProblemId, ProblemDO::getDefaultDescriptionId, ProblemDO::getUserId).eq(ProblemDO::getProblemId, descriptionDO.getProblemId()).one();
    AssertUtils.notNull(problemDO, ApiExceptionEnum.PROBLEM_NOT_FOUND);
    if (!problemCommonService.isProblemManager(descriptionDO.getProblemId(), userSessionDTO)) {
        Long defaultDescriptionId = problemDO.getDefaultDescriptionId();
        AssertUtils.isTrue(Objects.equals(defaultDescriptionId, descriptionDO.getId()) || descriptionDO.getIsPublic() == 1 || userSessionDTO.userIdEquals(descriptionDO.getUserId()), ApiExceptionEnum.PROBLEM_NOT_FOUND, "非public非default非自己所属的题面无法查看");
    }
    return problemDescriptionConverter.to(descriptionDO);
}
Also used : ProblemDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDO) ProblemDescriptionDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO)

Example 4 with ProblemDescriptionDO

use of cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO in project sduoj-server by SDUOJ.

the class ProblemManageService method queryDescriptionList.

public List<ProblemDescriptionListDTO> queryDescriptionList(String problemCode, UserSessionDTO userSessionDTO) {
    ProblemDO problemDO = problemDao.lambdaQuery().select(ProblemDO::getProblemId, ProblemDO::getDefaultDescriptionId, ProblemDO::getUserId).eq(ProblemDO::getProblemCode, problemCode).one();
    AssertUtils.notNull(problemDO, ApiExceptionEnum.PROBLEM_NOT_FOUND);
    Long defaultDescriptionId = problemDO.getDefaultDescriptionId();
    LambdaQueryChainWrapper<ProblemDescriptionDO> query = problemDescriptionDao.lambdaQuery().select(ProblemDescriptionDO::getId, ProblemDescriptionDO::getIsPublic, ProblemDescriptionDO::getProblemId, ProblemDescriptionDO::getVoteNum, ProblemDescriptionDO::getUserId, ProblemDescriptionDO::getTitle);
    // 题目管理员能看到所有,admin 只能看到公开/默认/自己的题面
    if (!problemCommonService.isProblemManager(problemDO, userSessionDTO)) {
        Long userId = Optional.ofNullable(userSessionDTO).map(UserSessionDTO::getUserId).orElse(null);
        query.and(o1 -> o1.eq(ProblemDescriptionDO::getIsPublic, 1).or(o2 -> o2.eq(ProblemDescriptionDO::getIsPublic, 0).eq(ProblemDescriptionDO::getUserId, userId)).or(o3 -> o3.eq(ProblemDescriptionDO::getId, defaultDescriptionId)));
    }
    List<ProblemDescriptionDO> problemDescriptionDOList = query.eq(ProblemDescriptionDO::getProblemId, problemDO.getProblemId()).list();
    List<ProblemDescriptionListDTO> problemDescriptionDTOList = problemDescriptionListConverter.to(problemDescriptionDOList);
    problemDescriptionDTOList.forEach(o -> {
        o.setProblemCode(problemCode);
        o.setUsername(userClient.userIdToUsername(o.getUserId()));
    });
    return problemDescriptionDTOList;
}
Also used : ProblemDescriptionDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO) LambdaQueryChainWrapper(com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper) java.util(java.util) LambdaUpdateChainWrapper(com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper) Autowired(org.springframework.beans.factory.annotation.Autowired) PermissionEnum(cn.edu.sdu.qd.oj.auth.enums.PermissionEnum) ApiExceptionEnum(cn.edu.sdu.qd.oj.common.enums.ApiExceptionEnum) PageResult(cn.edu.sdu.qd.oj.common.entity.PageResult) JudgeTemplateListDTO(cn.edu.sdu.qd.oj.judgetemplate.dto.JudgeTemplateListDTO) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) cn.edu.sdu.qd.oj.common.util(cn.edu.sdu.qd.oj.common.util) Service(org.springframework.stereotype.Service) cn.edu.sdu.qd.oj.problem.dto(cn.edu.sdu.qd.oj.problem.dto) CheckpointManageService(cn.edu.sdu.qd.oj.checkpoint.service.CheckpointManageService) JudgeTemplateService(cn.edu.sdu.qd.oj.judgetemplate.service.JudgeTemplateService) ProblemDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDO) ProblemManageListDO(cn.edu.sdu.qd.oj.problem.entity.ProblemManageListDO) ProblemDescriptionDao(cn.edu.sdu.qd.oj.problem.dao.ProblemDescriptionDao) Collectors(java.util.stream.Collectors) UserClient(cn.edu.sdu.qd.oj.problem.client.UserClient) UserSessionDTO(cn.edu.sdu.qd.oj.common.entity.UserSessionDTO) ProblemDao(cn.edu.sdu.qd.oj.problem.dao.ProblemDao) ProblemManageListDao(cn.edu.sdu.qd.oj.problem.dao.ProblemManageListDao) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) Slf4j(lombok.extern.slf4j.Slf4j) ApiException(cn.edu.sdu.qd.oj.common.exception.ApiException) cn.edu.sdu.qd.oj.problem.converter(cn.edu.sdu.qd.oj.problem.converter) Lists(org.assertj.core.util.Lists) TagDTO(cn.edu.sdu.qd.oj.tag.dto.TagDTO) CheckpointDTO(cn.edu.sdu.qd.oj.checkpoint.dto.CheckpointDTO) Transactional(org.springframework.transaction.annotation.Transactional) ProblemDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDO) ProblemDescriptionDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO)

Example 5 with ProblemDescriptionDO

use of cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO in project sduoj-server by SDUOJ.

the class ProblemService method queryByCode.

public ProblemDTO queryByCode(String problemCode, Long descriptionId, UserSessionDTO userSessionDTO) {
    // TODO: cache, polish
    Long userId = Optional.ofNullable(userSessionDTO).map(UserSessionDTO::getUserId).orElse(null);
    ProblemDO problemDO = problemDao.lambdaQuery().select(ProblemDO.class, field -> !field.getColumn().equals(ProblemDOField.CHECKPOINTS)).eq(ProblemDO::getProblemCode, problemCode).one();
    AssertUtils.notNull(problemDO, ApiExceptionEnum.PROBLEM_NOT_FOUND);
    // 非公开题只能出题者和超管查询
    AssertUtils.isTrue(problemDO.getIsPublic() == 1 || problemDO.getUserId().equals(userId) || PermissionEnum.SUPERADMIN.in(userSessionDTO), ApiExceptionEnum.USER_NOT_MATCHING);
    // 查询题目描述
    ProblemDescriptionDO problemDescriptionDO = problemDescriptionDao.lambdaQuery().eq(ProblemDescriptionDO::getProblemId, problemDO.getProblemId()).eq(ProblemDescriptionDO::getId, descriptionId != null ? descriptionId : problemDO.getDefaultDescriptionId()).one();
    // 若非 superadmin 则进行过滤,过滤掉非公开且非默认且非自己的题面
    if (problemDescriptionDO != null && problemDescriptionDO.getIsPublic() == 0 && !problemDescriptionDO.getId().equals(problemDO.getDefaultDescriptionId()) && !problemDescriptionDO.getUserId().equals(userId) && PermissionEnum.SUPERADMIN.notIn(userSessionDTO)) {
        problemDescriptionDO = null;
    }
    // 查询所有公开的题面 list
    LambdaQueryChainWrapper<ProblemDescriptionDO> descriptionListQuery = problemDescriptionDao.lambdaQuery().select(ProblemDescriptionDO::getIsPublic, ProblemDescriptionDO::getId, ProblemDescriptionDO::getProblemId, ProblemDescriptionDO::getUserId, ProblemDescriptionDO::getVoteNum, ProblemDescriptionDO::getTitle).eq(ProblemDescriptionDO::getProblemId, problemDO.getProblemId());
    // 查询,若非 superadmin 则进行过滤,过滤掉非公开非自己非默认的题面,并按照 descriptionId 排序
    List<ProblemDescriptionDO> problemDescriptionDOList = descriptionListQuery.list();
    problemDescriptionDOList.sort(ProblemDescriptionDO::compareById);
    if (PermissionEnum.SUPERADMIN.notIn(userSessionDTO)) {
        problemDescriptionDOList = problemDescriptionDOList.stream().filter(o -> o.getIsPublic() == 1 || (o.getIsPublic() == 0 && o.getUserId().equals(userId)) || o.getId().equals(problemDO.getDefaultDescriptionId())).collect(Collectors.toList());
    }
    // 查询 problemCase
    List<ProblemCaseDTO> problemCaseDTOList = problemExtensionSerivce.queryProblemCase(problemDO.getProblemId());
    ProblemDTO problemDTO = problemConverter.to(problemDO, problemDescriptionDO, problemDescriptionDOList, problemCaseDTOList);
    // TODO: 考虑设计一个 annotation 和 cacheUtil 关联起来,自动填充一些业务字段
    try {
        problemDTO.getProblemDescriptionDTO().setProblemCode(problemCode);
        problemDTO.getProblemDescriptionListDTOList().forEach(o -> {
            o.setProblemCode(problemCode);
            o.setUsername(userClient.userIdToUsername(o.getUserId()));
        });
    } catch (Exception ignore) {
    }
    // 置 tagDTO
    List<Long> tags = getTagIdListFromFeatureMap(problemDTO.getFeatures());
    if (!CollectionUtils.isEmpty(tags)) {
        List<TagDO> tagDOList = tagDao.lambdaQuery().in(TagDO::getId, tags).list();
        problemDTO.setTagDTOList(tagConverter.to(tagDOList));
    }
    return problemDTO;
}
Also used : ProblemCaseDTO(cn.edu.sdu.qd.oj.problem.dto.ProblemCaseDTO) ProblemDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDO) TagDO(cn.edu.sdu.qd.oj.tag.entity.TagDO) ProblemDescriptionDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO) ProblemDTO(cn.edu.sdu.qd.oj.problem.dto.ProblemDTO)

Aggregations

ProblemDescriptionDO (cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO)6 ProblemDO (cn.edu.sdu.qd.oj.problem.entity.ProblemDO)4 ProblemCaseDTO (cn.edu.sdu.qd.oj.problem.dto.ProblemCaseDTO)2 PermissionEnum (cn.edu.sdu.qd.oj.auth.enums.PermissionEnum)1 CheckpointDTO (cn.edu.sdu.qd.oj.checkpoint.dto.CheckpointDTO)1 CheckpointManageService (cn.edu.sdu.qd.oj.checkpoint.service.CheckpointManageService)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 cn.edu.sdu.qd.oj.common.util (cn.edu.sdu.qd.oj.common.util)1 JudgeTemplateListDTO (cn.edu.sdu.qd.oj.judgetemplate.dto.JudgeTemplateListDTO)1 JudgeTemplateService (cn.edu.sdu.qd.oj.judgetemplate.service.JudgeTemplateService)1 UserClient (cn.edu.sdu.qd.oj.problem.client.UserClient)1 cn.edu.sdu.qd.oj.problem.converter (cn.edu.sdu.qd.oj.problem.converter)1 ProblemDao (cn.edu.sdu.qd.oj.problem.dao.ProblemDao)1 ProblemDescriptionDao (cn.edu.sdu.qd.oj.problem.dao.ProblemDescriptionDao)1 ProblemManageListDao (cn.edu.sdu.qd.oj.problem.dao.ProblemManageListDao)1 cn.edu.sdu.qd.oj.problem.dto (cn.edu.sdu.qd.oj.problem.dto)1 ProblemDTO (cn.edu.sdu.qd.oj.problem.dto.ProblemDTO)1