From 34223b096cf6ad9d92c3702bb9529e764f523b11 Mon Sep 17 00:00:00 2001
From: inleft <inleft@qq.com>
Date: Wed, 02 Mar 2022 21:44:40 +0800
Subject: [PATCH] 调整查询

---
 snowy-main/src/main/java/vip/xiaonuo/modular/blogarticlecomment/controller/BlogArticleCommentOutsideController.java |   49 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticlecomment/controller/BlogArticleCommentOutsideController.java b/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticlecomment/controller/BlogArticleCommentOutsideController.java
index 544c4c4..fa50c0e 100644
--- a/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticlecomment/controller/BlogArticleCommentOutsideController.java
+++ b/snowy-main/src/main/java/vip/xiaonuo/modular/blogarticlecomment/controller/BlogArticleCommentOutsideController.java
@@ -25,6 +25,7 @@
 package vip.xiaonuo.modular.blogarticlecomment.controller;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -34,6 +35,7 @@
 import vip.xiaonuo.core.exception.BlogException;
 import vip.xiaonuo.core.pojo.response.ResponseData;
 import vip.xiaonuo.core.pojo.response.SuccessResponseData;
+import vip.xiaonuo.modular.blogarticle.entity.BlogArticle;
 import vip.xiaonuo.modular.blogarticle.service.BlogArticleService;
 import vip.xiaonuo.modular.blogarticlecomment.entity.BlogArticleComment;
 import vip.xiaonuo.modular.blogarticlecomment.entity.BlogCommentVo;
@@ -70,13 +72,18 @@
             if (addDto.getArticleId() == null) {
                 throw new BlogException("评论类型为日志评论,日志id不能为空");
             }
-            if (blogArticleService.getById(addDto.getId()) == null) {
+            BlogArticle checkArticle = blogArticleService.getById(addDto.getArticleId());
+            if (checkArticle == null) {
                 throw new BlogException("查询不到相关日志");
+            }
+
+            if (checkArticle.getIsAllowedComment().equals(MyConstant.No)) {
+                throw new BlogException("该日志评论已经关闭..");
             }
         }
         BlogArticleComment insert = new BlogArticleComment();
         BeanUtil.copyProperties(addDto, insert);
-        insert.setIsCheck(MyConstant.No);
+        insert.setIsCheck(MyConstant.Yes);
         insert.setIsEnable(MyConstant.Yes);
         insert.setIsReceiveCallback(addDto.getIsReceiveMail());
 
@@ -99,15 +106,32 @@
         List<BlogArticleComment> commentList = blogArticleCommentService.lambdaQuery()
                 .eq(queryDto.getArticleId() != null, BlogArticleComment::getArticleId, queryDto.getArticleId())
                 .eq(BlogArticleComment::getCommentType, queryDto.getArticleId() == null ? MyConstant.CommentType.type_1 : MyConstant.CommentType.type_2)
+                .eq(BlogArticleComment::getIsCheck, MyConstant.Yes)
                 .eq(BlogArticleComment::getIsEnable, MyConstant.Yes)
-                .eq(BlogArticleComment::getParentId,0)
+                .eq(BlogArticleComment::getParentId, 0)
                 .orderByDesc(BlogArticleComment::getCreateDate)
                 .page(queryPage).getRecords();
 
+        int limitCount = 2;
         List<BlogCommentVo> res = commentList.stream().map(e -> {
                     BlogCommentVo vo = new BlogCommentVo();
                     BeanUtil.copyProperties(e, vo);
+                    vo.setIsHasNext(MyConstant.No);
+                    List<BlogCommentVo> replyList = blogArticleCommentService.getReplyListById(e.getId(), limitCount);
+                    vo.setReplyList(replyList);
 
+                    if (e.getAuthStatus().equals(MyConstant.AuthStatus.privateCode)) {
+                        vo.setCommentContent(MyConstant.privateComment);
+                    }
+
+                    if (CollUtil.isNotEmpty(replyList)
+                            && blogArticleCommentService.lambdaQuery()
+                            .eq(BlogArticleComment::getParentId, e.getId())
+                            .eq(BlogArticleComment::getIsCheck, MyConstant.Yes)
+                            .eq(BlogArticleComment::getIsEnable, MyConstant.Yes)
+                            .count() > limitCount) {
+                        vo.setIsHasNext(MyConstant.Yes);
+                    }
                     return vo;
                 }
         ).collect(Collectors.toList());
@@ -115,4 +139,23 @@
         queryPage.setRecords(res);
         return new SuccessResponseData(queryPage);
     }
+
+    @GetMapping("/blogComment/queryBlogCommentSubList")
+    @BusinessLog(title = "外部blog系统_blog留言/评论子列表_查询", opType = LogAnnotionOpTypeEnum.QUERY)
+    public ResponseData queryBlogCommentSubList(BlogCommentQueryDto queryDto) {
+        if (queryDto.getArticleId() != null && blogArticleCommentService.getById(queryDto.getCommentId()) == null) {
+            throw new BlogException("查询不到相关评论");
+        }
+
+
+        List<BlogCommentVo> replyList = blogArticleCommentService.getReplyListById(queryDto.getCommentId(), null);
+//        for (BlogCommentVo vo : replyList) {
+//            vo.setIsHasNext(MyConstant.No);
+//            if (vo.getAuthStatus().equals(MyConstant.AuthStatus.privateCode)) {
+//                vo.setCommentContent(MyConstant.privateComment);
+//            }
+//        }
+
+        return new SuccessResponseData(replyList);
+    }
 }

--
Gitblit v1.9.1