From 1ef5f5c898247262d56b389c67398972484c1e3b Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 18 Dec 2020 14:20:47 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=96=87=E7=AB=A0=E4=BC=98?= =?UTF-8?q?=E9=80=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/dto/ArticleDTO.java | 2 ++ .../java/com/rymcu/forest/entity/Article.java | 2 +- .../rymcu/forest/mapper/ArticleMapper.java | 8 ++++++ .../rymcu/forest/service/ArticleService.java | 10 ++++++++ .../service/impl/ArticleServiceImpl.java | 25 ++++++++++++++----- .../web/api/article/ArticleController.java | 6 +++++ src/main/java/mapper/ArticleMapper.xml | 4 +++ 7 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/rymcu/forest/dto/ArticleDTO.java b/src/main/java/com/rymcu/forest/dto/ArticleDTO.java index 0950118..8d50f66 100644 --- a/src/main/java/com/rymcu/forest/dto/ArticleDTO.java +++ b/src/main/java/com/rymcu/forest/dto/ArticleDTO.java @@ -53,4 +53,6 @@ public class ArticleDTO { private List portfolios; private Integer sortNo; + /** 0:非优选1:优选;0 */ + private String articlePerfect; } diff --git a/src/main/java/com/rymcu/forest/entity/Article.java b/src/main/java/com/rymcu/forest/entity/Article.java index 3fded31..2a16cea 100644 --- a/src/main/java/com/rymcu/forest/entity/Article.java +++ b/src/main/java/com/rymcu/forest/entity/Article.java @@ -36,7 +36,7 @@ public class Article implements Serializable,Cloneable { private String articlePreviewContent; /** 评论总数 */ private Integer articleCommentCount; - /** 0:非优选1:优选;0 */ + /** 0:非优选1:优选; */ private String articlePerfect; /** 文章永久链接 */ private String articlePermalink; diff --git a/src/main/java/com/rymcu/forest/mapper/ArticleMapper.java b/src/main/java/com/rymcu/forest/mapper/ArticleMapper.java index bb54796..4f9d5ca 100644 --- a/src/main/java/com/rymcu/forest/mapper/ArticleMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/ArticleMapper.java @@ -176,4 +176,12 @@ public interface ArticleMapper extends Mapper
{ * @return */ List selectPortfolioArticlesByIdPortfolioAndSortNo(@Param("idPortfolio") Integer idPortfolio, @Param("sortNo") Integer sortNo); + + /** + * 更新文章优选状态 + * @param idArticle + * @param articlePerfect + * @return + */ + int updatePerfect(@Param("idArticle") Integer idArticle, @Param("articlePerfect") String articlePerfect); } diff --git a/src/main/java/com/rymcu/forest/service/ArticleService.java b/src/main/java/com/rymcu/forest/service/ArticleService.java index 9454bad..f839ed5 100644 --- a/src/main/java/com/rymcu/forest/service/ArticleService.java +++ b/src/main/java/com/rymcu/forest/service/ArticleService.java @@ -111,6 +111,16 @@ public interface ArticleService extends Service
{ * @param idArticle * @param tags * @return + * @throws UnsupportedEncodingException + * @throws BaseApiException */ Map updateTags(Integer idArticle, String tags) throws UnsupportedEncodingException, BaseApiException; + + /** + * 更新文章优选状态 + * @param idArticle + * @param articlePerfect + * @return + */ + Map updatePerfect(Integer idArticle, String articlePerfect); } 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 a9ba491..faaa500 100644 --- a/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/ArticleServiceImpl.java @@ -334,24 +334,37 @@ public class ArticleServiceImpl extends AbstractService
implements Arti return map; } + @Override + public Map updatePerfect(Integer idArticle, String articlePerfect) { + Map map = new HashMap(2); + int result = articleMapper.updatePerfect(idArticle, articlePerfect); + if (result == 0) { + map.put("success", false); + map.put("message", "设置优选文章失败!"); + } else { + map.put("success", true); + } + return map; + } + private ArticleDTO genArticle(ArticleDTO article, Integer type) { - Integer ARTICLE_LIST = 0; - Integer ARTICLE_VIEW = 1; - Integer ARTICLE_EDIT = 2; + Integer articleList = 0; + Integer articleView = 1; + Integer articleEdit = 2; Author author = genAuthor(article); article.setArticleAuthor(author); article.setTimeAgo(Utils.getTimeAgo(article.getUpdatedTime())); List tags = articleMapper.selectTags(article.getIdArticle()); article.setTags(tags); - if (!type.equals(ARTICLE_LIST)) { + if (!type.equals(articleList)) { ArticleContent articleContent = articleMapper.selectArticleContent(article.getIdArticle()); - if (type.equals(ARTICLE_VIEW)) { + if (type.equals(articleView)) { article.setArticleContent(articleContent.getArticleContentHtml()); // 获取所属作品集列表数据 List portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle()); portfolioArticleDTOList.forEach(portfolioArticleDTO -> genPortfolioArticles(portfolioArticleDTO)); article.setPortfolios(portfolioArticleDTOList); - } else if (type.equals(ARTICLE_EDIT)) { + } else if (type.equals(articleEdit)) { article.setArticleContent(articleContent.getArticleContent()); } else { article.setArticleContent(articleContent.getArticleContentHtml()); diff --git a/src/main/java/com/rymcu/forest/web/api/article/ArticleController.java b/src/main/java/com/rymcu/forest/web/api/article/ArticleController.java index 118bf38..8f347f4 100644 --- a/src/main/java/com/rymcu/forest/web/api/article/ArticleController.java +++ b/src/main/java/com/rymcu/forest/web/api/article/ArticleController.java @@ -87,4 +87,10 @@ public class ArticleController { return GlobalResultGenerator.genSuccessResult(map); } + @PatchMapping("/update-perfect") + public GlobalResult updatePerfect(@RequestBody Article article) { + Map map = articleService.updatePerfect(article.getIdArticle(), article.getArticlePerfect()); + return GlobalResultGenerator.genSuccessResult(map); + } + } diff --git a/src/main/java/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml index b979420..626371b 100644 --- a/src/main/java/mapper/ArticleMapper.xml +++ b/src/main/java/mapper/ArticleMapper.xml @@ -38,6 +38,7 @@ + @@ -78,6 +79,9 @@ update vertical_article set article_link = #{articleLink}, article_permalink = #{articlePermalink}, article_preview_content = #{articlePreviewContent} where id = #{idArticle} + + update vertical_article set article_perfect = #{articlePerfect} where id = #{idArticle} + delete from vertical_tag_article where id_article = #{id}