From d4d5d8b6168f3f140372d145c8a9918d4703c289 Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 30 Jun 2021 11:47:47 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E6=94=B9=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=B1=95=E7=A4=BA=E6=95=88=E6=9E=9C=E5=90=8E?= =?UTF-8?q?,=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/LuceneServiceImpl.java | 35 ++++++++++++++++++- .../service/impl/ArticleServiceImpl.java | 4 --- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java b/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java index 294a93e..ed6cbc2 100644 --- a/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java +++ b/src/main/java/com/rymcu/forest/lucene/service/impl/LuceneServiceImpl.java @@ -1,6 +1,11 @@ package com.rymcu.forest.lucene.service.impl; import com.rymcu.forest.dto.ArticleDTO; +import com.rymcu.forest.dto.ArticleTagDTO; +import com.rymcu.forest.dto.Author; +import com.rymcu.forest.dto.PortfolioArticleDTO; +import com.rymcu.forest.entity.ArticleContent; +import com.rymcu.forest.entity.User; import com.rymcu.forest.lucene.lucene.ArticleBeanIndex; import com.rymcu.forest.lucene.lucene.IKAnalyzer; import com.rymcu.forest.lucene.mapper.ArticleLuceneMapper; @@ -9,7 +14,10 @@ import com.rymcu.forest.lucene.service.LuceneService; import com.rymcu.forest.lucene.util.ArticleIndexUtil; import com.rymcu.forest.lucene.util.LucenePath; import com.rymcu.forest.lucene.util.SearchUtil; +import com.rymcu.forest.mapper.ArticleMapper; +import com.rymcu.forest.service.UserService; import com.rymcu.forest.util.Html2TextUtil; +import com.rymcu.forest.util.Utils; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Document; @@ -44,6 +52,10 @@ public class LuceneServiceImpl implements LuceneService { @Resource private ArticleLuceneMapper luceneMapper; + @Resource + private ArticleMapper articleMapper; + @Resource + private UserService userService; /** * 将文章的数据解析为一个个关键字词存储到索引文件中 @@ -198,6 +210,27 @@ public class LuceneServiceImpl implements LuceneService { @Override public List getArticlesByIds(String[] ids) { - return luceneMapper.getArticlesByIds(ids); + List list = luceneMapper.getArticlesByIds(ids); + list.forEach(articleDTO -> genArticle(articleDTO)); + return list; + } + + private ArticleDTO genArticle(ArticleDTO article) { + Author author = genAuthor(article); + article.setArticleAuthor(author); + article.setTimeAgo(Utils.getTimeAgo(article.getUpdatedTime())); + List tags = articleMapper.selectTags(article.getIdArticle()); + article.setTags(tags); + return article; + } + + private Author genAuthor(ArticleDTO article) { + Author author = new Author(); + User user = userService.findById(String.valueOf(article.getArticleAuthorId())); + author.setUserNickname(article.getArticleAuthorName()); + author.setUserAvatarURL(article.getArticleAuthorAvatarUrl()); + author.setIdUser(article.getArticleAuthorId()); + author.setUserAccount(user.getAccount()); + return author; } } diff --git a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java index dbcf9a5..7db94a9 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java @@ -11,12 +11,10 @@ import com.rymcu.forest.entity.User; import com.rymcu.forest.lucene.service.LuceneService; import com.rymcu.forest.mapper.ArticleMapper; import com.rymcu.forest.service.ArticleService; -import com.rymcu.forest.service.CommentService; import com.rymcu.forest.service.TagService; import com.rymcu.forest.service.UserService; import com.rymcu.forest.util.*; import com.rymcu.forest.web.api.exception.BaseApiException; -import lombok.extern.java.Log; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.apache.commons.text.StringEscapeUtils; @@ -44,8 +42,6 @@ public class ArticleServiceImpl extends AbstractService
implements Arti @Resource private UserService userService; @Resource - private CommentService commentService; - @Resource private LuceneService luceneService; @Value("${resource.domain}")