use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.
the class AdminContestController method addProblemFromPublic.
@PostMapping("/add-problem-from-public")
@RequiresAuthentication
@RequiresRoles(value = { "root", "admin", "problem_admin" }, logical = Logical.OR)
public CommonResult addProblemFromPublic(@RequestBody HashMap<String, String> params) {
String pidStr = params.get("pid");
String cidStr = params.get("cid");
String displayId = params.get("displayId");
if (StringUtils.isEmpty(pidStr) || StringUtils.isEmpty(cidStr) || StringUtils.isEmpty(displayId)) {
return CommonResult.errorResponse("参数错误!", CommonResult.STATUS_FAIL);
}
Long pid = Long.valueOf(pidStr);
Long cid = Long.valueOf(cidStr);
QueryWrapper<ContestProblem> contestProblemQueryWrapper = new QueryWrapper<>();
contestProblemQueryWrapper.eq("cid", cid).and(wrapper -> wrapper.eq("pid", pid).or().eq("display_id", displayId));
ContestProblem contestProblem = contestProblemService.getOne(contestProblemQueryWrapper, false);
if (contestProblem != null) {
return CommonResult.errorResponse("添加失败,该题目已添加或者题目的比赛展示ID已存在!", CommonResult.STATUS_FAIL);
}
// 比赛中题目显示默认为原标题
Problem problem = problemService.getById(pid);
String displayName = problem.getTitle();
// 修改成比赛题目
boolean updateProblem = problemService.saveOrUpdate(problem.setAuth(3));
boolean result = contestProblemService.saveOrUpdate(new ContestProblem().setCid(cid).setPid(pid).setDisplayTitle(displayName).setDisplayId(displayId));
if (result && updateProblem) {
// 添加成功
return CommonResult.successResponse(null, "添加成功!");
} else {
return CommonResult.errorResponse("添加失败", CommonResult.STATUS_FAIL);
}
}
use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.
the class AdminContestController method getProblem.
@GetMapping("/problem")
@RequiresAuthentication
@RequiresRoles(value = { "root", "admin", "problem_admin" }, logical = Logical.OR)
public CommonResult getProblem(@Valid @RequestParam("pid") Long pid, HttpServletRequest request) {
Problem problem = problemService.getById(pid);
if (problem != null) {
// 查询成功
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
boolean isProblemAdmin = SecurityUtils.getSubject().hasRole("problem_admin");
// 只有超级管理员和题目管理员、题目创建者才能操作
if (!isRoot && !isProblemAdmin && !userRolesVo.getUsername().equals(problem.getAuthor())) {
return CommonResult.errorResponse("对不起,你无权限查看题目!", CommonResult.STATUS_FORBIDDEN);
}
return CommonResult.successResponse(problem, "查询成功!");
} else {
return CommonResult.errorResponse("查询失败!", CommonResult.STATUS_FAIL);
}
}
use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.
the class AdminProblemController method changeProblemAuth.
@PutMapping("/change-problem-auth")
@RequiresAuthentication
@RequiresRoles(value = { "root", "problem_admin", "admin" }, logical = Logical.OR)
public CommonResult changeProblemAuth(@RequestBody Problem problem, HttpServletRequest request) {
// 普通管理员只能将题目变成隐藏题目和比赛题目
boolean root = SecurityUtils.getSubject().hasRole("root");
boolean problemAdmin = SecurityUtils.getSubject().hasRole("problem_admin");
if (!problemAdmin && !root && problem.getAuth() == 1) {
return CommonResult.errorResponse("修改失败!你无权限公开题目!", CommonResult.STATUS_FORBIDDEN);
}
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
UpdateWrapper<Problem> problemUpdateWrapper = new UpdateWrapper<>();
problemUpdateWrapper.eq("id", problem.getId()).set("auth", problem.getAuth()).set("modified_user", userRolesVo.getUsername());
boolean result = problemService.update(problemUpdateWrapper);
if (result) {
// 更新成功
return CommonResult.successResponse(null, "修改成功!");
} else {
return CommonResult.errorResponse("修改失败", CommonResult.STATUS_FAIL);
}
}
use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.
the class AdminProblemController method addProblem.
@PostMapping("")
@RequiresAuthentication
@RequiresRoles(value = { "root", "admin", "problem_admin" }, logical = Logical.OR)
public CommonResult addProblem(@RequestBody ProblemDto problemDto, HttpServletRequest request) {
QueryWrapper<Problem> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("problem_id", problemDto.getProblem().getProblemId().toUpperCase());
Problem problem = problemService.getOne(queryWrapper);
if (problem != null) {
return CommonResult.errorResponse("该题目的Problem ID已存在,请更换!", CommonResult.STATUS_FAIL);
}
boolean result = problemService.adminAddProblem(problemDto);
if (result) {
// 添加成功
return CommonResult.successResponse(null, "添加成功!");
} else {
return CommonResult.errorResponse("添加失败", CommonResult.STATUS_FAIL);
}
}
use of top.hcode.hoj.pojo.entity.problem.Problem in project HOJ by HimitZH.
the class JudgeServiceImpl method judge.
@Override
public void judge(Judge judge) {
// 标志该判题过程进入编译阶段
judge.setStatus(Constants.Judge.STATUS_COMPILING.getStatus());
// 写入当前判题服务的名字
judge.setJudger(name);
judgeEntityService.updateById(judge);
// 进行判题操作
Problem problem = problemEntityService.getById(judge.getPid());
Judge finalJudge = judgeContext.Judge(problem, judge);
// 更新该次提交
judgeEntityService.updateById(finalJudge);
if (finalJudge.getStatus().intValue() != Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus()) {
// 更新其它表
judgeContext.updateOtherTable(finalJudge.getSubmitId(), finalJudge.getStatus(), finalJudge.getCid(), finalJudge.getUid(), finalJudge.getPid(), finalJudge.getGid(), finalJudge.getScore(), finalJudge.getTime());
}
}
Aggregations