use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.
the class GroupContestProblemManager method addProblemFromPublic.
public void addProblemFromPublic(ContestProblemDto contestProblemDto) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Long pid = contestProblemDto.getPid();
Problem problem = problemEntityService.getById(pid);
if (problem == null || problem.getAuth() != 1 || problem.getIsGroup()) {
throw new StatusNotFoundException("该题目不存在或已被隐藏!");
}
Long cid = contestProblemDto.getCid();
Contest contest = contestEntityService.getById(cid);
if (contest == null) {
throw new StatusNotFoundException("该比赛不存在!");
}
Long gid = contest.getGid();
Group group = groupEntityService.getById(gid);
if (group == null || group.getStatus() == 1 && !isRoot) {
throw new StatusNotFoundException("该团队不存在或已被封禁!");
}
if (!userRolesVo.getUid().equals(contest.getUid()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
String displayId = contestProblemDto.getDisplayId();
QueryWrapper<ContestProblem> contestProblemQueryWrapper = new QueryWrapper<>();
contestProblemQueryWrapper.eq("cid", cid).and(wrapper -> wrapper.eq("pid", pid).or().eq("display_id", displayId));
ContestProblem contestProblem = contestProblemEntityService.getOne(contestProblemQueryWrapper, false);
if (contestProblem != null) {
throw new StatusFailException("添加失败,该题目已添加或者题目的比赛展示ID已存在!");
}
String displayName = problem.getTitle();
ContestProblem newCProblem = new ContestProblem();
boolean isOk = contestProblemEntityService.saveOrUpdate(newCProblem.setCid(cid).setPid(pid).setDisplayTitle(displayName).setDisplayId(displayId));
if (!isOk) {
throw new StatusFailException("添加失败");
}
}
use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.
the class GroupProblemManager method changeProblemAuth.
public void changeProblemAuth(Long pid, Integer auth) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Problem problem = problemEntityService.getById(pid);
if (problem == null) {
throw new StatusNotFoundException("该题目不存在!");
}
Long gid = problem.getGid();
Group group = groupEntityService.getById(gid);
if (group == null || group.getStatus() == 1 && !isRoot) {
throw new StatusNotFoundException("该团队不存在或已被封禁!");
}
if (!userRolesVo.getUsername().equals(problem.getAuthor()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
UpdateWrapper<Problem> problemUpdateWrapper = new UpdateWrapper<>();
problemUpdateWrapper.eq("id", pid).set("auth", auth).set("modified_user", userRolesVo.getUsername());
boolean isOk = problemEntityService.update(problemUpdateWrapper);
if (!isOk) {
throw new StatusFailException("修改失败");
}
}
use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.
the class GroupProblemManager method getProblem.
public Problem getProblem(Long pid) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Problem problem = problemEntityService.getById(pid);
if (problem == null) {
throw new StatusNotFoundException("该题目不存在!");
}
Long gid = problem.getGid();
Group group = groupEntityService.getById(gid);
if (group == null || group.getStatus() == 1 && !isRoot) {
throw new StatusNotFoundException("该团队不存在或已被封禁!");
}
if (!groupValidator.isGroupRoot(userRolesVo.getUid(), gid) && !userRolesVo.getUsername().equals(problem.getAuthor()) && !isRoot) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
return problem;
}
use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.
the class GroupProblemManager method addProblem.
public void addProblem(ProblemDto problemDto) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Long gid = problemDto.getProblem().getGid();
Group group = groupEntityService.getById(gid);
if (group == null || group.getStatus() == 1 && !isRoot) {
throw new StatusNotFoundException("该团队不存在或已被封禁!");
}
if (!isRoot && !groupValidator.isGroupAdmin(userRolesVo.getUid(), gid)) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
problemDto.getProblem().setProblemId(group.getShortName() + problemDto.getProblem().getProblemId());
QueryWrapper<Problem> problemQueryWrapper = new QueryWrapper<>();
problemQueryWrapper.eq("problem_id", problemDto.getProblem().getProblemId().toUpperCase());
int sameProblemIDCount = problemEntityService.count(problemQueryWrapper);
if (sameProblemIDCount > 0) {
throw new StatusFailException("该题目的Problem ID已存在,请更换!");
}
problemDto.getProblem().setIsGroup(true);
List<Tag> tagList = new LinkedList<>();
for (Tag tag : problemDto.getTags()) {
if (tag.getGid() != null && tag.getGid().longValue() != gid) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
if (tag.getId() == null) {
tag.setGid(gid);
}
tagList.add(tag);
}
problemDto.setTags(tagList);
boolean isOk = problemEntityService.adminAddProblem(problemDto);
if (!isOk) {
throw new StatusFailException("添加失败");
}
}
use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.
the class GroupProblemManager method getProblemCases.
public List<ProblemCase> getProblemCases(Long pid, Boolean isUpload) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Problem problem = problemEntityService.getById(pid);
if (problem == null) {
throw new StatusNotFoundException("该题目不存在!");
}
Long gid = problem.getGid();
Group group = groupEntityService.getById(gid);
if (group == null || group.getStatus() == 1 && !isRoot) {
throw new StatusNotFoundException("该团队不存在或已被封禁!");
}
if (!userRolesVo.getUsername().equals(problem.getAuthor()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
QueryWrapper<ProblemCase> problemCaseQueryWrapper = new QueryWrapper<>();
problemCaseQueryWrapper.eq("pid", pid).eq("status", 0);
if (isUpload) {
problemCaseQueryWrapper.last("order by length(input) asc,input asc");
}
return problemCaseEntityService.list(problemCaseQueryWrapper);
}
Aggregations