✨
1. 判断文章是否有评论数据 2. 删除文章时删除关联数据 3. sql 优化
This commit is contained in:
parent
b817034dbf
commit
d701c94bf5
@ -144,4 +144,18 @@ public interface ArticleMapper extends Mapper<Article> {
|
||||
* @return
|
||||
*/
|
||||
Integer updateArticleTags(@Param("idArticle") Integer idArticle, @Param("tags") String tags);
|
||||
|
||||
/**
|
||||
* 判断是否有评论
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
boolean existsCommentWithPrimaryKey(@Param("id") Integer id);
|
||||
|
||||
/**
|
||||
* 删除关联作品集数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
Integer deleteLinkedPortfolioData(@Param("id") Integer id);
|
||||
}
|
||||
|
@ -229,21 +229,29 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
||||
public Map delete(Integer id) {
|
||||
Map<String, String> map = new HashMap(1);
|
||||
Integer result;
|
||||
Article article = articleMapper.selectByPrimaryKey(id);
|
||||
// 删除引用标签记录
|
||||
result = articleMapper.deleteTagArticle(id);
|
||||
// 无标签情况下无法删除文章问题修复
|
||||
if (result > 0 || StringUtils.isBlank(article.getArticleTags())) {
|
||||
// 判断是否有评论
|
||||
boolean isHavComment = articleMapper.existsCommentWithPrimaryKey(id);
|
||||
if (isHavComment) {
|
||||
map.put("message", "已有评论的文章不允许删除!");
|
||||
} else {
|
||||
// 删除关联数据(作品集关联关系,标签关联关系)
|
||||
deleteLinkedData(id);
|
||||
// 删除文章
|
||||
result = articleMapper.deleteByPrimaryKey(id);
|
||||
if (result < 1) {
|
||||
map.put("message", "删除失败!");
|
||||
}
|
||||
} else {
|
||||
map.put("message", "删除失败!");
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private void deleteLinkedData(Integer id) {
|
||||
// 删除关联作品集
|
||||
articleMapper.deleteLinkedPortfolioData(id);
|
||||
// 删除引用标签记录
|
||||
articleMapper.deleteTagArticle(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void incrementArticleViewCount(Integer id) {
|
||||
|
@ -80,12 +80,15 @@
|
||||
<delete id="deleteUnusedArticleTag">
|
||||
delete from vertical_tag_article where id = #{idArticleTag}
|
||||
</delete>
|
||||
<delete id="deleteLinkedPortfolioData">
|
||||
delete from vertical_portfolio_article where id_vertical_article = #{id}
|
||||
</delete>
|
||||
<select id="selectArticles" resultMap="DTOResultMap">
|
||||
select art.*,su.nickname,su.avatar_url from vertical_article art join vertical_user su on art.article_author_id = su.id
|
||||
where article_status = '0'
|
||||
<if test="topicUri != 'news'">
|
||||
and art.id not in (select id_article from vertical_tag_article vta
|
||||
join vertical_tag vt on vta.id_tag = vt.id where vt.tag_title = '划水')
|
||||
and not exists (select * from vertical_tag_article vta where vta.id_article = art.id
|
||||
and exists (select * from vertical_tag vt where vta.id_tag = vt.id and vt.tag_title = '划水'))
|
||||
</if>
|
||||
order by updated_time desc
|
||||
</select>
|
||||
@ -128,4 +131,7 @@
|
||||
<select id="selectPortfolioArticles" resultMap="PortfolioArticleResultMap">
|
||||
select vp.portfolio_title,vp.portfolio_head_img_url,vpa.id_vertical_portfolio,vpa.id_vertical_article from vertical_portfolio vp join vertical_portfolio_article vpa on vp.id = vpa.id_vertical_portfolio where vpa.id_vertical_article = #{idArticle}
|
||||
</select>
|
||||
<select id="existsCommentWithPrimaryKey" resultType="java.lang.Boolean">
|
||||
select exists (select * from vertical_comment where comment_article_id = #{id})
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user