Browse Source

青涩知夏:评论管理修复

huanghuijie 4 years ago
parent
commit
826a46048c

+ 1 - 1
src/main/java/com/sumbytes/helloblog/posts/controller/PostsCommentsController.java

@@ -52,7 +52,7 @@ public class PostsCommentsController {
     }
 
     @LoginRequired
-    @GetMapping("/comments/v1/get")
+    @GetMapping("/comments/v1/list")
     public Result getPostsCommentsList(PostsCommentsVO postsCommentsVO) {
         return this.postsCommentsService.getPostsCommentsList(postsCommentsVO);
     }

+ 10 - 5
src/main/java/com/sumbytes/helloblog/posts/service/impl/PostsCommentsServiceImpl.java

@@ -78,15 +78,20 @@ public class PostsCommentsServiceImpl extends BaseServiceImpl<PostsCommentsDao,
 
     @Override
     public Result replyComments(PostsCommentsVO postsCommentsVO) {
+        // 由于是使用后台管理系统直接评论,所以此处直接将评论对象设置为管理员
         AuthUser authUser=authUserDao.selectAdmin();
-        PostsComments postsComments=postsCommentsDao.selectById(postsCommentsVO.getParentId())
-                .setParentId(postsCommentsVO.getParentId())
+        PostsComments postsComments=postsCommentsDao.selectById(postsCommentsVO.getParentId());
+        // 准备更新前的参数内容
+        postsComments.setParentId(postsCommentsVO.getParentId())
                 .setContent(postsCommentsVO.getContent())
                 .setAuthorId(authUser.getId())
-                .setCreateTime(LocalDateTime.now());
+                .setCreateTime(LocalDateTime.now())
+                .setId(null);
+        // 添加评论
         this.postsCommentsDao.insert(postsComments);
-        String treePath = postsComments.getTreePath() + postsComments.getId() + Constants.TREE_PATH;
-        this.postsCommentsDao.updateById(postsComments.setTreePath(treePath));
+        // 增加完成后会默认获取id,此时需要将id,增加到层级结构当中
+        this.postsCommentsDao.updateById(postsComments.setTreePath(postsComments.getTreePath() + postsComments.getId() + Constants.TREE_PATH));
+        // 为文章添加评论数
         this.postsDao.incrementComments( postsCommentsVO.getPostsId());
         return Result.createWithSuccessMessage();
     }

+ 3 - 3
src/main/resources/mapper/posts/PostsCommentsMapper.xml

@@ -26,11 +26,10 @@
         hello_blog_posts_comments postsComments
         LEFT JOIN hello_blog_auth_user authUser ON postsComments.author_id = authUser.id
         LEFT JOIN hello_blog_posts_comments parentPostsComments ON postsComments.parent_id = parentPostsComments.id
-        LEFT JOIN hello_blog_auth_user parentAuthUser ON parentPostsComments.author_id = parentAuthUser.id
+        LEFT JOIN hello_blog_auth_user parentAuthUser ON parentAuthUser.id = ( SELECT author_id FROM hello_blog_posts_comments WHERE id = postsComments.parent_id )
         <where>
             postsComments.posts_id = #{postsId}
         </where>
-
         ORDER BY postsComments.id DESC
     </select>
 
@@ -46,7 +45,7 @@
         hello_blog_posts_comments postsComments
         LEFT JOIN hello_blog_auth_user authUser ON postsComments.author_id = authUser.id
         LEFT JOIN hello_blog_posts_comments parentPostsComments ON postsComments.id = parentPostsComments.parent_id
-        LEFT JOIN hello_blog_auth_user parentAuthUser ON parentPostsComments.author_id = parentAuthUser.id
+        LEFT JOIN hello_blog_auth_user parentAuthUser ON parentAuthUser.id = ( SELECT author_id FROM hello_blog_posts_comments WHERE id = postsComments.parent_id )
         LEFT JOIN hello_blog_posts posts ON posts.id = postsComments.posts_id
         <where>
             <if test="postsComments.keywords != null and postsComments.keywords != ''">
@@ -56,5 +55,6 @@
                 and postsComments.id=#{postsComments.id}
             </if>
         </where>
+        ORDER BY postsComments.id DESC
     </select>
 </mapper>