|
@@ -1,6 +1,8 @@
|
|
|
package com.etotem.cfc.service;
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.etotem.cfc.entity.Article;
|
|
|
import com.etotem.cfc.entity.ArticleComment;
|
|
import com.etotem.cfc.entity.ArticleComment;
|
|
|
import com.etotem.cfc.entity.User;
|
|
import com.etotem.cfc.entity.User;
|
|
|
import com.etotem.cfc.mapper.ArticleCommentMapper;
|
|
import com.etotem.cfc.mapper.ArticleCommentMapper;
|
|
@@ -11,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
public class ArticleCommentService {
|
|
public class ArticleCommentService {
|
|
@@ -151,6 +154,117 @@ public class ArticleCommentService {
|
|
|
return articleCommentMapper.selectList(wrapper);
|
|
return articleCommentMapper.selectList(wrapper);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public List<Map<String, Object>> getPendingCommentsWithDetail(Long articleId, Long userId, String role) {
|
|
|
|
|
+ LambdaQueryWrapper<ArticleComment> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(ArticleComment::getStatus, "pending");
|
|
|
|
|
+
|
|
|
|
|
+ if (articleId != null) {
|
|
|
|
|
+ wrapper.eq(ArticleComment::getArticleId, articleId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 非管理员则只看自己文章的评论
|
|
|
|
|
+ if (!"admin".equals(role) && userId != null) {
|
|
|
|
|
+ List<Article> myArticles = articleMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<Article>().eq(Article::getCreatedBy, userId)
|
|
|
|
|
+ );
|
|
|
|
|
+ if (myArticles.isEmpty()) return new ArrayList<>();
|
|
|
|
|
+ Set<Long> articleIds = myArticles.stream().map(Article::getId).collect(Collectors.toSet());
|
|
|
|
|
+ wrapper.in(ArticleComment::getArticleId, articleIds);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ wrapper.orderByDesc(ArticleComment::getCreatedAt);
|
|
|
|
|
+ List<ArticleComment> comments = articleCommentMapper.selectList(wrapper);
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, User> userCache = new HashMap<>();
|
|
|
|
|
+ Map<Long, Article> articleCache = new HashMap<>();
|
|
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (ArticleComment c : comments) {
|
|
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
|
|
+ item.put("id", c.getId());
|
|
|
|
|
+ item.put("articleId", c.getArticleId());
|
|
|
|
|
+ item.put("parentId", c.getParentId());
|
|
|
|
|
+ item.put("replyToId", c.getReplyToId());
|
|
|
|
|
+ item.put("content", c.getContent());
|
|
|
|
|
+ item.put("status", c.getStatus());
|
|
|
|
|
+ item.put("createdAt", c.getCreatedAt());
|
|
|
|
|
+ item.put("auditBy", c.getAuditBy());
|
|
|
|
|
+ item.put("auditAt", c.getAuditAt());
|
|
|
|
|
+
|
|
|
|
|
+ User user = getUserCached(c.getUserId(), userCache);
|
|
|
|
|
+ if (user != null) {
|
|
|
|
|
+ item.put("userName", user.getNickname() != null ? user.getNickname() : user.getPhone());
|
|
|
|
|
+ item.put("userAvatar", user.getAvatar());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Article article = getArticleCached(c.getArticleId(), articleCache);
|
|
|
|
|
+ if (article != null) {
|
|
|
|
|
+ item.put("articleTitle", article.getTitle());
|
|
|
|
|
+ item.put("articleAuthorId", article.getCreatedBy());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ result.add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 管理员获取评论列表(分页,按状态筛选,含用户和文章信息)
|
|
|
|
|
+ */
|
|
|
|
|
+ public Page<Map<String, Object>> getAdminCommentList(Long articleId, String status, int page, int size) {
|
|
|
|
|
+ LambdaQueryWrapper<ArticleComment> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ if (articleId != null) {
|
|
|
|
|
+ wrapper.eq(ArticleComment::getArticleId, articleId);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (status != null && !status.isEmpty()) {
|
|
|
|
|
+ wrapper.eq(ArticleComment::getStatus, status);
|
|
|
|
|
+ }
|
|
|
|
|
+ wrapper.orderByDesc(ArticleComment::getCreatedAt);
|
|
|
|
|
+
|
|
|
|
|
+ Page<ArticleComment> p = articleCommentMapper.selectPage(new Page<>(page, size), wrapper);
|
|
|
|
|
+ Page<Map<String, Object>> result = new Page<>(p.getCurrent(), p.getSize(), p.getTotal());
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, User> userCache = new HashMap<>();
|
|
|
|
|
+ Map<Long, Article> articleCache = new HashMap<>();
|
|
|
|
|
+ List<Map<String, Object>> records = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (ArticleComment c : p.getRecords()) {
|
|
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
|
|
+ item.put("id", c.getId());
|
|
|
|
|
+ item.put("articleId", c.getArticleId());
|
|
|
|
|
+ item.put("parentId", c.getParentId());
|
|
|
|
|
+ item.put("replyToId", c.getReplyToId());
|
|
|
|
|
+ item.put("content", c.getContent());
|
|
|
|
|
+ item.put("status", c.getStatus());
|
|
|
|
|
+ item.put("createdAt", c.getCreatedAt());
|
|
|
|
|
+ item.put("auditBy", c.getAuditBy());
|
|
|
|
|
+ item.put("auditAt", c.getAuditAt());
|
|
|
|
|
+
|
|
|
|
|
+ User user = getUserCached(c.getUserId(), userCache);
|
|
|
|
|
+ if (user != null) {
|
|
|
|
|
+ item.put("userName", user.getNickname() != null ? user.getNickname() : user.getPhone());
|
|
|
|
|
+ item.put("userAvatar", user.getAvatar());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Article article = getArticleCached(c.getArticleId(), articleCache);
|
|
|
|
|
+ if (article != null) {
|
|
|
|
|
+ item.put("articleTitle", article.getTitle());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ records.add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ result.setRecords(records);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Article getArticleCached(Long articleId, Map<Long, Article> cache) {
|
|
|
|
|
+ if (articleId == null) return null;
|
|
|
|
|
+ if (!cache.containsKey(articleId)) {
|
|
|
|
|
+ cache.put(articleId, articleMapper.selectById(articleId));
|
|
|
|
|
+ }
|
|
|
|
|
+ return cache.get(articleId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取用户的评论
|
|
* 获取用户的评论
|
|
|
*/
|
|
*/
|