use of top.hcode.hoj.pojo.entity.user.UserAcproblem in project HOJ by HimitZH.
the class JudgeController method resubmit.
/**
* @MethodName resubmit
* @Params * @param null
* @Description 调用判题服务器提交失败超过60s后,用户点击按钮重新提交判题进入的方法
* @Return
* @Since 2021/2/12
*/
@RequiresAuthentication
@GetMapping(value = "/resubmit")
@Transactional(rollbackFor = Exception.class)
public CommonResult resubmit(@RequestParam("submitId") Long submitId, HttpServletRequest request) {
Judge judge = judgeService.getById(submitId);
if (judge == null) {
return CommonResult.errorResponse("此提交数据不存在!");
}
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
if (!judge.getUid().equals(userRolesVo.getUid())) {
// 不是本人无法重新提交
return CommonResult.errorResponse("对不起!您并非提交数据的本人,无法重新提交!");
}
Problem problem = problemService.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());
userAcproblemService.remove(userAcproblemQueryWrapper);
}
} else {
if (problem.getIsRemote()) {
// 将对应比赛记录设置成默认值
UpdateWrapper<ContestRecord> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("submit_id", submitId).setSql("status=null,score=null");
contestRecordService.update(updateWrapper);
} else {
return CommonResult.errorResponse("错误!非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);
judgeService.updateById(judge);
// 将提交加入任务队列
if (problem.getIsRemote()) {
// 如果是远程oj判题
remoteJudgeDispatcher.sendTask(judge, judgeToken, problem.getProblemId(), judge.getCid() != 0, isHasSubmitIdRemoteRejudge);
} else {
judgeDispatcher.sendTask(judge, judgeToken, judge.getCid() != 0);
}
return CommonResult.successResponse(judge, "重新提交成功!");
}
use of top.hcode.hoj.pojo.entity.user.UserAcproblem in project HOJ by HimitZH.
the class CommentController method addComment.
@PostMapping("/comment")
@RequiresPermissions("comment_add")
@RequiresAuthentication
@Transactional
public CommonResult addComment(@RequestBody Comment comment, HttpServletRequest request) {
if (StringUtils.isEmpty(comment.getContent().trim())) {
return CommonResult.errorResponse("评论内容不能为空!");
}
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
// 比赛外的评论 除管理员外 只有AC 10道以上才可评论
if (comment.getCid() == null) {
if (!SecurityUtils.getSubject().hasRole("root") && !SecurityUtils.getSubject().hasRole("admin") && !SecurityUtils.getSubject().hasRole("problem_admin")) {
QueryWrapper<UserAcproblem> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("uid", userRolesVo.getUid()).select("distinct pid");
int userAcProblemCount = userAcproblemService.count(queryWrapper);
if (userAcProblemCount < 10) {
return CommonResult.errorResponse("对不起,您暂时不能评论!请先去提交题目通过10道以上~", CommonResult.STATUS_FORBIDDEN);
}
}
}
comment.setFromAvatar(userRolesVo.getAvatar()).setFromName(userRolesVo.getUsername()).setFromUid(userRolesVo.getUid());
if (SecurityUtils.getSubject().hasRole("root")) {
comment.setFromRole("root");
} else if (SecurityUtils.getSubject().hasRole("admin") || SecurityUtils.getSubject().hasRole("problem_admin")) {
comment.setFromRole("admin");
} else {
comment.setFromRole("user");
}
// 带有表情的字符串转换为编码
comment.setContent(EmojiUtil.toHtml(comment.getContent()));
boolean isOk = commentService.saveOrUpdate(comment);
if (isOk) {
CommentsVo commentsVo = new CommentsVo();
commentsVo.setContent(comment.getContent());
commentsVo.setId(comment.getId());
commentsVo.setFromAvatar(comment.getFromAvatar());
commentsVo.setFromName(comment.getFromName());
commentsVo.setFromUid(comment.getFromUid());
commentsVo.setLikeNum(0);
commentsVo.setGmtCreate(comment.getGmtCreate());
commentsVo.setReplyList(new LinkedList<>());
// 如果是讨论区的回复,发布成功需要添加统计该讨论的回复数
if (comment.getDid() != null) {
Discussion discussion = discussionService.getById(comment.getDid());
if (discussion != null) {
discussion.setCommentNum(discussion.getCommentNum() + 1);
discussionService.updateById(discussion);
// 更新消息
commentService.updateCommentMsg(discussion.getUid(), userRolesVo.getUid(), comment.getContent(), comment.getDid());
}
}
return CommonResult.successResponse(commentsVo, "评论成功");
} else {
return CommonResult.errorResponse("评论失败,请重新尝试!");
}
}
use of top.hcode.hoj.pojo.entity.user.UserAcproblem in project HOJ by HimitZH.
the class GroupManager method addGroup.
@Transactional(rollbackFor = Exception.class)
public void addGroup(Group group) throws StatusFailException, StatusForbiddenException {
Session session = SecurityUtils.getSubject().getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
boolean isProblemAdmin = SecurityUtils.getSubject().hasRole("problem_admin");
boolean isAdmin = SecurityUtils.getSubject().hasRole("admin");
if (!isRoot && !isAdmin && !isProblemAdmin) {
QueryWrapper<UserAcproblem> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("uid", userRolesVo.getUid()).select("distinct pid");
int userAcProblemCount = userAcproblemEntityService.count(queryWrapper);
if (userAcProblemCount < configVo.getDefaultCreateGroupACInitValue()) {
throw new StatusForbiddenException("对不起,您暂时无权限创建团队!请先去提交题目通过" + configVo.getDefaultCreateGroupACInitValue() + "道以上!");
}
String lockKey = Constants.Account.GROUP_ADD_NUM_LOCK.getCode() + userRolesVo.getUid();
Integer num = (Integer) redisUtils.get(lockKey);
if (num == null) {
redisUtils.set(lockKey, 1, 3600 * 24);
} else if (num >= configVo.getDefaultCreateGroupDailyLimit()) {
throw new StatusForbiddenException("对不起,您今天创建团队次数已超过" + configVo.getDefaultCreateGroupDailyLimit() + "次,已被限制!");
} else {
redisUtils.incr(lockKey, 1);
}
QueryWrapper<Group> existedGroupQueryWrapper = new QueryWrapper<>();
existedGroupQueryWrapper.eq("owner", userRolesVo.getUsername());
int existedGroupNum = groupEntityService.count(existedGroupQueryWrapper);
if (existedGroupNum >= configVo.getDefaultCreateGroupLimit()) {
throw new StatusForbiddenException("对不起,您总共已创建了" + configVo.getDefaultCreateGroupLimit() + "个团队,不可再创建,已被限制!");
}
}
group.setOwner(userRolesVo.getUsername());
group.setUid(userRolesVo.getUid());
if (!StringUtils.isEmpty(group.getName()) && (group.getName().length() < 5 || group.getName().length() > 25)) {
throw new StatusFailException("团队名称的长度应为 5 到 25!");
}
if (!StringUtils.isEmpty(group.getShortName()) && (group.getShortName().length() < 5 || group.getShortName().length() > 10)) {
throw new StatusFailException("团队简称的长度应为 5 到 10!");
}
if (!StringUtils.isEmpty(group.getBrief()) && (group.getBrief().length() < 5 || group.getBrief().length() > 50)) {
throw new StatusFailException("团队简介的长度应为 5 到 50!");
}
if (group.getAuth() == null || group.getAuth() < 1 || group.getAuth() > 3) {
throw new StatusFailException("团队权限不能为空且应为1~3!");
}
if (group.getAuth() == 2 || group.getAuth() == 3) {
if (StringUtils.isEmpty(group.getCode()) || group.getCode().length() != 6) {
throw new StatusFailException("团队邀请码不能为空且长度应为 6!");
}
}
if (!StringUtils.isEmpty(group.getDescription()) && (group.getDescription().length() < 5 || group.getDescription().length() > 1000)) {
throw new StatusFailException("团队描述的长度应为 5 到 1000!");
}
QueryWrapper<Group> groupQueryWrapper = new QueryWrapper<>();
groupQueryWrapper.eq("name", group.getName());
int sameNameGroupCount = groupEntityService.count(groupQueryWrapper);
if (sameNameGroupCount > 0) {
throw new StatusFailException("团队名称已存在,请修改后重试!");
}
groupQueryWrapper = new QueryWrapper<>();
groupQueryWrapper.eq("short_name", group.getShortName());
int sameShortNameGroupCount = groupEntityService.count(groupQueryWrapper);
if (sameShortNameGroupCount > 0) {
throw new StatusFailException("团队简称已存在,请修改后重试!");
}
boolean isOk = groupEntityService.save(group);
if (!isOk) {
throw new StatusFailException("创建失败,请重新尝试!");
} else {
groupMemberEntityService.save(new GroupMember().setUid(userRolesVo.getUid()).setGid(group.getId()).setAuth(5));
}
}
use of top.hcode.hoj.pojo.entity.user.UserAcproblem in project HOJ by HimitZH.
the class RejudgeServiceImpl method rejudge.
@Override
@Transactional(rollbackFor = Exception.class)
public CommonResult rejudge(Long submitId) {
Judge judge = judgeService.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());
userAcproblemService.remove(userAcproblemQueryWrapper);
}
} else {
// 将对应比赛记录设置成默认值
UpdateWrapper<ContestRecord> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("submit_id", submitId).setSql("status=null,score=null");
resetContestRecordResult = contestRecordService.update(updateWrapper);
}
// 清除该提交对应的测试点结果
QueryWrapper<JudgeCase> judgeCaseQueryWrapper = new QueryWrapper<>();
judgeCaseQueryWrapper.eq("submit_id", submitId);
judgeCaseService.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 = judgeService.updateById(judge);
if (result && resetContestRecordResult) {
// 调用判题服务
Problem problem = problemService.getById(judge.getPid());
if (problem.getIsRemote()) {
// 如果是远程oj判题
remoteJudgeDispatcher.sendTask(judge, judgeToken, problem.getProblemId(), isContestSubmission, hasSubmitIdRemoteRejudge);
} else {
judgeDispatcher.sendTask(judge, judgeToken, isContestSubmission);
}
return CommonResult.successResponse(judge, "重判成功!该提交已进入判题队列!");
} else {
return CommonResult.successResponse(judge, "重判失败!请重新尝试!");
}
}
use of top.hcode.hoj.pojo.entity.user.UserAcproblem in project HOJ by HimitZH.
the class DiscussionController method addDiscussion.
@PostMapping("/discussion")
@RequiresPermissions("discussion_add")
@RequiresAuthentication
public CommonResult addDiscussion(@RequestBody Discussion discussion, HttpServletRequest request) {
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
// 除管理员外 其它用户需要AC20道题目以上才可发帖,同时限制一天只能发帖5次
if (!SecurityUtils.getSubject().hasRole("root") && !SecurityUtils.getSubject().hasRole("admin") && !SecurityUtils.getSubject().hasRole("problem_admin")) {
QueryWrapper<UserAcproblem> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("uid", userRolesVo.getUid()).select("distinct pid");
int userAcProblemCount = userAcproblemService.count(queryWrapper);
if (userAcProblemCount < 20) {
return CommonResult.errorResponse("对不起,您暂时无权限发帖!请先去提交题目通过20道以上~", CommonResult.STATUS_FORBIDDEN);
}
String lockKey = Constants.Account.DISCUSSION_ADD_NUM_LOCK.getCode() + userRolesVo.getUid();
Integer num = (Integer) redisUtils.get(lockKey);
if (num == null) {
redisUtils.set(lockKey, 1, 3600 * 24);
} else if (num >= 5) {
return CommonResult.errorResponse("对不起,您今天发帖次数已超过5次,已被限制!", CommonResult.STATUS_FORBIDDEN);
} else {
redisUtils.incr(lockKey, 1);
}
}
discussion.setAuthor(userRolesVo.getUsername()).setAvatar(userRolesVo.getAvatar()).setUid(userRolesVo.getUid());
if (SecurityUtils.getSubject().hasRole("root")) {
discussion.setRole("root");
} else if (SecurityUtils.getSubject().hasRole("admin") || SecurityUtils.getSubject().hasRole("problem_admin")) {
discussion.setRole("admin");
} else {
// 如果不是管理员角色,一律重置为不置顶
discussion.setTopPriority(false);
}
boolean isOk = discussionService.saveOrUpdate(discussion);
if (isOk) {
return CommonResult.successResponse(null, "发布成功!");
} else {
return CommonResult.errorResponse("发布失败,请重新尝试!");
}
}
Aggregations