use of top.hcode.hoj.pojo.entity.training.Training in project HOJ by HimitZH.
the class AdminTrainingController method changeTrainingStatus.
@PutMapping("/change-training-status")
@RequiresAuthentication
@RequiresRoles(value = { "root", "admin", "problem_admin" }, logical = Logical.OR)
public CommonResult changeTrainingStatus(@RequestParam(value = "tid", required = true) Long tid, @RequestParam(value = "author", required = true) String author, @RequestParam(value = "status", required = true) Boolean status, HttpServletRequest request) {
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
// 是否为超级管理员
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
// 只有超级管理员和训练拥有者才能操作
if (!isRoot && !userRolesVo.getUsername().equals(author)) {
return CommonResult.errorResponse("对不起,你无权限操作!", CommonResult.STATUS_FORBIDDEN);
}
boolean result = trainingService.saveOrUpdate(new Training().setId(tid).setStatus(status));
if (result) {
// 添加成功
return CommonResult.successResponse(null, "修改成功!");
} else {
return CommonResult.errorResponse("修改失败", CommonResult.STATUS_FAIL);
}
}
use of top.hcode.hoj.pojo.entity.training.Training in project HOJ by HimitZH.
the class TrainingController method getTrainingProblemList.
/**
* @param tid
* @param request
* @MethodName getTrainingProblemList
* @Description 根据tid获取指定训练的题单题目列表
* @Return
* @Since 2021/11/20
*/
@GetMapping("/get-training-problem-list")
@RequiresAuthentication
public CommonResult getTrainingProblemList(@RequestParam(value = "tid") Long tid, HttpServletRequest request) {
Training training = trainingService.getById(tid);
if (training == null || !training.getStatus()) {
return CommonResult.errorResponse("该训练不存在或不允许显示!");
}
CommonResult result = trainingRegisterService.checkTrainingAuth(training, request);
if (result != null) {
return result;
}
List<ProblemVo> trainingProblemList = trainingProblemService.getTrainingProblemList(tid);
return CommonResult.successResponse(trainingProblemList, "success");
}
use of top.hcode.hoj.pojo.entity.training.Training in project HOJ by HimitZH.
the class TrainingController method getTrainingAccess.
/**
* @param tid
* @param request
* @MethodName getTrainingAccess
* @Description 私有权限的训练需要获取当前用户是否有进入训练的权限
* @Return
* @Since 2021/11/20
*/
@RequiresAuthentication
@GetMapping("/get-training-access")
public CommonResult getTrainingAccess(@RequestParam(value = "tid") Long tid, HttpServletRequest request) {
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
QueryWrapper<TrainingRegister> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tid", tid).eq("uid", userRolesVo.getUid());
TrainingRegister trainingRegister = trainingRegisterService.getOne(queryWrapper, false);
boolean access = false;
if (trainingRegister != null) {
access = true;
Training training = trainingService.getById(tid);
if (training == null || !training.getStatus()) {
return CommonResult.errorResponse("对不起,该训练不存在!");
}
}
HashMap<String, Object> result = new HashMap<>();
result.put("access", access);
return CommonResult.successResponse(result);
}
use of top.hcode.hoj.pojo.entity.training.Training 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.entity.training.Training in project HOJ by HimitZH.
the class TrainingServiceImpl method updateTraining.
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateTraining(TrainingDto trainingDto) {
Training training = trainingDto.getTraining();
Training oldTraining = trainingMapper.selectById(training.getId());
trainingMapper.updateById(training);
// 私有训练 修改密码 需要清空之前注册训练的记录
if (training.getAuth().equals(Constants.Training.AUTH_PRIVATE.getValue())) {
if (!Objects.equals(training.getPrivatePwd(), oldTraining.getPrivatePwd())) {
UpdateWrapper<TrainingRegister> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("tid", training.getId());
trainingRegisterMapper.delete(updateWrapper);
}
}
TrainingCategory trainingCategory = trainingDto.getTrainingCategory();
if (trainingCategory.getId() == null) {
try {
trainingCategoryService.save(trainingCategory);
} catch (Exception ignored) {
QueryWrapper<TrainingCategory> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("name", trainingCategory.getName());
trainingCategory = trainingCategoryService.getOne(queryWrapper, false);
}
}
MappingTrainingCategory mappingTrainingCategory = mappingTrainingCategoryMapper.selectOne(new QueryWrapper<MappingTrainingCategory>().eq("tid", training.getId()));
if (mappingTrainingCategory == null) {
mappingTrainingCategoryMapper.insert(new MappingTrainingCategory().setTid(training.getId()).setCid(trainingCategory.getId()));
} else {
if (!mappingTrainingCategory.getCid().equals(trainingCategory.getId())) {
UpdateWrapper<MappingTrainingCategory> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("tid", training.getId()).set("cid", trainingCategory.getId());
int update = mappingTrainingCategoryMapper.update(null, updateWrapper);
return update > 0;
}
}
return true;
}
Aggregations