Search in sources :

Example 6 with Judge

use of top.hcode.hoj.pojo.entity.judge.Judge in project HOJ by HimitZH.

the class JudgeController method checkContestJudgeResult.

/**
 * @MethodName checkContestJudgeResult
 * @Params * @param submitIdListDto
 * @Description 需要检查是否为封榜,是否可以查询结果,避免有人恶意查询
 * @Return
 * @Since 2021/6/11
 */
@RequestMapping(value = "/check-contest-submissions-status", method = RequestMethod.POST)
@RequiresAuthentication
public CommonResult checkContestJudgeResult(@RequestBody SubmitIdListDto submitIdListDto, HttpServletRequest request) {
    if (submitIdListDto.getCid() == null) {
        return CommonResult.errorResponse("查询比赛ID不能为空");
    }
    if (CollectionUtils.isEmpty(submitIdListDto.getSubmitIds())) {
        return CommonResult.successResponse(new HashMap<>(), "查询的提交id列表为空!");
    }
    HttpSession session = request.getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    // 是否为超级管理员
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Contest contest = contestService.getById(submitIdListDto.getCid());
    boolean isContestAdmin = isRoot || userRolesVo.getUid().equals(contest.getUid());
    // 如果是封榜时间且不是比赛管理员和超级管理员
    boolean isSealRank = contestService.isSealRank(userRolesVo.getUid(), contest, true, isRoot);
    QueryWrapper<Judge> queryWrapper = new QueryWrapper<>();
    // lambada表达式过滤掉code
    queryWrapper.select(Judge.class, info -> !info.getColumn().equals("code")).in("submit_id", submitIdListDto.getSubmitIds()).eq("cid", submitIdListDto.getCid()).between(isSealRank, "submit_time", contest.getStartTime(), contest.getSealRankTime());
    List<Judge> judgeList = judgeService.list(queryWrapper);
    HashMap<Long, Object> result = new HashMap<>();
    for (Judge judge : judgeList) {
        judge.setCode(null);
        judge.setDisplayPid(null);
        judge.setErrorMessage(null);
        judge.setVjudgeUsername(null);
        judge.setVjudgeSubmitId(null);
        judge.setVjudgePassword(null);
        if (!judge.getUid().equals(userRolesVo.getUid()) && !isContestAdmin) {
            judge.setTime(null);
            judge.setMemory(null);
            judge.setLength(null);
        }
        result.put(judge.getSubmitId(), judge);
    }
    return CommonResult.successResponse(result, "获取最新判题数据成功!");
}
Also used : java.util(java.util) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) Problem(top.hcode.hoj.pojo.entity.problem.Problem) TrainingRecordServiceImpl(top.hcode.hoj.service.training.impl.TrainingRecordServiceImpl) ContestRecord(top.hcode.hoj.pojo.entity.contest.ContestRecord) JudgeVo(top.hcode.hoj.pojo.vo.JudgeVo) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) RemoteJudgeDispatcher(top.hcode.hoj.judge.remote.RemoteJudgeDispatcher) Autowired(org.springframework.beans.factory.annotation.Autowired) RedisUtils(top.hcode.hoj.utils.RedisUtils) CommonResult(top.hcode.hoj.common.result.CommonResult) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Value(org.springframework.beans.factory.annotation.Value) Judge(top.hcode.hoj.pojo.entity.judge.Judge) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) HttpServletRequest(javax.servlet.http.HttpServletRequest) ProblemService(top.hcode.hoj.service.problem.ProblemService) JudgeCaseServiceImpl(top.hcode.hoj.service.judge.impl.JudgeCaseServiceImpl) ContestRecordServiceImpl(top.hcode.hoj.service.contest.impl.ContestRecordServiceImpl) JudgeServiceImpl(top.hcode.hoj.service.judge.impl.JudgeServiceImpl) JudgeCase(top.hcode.hoj.pojo.entity.judge.JudgeCase) JudgeDispatcher(top.hcode.hoj.judge.self.JudgeDispatcher) HttpSession(javax.servlet.http.HttpSession) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) IpUtils(top.hcode.hoj.utils.IpUtils) Contest(top.hcode.hoj.pojo.entity.contest.Contest) SubmitIdListDto(top.hcode.hoj.pojo.dto.SubmitIdListDto) UserAcproblem(top.hcode.hoj.pojo.entity.user.UserAcproblem) CollectionUtils(org.springframework.util.CollectionUtils) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ToJudgeDto(top.hcode.hoj.pojo.dto.ToJudgeDto) ContestServiceImpl(top.hcode.hoj.service.contest.impl.ContestServiceImpl) Constants(top.hcode.hoj.utils.Constants) UserAcproblemServiceImpl(top.hcode.hoj.service.user.impl.UserAcproblemServiceImpl) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) IPage(com.baomidou.mybatisplus.core.metadata.IPage) SecurityUtils(org.apache.shiro.SecurityUtils) Transactional(org.springframework.transaction.annotation.Transactional) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) HttpSession(javax.servlet.http.HttpSession) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Judge(top.hcode.hoj.pojo.entity.judge.Judge) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication)

Example 7 with Judge

use of top.hcode.hoj.pojo.entity.judge.Judge in project HOJ by HimitZH.

the class JudgeController method getALLCaseResult.

/**
 * @MethodName getJudgeCase
 * @Params * @param null
 * @Description 获得指定提交id的测试样例结果,暂不支持查看测试数据,只可看测试点结果,时间,空间,或者IO得分
 * @Return
 * @Since 2020/10/29
 */
@GetMapping("/get-all-case-result")
public CommonResult getALLCaseResult(@RequestParam(value = "submitId", required = true) Long submitId, HttpServletRequest request) {
    Judge judge = judgeService.getById(submitId);
    if (judge == null) {
        return CommonResult.errorResponse("此提交数据不存在!");
    }
    Problem problem = problemService.getById(judge.getPid());
    // 如果该题不支持开放测试点结果查看
    if (!problem.getOpenCaseResult()) {
        return CommonResult.successResponse(null, "对不起,该题测试样例详情不支持开放!");
    }
    HttpSession session = request.getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    // 是否为超级管理员
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    if (judge.getCid() != 0 && userRolesVo != null && !isRoot) {
        Contest contest = contestService.getById(judge.getCid());
        // 如果不是比赛管理员 比赛封榜不能看
        if (!contest.getUid().equals(userRolesVo.getUid())) {
            // 当前是比赛期间 同时处于封榜时间
            if (contest.getSealRank() && contest.getStatus().intValue() == Constants.Contest.STATUS_RUNNING.getCode() && contest.getSealRankTime().before(new Date())) {
                return CommonResult.successResponse(null, "对不起,该题测试样例详情不能查看!");
            }
            // 若是比赛题目,只支持OI查看测试点情况,ACM强制禁止查看,比赛管理员除外
            if (problem.getType().intValue() == Constants.Contest.TYPE_ACM.getCode()) {
                return CommonResult.successResponse(null, "对不起,该题测试样例详情不能查看!");
            }
        }
    }
    QueryWrapper<JudgeCase> wrapper = new QueryWrapper<>();
    if (userRolesVo == null || (!isRoot && !SecurityUtils.getSubject().hasRole("admin") && !SecurityUtils.getSubject().hasRole("problem_admin"))) {
        wrapper.select("time", "memory", "score", "status", "user_output");
    }
    wrapper.eq("submit_id", submitId).last("order by length(input_data) asc,input_data asc");
    // 当前所有测试点只支持 空间 时间 状态码 IO得分 输出文件名 输入文件名和错误信息提示查看而已
    List<JudgeCase> judgeCaseList = judgeCaseService.list(wrapper);
    if (judgeCaseList.isEmpty()) {
        // 未查询到一条数据
        return CommonResult.successResponse(null, "暂无数据");
    } else {
        return CommonResult.successResponse(judgeCaseList, "获取成功");
    }
}
Also used : JudgeCase(top.hcode.hoj.pojo.entity.judge.JudgeCase) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) HttpSession(javax.servlet.http.HttpSession) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Problem(top.hcode.hoj.pojo.entity.problem.Problem) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Judge(top.hcode.hoj.pojo.entity.judge.Judge)

Example 8 with Judge

use of top.hcode.hoj.pojo.entity.judge.Judge in project HOJ by HimitZH.

the class ProblemController method getUserProblemStatus.

/**
 * @MethodName getUserProblemStatus
 * @Params * @param UidAndPidListDto
 * @Description 获取用户对应该题目列表中各个题目的做题情况
 * @Return CommonResult
 * @Since 2020/12/29
 */
@RequiresAuthentication
@PostMapping("/get-user-problem-status")
public CommonResult getUserProblemStatus(@Validated @RequestBody PidListDto pidListDto, HttpServletRequest request) {
    // 需要获取一下该token对应用户的数据
    HttpSession session = request.getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    HashMap<Long, Object> result = new HashMap<>();
    // 先查询判断该用户对于这些题是否已经通过,若已通过,则无论后续再提交结果如何,该题都标记为通过
    QueryWrapper<Judge> queryWrapper = new QueryWrapper<>();
    queryWrapper.select("distinct pid,status,submit_time,score").in("pid", pidListDto.getPidList()).eq("uid", userRolesVo.getUid()).orderByDesc("submit_time");
    if (pidListDto.getIsContestProblemList()) {
        // 如果是比赛的提交记录需要判断cid
        queryWrapper.eq("cid", pidListDto.getCid());
    } else {
        queryWrapper.eq("cid", 0);
    }
    List<Judge> judges = judgeService.list(queryWrapper);
    boolean isACMContest = true;
    Contest contest = null;
    if (pidListDto.getIsContestProblemList()) {
        contest = contestService.getById(pidListDto.getCid());
        if (contest == null) {
            return CommonResult.errorResponse("比赛参数错误!");
        }
        isACMContest = contest.getType().intValue() == Constants.Contest.TYPE_ACM.getCode();
    }
    for (Judge judge : judges) {
        // 如果是比赛的题目列表状态
        HashMap<String, Object> temp = new HashMap<>();
        if (pidListDto.getIsContestProblemList()) {
            if (!isACMContest) {
                if (!result.containsKey(judge.getPid())) {
                    // 只有比赛结束可以看到,比赛管理员与超级管理员的提交除外
                    if (contestService.isSealRank(userRolesVo.getUid(), contest, true, SecurityUtils.getSubject().hasRole("root"))) {
                        temp.put("status", Constants.Judge.STATUS_SUBMITTED_UNKNOWN_RESULT.getStatus());
                        temp.put("score", null);
                    } else {
                        temp.put("status", judge.getStatus());
                        temp.put("score", judge.getScore());
                    }
                    result.put(judge.getPid(), temp);
                }
            } else {
                // 如果该题目已通过,且同时是为不封榜前提交的,则强制写为通过(0)
                if (judge.getStatus().intValue() == Constants.Judge.STATUS_ACCEPTED.getStatus()) {
                    temp.put("status", Constants.Judge.STATUS_ACCEPTED.getStatus());
                    temp.put("score", null);
                    result.put(judge.getPid(), temp);
                } else if (!result.containsKey(judge.getPid())) {
                    // 还未写入,则使用最新一次提交的结果
                    temp.put("status", judge.getStatus());
                    temp.put("score", null);
                    result.put(judge.getPid(), temp);
                }
            }
        } else {
            // 不是比赛题目
            if (judge.getStatus().intValue() == Constants.Judge.STATUS_ACCEPTED.getStatus()) {
                // 如果该题目已通过,则强制写为通过(0)
                temp.put("status", Constants.Judge.STATUS_ACCEPTED.getStatus());
                result.put(judge.getPid(), temp);
            } else if (!result.containsKey(judge.getPid())) {
                // 还未写入,则使用最新一次提交的结果
                temp.put("status", judge.getStatus());
                result.put(judge.getPid(), temp);
            }
        }
    }
    // 再次检查,应该可能从未提交过该题,则状态写为-10
    for (Long pid : pidListDto.getPidList()) {
        // 如果是比赛的题目列表状态
        if (pidListDto.getIsContestProblemList()) {
            if (!result.containsKey(pid)) {
                HashMap<String, Object> temp = new HashMap<>();
                temp.put("score", null);
                temp.put("status", Constants.Judge.STATUS_NOT_SUBMITTED.getStatus());
                result.put(pid, temp);
            }
        } else {
            if (!result.containsKey(pid)) {
                HashMap<String, Object> temp = new HashMap<>();
                temp.put("status", Constants.Judge.STATUS_NOT_SUBMITTED.getStatus());
                result.put(pid, temp);
            }
        }
    }
    return CommonResult.successResponse(result, "查询成功");
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) HttpSession(javax.servlet.http.HttpSession) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Judge(top.hcode.hoj.pojo.entity.judge.Judge) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication)

Example 9 with Judge

use of top.hcode.hoj.pojo.entity.judge.Judge in project HOJ by HimitZH.

the class TrainingRecordServiceImpl method syncAllUserProblemRecord.

private void syncAllUserProblemRecord(Long tid) {
    QueryWrapper<TrainingProblem> trainingProblemQueryWrapper = new QueryWrapper<>();
    trainingProblemQueryWrapper.eq("tid", tid);
    List<TrainingProblem> trainingProblemList = trainingProblemService.list(trainingProblemQueryWrapper);
    if (trainingProblemList.size() == 0) {
        return;
    }
    List<Long> pidList = new ArrayList<>();
    HashMap<Long, Long> pidMapTPid = new HashMap<>();
    for (TrainingProblem trainingProblem : trainingProblemList) {
        pidList.add(trainingProblem.getPid());
        pidMapTPid.put(trainingProblem.getPid(), trainingProblem.getId());
    }
    List<String> uidList = trainingRegisterService.getAlreadyRegisterUidList(tid);
    if (uidList.size() == 0) {
        return;
    }
    QueryWrapper<Judge> judgeQueryWrapper = new QueryWrapper<>();
    judgeQueryWrapper.in("pid", pidList).eq("cid", 0).eq("status", // 只同步ac的提交
    Constants.Judge.STATUS_ACCEPTED.getStatus()).in("uid", uidList);
    List<Judge> judgeList = judgeService.list(judgeQueryWrapper);
    saveBatchNewRecordByJudgeList(judgeList, tid, null, pidMapTPid);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) TrainingProblem(top.hcode.hoj.pojo.entity.training.TrainingProblem) Judge(top.hcode.hoj.pojo.entity.judge.Judge)

Example 10 with Judge

use of top.hcode.hoj.pojo.entity.judge.Judge in project HOJ by HimitZH.

the class TrainingRecordServiceImpl method syncUserSubmissionToRecordByTid.

@Override
@Async
public void syncUserSubmissionToRecordByTid(Long tid, String uid) {
    QueryWrapper<TrainingProblem> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("tid", tid);
    List<TrainingProblem> trainingProblemList = trainingProblemService.list(queryWrapper);
    List<Long> pidList = new ArrayList<>();
    HashMap<Long, Long> pidMapTPid = new HashMap<>();
    for (TrainingProblem trainingProblem : trainingProblemList) {
        pidList.add(trainingProblem.getPid());
        pidMapTPid.put(trainingProblem.getPid(), trainingProblem.getId());
    }
    if (!CollectionUtils.isEmpty(pidList)) {
        QueryWrapper<Judge> judgeQueryWrapper = new QueryWrapper<>();
        judgeQueryWrapper.in("pid", pidList).eq("cid", 0).eq("status", // 只同步ac的提交
        Constants.Judge.STATUS_ACCEPTED.getStatus()).eq("uid", uid);
        List<Judge> judgeList = judgeService.list(judgeQueryWrapper);
        saveBatchNewRecordByJudgeList(judgeList, tid, null, pidMapTPid);
    }
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) TrainingProblem(top.hcode.hoj.pojo.entity.training.TrainingProblem) Judge(top.hcode.hoj.pojo.entity.judge.Judge) Async(org.springframework.scheduling.annotation.Async)

Aggregations

Judge (top.hcode.hoj.pojo.entity.judge.Judge)50 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)29 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)21 Transactional (org.springframework.transaction.annotation.Transactional)18 Problem (top.hcode.hoj.pojo.entity.problem.Problem)18 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)14 Contest (top.hcode.hoj.pojo.entity.contest.Contest)13 Session (org.apache.shiro.session.Session)11 HttpSession (javax.servlet.http.HttpSession)10 ContestRecord (top.hcode.hoj.pojo.entity.contest.ContestRecord)10 JudgeCase (top.hcode.hoj.pojo.entity.judge.JudgeCase)10 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)8 UserAcproblem (top.hcode.hoj.pojo.entity.user.UserAcproblem)8 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)7 java.util (java.util)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 SecurityUtils (org.apache.shiro.SecurityUtils)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Constants (top.hcode.hoj.utils.Constants)6 JSONObject (cn.hutool.json.JSONObject)4