From 3d64707c9b0960c6261db24a07a0f317aec0abc1 Mon Sep 17 00:00:00 2001 From: x ronger Date: Wed, 23 Sep 2020 22:39:08 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E4=BF=AE=E6=94=B9=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E6=A0=87=E7=AD=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rymcu/vertical/mapper/ArticleMapper.java | 8 +++++++ .../vertical/service/ArticleService.java | 8 +++++++ .../service/impl/ArticleServiceImpl.java | 22 +++++++++++++++---- .../web/api/article/ArticleController.java | 7 ++++++ src/main/java/mapper/ArticleMapper.xml | 3 +++ 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java index 8c74ece..b9e6863 100644 --- a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java @@ -136,4 +136,12 @@ public interface ArticleMapper extends Mapper
{ * @return */ List selectPortfolioArticles(@Param("idArticle") Integer idArticle); + + /** + * 更新文章标签 + * @param idArticle + * @param tags + * @return + */ + Integer updateArticleTags(@Param("idArticle") Integer idArticle, @Param("tags") String tags); } diff --git a/src/main/java/com/rymcu/vertical/service/ArticleService.java b/src/main/java/com/rymcu/vertical/service/ArticleService.java index 65f6718..74ead8d 100644 --- a/src/main/java/com/rymcu/vertical/service/ArticleService.java +++ b/src/main/java/com/rymcu/vertical/service/ArticleService.java @@ -105,4 +105,12 @@ public interface ArticleService extends Service
{ * @return */ List selectUnbindArticles(Integer idPortfolio, String searchText, Integer idUser); + + /** + * 更新文章标签 + * @param idArticle + * @param tags + * @return + */ + Map updateTags(Integer idArticle, String tags) throws UnsupportedEncodingException, BaseApiException; } 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 94124f3..d66f258 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/ArticleServiceImpl.java @@ -25,10 +25,7 @@ import tk.mybatis.mapper.entity.Condition; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author ronger @@ -294,6 +291,23 @@ public class ArticleServiceImpl extends AbstractService
implements Arti return list; } + @Override + @Transactional(rollbackFor = Exception.class) + public Map updateTags(Integer idArticle, String tags) throws UnsupportedEncodingException, BaseApiException { + Map map = new HashMap(2); + Article article = articleMapper.selectByPrimaryKey(idArticle); + if (Objects.nonNull(article)) { + article.setArticleTags(tags); + articleMapper.updateArticleTags(idArticle, tags); + tagService.saveTagArticle(article); + map.put("success", true); + } else { + map.put("success", false); + map.put("message", "更新失败,文章不存在!"); + } + return map; + } + private ArticleDTO genArticle(ArticleDTO article, Integer type) { Integer ARTICLE_LIST = 0; Integer ARTICLE_VIEW = 1; diff --git a/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java b/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java index 13aab2c..1bf5b85 100644 --- a/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java +++ b/src/main/java/com/rymcu/vertical/web/api/article/ArticleController.java @@ -6,6 +6,7 @@ import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResultGenerator; import com.rymcu.vertical.dto.ArticleDTO; import com.rymcu.vertical.dto.CommentDTO; +import com.rymcu.vertical.entity.Article; import com.rymcu.vertical.service.ArticleService; import com.rymcu.vertical.service.CommentService; import com.rymcu.vertical.util.Utils; @@ -80,4 +81,10 @@ public class ArticleController { return GlobalResultGenerator.genSuccessResult(map); } + @PostMapping("/{id}/update-tags") + public GlobalResult updateTags(@PathVariable Integer id, @RequestBody Article article) throws BaseApiException, UnsupportedEncodingException { + Map map = articleService.updateTags(id, article.getArticleTags()); + return GlobalResultGenerator.genSuccessResult(map); + } + } diff --git a/src/main/java/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml index 9d64f96..a66e180 100644 --- a/src/main/java/mapper/ArticleMapper.xml +++ b/src/main/java/mapper/ArticleMapper.xml @@ -71,6 +71,9 @@ update vertical_article set article_view_count = #{articleViewCount} where id = #{id} + + update vertical_article set article_tags = #{tags} where id = #{idArticle} + delete from vertical_tag_article where id_article = #{id}