| <?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.ruoyi.web.controller.post.mapper.PostCommentMapper"> |
| |
| <resultMap type="PostComment" id="PostCommentResult"> |
| <id property="commentId" column="comment_id" /> |
| <result property="postId" column="post_id" /> |
| <result property="content" column="content" /> |
| <result property="userId" column="user_id" /> |
| <result property="userName" column="user_name" /> |
| <result property="userAvatar" column="user_avatar" /> |
| <result property="parentId" column="parent_id" /> |
| <result property="replyUserId" column="reply_user_id" /> |
| <result property="replyUserName" column="reply_user_name"/> |
| <result property="status" column="status" /> |
| <result property="likes" column="likes" /> |
| <result property="createBy" column="create_by" /> |
| <result property="createTime" column="create_time" /> |
| <result property="updateBy" column="update_by" /> |
| <result property="updateTime" column="update_time" /> |
| <result property="remark" column="remark" /> |
| </resultMap> |
| |
| <sql id="selectPostCommentVo"> |
| select comment_id, post_id, content, user_id, user_name, user_avatar, parent_id, reply_user_id, reply_user_name, status, likes, |
| create_by, create_time, update_by, update_time, remark |
| from post_comment |
| </sql> |
| |
| <select id="selectPostCommentList" parameterType="PostComment" resultMap="PostCommentResult"> |
| <include refid="selectPostCommentVo"/> |
| <where> |
| <if test="postId != null"> |
| AND post_id = #{postId} |
| </if> |
| <if test="userId != null"> |
| AND user_id = #{userId} |
| </if> |
| <if test="userName != null and userName != ''"> |
| AND user_name like concat('%', #{userName}, '%') |
| </if> |
| <if test="parentId != null"> |
| AND parent_id = #{parentId} |
| </if> |
| <if test="status != null and status != ''"> |
| AND status = #{status} |
| </if> |
| </where> |
| order by create_time desc |
| </select> |
| |
| <select id="selectPostCommentById" parameterType="Long" resultMap="PostCommentResult"> |
| <include refid="selectPostCommentVo"/> |
| where comment_id = #{commentId} |
| </select> |
| |
| <select id="selectCommentsByPostId" resultMap="PostCommentResult"> |
| <include refid="selectPostCommentVo"/> |
| where post_id = #{postId} and parent_id = 0 and status = '1' |
| order by create_time desc |
| <if test="limit > 0"> |
| limit #{limit} |
| </if> |
| </select> |
| |
| <select id="selectCommentsByParentId" parameterType="Long" resultMap="PostCommentResult"> |
| <include refid="selectPostCommentVo"/> |
| where parent_id = #{parentId} and status = '1' |
| order by create_time asc |
| </select> |
| |
| <insert id="insertPostComment" parameterType="PostComment" useGeneratedKeys="true" keyProperty="commentId"> |
| insert into post_comment ( |
| post_id, |
| content, |
| user_id, |
| user_name, |
| user_avatar, |
| parent_id, |
| reply_user_id, |
| reply_user_name, |
| status, |
| likes, |
| create_by, |
| create_time, |
| update_by, |
| update_time, |
| remark |
| ) values ( |
| #{postId}, |
| #{content}, |
| #{userId}, |
| #{userName}, |
| #{userAvatar}, |
| #{parentId}, |
| #{replyUserId}, |
| #{replyUserName}, |
| #{status}, |
| #{likes}, |
| #{createBy}, |
| now(), |
| #{updateBy}, |
| now(), |
| #{remark} |
| ) |
| </insert> |
| |
| <update id="updatePostComment" parameterType="PostComment"> |
| update post_comment |
| <set> |
| <if test="content != null and content != ''">content = #{content},</if> |
| <if test="status != null and status != ''">status = #{status},</if> |
| <if test="likes != null">likes = #{likes},</if> |
| <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> |
| update_time = now(), |
| <if test="remark != null">remark = #{remark},</if> |
| </set> |
| where comment_id = #{commentId} |
| </update> |
| |
| <delete id="deletePostCommentById" parameterType="Long"> |
| delete from post_comment where comment_id = #{commentId} |
| </delete> |
| |
| <delete id="deletePostCommentByIds" parameterType="Long"> |
| delete from post_comment where comment_id in |
| <foreach collection="array" item="commentId" open="(" separator="," close=")"> |
| #{commentId} |
| </foreach> |
| </delete> |
| |
| <delete id="deletePostCommentByPostId" parameterType="Long"> |
| delete from post_comment where post_id = #{postId} |
| </delete> |
| |
| <update id="updateCommentLikes" parameterType="PostComment"> |
| update post_comment set likes = likes + #{likes} where comment_id = #{commentId} |
| </update> |
| |
| </mapper> |