From ee1de2f785857aaf6912e78b25cf18eea7165b2c Mon Sep 17 00:00:00 2001 From: x ronger Date: Sat, 14 Mar 2020 17:21:05 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E5=88=A0=E9=99=A4=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/vertical/dto/ArticleTagDTO.java | 5 +++++ .../rymcu/vertical/mapper/ArticleMapper.java | 7 +++++++ .../vertical/service/impl/TagServiceImpl.java | 10 +++++++++- src/main/java/mapper/ArticleMapper.xml | 17 +++++++++++------ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/dto/ArticleTagDTO.java b/src/main/java/com/rymcu/vertical/dto/ArticleTagDTO.java index 7eb15f7..ed69468 100644 --- a/src/main/java/com/rymcu/vertical/dto/ArticleTagDTO.java +++ b/src/main/java/com/rymcu/vertical/dto/ArticleTagDTO.java @@ -7,8 +7,13 @@ import lombok.Data; */ @Data public class ArticleTagDTO { + + private Integer idArticleTag; + private Integer idTag; + private Integer idArticle; + private String tagTitle; private String tagUri; diff --git a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java index 05bc666..d7408b6 100644 --- a/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/ArticleMapper.java @@ -111,4 +111,11 @@ public interface ArticleMapper extends Mapper
{ * @return */ List selectDrafts(@Param("idUser") Integer idUser); + + /** + * 删除未使用的文章标签 + * @param idArticleTag + * @return + */ + Integer deleteUnusedArticleTag(@Param("idArticleTag") Integer idArticleTag); } diff --git a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java index 256e56a..1b658cb 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java @@ -41,13 +41,13 @@ public class TagServiceImpl extends AbstractService implements TagService { String articleTags = article.getArticleTags(); if(StringUtils.isNotBlank(articleTags)){ String[] tags = articleTags.split(","); + List articleTagDTOList = articleMapper.selectTags(article.getIdArticle()); for (int i = 0; i < tags.length; i++) { boolean addTagArticle = false; boolean addUserTag = false; Tag tag = new Tag(); tag.setTagTitle(tags[i]); tag = tagMapper.selectOne(tag); - List articleTagDTOList = articleMapper.selectTags(article.getIdArticle()); if(tag == null){ tag = new Tag(); tag.setTagTitle(tags[i]); @@ -59,6 +59,11 @@ public class TagServiceImpl extends AbstractService implements TagService { addTagArticle = true; addUserTag = true; } else { + for(ArticleTagDTO articleTag : articleTagDTOList) { + if (articleTag.getIdTag().equals(tag.getIdTag())) { + articleTagDTOList.remove(articleTag); + } + } Integer count = tagMapper.selectCountTagArticleById(tag.getIdTag(),article.getIdArticle()); if(count == 0){ tag.setTagArticleCount(tag.getTagArticleCount() + 1); @@ -70,6 +75,9 @@ public class TagServiceImpl extends AbstractService implements TagService { addUserTag = true; } } + articleTagDTOList.forEach(articleTagDTO -> { + articleMapper.deleteUnusedArticleTag(articleTagDTO.getIdArticleTag()); + }); if(addTagArticle){ tagMapper.insertTagArticle(tag.getIdTag(),article.getIdArticle()); } diff --git a/src/main/java/mapper/ArticleMapper.xml b/src/main/java/mapper/ArticleMapper.xml index 49335d9..d2426a5 100644 --- a/src/main/java/mapper/ArticleMapper.xml +++ b/src/main/java/mapper/ArticleMapper.xml @@ -51,11 +51,13 @@ - - - - - + + + + + + + insert into vertical_article_content (id_article,article_content,article_content_html,created_time,updated_time) @@ -70,6 +72,9 @@ delete from vertical_tag_article where id_article = #{id} + + delete from vertical_tag_article where id = #{idArticleTag} + @@ -95,7 +100,7 @@ select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on su.id = #{idUser} and art.article_author_id = su.id where article_author_id = #{idUser} order by updated_time desc