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);
}
}
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();
}
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;
}
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);
}
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;
}
Aggregations