mapper.MkCommunityCommentMapper.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.MkCommunityCommentMapper"> <sql id="commentDTO"> SELECT c.*, u.nickname, IF(f.state = 0, f.path, NULL) avatar FROM mk_community_comment c LEFT JOIN mk_user u ON c.user_id = u.id LEFT JOIN mk_file f ON u.avatar = f.id WHERE c.root_id = ${articleId} </sql> <select id="articleCommentPage" resultType="com.github.xujiaji.mk.community.dto.FrontArticleCommentDTO"> <include refid="commentDTO"/> AND c.reply_id IS NULL AND c.parent_id IS NOT NULL ORDER BY IF(${type} = 1, c.create_time, c.create_time * -1) ASC </select> <select id="selectThreeReplyComment" resultType="com.github.xujiaji.mk.community.dto.FrontArticleCommentDTO"> SELECT c.content, u.nickname FROM mk_community_comment c LEFT JOIN mk_user u ON c.user_id = u.id WHERE c.root_id = ${articleId} AND c.parent_id = ${commentId} AND c.reply_id IS NOT NULL LIMIT 3 </select> <select id="commentDetailsPage" resultType="com.github.xujiaji.mk.community.dto.FrontArticleCommentDetailsDTO"> SELECT c.*, u.nickname, IF(f.state = 0, f.path, NULL) avatar, IF(c.reply_id IS NOT NULL AND c.reply_id != c.parent_id, ( SELECT inu.nickname FROM mk_community_comment inc LEFT JOIN mk_user inu ON inc.user_id = inu.id WHERE inc.id = c.reply_id), NULL) reply_nickname FROM mk_community_comment c LEFT JOIN mk_user u ON c.user_id = u.id LEFT JOIN mk_file f ON u.avatar = f.id WHERE c.parent_id = ${commentId} </select> <select id="countAllReplyComment" resultType="java.lang.Long"> SELECT COUNT(*) FROM mk_community_comment WHERE parent_id = ${commentId} AND reply_id IS NOT NULL </select> <select id="selectAuthorIdByCommentId" resultType="java.lang.Long"> SELECT user_id FROM mk_community_comment WHERE id = ${commentId} </select> <update id="updatePraiseAdd1"> UPDATE mk_community_comment SET praise_num = praise_num + 1 WHERE id = ${commentId} </update> <update id="updatePraiseSub1"> UPDATE mk_community_comment SET praise_num = praise_num - 1 WHERE id = ${commentId} </update> </mapper>