Browse Source

青涩知夏:评论管理

huanghuijie 4 years ago
parent
commit
9010154229

+ 2 - 0
src/main/java/com/sumbytes/helloblog/auth/dao/AuthUserDao.java

@@ -15,4 +15,6 @@ public interface AuthUserDao extends BaseDao<AuthUser> {
 
     String selectAvatar();
 
+    AuthUser selectAdmin();
+
 }

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

@@ -9,12 +9,7 @@ import com.sumbytes.helloblog.posts.service.PostsCommentsService;
 import com.sumbytes.system.enums.RoleEnum;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * @author sumbytes
@@ -33,8 +28,14 @@ public class PostsCommentsController {
         return this.postsCommentsService.savePostsComments(postsCommentsVO);
     }
 
+    @LoginRequired(role = RoleEnum.USER)
+    @PostMapping("/admin/v1/reply")
+    public Result replyComments(@RequestBody PostsCommentsVO postsCommentsVO) {
+        return this.postsCommentsService.replyComments(postsCommentsVO);
+    }
+
     @LoginRequired
-    @PostMapping("/comments/v1/{id}")
+    @DeleteMapping("/comments/v1/{id}")
     public Result deletePostsComments(@PathVariable(value = "id") Long id) {
         return this.postsCommentsService.deletePostsComments(id);
     }

+ 3 - 0
src/main/java/com/sumbytes/helloblog/posts/service/PostsCommentsService.java

@@ -36,4 +36,7 @@ public interface PostsCommentsService extends BaseService<PostsComments> {
 
 
     Result getPostsComment(Long id);
+
+    Result replyComments(PostsCommentsVO postsCommentsVO);
+
 }

+ 22 - 1
src/main/java/com/sumbytes/helloblog/posts/service/impl/PostsCommentsServiceImpl.java

@@ -9,8 +9,11 @@ import com.sumbytes.common.enums.ErrorEnum;
 import com.sumbytes.common.util.ExceptionUtil;
 import com.sumbytes.common.util.PageUtil;
 import com.sumbytes.common.util.SessionUtil;
+import com.sumbytes.helloblog.auth.dao.AuthUserDao;
+import com.sumbytes.helloblog.auth.domain.po.AuthUser;
 import com.sumbytes.helloblog.posts.dao.PostsCommentsDao;
 import com.sumbytes.helloblog.posts.dao.PostsDao;
+import com.sumbytes.helloblog.posts.domain.po.Posts;
 import com.sumbytes.helloblog.posts.domain.po.PostsComments;
 import com.sumbytes.helloblog.posts.domain.vo.PostsCommentsVO;
 import com.sumbytes.helloblog.posts.service.PostsCommentsService;
@@ -37,9 +40,11 @@ public class PostsCommentsServiceImpl extends BaseServiceImpl<PostsCommentsDao,
     @Autowired
     private PostsDao postsDao;
 
+    @Autowired
+    private AuthUserDao authUserDao;
+
     @Override
     public Result savePostsComments(PostsCommentsVO postsCommentsVO) {
-
         UserSessionVO userSessionInfo = SessionUtil.getUserSessionInfo();
         PostsComments postsComments = new PostsComments();
         postsComments.setAuthorId(userSessionInfo.getId());
@@ -70,6 +75,22 @@ public class PostsCommentsServiceImpl extends BaseServiceImpl<PostsCommentsDao,
         return Result.createWithSuccessMessage();
     }
 
+
+    @Override
+    public Result replyComments(PostsCommentsVO postsCommentsVO) {
+        AuthUser authUser=authUserDao.selectAdmin();
+        PostsComments postsComments=postsCommentsDao.selectById(postsCommentsVO.getParentId())
+                .setParentId(postsCommentsVO.getParentId())
+                .setContent(postsCommentsVO.getContent())
+                .setAuthorId(authUser.getId())
+                .setCreateTime(LocalDateTime.now());
+        this.postsCommentsDao.insert(postsComments);
+        String treePath = postsComments.getTreePath() + postsComments.getId() + Constants.TREE_PATH;
+        this.postsCommentsDao.updateById(postsComments.setTreePath(treePath));
+        this.postsDao.incrementComments( postsCommentsVO.getPostsId());
+        return Result.createWithSuccessMessage();
+    }
+
     @Override
     public Result getPostsCommentsByPostsIdList(PostsCommentsVO postsCommentsVO) {
 

+ 5 - 0
src/main/resources/mapper/auth/AuthUserMapper.xml

@@ -15,5 +15,10 @@
     <select id="selectAvatar" resultType="java.lang.String">
         SELECT avatar FROM hello_blog_auth_user WHERE role_id=2 limit 1
     </select>
+    <select id="selectAdmin" resultType="com.sumbytes.helloblog.auth.domain.po.AuthUser">
+        SELECT `id`, `social_id`, `password`, `name`, `role_id`, `email`, `introduction`, `avatar`, `create_time`, `access_key`, `secret_key`, `status`
+        FROM hello_blog_auth_user
+        WHERE role_id=2 limit 1
+    </select>
 
 </mapper>