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, "或 修改他人题面出错");
}
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();
}
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);
}
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;
}
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;
}
Aggregations