Search in sources :

Example 11 with StatusFailException

use of top.hcode.hoj.common.exception.StatusFailException in project HOJ by HimitZH.

the class ContestManager method getContestRank.

public IPage getContestRank(ContestRankDto contestRankDto) throws StatusFailException, StatusForbiddenException {
    Long cid = contestRankDto.getCid();
    List<String> concernedList = contestRankDto.getConcernedList();
    Integer currentPage = contestRankDto.getCurrentPage();
    Integer limit = contestRankDto.getLimit();
    Boolean removeStar = contestRankDto.getRemoveStar();
    Boolean forceRefresh = contestRankDto.getForceRefresh();
    if (cid == null) {
        throw new StatusFailException("错误:cid不能为空");
    }
    if (removeStar == null) {
        removeStar = false;
    }
    if (forceRefresh == null) {
        forceRefresh = false;
    }
    // 页数,每页题数若为空,设置默认值
    if (currentPage == null || currentPage < 1)
        currentPage = 1;
    if (limit == null || limit < 1)
        limit = 30;
    // 获取当前登录的用户
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    // 获取本场比赛的状态
    Contest contest = contestEntityService.getById(contestRankDto.getCid());
    // 超级管理员或者该比赛的创建者,则为比赛管理者
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    // 需要对该比赛做判断,是否处于开始或结束状态才可以获取题目,同时若是私有赛需要判断是否已注册(比赛管理员包括超级管理员可以直接获取)
    contestValidator.validateContestAuth(contest, userRolesVo, isRoot);
    // 校验该比赛是否开启了封榜模式,超级管理员和比赛创建者可以直接看到实际榜单
    boolean isOpenSealRank = contestValidator.isSealRank(userRolesVo.getUid(), contest, forceRefresh, isRoot);
    IPage resultList;
    if (contest.getType().intValue() == Constants.Contest.TYPE_ACM.getCode()) {
        // ACM比赛
        // 进行排行榜计算以及排名分页
        resultList = contestRankManager.getContestACMRankPage(isOpenSealRank, removeStar, userRolesVo.getUid(), concernedList, contest, currentPage, limit);
    } else {
        // OI比赛
        resultList = contestRankManager.getContestOIRankPage(isOpenSealRank, removeStar, userRolesVo.getUid(), concernedList, contest, currentPage, limit);
    }
    return resultList;
}
Also used : IPage(com.baomidou.mybatisplus.core.metadata.IPage) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session)

Example 12 with StatusFailException

use of top.hcode.hoj.common.exception.StatusFailException in project HOJ by HimitZH.

the class ContestManager method toRegisterContest.

public void toRegisterContest(RegisterContestDto registerContestDto) throws StatusFailException, StatusForbiddenException {
    Long cid = registerContestDto.getCid();
    String password = registerContestDto.getPassword();
    if (cid == null || StringUtils.isEmpty(password)) {
        throw new StatusFailException("cid或者password不能为空!");
    }
    // 获取当前登录的用户
    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 || !contest.getVisible()) {
        throw new StatusFailException("对不起,该比赛不存在!");
    }
    if (contest.getIsGroup()) {
        if (!groupValidator.isGroupMember(userRolesVo.getUid(), contest.getGid()) && !isRoot) {
            throw new StatusForbiddenException("对不起,您无权限操作!");
        }
    }
    if (!contest.getPwd().equals(password)) {
        // 密码不对
        throw new StatusFailException("比赛密码错误,请重新输入!");
    }
    // 需要校验当前比赛是否开启账号规则限制,如果有,需要对当前用户的用户名进行验证
    if (contest.getOpenAccountLimit() && !contestValidator.validateAccountRule(contest.getAccountLimitRule(), userRolesVo.getUsername())) {
        throw new StatusFailException("对不起!本次比赛只允许特定账号规则的用户参赛!");
    }
    QueryWrapper<ContestRegister> wrapper = new QueryWrapper<ContestRegister>().eq("cid", cid).eq("uid", userRolesVo.getUid());
    if (contestRegisterEntityService.getOne(wrapper, false) != null) {
        throw new StatusFailException("您已注册过该比赛,请勿重复注册!");
    }
    boolean isOk = contestRegisterEntityService.saveOrUpdate(new ContestRegister().setCid(cid).setUid(userRolesVo.getUid()));
    if (!isOk) {
        throw new StatusFailException("校验比赛密码失败,请稍后再试");
    }
}
Also used : StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session)

Example 13 with StatusFailException

use of top.hcode.hoj.common.exception.StatusFailException in project HOJ by HimitZH.

the class GroupContestManager method deleteContest.

public void deleteContest(Long cid) 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("对不起,您无权限操作!");
    }
    boolean isOk = contestEntityService.removeById(cid);
    if (!isOk) {
        throw new StatusFailException("删除失败");
    }
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Session(org.apache.shiro.session.Session)

Example 14 with StatusFailException

use of top.hcode.hoj.common.exception.StatusFailException in project HOJ by HimitZH.

the class GroupContestProblemManager method addProblemFromGroup.

@Transactional(rollbackFor = Exception.class)
public void addProblemFromGroup(String problemId, Long cid, String displayId) throws StatusNotFoundException, StatusForbiddenException, 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("对不起,您无权限操作!");
    }
    QueryWrapper<Problem> problemQueryWrapper = new QueryWrapper<>();
    problemQueryWrapper.eq("problem_id", problemId).eq("gid", gid);
    Problem problem = problemEntityService.getOne(problemQueryWrapper);
    if (problem == null) {
        throw new StatusNotFoundException("该题目不存在或不是团队题目!");
    }
    QueryWrapper<ContestProblem> contestProblemQueryWrapper = new QueryWrapper<>();
    contestProblemQueryWrapper.eq("cid", cid).and(wrapper -> wrapper.eq("pid", problem.getId()).or().eq("display_id", displayId));
    ContestProblem contestProblem = contestProblemEntityService.getOne(contestProblemQueryWrapper);
    if (contestProblem != null) {
        throw new StatusFailException("添加失败,该题目已添加或者题目的比赛展示ID已存在!");
    }
    ContestProblem newCProblem = new ContestProblem();
    String displayName = problem.getTitle();
    boolean updateProblem = problemEntityService.saveOrUpdate(problem.setAuth(3));
    boolean isOk = contestProblemEntityService.saveOrUpdate(newCProblem.setCid(cid).setPid(problem.getId()).setDisplayTitle(displayName).setDisplayId(displayId));
    if (!isOk || !updateProblem) {
        throw new StatusFailException("添加失败");
    }
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Problem(top.hcode.hoj.pojo.entity.problem.Problem) ContestProblem(top.hcode.hoj.pojo.entity.contest.ContestProblem) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Contest(top.hcode.hoj.pojo.entity.contest.Contest) ContestProblem(top.hcode.hoj.pojo.entity.contest.ContestProblem) Session(org.apache.shiro.session.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with StatusFailException

use of top.hcode.hoj.common.exception.StatusFailException in project HOJ by HimitZH.

the class GroupContestProblemManager method updateContestProblem.

public void updateContestProblem(ContestProblem contestProblem) throws StatusNotFoundException, StatusForbiddenException, StatusFailException {
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    Long cid = contestProblem.getCid();
    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("对不起,您无权限操作!");
    }
    boolean isOk = contestProblemEntityService.saveOrUpdate(contestProblem);
    if (isOk) {
        contestProblemEntityService.syncContestRecord(contestProblem.getPid(), contestProblem.getCid(), contestProblem.getDisplayId());
    } else {
        throw new StatusFailException("更新失败!");
    }
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Session(org.apache.shiro.session.Session)

Aggregations

StatusFailException (top.hcode.hoj.common.exception.StatusFailException)116 Session (org.apache.shiro.session.Session)89 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)83 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)78 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)60 Group (top.hcode.hoj.pojo.entity.group.Group)42 StatusNotFoundException (top.hcode.hoj.common.exception.StatusNotFoundException)40 Transactional (org.springframework.transaction.annotation.Transactional)29 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)28 Problem (top.hcode.hoj.pojo.entity.problem.Problem)26 Contest (top.hcode.hoj.pojo.entity.contest.Contest)25 ContestProblem (top.hcode.hoj.pojo.entity.contest.ContestProblem)14 StatusSystemErrorException (top.hcode.hoj.common.exception.StatusSystemErrorException)10 LinkedList (java.util.LinkedList)8 MultipartFile (org.springframework.web.multipart.MultipartFile)8 JSONObject (cn.hutool.json.JSONObject)7 GroupMember (top.hcode.hoj.pojo.entity.group.GroupMember)7 Judge (top.hcode.hoj.pojo.entity.judge.Judge)7 Training (top.hcode.hoj.pojo.entity.training.Training)7 Discussion (top.hcode.hoj.pojo.entity.discussion.Discussion)6