use of top.hcode.hoj.pojo.vo.UserRolesVo in project HOJ by HimitZH.
the class CommentController method getComments.
@GetMapping("/comments")
public CommonResult getComments(@RequestParam(value = "cid", required = false) Long cid, @RequestParam(value = "did", required = false) Integer did, @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit, @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage, HttpServletRequest request) {
// 如果有登录,则获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
IPage<CommentsVo> commentList = commentService.getCommentList(limit, currentPage, cid, did, isRoot, userRolesVo != null ? userRolesVo.getUid() : null);
HashMap<Integer, Boolean> commentLikeMap = new HashMap<>();
if (userRolesVo != null) {
// 如果是有登录 需要检查是否对评论有点赞
List<Integer> commentIdList = new LinkedList<>();
for (CommentsVo commentsVo : commentList.getRecords()) {
commentIdList.add(commentsVo.getId());
}
if (commentIdList.size() > 0) {
QueryWrapper<CommentLike> commentLikeQueryWrapper = new QueryWrapper<>();
commentLikeQueryWrapper.in("cid", commentIdList);
List<CommentLike> commentLikeList = commentLikeService.list(commentLikeQueryWrapper);
// 如果存在记录需要修正Map为true
for (CommentLike tmp : commentLikeList) {
commentLikeMap.put(tmp.getCid(), true);
}
}
}
return CommonResult.successResponse(MapUtil.builder().put("commentList", commentList).put("commentLikeMap", commentLikeMap).map(), "获取成功");
}
use of top.hcode.hoj.pojo.vo.UserRolesVo in project HOJ by HimitZH.
the class CommentController method addDiscussionLike.
@GetMapping("/comment-like")
@RequiresAuthentication
@Transactional
public CommonResult addDiscussionLike(@RequestParam("cid") Integer cid, @RequestParam("toLike") Boolean toLike, @RequestParam("sourceId") Integer sourceId, @RequestParam("sourceType") String sourceType, HttpServletRequest request) {
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
QueryWrapper<CommentLike> commentLikeQueryWrapper = new QueryWrapper<>();
commentLikeQueryWrapper.eq("cid", cid).eq("uid", userRolesVo.getUid());
CommentLike commentLike = commentLikeService.getOne(commentLikeQueryWrapper, false);
if (toLike) {
// 添加点赞
if (commentLike == null) {
// 如果不存在就添加
boolean isSave = commentLikeService.saveOrUpdate(new CommentLike().setUid(userRolesVo.getUid()).setCid(cid));
if (!isSave) {
return CommonResult.errorResponse("点赞失败,请重试尝试!");
}
}
// 点赞+1
Comment comment = commentService.getById(cid);
if (comment != null) {
comment.setLikeNum(comment.getLikeNum() + 1);
commentService.updateById(comment);
commentService.updateCommentLikeMsg(comment.getFromUid(), userRolesVo.getUid(), sourceId, sourceType);
}
return CommonResult.successResponse(null, "点赞成功");
} else {
// 取消点赞
if (commentLike != null) {
// 如果存在就删除
boolean isDelete = commentLikeService.removeById(commentLike.getId());
if (!isDelete) {
return CommonResult.errorResponse("取消点赞失败,请重试尝试!");
}
}
// 点赞-1
UpdateWrapper<Comment> commentUpdateWrapper = new UpdateWrapper<>();
commentUpdateWrapper.setSql("like_num=like_num-1").eq("id", cid);
commentService.update(commentUpdateWrapper);
return CommonResult.successResponse(null, "取消成功");
}
}
use of top.hcode.hoj.pojo.vo.UserRolesVo in project HOJ by HimitZH.
the class CommentController method deleteComment.
@DeleteMapping("/comment")
@RequiresAuthentication
@Transactional
public CommonResult deleteComment(@RequestBody Comment comment, HttpServletRequest request) {
// 获取当前登录的用户
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
// 如果不是评论本人 或者不是管理员 无权限删除该评论
if (comment.getFromUid().equals(userRolesVo.getUid()) || SecurityUtils.getSubject().hasRole("root") || SecurityUtils.getSubject().hasRole("admin") || SecurityUtils.getSubject().hasRole("problem_admin")) {
// 获取需要删除该评论的回复数
int replyNum = replyService.count(new QueryWrapper<Reply>().eq("comment_id", comment.getId()));
// 删除该数据 包括关联外键的reply表数据
boolean isDeleteComment = commentService.removeById(comment.getId());
// 同时需要删除该评论的回复表数据
replyService.remove(new UpdateWrapper<Reply>().eq("comment_id", comment.getId()));
if (isDeleteComment) {
// 如果是讨论区的回复,删除成功需要减少统计该讨论的回复数
if (comment.getDid() != null) {
UpdateWrapper<Discussion> discussionUpdateWrapper = new UpdateWrapper<>();
discussionUpdateWrapper.eq("id", comment.getDid()).setSql("comment_num=comment_num-" + (replyNum + 1));
discussionService.update(discussionUpdateWrapper);
}
return CommonResult.successResponse(null, "删除成功");
} else {
return CommonResult.errorResponse("删除失败,请重新尝试");
}
} else {
return CommonResult.errorResponse("无权删除该评论", CommonResult.STATUS_FORBIDDEN);
}
}
use of top.hcode.hoj.pojo.vo.UserRolesVo in project HOJ by HimitZH.
the class ContestAdminController method checkContestACInfo.
/**
* @MethodName checkContestACInfo
* @Params * @param null
* @Description 比赛管理员确定该次提交的ac情况
* @Return
* @Since 2021/1/17
*/
@PutMapping("/check-contest-ac-info")
@RequiresAuthentication
public CommonResult checkContestACInfo(@RequestBody CheckACDto checkACDto, HttpServletRequest request) {
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
// 获取本场比赛的状态
Contest contest = contestService.getById(checkACDto.getCid());
// 超级管理员或者该比赛的创建者,则为比赛管理者
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
if (!isRoot && !contest.getUid().equals(userRolesVo.getUid())) {
return CommonResult.errorResponse("对不起,你无权操作!", CommonResult.STATUS_FORBIDDEN);
}
boolean result = contestRecordService.updateById(new ContestRecord().setChecked(checkACDto.getChecked()).setId(checkACDto.getId()));
if (result) {
return CommonResult.successResponse(null, "修改校验确定成功!");
} else {
return CommonResult.errorResponse("修改校验确定失败!");
}
}
use of top.hcode.hoj.pojo.vo.UserRolesVo in project HOJ by HimitZH.
the class ContestAdminController method getContestPrint.
@GetMapping("/get-contest-print")
@RequiresAuthentication
public CommonResult getContestPrint(@RequestParam("cid") Long cid, @RequestParam(value = "currentPage", required = false) Integer currentPage, @RequestParam(value = "limit", required = false) Integer limit, HttpServletRequest request) {
HttpSession session = request.getSession();
UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
// 获取本场比赛的状态
Contest contest = contestService.getById(cid);
// 超级管理员或者该比赛的创建者,则为比赛管理者
boolean isRoot = SecurityUtils.getSubject().hasRole("root");
if (!isRoot && !contest.getUid().equals(userRolesVo.getUid())) {
return CommonResult.errorResponse("对不起,你无权查看!", CommonResult.STATUS_FORBIDDEN);
}
if (currentPage == null || currentPage < 1)
currentPage = 1;
if (limit == null || limit < 1)
limit = 30;
// 获取当前比赛的,未被确定的排在签名
IPage<ContestPrint> contestPrintIPage = new Page<>(currentPage, limit);
QueryWrapper<ContestPrint> contestPrintQueryWrapper = new QueryWrapper<>();
contestPrintQueryWrapper.select("id", "cid", "username", "realname", "status", "gmt_create").eq("cid", cid).orderByAsc("status").orderByDesc("gmt_create");
IPage<ContestPrint> contestPrintList = contestPrintService.page(contestPrintIPage, contestPrintQueryWrapper);
return CommonResult.successResponse(contestPrintList, "查询成功");
}
Aggregations