Search in sources :

Example 1 with ProblemDO

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

the class ProblemManageService method update.

@Transactional
public void update(ProblemManageDTO problem, UserSessionDTO userSessionDTO) {
    // 查出该题
    ProblemDO originalProblemDO = problemDao.lambdaQuery().select(ProblemDO::getProblemId, ProblemDO::getVersion, ProblemDO::getUserId).eq(ProblemDO::getProblemCode, problem.getProblemCode()).one();
    // 特判题目权限
    AssertUtils.notNull(originalProblemDO, ApiExceptionEnum.PROBLEM_NOT_FOUND);
    // 特判题目权限
    AssertUtils.isTrue(problemCommonService.isProblemManager(originalProblemDO, userSessionDTO), ApiExceptionEnum.USER_NOT_MATCHING, "只有超级管理员、出题者、权限用户组成员才能改题目详情");
    // 构造更新器
    ProblemDO problemUpdateDO = problemManageConverter.from(problem);
    problemUpdateDO.setProblemId(originalProblemDO.getProblemId());
    problemUpdateDO.setVersion(originalProblemDO.getVersion());
    if (CollectionUtils.isEmpty(problem.getJudgeTemplates())) {
        problemUpdateDO.setJudgeTemplates("");
    }
    // 更新题目
    log.info("{} -> {}", problem, problemUpdateDO);
    AssertUtils.isTrue(problemDao.updateById(problemUpdateDO), ApiExceptionEnum.UNKNOWN_ERROR);
    // 如果传的 caseList 不为 null,则更新 checkpointCase (增量更新和全量更新区别开)
    problem.setProblemId(originalProblemDO.getProblemId());
    if (problem.getCheckpointCases() != null) {
        if (problemUpdateDO.getCheckpointCases() == null) {
            problemDao.lambdaUpdate().set(ProblemDO::getCheckpointCases, null).eq(ProblemDO::getProblemId, originalProblemDO.getProblemId()).update();
        }
        updateCheckpointCase(problem);
    }
}
Also used : ProblemDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDO) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ProblemDO

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

the class ProblemManageService method createProblem.

@Transactional
public String createProblem(ProblemManageDTO problem) {
    problem.setProblemId(null);
    problem.setProblemCode(null);
    ProblemDO problemDO = problemManageConverter.from(problem);
    AssertUtils.isTrue(problemDao.save(problemDO), ApiExceptionEnum.UNKNOWN_ERROR);
    // TODO: 魔法值解决
    problemDO.setProblemCode("SDUOJ-" + problemDO.getProblemId());
    if (!problemDao.lambdaUpdate().eq(ProblemDO::getProblemId, problemDO.getProblemId()).set(ProblemDO::getProblemCode, problemDO.getProblemCode()).update()) {
        throw new ApiException(ApiExceptionEnum.UNKNOWN_ERROR);
    }
    return problemDO.getProblemCode();
}
Also used : ProblemDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDO) ApiException(cn.edu.sdu.qd.oj.common.exception.ApiException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ProblemDO

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

the class ProblemManageService method queryByCode.

public ProblemManageDTO queryByCode(String problemCode, UserSessionDTO userSessionDTO) {
    ProblemDO problemManageDO = problemDao.lambdaQuery().eq(ProblemDO::getProblemCode, problemCode).one();
    AssertUtils.notNull(problemManageDO, ApiExceptionEnum.PROBLEM_NOT_FOUND);
    ProblemManageDTO problemManageDTO = problemManageConverter.to(problemManageDO);
    problemManageDTO.setUsername(userClient.userIdToUsername(problemManageDO.getUserId()));
    AssertUtils.isTrue(problemCommonService.isProblemManager(problemManageDO, userSessionDTO), ApiExceptionEnum.USER_NOT_MATCHING);
    // 查询 judgeTemplate,置入
    List<Long> judgeTemplateIdList = problemManageDTO.getJudgeTemplates();
    problemManageDTO.setJudgeTemplateListDTOList(judgeTemplateService.listByIds(judgeTemplateIdList));
    return problemManageDTO;
}
Also used : ProblemDO(cn.edu.sdu.qd.oj.problem.entity.ProblemDO)

Example 4 with ProblemDO

use of cn.edu.sdu.qd.oj.problem.entity.ProblemDO 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 5 with ProblemDO

use of cn.edu.sdu.qd.oj.problem.entity.ProblemDO 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)

Aggregations

ProblemDO (cn.edu.sdu.qd.oj.problem.entity.ProblemDO)10 ProblemDescriptionDO (cn.edu.sdu.qd.oj.problem.entity.ProblemDescriptionDO)4 Transactional (org.springframework.transaction.annotation.Transactional)3 ApiException (cn.edu.sdu.qd.oj.common.exception.ApiException)2 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 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