Search in sources :

Example 1 with TrainingDto

use of top.hcode.hoj.pojo.dto.TrainingDto in project HOJ by HimitZH.

the class TrainingServiceImpl method getAdminTrainingDto.

@Override
public CommonResult getAdminTrainingDto(Long tid, HttpServletRequest request) {
    // 获取本场训练的信息
    Training training = trainingMapper.selectById(tid);
    if (training == null) {
        // 查询不存在
        return CommonResult.errorResponse("查询失败:该训练不存在,请检查参数tid是否准确!");
    }
    // 获取当前登录的用户
    HttpSession session = request.getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    // 是否为超级管理员
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    // 只有超级管理员和训练拥有者才能操作
    if (!isRoot && !userRolesVo.getUsername().equals(training.getAuthor())) {
        return CommonResult.errorResponse("对不起,你无权限操作!", CommonResult.STATUS_FORBIDDEN);
    }
    TrainingDto trainingDto = new TrainingDto();
    trainingDto.setTraining(training);
    QueryWrapper<MappingTrainingCategory> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("tid", tid);
    MappingTrainingCategory mappingTrainingCategory = mappingTrainingCategoryMapper.selectOne(queryWrapper);
    TrainingCategory trainingCategory = null;
    if (mappingTrainingCategory != null) {
        trainingCategory = trainingCategoryService.getById(mappingTrainingCategory.getCid());
    }
    trainingDto.setTrainingCategory(trainingCategory);
    return CommonResult.successResponse(trainingDto, "查询成功!");
}
Also used : Training(top.hcode.hoj.pojo.entity.training.Training) TrainingDto(top.hcode.hoj.pojo.dto.TrainingDto) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) HttpSession(javax.servlet.http.HttpSession) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) TrainingCategory(top.hcode.hoj.pojo.entity.training.TrainingCategory) MappingTrainingCategory(top.hcode.hoj.pojo.entity.training.MappingTrainingCategory) MappingTrainingCategory(top.hcode.hoj.pojo.entity.training.MappingTrainingCategory)

Example 2 with TrainingDto

use of top.hcode.hoj.pojo.dto.TrainingDto in project HOJ by HimitZH.

the class AdminTrainingManager method getTraining.

public TrainingDto getTraining(Long tid) throws StatusFailException, StatusForbiddenException {
    // 获取本场训练的信息
    Training training = trainingEntityService.getById(tid);
    if (training == null) {
        // 查询不存在
        throw new StatusFailException("查询失败:该训练不存在,请检查参数tid是否准确!");
    }
    // 获取当前登录的用户
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    // 是否为超级管理员
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    // 只有超级管理员和训练拥有者才能操作
    if (!isRoot && !userRolesVo.getUsername().equals(training.getAuthor())) {
        throw new StatusForbiddenException("对不起,你无权限操作!");
    }
    TrainingDto trainingDto = new TrainingDto();
    trainingDto.setTraining(training);
    QueryWrapper<MappingTrainingCategory> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq("tid", tid);
    MappingTrainingCategory mappingTrainingCategory = mappingTrainingCategoryEntityService.getOne(queryWrapper, false);
    TrainingCategory trainingCategory = null;
    if (mappingTrainingCategory != null) {
        trainingCategory = trainingCategoryEntityService.getById(mappingTrainingCategory.getCid());
    }
    trainingDto.setTrainingCategory(trainingCategory);
    return trainingDto;
}
Also used : Training(top.hcode.hoj.pojo.entity.training.Training) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) TrainingDto(top.hcode.hoj.pojo.dto.TrainingDto) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) TrainingCategory(top.hcode.hoj.pojo.entity.training.TrainingCategory) MappingTrainingCategory(top.hcode.hoj.pojo.entity.training.MappingTrainingCategory) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session) MappingTrainingCategory(top.hcode.hoj.pojo.entity.training.MappingTrainingCategory)

Example 3 with TrainingDto

use of top.hcode.hoj.pojo.dto.TrainingDto in project HOJ by HimitZH.

the class GroupTrainingManager method getTraining.

public TrainingDto getTraining(Long tid) 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("对不起,您无权限操作!");
    }
    TrainingDto trainingDto = new TrainingDto();
    trainingDto.setTraining(training);
    QueryWrapper<MappingTrainingCategory> mappingTrainingCategoryQueryWrapper = new QueryWrapper<>();
    mappingTrainingCategoryQueryWrapper.eq("tid", tid);
    MappingTrainingCategory mappingTrainingCategory = mappingTrainingCategoryEntityService.getOne(mappingTrainingCategoryQueryWrapper);
    TrainingCategory trainingCategory = null;
    if (mappingTrainingCategory != null) {
        trainingCategory = trainingCategoryEntityService.getById(mappingTrainingCategory.getCid());
    }
    trainingDto.setTrainingCategory(trainingCategory);
    return trainingDto;
}
Also used : Group(top.hcode.hoj.pojo.entity.group.Group) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) TrainingDto(top.hcode.hoj.pojo.dto.TrainingDto) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) StatusNotFoundException(top.hcode.hoj.common.exception.StatusNotFoundException) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) Session(org.apache.shiro.session.Session)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)3 TrainingDto (top.hcode.hoj.pojo.dto.TrainingDto)3 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)3 Session (org.apache.shiro.session.Session)2 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)2 MappingTrainingCategory (top.hcode.hoj.pojo.entity.training.MappingTrainingCategory)2 Training (top.hcode.hoj.pojo.entity.training.Training)2 TrainingCategory (top.hcode.hoj.pojo.entity.training.TrainingCategory)2 HttpSession (javax.servlet.http.HttpSession)1 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)1 StatusNotFoundException (top.hcode.hoj.common.exception.StatusNotFoundException)1 Group (top.hcode.hoj.pojo.entity.group.Group)1