use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project HOJ by HimitZH.
the class GroupProblemManager method updateProblem.
public void updateProblem(ProblemDto problemDto) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Long pid = problemDto.getProblem().getId();
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("对不起,您无权限操作!");
}
problemDto.getProblem().setProblemId(group.getShortName() + problemDto.getProblem().getProblemId());
String problemId = problemDto.getProblem().getProblemId().toUpperCase();
QueryWrapper<Problem> problemQueryWrapper = new QueryWrapper<>();
problemQueryWrapper.eq("problem_id", problemId);
Problem existedProblem = problemEntityService.getOne(problemQueryWrapper);
problemDto.getProblem().setModifiedUser(userRolesVo.getUsername());
if (existedProblem != null && existedProblem.getId().longValue() != pid) {
throw new StatusFailException("当前的Problem ID 已被使用,请重新更换新的!");
}
problemDto.getProblem().setIsGroup(problem.getIsGroup());
List<Tag> tagList = new LinkedList<>();
for (Tag tag : problemDto.getTags()) {
if (tag.getGid() != null && tag.getGid().longValue() != gid) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
if (tag.getId() == null) {
tag.setGid(gid);
}
tagList.add(tag);
}
problemDto.setTags(tagList);
boolean isOk = problemEntityService.adminUpdateProblem(problemDto);
if (isOk) {
if (existedProblem == null) {
UpdateWrapper<Judge> judgeUpdateWrapper = new UpdateWrapper<>();
judgeUpdateWrapper.eq("pid", problemDto.getProblem().getId()).set("display_pid", problemId);
judgeEntityService.update(judgeUpdateWrapper);
}
} else {
throw new StatusFailException("修改失败");
}
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project HOJ by HimitZH.
the class GroupTrainingManager method changeTrainingStatus.
public void changeTrainingStatus(Long tid, Boolean status) throws StatusForbiddenException, StatusNotFoundException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Training training = trainingEntityService.getById(tid);
if (training == null) {
throw new StatusNotFoundException("该训练不存在!");
}
Long gid = training.getGid();
Group group = groupEntityService.getById(gid);
if (group == null || group.getStatus() == 1 && !isRoot) {
throw new StatusNotFoundException("该团队不存在或已被封禁!");
}
if (!userRolesVo.getUsername().equals(training.getAuthor()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
UpdateWrapper<Training> trainingUpdateWrapper = new UpdateWrapper<>();
trainingUpdateWrapper.eq("id", tid).set("status", status);
boolean isOk = trainingEntityService.update(trainingUpdateWrapper);
if (!isOk) {
throw new StatusFailException("修改失败");
}
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project HOJ by HimitZH.
the class GroupTrainingProblemManager method addProblemFromPublic.
@Transactional(rollbackFor = Exception.class)
public void addProblemFromPublic(TrainingProblemDto trainingProblemDto) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
Long pid = trainingProblemDto.getPid();
Problem problem = problemEntityService.getById(pid);
if (problem == null || problem.getAuth() != 1 || problem.getIsGroup()) {
throw new StatusNotFoundException("该题目不存在或已被隐藏!");
}
Long tid = trainingProblemDto.getTid();
Training training = trainingEntityService.getById(tid);
if (training == null) {
throw new StatusNotFoundException("该训练不存在!");
}
Long gid = training.getGid();
Group group = groupEntityService.getById(gid);
if (group == null || group.getStatus() == 1 && !isRoot) {
throw new StatusNotFoundException("该团队不存在或已被封禁!");
}
if (!userRolesVo.getUsername().equals(training.getAuthor()) && !isRoot && !groupValidator.isGroupRoot(userRolesVo.getUid(), gid)) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
String displayId = trainingProblemDto.getDisplayId();
QueryWrapper<TrainingProblem> trainingProblemQueryWrapper = new QueryWrapper<>();
trainingProblemQueryWrapper.eq("tid", tid).and(wrapper -> wrapper.eq("pid", pid).or().eq("display_id", displayId));
TrainingProblem trainingProblem = trainingProblemEntityService.getOne(trainingProblemQueryWrapper);
if (trainingProblem != null) {
throw new StatusFailException("添加失败,该题目已添加或者题目的训练展示ID已存在!");
}
TrainingProblem newTProblem = new TrainingProblem();
boolean isOk = trainingProblemEntityService.saveOrUpdate(newTProblem.setTid(tid).setPid(pid).setDisplayId(displayId));
if (isOk) {
// 添加成功
// 更新训练最近更新时间
UpdateWrapper<Training> trainingUpdateWrapper = new UpdateWrapper<>();
trainingUpdateWrapper.set("gmt_modified", new Date()).eq("id", tid);
trainingEntityService.update(trainingUpdateWrapper);
adminTrainingRecordManager.syncAlreadyRegisterUserRecord(tid, pid, newTProblem.getId());
} else {
throw new StatusFailException("添加失败!");
}
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project HOJ by HimitZH.
the class DiscussionManager method addDiscussionLike.
@Transactional(rollbackFor = Exception.class)
public void addDiscussionLike(Integer did, boolean toLike) throws StatusFailException, StatusForbiddenException {
// 获取当前登录的用户
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
Discussion discussion = discussionEntityService.getById(did);
if (discussion.getGid() != null) {
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
if (!isRoot && !discussion.getUid().equals(userRolesVo.getUid()) && !groupValidator.isGroupMember(userRolesVo.getUid(), discussion.getGid())) {
throw new StatusForbiddenException("对不起,您无权限操作!");
}
}
QueryWrapper<DiscussionLike> discussionLikeQueryWrapper = new QueryWrapper<>();
discussionLikeQueryWrapper.eq("did", did).eq("uid", userRolesVo.getUid());
DiscussionLike discussionLike = discussionLikeEntityService.getOne(discussionLikeQueryWrapper, false);
if (toLike) {
// 添加点赞
if (discussionLike == null) {
// 如果不存在就添加
boolean isSave = discussionLikeEntityService.saveOrUpdate(new DiscussionLike().setUid(userRolesVo.getUid()).setDid(did));
if (!isSave) {
throw new StatusFailException("点赞失败,请重试尝试!");
}
}
// 点赞+1
UpdateWrapper<Discussion> discussionUpdateWrapper = new UpdateWrapper<>();
discussionUpdateWrapper.eq("id", discussion.getId()).setSql("like_num=like_num+1");
discussionEntityService.update(discussionUpdateWrapper);
// 当前帖子要不是点赞者的 才发送点赞消息
if (!userRolesVo.getUsername().equals(discussion.getAuthor())) {
discussionEntityService.updatePostLikeMsg(discussion.getUid(), userRolesVo.getUid(), did, discussion.getGid());
}
} else {
// 取消点赞
if (discussionLike != null) {
// 如果存在就删除
boolean isDelete = discussionLikeEntityService.removeById(discussionLike.getId());
if (!isDelete) {
throw new StatusFailException("取消点赞失败,请重试尝试!");
}
}
// 点赞-1
UpdateWrapper<Discussion> discussionUpdateWrapper = new UpdateWrapper<>();
discussionUpdateWrapper.setSql("like_num=like_num-1").eq("id", did);
discussionEntityService.update(discussionUpdateWrapper);
}
}
use of com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper in project HOJ by HimitZH.
the class JudgeManager method resubmit.
/**
* @MethodName resubmit
* @Description 调用判题服务器提交失败超过60s后,用户点击按钮重新提交判题进入的方法
* @Since 2021/2/12
*/
@Transactional(rollbackFor = Exception.class)
public Judge resubmit(Long submitId) throws StatusNotFoundException {
Judge judge = judgeEntityService.getById(submitId);
if (judge == null) {
throw new StatusNotFoundException("此提交数据不存在!");
}
Problem problem = problemEntityService.getById(judge.getPid());
// 如果是非比赛题目
if (judge.getCid() == 0) {
// 如果该题已经是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 {
if (problem.getIsRemote()) {
// 将对应比赛记录设置成默认值
UpdateWrapper<ContestRecord> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("submit_id", submitId).setSql("status=null,score=null");
contestRecordEntityService.update(updateWrapper);
} else {
throw new StatusNotFoundException("错误!非vJudge题目在比赛过程无权限重新提交");
}
}
boolean isHasSubmitIdRemoteRejudge = false;
if (Objects.nonNull(judge.getVjudgeSubmitId()) && (judge.getStatus().intValue() == Constants.Judge.STATUS_SUBMITTED_FAILED.getStatus() || judge.getStatus().intValue() == Constants.Judge.STATUS_PENDING.getStatus() || judge.getStatus().intValue() == Constants.Judge.STATUS_JUDGING.getStatus() || judge.getStatus().intValue() == Constants.Judge.STATUS_COMPILING.getStatus() || judge.getStatus().intValue() == Constants.Judge.STATUS_SYSTEM_ERROR.getStatus())) {
isHasSubmitIdRemoteRejudge = true;
}
// 重新进入等待队列
judge.setStatus(Constants.Judge.STATUS_PENDING.getStatus());
judge.setVersion(judge.getVersion() + 1);
judge.setErrorMessage(null).setOiRankScore(null).setScore(null).setTime(null).setJudger("").setMemory(null);
judgeEntityService.updateById(judge);
// 将提交加入任务队列
if (problem.getIsRemote()) {
// 如果是远程oj判题
remoteJudgeDispatcher.sendTask(judge, problem.getProblemId(), judge.getCid() != 0, isHasSubmitIdRemoteRejudge);
} else {
judgeDispatcher.sendTask(judge, judge.getCid() != 0);
}
return judge;
}
Aggregations