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