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, "查询成功!");
}
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;
}
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;
}
Aggregations