🐛 删除文章未使用标签
This commit is contained in:
parent
c2b576a811
commit
ee1de2f785
@ -7,8 +7,13 @@ import lombok.Data;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class ArticleTagDTO {
|
public class ArticleTagDTO {
|
||||||
|
|
||||||
|
private Integer idArticleTag;
|
||||||
|
|
||||||
private Integer idTag;
|
private Integer idTag;
|
||||||
|
|
||||||
|
private Integer idArticle;
|
||||||
|
|
||||||
private String tagTitle;
|
private String tagTitle;
|
||||||
|
|
||||||
private String tagUri;
|
private String tagUri;
|
||||||
|
@ -111,4 +111,11 @@ public interface ArticleMapper extends Mapper<Article> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<ArticleDTO> selectDrafts(@Param("idUser") Integer idUser);
|
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();
|
String articleTags = article.getArticleTags();
|
||||||
if(StringUtils.isNotBlank(articleTags)){
|
if(StringUtils.isNotBlank(articleTags)){
|
||||||
String[] tags = articleTags.split(",");
|
String[] tags = articleTags.split(",");
|
||||||
|
List<ArticleTagDTO> articleTagDTOList = articleMapper.selectTags(article.getIdArticle());
|
||||||
for (int i = 0; i < tags.length; i++) {
|
for (int i = 0; i < tags.length; i++) {
|
||||||
boolean addTagArticle = false;
|
boolean addTagArticle = false;
|
||||||
boolean addUserTag = false;
|
boolean addUserTag = false;
|
||||||
Tag tag = new Tag();
|
Tag tag = new Tag();
|
||||||
tag.setTagTitle(tags[i]);
|
tag.setTagTitle(tags[i]);
|
||||||
tag = tagMapper.selectOne(tag);
|
tag = tagMapper.selectOne(tag);
|
||||||
List<ArticleTagDTO> articleTagDTOList = articleMapper.selectTags(article.getIdArticle());
|
|
||||||
if(tag == null){
|
if(tag == null){
|
||||||
tag = new Tag();
|
tag = new Tag();
|
||||||
tag.setTagTitle(tags[i]);
|
tag.setTagTitle(tags[i]);
|
||||||
@ -59,6 +59,11 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
|
|||||||
addTagArticle = true;
|
addTagArticle = true;
|
||||||
addUserTag = true;
|
addUserTag = true;
|
||||||
} else {
|
} else {
|
||||||
|
for(ArticleTagDTO articleTag : articleTagDTOList) {
|
||||||
|
if (articleTag.getIdTag().equals(tag.getIdTag())) {
|
||||||
|
articleTagDTOList.remove(articleTag);
|
||||||
|
}
|
||||||
|
}
|
||||||
Integer count = tagMapper.selectCountTagArticleById(tag.getIdTag(),article.getIdArticle());
|
Integer count = tagMapper.selectCountTagArticleById(tag.getIdTag(),article.getIdArticle());
|
||||||
if(count == 0){
|
if(count == 0){
|
||||||
tag.setTagArticleCount(tag.getTagArticleCount() + 1);
|
tag.setTagArticleCount(tag.getTagArticleCount() + 1);
|
||||||
@ -70,6 +75,9 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
|
|||||||
addUserTag = true;
|
addUserTag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
articleTagDTOList.forEach(articleTagDTO -> {
|
||||||
|
articleMapper.deleteUnusedArticleTag(articleTagDTO.getIdArticleTag());
|
||||||
|
});
|
||||||
if(addTagArticle){
|
if(addTagArticle){
|
||||||
tagMapper.insertTagArticle(tag.getIdTag(),article.getIdArticle());
|
tagMapper.insertTagArticle(tag.getIdTag(),article.getIdArticle());
|
||||||
}
|
}
|
||||||
|
@ -51,11 +51,13 @@
|
|||||||
<result column="updated_time" property="updatedTime"/>
|
<result column="updated_time" property="updatedTime"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<resultMap id="ArticleTagDTOResultMap" type="com.rymcu.vertical.dto.ArticleTagDTO">
|
<resultMap id="ArticleTagDTOResultMap" type="com.rymcu.vertical.dto.ArticleTagDTO">
|
||||||
<id column="id" property="idTag"/>
|
<id column="id" property="idArticleTag"/>
|
||||||
<id column="tag_title" property="tagTitle"/>
|
<result column="id_tag" property="idTag"></result>
|
||||||
<id column="tag_icon_path" property="tagIconPath"/>
|
<result column="id_article" property="idArticle"></result>
|
||||||
<id column="tag_uri" property="tagUri"/>
|
<result column="tag_title" property="tagTitle"></result>
|
||||||
<id column="tag_description" property="tagDescription"/>
|
<result column="tag_icon_path" property="tagIconPath"></result>
|
||||||
|
<result column="tag_uri" property="tagUri"></result>
|
||||||
|
<result column="tag_description" property="tagDescription"></result>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<insert id="insertArticleContent">
|
<insert id="insertArticleContent">
|
||||||
insert into vertical_article_content (id_article,article_content,article_content_html,created_time,updated_time)
|
insert into vertical_article_content (id_article,article_content,article_content_html,created_time,updated_time)
|
||||||
@ -70,6 +72,9 @@
|
|||||||
<delete id="deleteTagArticle">
|
<delete id="deleteTagArticle">
|
||||||
delete from vertical_tag_article where id_article = #{id}
|
delete from vertical_tag_article where id_article = #{id}
|
||||||
</delete>
|
</delete>
|
||||||
|
<delete id="deleteUnusedArticleTag">
|
||||||
|
delete from vertical_tag_article where id = #{idArticleTag}
|
||||||
|
</delete>
|
||||||
<select id="selectArticles" resultMap="DTOResultMap">
|
<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 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>
|
</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 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>
|
||||||
<select id="selectTags" resultMap="ArticleTagDTOResultMap">
|
<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>
|
||||||
<select id="selectDrafts" resultMap="DTOResultMap">
|
<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
|
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