🐛 删除文章未使用标签
This commit is contained in:
parent
c2b576a811
commit
ee1de2f785
@ -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;
|
||||
|
@ -111,4 +111,11 @@ public interface ArticleMapper extends Mapper<Article> {
|
||||
* @return
|
||||
*/
|
||||
List<ArticleDTO> selectDrafts(@Param("idUser") Integer idUser);
|
||||
|
||||
/**
|
||||
* 删除未使用的文章标签
|
||||
* @param idArticleTag
|
||||
* @return
|
||||
*/
|
||||
Integer deleteUnusedArticleTag(@Param("idArticleTag") Integer idArticleTag);
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
|
||||
String articleTags = article.getArticleTags();
|
||||
if(StringUtils.isNotBlank(articleTags)){
|
||||
String[] tags = articleTags.split(",");
|
||||
List<ArticleTagDTO> 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<ArticleTagDTO> articleTagDTOList = articleMapper.selectTags(article.getIdArticle());
|
||||
if(tag == null){
|
||||
tag = new Tag();
|
||||
tag.setTagTitle(tags[i]);
|
||||
@ -59,6 +59,11 @@ public class TagServiceImpl extends AbstractService<Tag> 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<Tag> implements TagService {
|
||||
addUserTag = true;
|
||||
}
|
||||
}
|
||||
articleTagDTOList.forEach(articleTagDTO -> {
|
||||
articleMapper.deleteUnusedArticleTag(articleTagDTO.getIdArticleTag());
|
||||
});
|
||||
if(addTagArticle){
|
||||
tagMapper.insertTagArticle(tag.getIdTag(),article.getIdArticle());
|
||||
}
|
||||
|
@ -51,11 +51,13 @@
|
||||
<result column="updated_time" property="updatedTime"/>
|
||||
</resultMap>
|
||||
<resultMap id="ArticleTagDTOResultMap" type="com.rymcu.vertical.dto.ArticleTagDTO">
|
||||
<id column="id" property="idTag"/>
|
||||
<id column="tag_title" property="tagTitle"/>
|
||||
<id column="tag_icon_path" property="tagIconPath"/>
|
||||
<id column="tag_uri" property="tagUri"/>
|
||||
<id column="tag_description" property="tagDescription"/>
|
||||
<id column="id" property="idArticleTag"/>
|
||||
<result column="id_tag" property="idTag"></result>
|
||||
<result column="id_article" property="idArticle"></result>
|
||||
<result column="tag_title" property="tagTitle"></result>
|
||||
<result column="tag_icon_path" property="tagIconPath"></result>
|
||||
<result column="tag_uri" property="tagUri"></result>
|
||||
<result column="tag_description" property="tagDescription"></result>
|
||||
</resultMap>
|
||||
<insert id="insertArticleContent">
|
||||
insert into vertical_article_content (id_article,article_content,article_content_html,created_time,updated_time)
|
||||
@ -70,6 +72,9 @@
|
||||
<delete id="deleteTagArticle">
|
||||
delete from vertical_tag_article where id_article = #{id}
|
||||
</delete>
|
||||
<delete id="deleteUnusedArticleTag">
|
||||
delete from vertical_tag_article where id = #{idArticleTag}
|
||||
</delete>
|
||||
<select id="selectArticles" resultMap="DTOResultMap">
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id where article_status = '0' order by updated_time desc
|
||||
</select>
|
||||
@ -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
|
||||
</select>
|
||||
<select id="selectTags" resultMap="ArticleTagDTOResultMap">
|
||||
select vt.id, vt.tag_title, vt.tag_icon_path, vt.tag_uri, vt.tag_description from vertical_tag vt left join vertical_tag_article vta on vt.id = vta.id_tag where vta.id_article = #{idArticle}
|
||||
select vta.id, vta.id_tag, vta.id_article, vt.tag_title, vt.tag_icon_path, vt.tag_uri, vt.tag_description from vertical_tag vt left join vertical_tag_article vta on vt.id = vta.id_tag where vta.id_article = #{idArticle}
|
||||
</select>
|
||||
<select id="selectDrafts" resultMap="DTOResultMap">
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art left join vertical_user su on art.article_author_id = su.id where article_status = '1' and art.article_author_id = #{idUser} order by updated_time desc
|
||||
|
Loading…
Reference in New Issue
Block a user