Search in sources :

Example 1 with Comment

use of top.hcode.hoj.pojo.entity.discussion.Comment in project HOJ by HimitZH.

the class CommentManager method getAllReply.

public List<ReplyVo> getAllReply(Integer commentId, Long cid) throws StatusForbiddenException, StatusFailException, AccessException {
    // 如果有登录,则获取当前登录的用户
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    boolean isRoot = SecurityUtils.getSubject().hasRole("root");
    if (cid == null) {
        Comment comment = commentEntityService.getById(commentId);
        QueryWrapper<Discussion> discussionQueryWrapper = new QueryWrapper<>();
        discussionQueryWrapper.select("id", "gid").eq("id", comment.getDid());
        Discussion discussion = discussionEntityService.getOne(discussionQueryWrapper);
        Long gid = discussion.getGid();
        if (gid != null) {
            accessValidator.validateAccess(HOJAccessEnum.GROUP_DISCUSSION);
            if (!isRoot && !groupValidator.isGroupMember(userRolesVo.getUid(), gid)) {
                throw new StatusForbiddenException("对不起,您无权限操作!");
            }
        } else {
            accessValidator.validateAccess(HOJAccessEnum.PUBLIC_DISCUSSION);
        }
    } else {
        accessValidator.validateAccess(HOJAccessEnum.CONTEST_COMMENT);
        Contest contest = contestEntityService.getById(cid);
        contestValidator.validateContestAuth(contest, userRolesVo, isRoot);
    }
    return replyEntityService.getAllReplyByCommentId(cid, userRolesVo != null ? userRolesVo.getUid() : null, isRoot, commentId);
}
Also used : Comment(top.hcode.hoj.pojo.entity.discussion.Comment) StatusForbiddenException(top.hcode.hoj.common.exception.StatusForbiddenException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Discussion(top.hcode.hoj.pojo.entity.discussion.Discussion) Session(org.apache.shiro.session.Session)

Example 2 with Comment

use of top.hcode.hoj.pojo.entity.discussion.Comment in project HOJ by HimitZH.

the class CommentManager method addCommentLike.

@Transactional(rollbackFor = Exception.class)
public void addCommentLike(Integer cid, Boolean toLike, Integer sourceId, String sourceType) throws StatusFailException {
    // 获取当前登录的用户
    Session session = SecurityUtils.getSubject().getSession();
    UserRolesVo userRolesVo = (UserRolesVo) session.getAttribute("userInfo");
    QueryWrapper<CommentLike> commentLikeQueryWrapper = new QueryWrapper<>();
    commentLikeQueryWrapper.eq("cid", cid).eq("uid", userRolesVo.getUid());
    CommentLike commentLike = commentLikeEntityService.getOne(commentLikeQueryWrapper, false);
    if (toLike) {
        // 添加点赞
        if (commentLike == null) {
            // 如果不存在就添加
            boolean isSave = commentLikeEntityService.saveOrUpdate(new CommentLike().setUid(userRolesVo.getUid()).setCid(cid));
            if (!isSave) {
                throw new StatusFailException("点赞失败,请重试尝试!");
            }
        }
        // 点赞+1
        Comment comment = commentEntityService.getById(cid);
        if (comment != null) {
            comment.setLikeNum(comment.getLikeNum() + 1);
            commentEntityService.updateById(comment);
            // 当前的评论要不是点赞者的 才发送点赞消息
            if (!userRolesVo.getUsername().equals(comment.getFromName())) {
                commentEntityService.updateCommentLikeMsg(comment.getFromUid(), userRolesVo.getUid(), sourceId, sourceType);
            }
        }
    } else {
        // 取消点赞
        if (commentLike != null) {
            // 如果存在就删除
            boolean isDelete = commentLikeEntityService.removeById(commentLike.getId());
            if (!isDelete) {
                throw new StatusFailException("取消点赞失败,请重试尝试!");
            }
        }
        // 点赞-1
        UpdateWrapper<Comment> commentUpdateWrapper = new UpdateWrapper<>();
        commentUpdateWrapper.setSql("like_num=like_num-1").eq("id", cid);
        commentEntityService.update(commentUpdateWrapper);
    }
}
Also used : CommentLike(top.hcode.hoj.pojo.entity.discussion.CommentLike) Comment(top.hcode.hoj.pojo.entity.discussion.Comment) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) StatusFailException(top.hcode.hoj.common.exception.StatusFailException) Session(org.apache.shiro.session.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Comment

use of top.hcode.hoj.pojo.entity.discussion.Comment in project HOJ by HimitZH.

the class MsgRemindServiceImpl method getUserReplyMsgList.

public IPage<UserMsgVo> getUserReplyMsgList(IPage<UserMsgVo> userMsgList) {
    for (UserMsgVo userMsgVo : userMsgList.getRecords()) {
        if ("Discussion".equals(userMsgVo.getSourceType())) {
            Discussion discussion = discussionMapper.selectById(userMsgVo.getSourceId());
            if (discussion != null) {
                userMsgVo.setSourceTitle(discussion.getTitle());
            } else {
                userMsgVo.setSourceTitle("原讨论帖已被删除!【The original discussion post has been deleted!】");
            }
        } else if ("Contest".equals(userMsgVo.getSourceType())) {
            Contest contest = contestService.getById(userMsgVo.getSourceId());
            if (contest != null) {
                userMsgVo.setSourceTitle(contest.getTitle());
            } else {
                userMsgVo.setSourceTitle("原比赛已被删除!【The original contest has been deleted!】");
            }
        }
        if ("Comment".equals(userMsgVo.getQuoteType())) {
            Comment comment = commentMapper.selectById(userMsgVo.getQuoteId());
            if (comment != null) {
                String content;
                if (comment.getContent().length() < 100) {
                    content = comment.getFromName() + " : " + comment.getContent();
                } else {
                    content = comment.getFromName() + " : " + comment.getContent().substring(0, 100) + "...";
                }
                userMsgVo.setQuoteContent(content);
            } else {
                userMsgVo.setQuoteContent("您的原评论信息已被删除!【Your original comments have been deleted!】");
            }
        } else if ("Reply".equals(userMsgVo.getQuoteType())) {
            Reply reply = replyMapper.selectById(userMsgVo.getQuoteId());
            if (reply != null) {
                String content;
                if (reply.getContent().length() < 100) {
                    content = reply.getFromName() + " : @" + reply.getToName() + ":" + reply.getContent();
                } else {
                    content = reply.getFromName() + " : @" + reply.getToName() + ":" + reply.getContent().substring(0, 100) + "...";
                }
                userMsgVo.setQuoteContent(content);
            } else {
                userMsgVo.setQuoteContent("您的原回复信息已被删除!【Your original reply has been deleted!】");
            }
        }
    }
    applicationContext.getBean(MsgRemindServiceImpl.class).updateUserMsgRead(userMsgList);
    return userMsgList;
}
Also used : Comment(top.hcode.hoj.pojo.entity.discussion.Comment) Reply(top.hcode.hoj.pojo.entity.discussion.Reply) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Discussion(top.hcode.hoj.pojo.entity.discussion.Discussion) UserMsgVo(top.hcode.hoj.pojo.vo.UserMsgVo)

Example 4 with Comment

use of top.hcode.hoj.pojo.entity.discussion.Comment 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, "取消成功");
    }
}
Also used : CommentLike(top.hcode.hoj.pojo.entity.discussion.CommentLike) Comment(top.hcode.hoj.pojo.entity.discussion.Comment) UpdateWrapper(com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) HttpSession(javax.servlet.http.HttpSession) UserRolesVo(top.hcode.hoj.pojo.vo.UserRolesVo) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Comment

use of top.hcode.hoj.pojo.entity.discussion.Comment in project HOJ by HimitZH.

the class UserMessageManager method getUserReplyMsgList.

private IPage<UserMsgVo> getUserReplyMsgList(IPage<UserMsgVo> userMsgList) {
    for (UserMsgVo userMsgVo : userMsgList.getRecords()) {
        if ("Discussion".equals(userMsgVo.getSourceType())) {
            Discussion discussion = discussionEntityService.getById(userMsgVo.getSourceId());
            if (discussion != null) {
                userMsgVo.setSourceTitle(discussion.getTitle());
            } else {
                userMsgVo.setSourceTitle("原讨论帖已被删除!【The original discussion post has been deleted!】");
            }
        } else if ("Contest".equals(userMsgVo.getSourceType())) {
            Contest contest = contestEntityService.getById(userMsgVo.getSourceId());
            if (contest != null) {
                userMsgVo.setSourceTitle(contest.getTitle());
            } else {
                userMsgVo.setSourceTitle("原比赛已被删除!【The original contest has been deleted!】");
            }
        }
        if ("Comment".equals(userMsgVo.getQuoteType())) {
            Comment comment = commentEntityService.getById(userMsgVo.getQuoteId());
            if (comment != null) {
                String content;
                if (comment.getContent().length() < 100) {
                    content = comment.getFromName() + " : " + comment.getContent();
                } else {
                    content = comment.getFromName() + " : " + comment.getContent().substring(0, 100) + "...";
                }
                userMsgVo.setQuoteContent(content);
            } else {
                userMsgVo.setQuoteContent("您的原评论信息已被删除!【Your original comments have been deleted!】");
            }
        } else if ("Reply".equals(userMsgVo.getQuoteType())) {
            Reply reply = replyEntityService.getById(userMsgVo.getQuoteId());
            if (reply != null) {
                String content;
                if (reply.getContent().length() < 100) {
                    content = reply.getFromName() + " : @" + reply.getToName() + ":" + reply.getContent();
                } else {
                    content = reply.getFromName() + " : @" + reply.getToName() + ":" + reply.getContent().substring(0, 100) + "...";
                }
                userMsgVo.setQuoteContent(content);
            } else {
                userMsgVo.setQuoteContent("您的原回复信息已被删除!【Your original reply has been deleted!】");
            }
        }
    }
    applicationContext.getBean(UserMessageManager.class).updateUserMsgRead(userMsgList);
    return userMsgList;
}
Also used : Comment(top.hcode.hoj.pojo.entity.discussion.Comment) Reply(top.hcode.hoj.pojo.entity.discussion.Reply) Contest(top.hcode.hoj.pojo.entity.contest.Contest) Discussion(top.hcode.hoj.pojo.entity.discussion.Discussion) UserMsgVo(top.hcode.hoj.pojo.vo.UserMsgVo)

Aggregations

Comment (top.hcode.hoj.pojo.entity.discussion.Comment)7 Contest (top.hcode.hoj.pojo.entity.contest.Contest)5 Discussion (top.hcode.hoj.pojo.entity.discussion.Discussion)5 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)4 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)4 Session (org.apache.shiro.session.Session)4 Reply (top.hcode.hoj.pojo.entity.discussion.Reply)4 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)3 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)3 Transactional (org.springframework.transaction.annotation.Transactional)2 CommentLike (top.hcode.hoj.pojo.entity.discussion.CommentLike)2 UserMsgVo (top.hcode.hoj.pojo.vo.UserMsgVo)2 HttpSession (javax.servlet.http.HttpSession)1 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)1 UserAcproblem (top.hcode.hoj.pojo.entity.user.UserAcproblem)1 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)1