Search in sources :

Example 1 with SubmitIdListDto

use of top.hcode.hoj.pojo.dto.SubmitIdListDto in project HOJ by HimitZH.

the class JudgeController method checkCommonJudgeResult.

/**
 * @MethodName checkJudgeResult
 * @Params * @param null
 * @Description 对提交列表状态为Pending和Judging的提交进行更新检查
 * @Return
 * @Since 2021/1/3
 */
@RequestMapping(value = "/check-submissions-status", method = RequestMethod.POST)
public CommonResult checkCommonJudgeResult(@RequestBody SubmitIdListDto submitIdListDto) {
    List<Long> submitIds = submitIdListDto.getSubmitIds();
    if (CollectionUtils.isEmpty(submitIds)) {
        return CommonResult.successResponse(new HashMap<>(), "查询的提交id列表为空!");
    }
    QueryWrapper<Judge> queryWrapper = new QueryWrapper<>();
    // lambada表达式过滤掉code
    queryWrapper.select(Judge.class, info -> !info.getColumn().equals("code")).in("submit_id", submitIds);
    List<Judge> judgeList = judgeService.list(queryWrapper);
    HashMap<Long, Object> result = new HashMap<>();
    for (Judge judge : judgeList) {
        judge.setCode(null);
        judge.setErrorMessage(null);
        judge.setVjudgeUsername(null);
        judge.setVjudgeSubmitId(null);
        judge.setVjudgePassword(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) Judge(top.hcode.hoj.pojo.entity.judge.Judge)

Example 2 with SubmitIdListDto

use of top.hcode.hoj.pojo.dto.SubmitIdListDto 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)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)2 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)2 IPage (com.baomidou.mybatisplus.core.metadata.IPage)2 java.util (java.util)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpSession (javax.servlet.http.HttpSession)2 SecurityUtils (org.apache.shiro.SecurityUtils)2 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)2 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Value (org.springframework.beans.factory.annotation.Value)2 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CollectionUtils (org.springframework.util.CollectionUtils)2 org.springframework.web.bind.annotation (org.springframework.web.bind.annotation)2 CommonResult (top.hcode.hoj.common.result.CommonResult)2 RemoteJudgeDispatcher (top.hcode.hoj.judge.remote.RemoteJudgeDispatcher)2 JudgeDispatcher (top.hcode.hoj.judge.self.JudgeDispatcher)2 SubmitIdListDto (top.hcode.hoj.pojo.dto.SubmitIdListDto)2 ToJudgeDto (top.hcode.hoj.pojo.dto.ToJudgeDto)2