use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project HOJ by HimitZH.
the class RejudgeManager method rejudge.
@Transactional(rollbackFor = Exception.class)
public Judge rejudge(Long submitId) throws StatusFailException {
Judge judge = judgeEntityService.getById(submitId);
boolean isContestSubmission = judge.getCid() != 0;
boolean resetContestRecordResult = true;
// 如果是非比赛题目
if (!isContestSubmission) {
// 如果该题已经是AC通过状态,更新该题目的用户ac做题表 user_acproblem
if (judge.getStatus().intValue() == Constants.Judge.STATUS_ACCEPTED.getStatus().intValue()) {
QueryWrapper<UserAcproblem> userAcproblemQueryWrapper = new QueryWrapper<>();
userAcproblemQueryWrapper.eq("submit_id", judge.getSubmitId());
userAcproblemEntityService.remove(userAcproblemQueryWrapper);
}
} else {
// 将对应比赛记录设置成默认值
UpdateWrapper<ContestRecord> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("submit_id", submitId).setSql("status=null,score=null");
resetContestRecordResult = contestRecordEntityService.update(updateWrapper);
}
// 清除该提交对应的测试点结果
QueryWrapper<JudgeCase> judgeCaseQueryWrapper = new QueryWrapper<>();
judgeCaseQueryWrapper.eq("submit_id", submitId);
judgeCaseEntityService.remove(judgeCaseQueryWrapper);
boolean hasSubmitIdRemoteRejudge = isHasSubmitIdRemoteRejudge(judge.getVjudgeSubmitId(), judge.getStatus());
// 设置默认值
// 开始进入判题队列
judge.setStatus(Constants.Judge.STATUS_PENDING.getStatus());
judge.setVersion(judge.getVersion() + 1);
judge.setJudger("").setTime(null).setMemory(null).setErrorMessage(null).setOiRankScore(null).setScore(null);
boolean result = judgeEntityService.updateById(judge);
if (result && resetContestRecordResult) {
// 调用判题服务
Problem problem = problemEntityService.getById(judge.getPid());
if (problem.getIsRemote()) {
// 如果是远程oj判题
remoteJudgeDispatcher.sendTask(judge, problem.getProblemId(), isContestSubmission, hasSubmitIdRemoteRejudge);
} else {
judgeDispatcher.sendTask(judge, isContestSubmission);
}
return judge;
} else {
throw new StatusFailException("重判失败!请重新尝试!");
}
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project HOJ by HimitZH.
the class ChooseUtils method chooseFixedServer.
@Transactional(rollbackFor = Exception.class)
public JudgeServer chooseFixedServer(Boolean isRemote, String fixedTag, Integer index, Integer total) {
// 获取该微服务的所有健康实例
List<Instance> instances = getInstances(JudgeServiceName);
if (instances.size() <= 0) {
return null;
}
List<String> keyList = new ArrayList<>();
// 获取当前健康实例取出ip和port拼接
for (Instance instance : instances) {
keyList.add(instance.getIp() + ":" + instance.getPort());
}
// 过滤出小于或等于规定最大并发判题任务数的服务实例且健康的判题机
QueryWrapper<JudgeServer> judgeServerQueryWrapper = new QueryWrapper<>();
judgeServerQueryWrapper.in("url", keyList).eq("is_remote", isRemote).last(// 开启悲观锁
"for update");
/**
* 如果一个条件无法通过索引快速过滤,存储引擎层面就会将所有记录加锁后返回,
* 再由MySQL Server层进行过滤,但在实际使用过程当中,MySQL做了一些改进,
* 在MySQL Server过滤条件,发现不满足后,会调用unlock_row方法,
* 把不满足条件的记录释放锁 (违背了二段锁协议的约束)。
*/
List<JudgeServer> judgeServerList = judgeServerEntityService.list(judgeServerQueryWrapper);
// CF的VJ判題需要一机一题(根据序号保持一定的固定)
int len = judgeServerList.size();
for (int i = 0; i < len; i++) {
if (i % total == index) {
JudgeServer judgeServer = judgeServerList.get(i);
UpdateWrapper<JudgeServer> judgeServerUpdateWrapper = new UpdateWrapper<>();
judgeServerUpdateWrapper.set(fixedTag, false).eq("id", judgeServer.getId()).eq(fixedTag, true);
boolean isOk = judgeServerEntityService.update(judgeServerUpdateWrapper);
if (isOk) {
return judgeServer;
}
}
}
return null;
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project HOJ by HimitZH.
the class GroupContestManager method updateContest.
public void updateContest(AdminContestVo adminContestVo) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Long cid = adminContestVo.getId();
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("对不起,您无权限操作!");
}
Contest contest1 = BeanUtil.copyProperties(adminContestVo, Contest.class, "starAccount");
JSONObject accountJson = new JSONObject();
accountJson.set("star_account", adminContestVo.getStarAccount());
contest1.setStarAccount(accountJson.toString());
Contest oldContest = contestEntityService.getById(contest1.getId());
boolean isOk = contestEntityService.saveOrUpdate(contest1);
if (isOk) {
if (!contest1.getAuth().equals(Constants.Contest.AUTH_PUBLIC.getCode())) {
if (!Objects.equals(oldContest.getPwd(), contest1.getPwd())) {
UpdateWrapper<ContestRegister> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("cid", contest1.getId());
contestRegisterEntityService.remove(updateWrapper);
}
}
} else {
throw new StatusFailException("修改失败");
}
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project HOJ by HimitZH.
the class GroupContestManager method changeContestVisible.
public void changeContestVisible(Long cid, Boolean visible) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
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("对不起,您无权限操作!");
}
UpdateWrapper<Contest> contestUpdateWrapper = new UpdateWrapper<>();
contestUpdateWrapper.eq("id", cid).set("visible", visible);
boolean isOK = contestEntityService.update(contestUpdateWrapper);
if (!isOK) {
throw new StatusFailException("修改失败");
}
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project HOJ by HimitZH.
the class GroupProblemManager method applyPublic.
public void applyPublic(Long pid, Boolean isApplied) throws StatusNotFoundException, StatusForbiddenException, 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);
if (isApplied) {
// 申请
problemUpdateWrapper.set("apply_public_progress", 1);
} else {
// 取消
problemUpdateWrapper.set("apply_public_progress", null);
problemUpdateWrapper.set("is_group", true);
}
boolean isOk = problemEntityService.update(problemUpdateWrapper);
if (!isOk) {
throw new StatusFailException("修改失败");
}
}
Aggregations