|
|
@ -185,22 +185,42 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> impl
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void deleteComment(Long id) {
|
|
|
|
public void deleteComment(Long id) {
|
|
|
|
validatePostUtil.validateCommentOwnership(id);
|
|
|
|
validatePostUtil.validateCommentOwnership(id);
|
|
|
|
LambdaQueryWrapper<Comment> queryWrapper = Wrappers.lambdaQuery(Comment.class)
|
|
|
|
|
|
|
|
.eq(Comment::getTopId, id);
|
|
|
|
|
|
|
|
int delete = commentMapper.delete(queryWrapper);
|
|
|
|
|
|
|
|
if(delete <= 0) {
|
|
|
|
|
|
|
|
throw new PostException("删除评论失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Comment comment = commentMapper.selectById(id);
|
|
|
|
Comment comment = commentMapper.selectById(id);
|
|
|
|
if(comment.getId().equals(comment.getTopId())) {
|
|
|
|
if(comment.getId().equals(comment.getTopId())) {
|
|
|
|
|
|
|
|
LambdaQueryWrapper<Comment> queryWrapper = Wrappers.lambdaQuery(Comment.class)
|
|
|
|
|
|
|
|
.eq(Comment::getTopId, id);
|
|
|
|
|
|
|
|
int delete = commentMapper.delete(queryWrapper);
|
|
|
|
|
|
|
|
if(delete <= 0) {
|
|
|
|
|
|
|
|
throw new PostException("删除根评论失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Post post = postMapper.selectById(comment.getPostId());
|
|
|
|
|
|
|
|
post.setCommentCount(post.getCommentCount() - delete);
|
|
|
|
|
|
|
|
postMapper.updateById(post);
|
|
|
|
|
|
|
|
|
|
|
|
redisUtil.zRemove("post:comment_by_time:" + comment.getPostId(), comment.getId());
|
|
|
|
redisUtil.zRemove("post:comment_by_time:" + comment.getPostId(), comment.getId());
|
|
|
|
redisUtil.zRemove("post:comment_by_hot:" + comment.getPostId(), comment.getId());
|
|
|
|
redisUtil.zRemove("post:comment_by_hot:" + comment.getPostId(), comment.getId());
|
|
|
|
redisUtil.delete("comment:reply_by_time:" + comment.getTopId());
|
|
|
|
redisUtil.delete("comment:reply_by_time:" + comment.getTopId());
|
|
|
|
redisUtil.delete("comment:reply_by_hot:" + comment.getTopId());
|
|
|
|
redisUtil.delete("comment:reply_by_hot:" + comment.getTopId());
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
|
|
|
|
int delete = commentMapper.deleteById(id);
|
|
|
|
|
|
|
|
if(delete <= 0){
|
|
|
|
|
|
|
|
throw new PostException("删除评论失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Post post = postMapper.selectById(comment.getPostId());
|
|
|
|
|
|
|
|
post.setCommentCount(post.getCommentCount() - delete);
|
|
|
|
|
|
|
|
postMapper.updateById(post);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Comment parentComment = commentMapper.selectById(comment.getParentCommentId());
|
|
|
|
|
|
|
|
Comment topComment = commentMapper.selectById(comment.getTopId());
|
|
|
|
|
|
|
|
parentComment.setReplyCount(parentComment.getReplyCount() - delete);
|
|
|
|
|
|
|
|
topComment.setReplyCount(topComment.getReplyCount() - delete);
|
|
|
|
|
|
|
|
updateById(parentComment);
|
|
|
|
|
|
|
|
updateById(topComment);
|
|
|
|
|
|
|
|
|
|
|
|
redisUtil.zRemove("comment:reply_by_time:" + comment.getTopId(), comment.getId());
|
|
|
|
redisUtil.zRemove("comment:reply_by_time:" + comment.getTopId(), comment.getId());
|
|
|
|
redisUtil.zRemove("comment:reply_by_hot:" + comment.getTopId(), comment.getId());
|
|
|
|
redisUtil.zRemove("comment:reply_by_hot:" + comment.getTopId(), comment.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO 如果根评论删除,那么其他评论怎么办,目前做法是删除其下所有的子评论
|
|
|
|
// TODO 如果根评论删除,那么其他评论怎么办,目前做法是删除其下所有的子评论
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|