From e1aa873e3313b2656d996fdd82189bddf0f6845d Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 6 May 2020 19:03:30 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ArticleServiceImpl.java | 60 ++++++++++--------- src/main/java/mapper/ArticleMapper.xml | 20 +++---- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java index 8e93a8d..271c40d 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java @@ -146,14 +146,6 @@ public class ArticleServiceImpl extends AbstractService
implements Arti } newArticle.setArticleTitle(articleTitle); newArticle.setArticleTags(articleTags); - if(StringUtils.isNotBlank(articleContentHtml)){ - Integer length = articleContentHtml.length(); - if(length > MAX_PREVIEW){ - length = 200; - } - String articlePreviewContent = articleContentHtml.substring(0,length); - newArticle.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent)); - } newArticle.setArticleStatus(article.getArticleStatus()); newArticle.setUpdatedTime(new Date()); articleMapper.updateArticleContent(newArticle.getIdArticle(),articleContent,articleContentHtml); @@ -175,6 +167,15 @@ public class ArticleServiceImpl extends AbstractService
implements Arti newArticle.setArticlePermalink(domain + "/draft/" + newArticle.getIdArticle()); newArticle.setArticleLink("/draft/" + newArticle.getIdArticle()); } + + if(StringUtils.isNotBlank(articleContentHtml)){ + Integer length = articleContentHtml.length(); + if(length > MAX_PREVIEW){ + length = MAX_PREVIEW; + } + String articlePreviewContent = articleContentHtml.substring(0,length); + newArticle.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent)); + } articleMapper.updateByPrimaryKeySelective(newArticle); map.put("id", newArticle.getIdArticle()); @@ -279,31 +280,36 @@ public class ArticleServiceImpl extends AbstractService
implements Arti } private ArticleDTO genArticle(ArticleDTO article, Integer type) { - Author author = userService.selectAuthor(article.getArticleAuthorId()); + Integer ARTICLE_LIST = 0; + Integer ARTICLE_VIEW = 1; + Integer ARTICLE_EDIT = 2; + Author author = genAuthor(article); article.setArticleAuthor(author); article.setTimeAgo(Utils.getTimeAgo(article.getUpdatedTime())); List tags = articleMapper.selectTags(article.getIdArticle()); article.setTags(tags); - ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle()); - if (type.equals(1) || type.equals(0)){ - article.setArticleContent(articleContent.getArticleContentHtml()); - } else if (type.equals(2)) { - article.setArticleContent(articleContent.getArticleContent()); - } - - if(StringUtils.isBlank(article.getArticlePreviewContent())){ - Integer length = articleContent.getArticleContentHtml().length(); - if(length > MAX_PREVIEW){ - length = 200; + if (!type.equals(ARTICLE_LIST)) { + ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle()); + if (type.equals(ARTICLE_VIEW)){ + article.setArticleContent(articleContent.getArticleContentHtml()); + // 获取评论列表数据 + List commentDTOList = commentService.getArticleComments(article.getIdArticle()); + article.setArticleComments(commentDTOList); + // 获取所属作品集列表数据 + List portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle()); + article.setPortfolios(portfolioArticleDTOList); + } else if (type.equals(ARTICLE_EDIT)) { + article.setArticleContent(articleContent.getArticleContent()); } - String articlePreviewContent = articleContent.getArticleContentHtml().substring(0,length); - article.setArticlePreviewContent(Html2TextUtil.getContent(articlePreviewContent)); } - List commentDTOList = commentService.getArticleComments(article.getIdArticle()); - article.setArticleComments(commentDTOList); - - List portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle()); - article.setPortfolios(portfolioArticleDTOList); return article; } + + private Author genAuthor(ArticleDTO article) { + Author author = new Author(); + author.setUserNickname(article.getArticleAuthorName()); + author.setUserAvatarURL(article.getArticleAuthorAvatarUrl()); + author.setIdUser(article.getArticleAuthorId()); + return author; + } } diff --git a/src/main/java/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml index 526982c..3aac306 100644 --- a/src/main/java/mapper/ArticleMapper.xml +++ b/src/main/java/mapper/ArticleMapper.xml @@ -78,10 +78,10 @@ delete from vertical_tag_article where id = #{idArticleTag}