mapper.MkCommunityArticleMapper.xml Maven / Gradle / Ivy
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.github.xujiaji.mk.community.mapper.MkCommunityArticleMapper"> <update id="updateCollectAdd1"> UPDATE mk_community_article SET collect_num = collect_num + 1 WHERE id = ${articleId} </update> <update id="updatePraiseAdd1"> UPDATE mk_community_article SET praise_num = praise_num + 1 WHERE id = ${articleId} </update> <update id="updateCollectSub1"> UPDATE mk_community_article SET collect_num = collect_num - 1 WHERE id = ${articleId} </update> <update id="updatePraiseSub1"> UPDATE mk_community_article SET praise_num = praise_num - 1 WHERE id = ${articleId} </update> <sql id="articleSql"> SELECT a.*, c.title category_title, u.nickname, IF(f.state = 0, f.path, NULL) avatar, (SELECT COUNT(*) FROM mk_community_comment WHERE root_id = a.id) comment_num FROM mk_community_article a LEFT JOIN mk_community_category c ON a.category_id = c.id LEFT JOIN mk_user u ON a.user_id = u.id LEFT JOIN mk_file f ON u.avatar = f.id </sql> <select id="articlePage" resultType="com.github.xujiaji.mk.community.dto.FrontArticleDTO"> <include refid="articleSql"/> WHERE a.category_id = ${categoryId} ORDER BY IF(${type} = 1, a.create_time, a.update_time) DESC </select> <select id="ownArticlePage" resultType="com.github.xujiaji.mk.community.dto.FrontArticleDTO"> <include refid="articleSql"/> WHERE a.user_id = ${userId} ORDER BY a.create_time DESC </select> <select id="collectArticlePage" resultType="com.github.xujiaji.mk.community.dto.FrontArticleDTO"> <include refid="articleSql"/> RIGHT JOIN mk_community_collect collect ON collect.collected_id = a.id WHERE collect.type = 0 AND collect.user_id = ${userId} ORDER BY collect.create_time DESC </select> <select id="articleImagePage" resultType="com.github.xujiaji.mk.community.dto.FrontArticleImageDTO"> SELECT DATE_FORMAT(af.create_time, '%Y-%m') `year_month` FROM mk_community_article_file af LEFT JOIN mk_file f ON af.file_id = f.id WHERE f.user_id = ${userId} AND f.state = 0 GROUP BY DATE_FORMAT(af.create_time, '%Y-%m') </select> <select id="selectArticleDetails" resultType="com.github.xujiaji.mk.community.dto.FrontArticleDTO"> SELECT a.*, c.title category_title, u.nickname, IF(f.state = 0, f.path, NULL) avatar, (SELECT COUNT(*) FROM mk_community_comment WHERE root_id = a.id) comment_num FROM mk_community_article a LEFT JOIN mk_community_category c ON a.category_id = c.id LEFT JOIN mk_user u ON a.user_id = u.id LEFT JOIN mk_file f ON u.avatar = f.id WHERE a.id = ${articleId} </select> <select id="selectArticleBy" resultType="com.github.xujiaji.mk.community.entity.MkCommunityArticle"> SELECT * FROM mk_community_article WHERE user_id = ${userId} AND id = ${articleId} </select> <select id="selectAuthorIdByArticleId" resultType="java.lang.Long"> SELECT user_id FROM mk_community_article WHERE id = ${articleId} </select> <select id="countArticleImage" resultType="java.lang.Integer"> SELECT COUNT(*) FROM mk_community_article_file WHERE article_id = ${articleId} AND type = 0 </select> </mapper>