fix before contest submission rejudge bug

This commit is contained in:
Himit_ZH 2022-01-22 18:58:45 +08:00
parent 1beab3d386
commit 69b7dbdbf7
2 changed files with 20 additions and 17 deletions

View File

@ -130,24 +130,25 @@ public class ContestRecordServiceImpl extends ServiceImpl<ContestRecordMapper, C
// 将新提交数据插入数据库 // 将新提交数据插入数据库
judgeMapper.insert(judge); judgeMapper.insert(judge);
// 管理员比赛前的提交不纳入记录 // 同时初始化写入contest_record表
if (contest.getStatus().intValue() == Constants.Contest.STATUS_RUNNING.getCode()) { ContestRecord contestRecord = new ContestRecord();
// 同时初始化写入contest_record表 contestRecord.setDisplayId(judgeDto.getPid())
ContestRecord contestRecord = new ContestRecord(); .setCpid(contestProblem.getId())
contestRecord.setDisplayId(judgeDto.getPid()) .setSubmitId(judge.getSubmitId())
.setCpid(contestProblem.getId()) .setPid(judge.getPid())
.setSubmitId(judge.getSubmitId()) .setUsername(userRolesVo.getUsername())
.setPid(judge.getPid()) .setRealname(userRolesVo.getRealname())
.setUsername(userRolesVo.getUsername()) .setUid(userRolesVo.getUid())
.setRealname(userRolesVo.getRealname()) .setCid(judge.getCid())
.setUid(userRolesVo.getUid()) .setSubmitTime(judge.getSubmitTime());
.setCid(judge.getCid())
.setSubmitTime(judge.getSubmitTime())
// 设置比赛开始时间到提交时间之间的秒数
.setTime(DateUtil.between(contest.getStartTime(), judge.getSubmitTime(), DateUnit.SECOND));
contestRecordMapper.insert(contestRecord);
if (contest.getStatus().intValue() == Constants.Contest.STATUS_SCHEDULED.getCode()) {
contestRecord.setTime(0L);
} else {
// 设置比赛开始时间到提交时间之间的秒数
contestRecord.setTime(DateUtil.between(contest.getStartTime(), judge.getSubmitTime(), DateUnit.SECOND));
} }
contestRecordMapper.insert(contestRecord);
return null; return null;
} }

View File

@ -2,10 +2,10 @@ package top.hcode.hoj.service.judge.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.hcode.hoj.common.result.CommonResult; import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.judge.remote.RemoteJudgeDispatcher; import top.hcode.hoj.judge.remote.RemoteJudgeDispatcher;
import top.hcode.hoj.judge.self.JudgeDispatcher; import top.hcode.hoj.judge.self.JudgeDispatcher;
@ -59,6 +59,7 @@ public class RejudgeServiceImpl implements RejudgeService {
private RemoteJudgeDispatcher remoteJudgeDispatcher; private RemoteJudgeDispatcher remoteJudgeDispatcher;
@Override @Override
@Transactional(rollbackFor = Exception.class)
public CommonResult rejudge(Long submitId) { public CommonResult rejudge(Long submitId) {
Judge judge = judgeService.getById(submitId); Judge judge = judgeService.getById(submitId);
@ -117,6 +118,7 @@ public class RejudgeServiceImpl implements RejudgeService {
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public CommonResult rejudgeContestProblem(Long cid, Long pid) { public CommonResult rejudgeContestProblem(Long cid, Long pid) {
QueryWrapper<Judge> queryWrapper = new QueryWrapper<>(); QueryWrapper<Judge> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("cid", cid).eq("pid", pid); queryWrapper.eq("cid", cid).eq("pid", pid);