meisiyu | c98fc52 | 2025-06-02 20:33:40 +0800 | [diff] [blame] | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <!DOCTYPE mapper |
| 3 | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| 4 | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| 5 | <mapper namespace="com.ruoyi.web.controller.post.mapper.PostCommentMapper"> |
| 6 | |
| 7 | <resultMap type="PostComment" id="PostCommentResult"> |
| 8 | <id property="commentId" column="comment_id" /> |
| 9 | <result property="postId" column="post_id" /> |
| 10 | <result property="content" column="content" /> |
| 11 | <result property="userId" column="user_id" /> |
| 12 | <result property="userName" column="user_name" /> |
| 13 | <result property="userAvatar" column="user_avatar" /> |
| 14 | <result property="parentId" column="parent_id" /> |
| 15 | <result property="replyUserId" column="reply_user_id" /> |
| 16 | <result property="replyUserName" column="reply_user_name"/> |
| 17 | <result property="status" column="status" /> |
| 18 | <result property="likes" column="likes" /> |
| 19 | <result property="createBy" column="create_by" /> |
| 20 | <result property="createTime" column="create_time" /> |
| 21 | <result property="updateBy" column="update_by" /> |
| 22 | <result property="updateTime" column="update_time" /> |
| 23 | <result property="remark" column="remark" /> |
| 24 | </resultMap> |
| 25 | |
| 26 | <sql id="selectPostCommentVo"> |
| 27 | select comment_id, post_id, content, user_id, user_name, user_avatar, parent_id, reply_user_id, reply_user_name, status, likes, |
| 28 | create_by, create_time, update_by, update_time, remark |
| 29 | from post_comment |
| 30 | </sql> |
| 31 | |
| 32 | <select id="selectPostCommentList" parameterType="PostComment" resultMap="PostCommentResult"> |
| 33 | <include refid="selectPostCommentVo"/> |
| 34 | <where> |
| 35 | <if test="postId != null"> |
| 36 | AND post_id = #{postId} |
| 37 | </if> |
| 38 | <if test="userId != null"> |
| 39 | AND user_id = #{userId} |
| 40 | </if> |
| 41 | <if test="userName != null and userName != ''"> |
| 42 | AND user_name like concat('%', #{userName}, '%') |
| 43 | </if> |
| 44 | <if test="parentId != null"> |
| 45 | AND parent_id = #{parentId} |
| 46 | </if> |
| 47 | <if test="status != null and status != ''"> |
| 48 | AND status = #{status} |
| 49 | </if> |
| 50 | </where> |
| 51 | order by create_time desc |
| 52 | </select> |
| 53 | |
| 54 | <select id="selectPostCommentById" parameterType="Long" resultMap="PostCommentResult"> |
| 55 | <include refid="selectPostCommentVo"/> |
| 56 | where comment_id = #{commentId} |
| 57 | </select> |
| 58 | |
| 59 | <select id="selectCommentsByPostId" resultMap="PostCommentResult"> |
| 60 | <include refid="selectPostCommentVo"/> |
| 61 | where post_id = #{postId} and parent_id = 0 and status = '1' |
| 62 | order by create_time desc |
| 63 | <if test="limit > 0"> |
| 64 | limit #{limit} |
| 65 | </if> |
| 66 | </select> |
| 67 | |
| 68 | <select id="selectCommentsByParentId" parameterType="Long" resultMap="PostCommentResult"> |
| 69 | <include refid="selectPostCommentVo"/> |
| 70 | where parent_id = #{parentId} and status = '1' |
| 71 | order by create_time asc |
| 72 | </select> |
| 73 | |
| 74 | <insert id="insertPostComment" parameterType="PostComment" useGeneratedKeys="true" keyProperty="commentId"> |
| 75 | insert into post_comment ( |
| 76 | post_id, |
| 77 | content, |
| 78 | user_id, |
| 79 | user_name, |
| 80 | user_avatar, |
| 81 | parent_id, |
| 82 | reply_user_id, |
| 83 | reply_user_name, |
| 84 | status, |
| 85 | likes, |
| 86 | create_by, |
| 87 | create_time, |
| 88 | update_by, |
| 89 | update_time, |
| 90 | remark |
| 91 | ) values ( |
| 92 | #{postId}, |
| 93 | #{content}, |
| 94 | #{userId}, |
| 95 | #{userName}, |
| 96 | #{userAvatar}, |
| 97 | #{parentId}, |
| 98 | #{replyUserId}, |
| 99 | #{replyUserName}, |
| 100 | #{status}, |
| 101 | #{likes}, |
| 102 | #{createBy}, |
| 103 | now(), |
| 104 | #{updateBy}, |
| 105 | now(), |
| 106 | #{remark} |
| 107 | ) |
| 108 | </insert> |
| 109 | |
| 110 | <update id="updatePostComment" parameterType="PostComment"> |
| 111 | update post_comment |
| 112 | <set> |
| 113 | <if test="content != null and content != ''">content = #{content},</if> |
| 114 | <if test="status != null and status != ''">status = #{status},</if> |
| 115 | <if test="likes != null">likes = #{likes},</if> |
| 116 | <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> |
| 117 | update_time = now(), |
| 118 | <if test="remark != null">remark = #{remark},</if> |
| 119 | </set> |
| 120 | where comment_id = #{commentId} |
| 121 | </update> |
| 122 | |
| 123 | <delete id="deletePostCommentById" parameterType="Long"> |
| 124 | delete from post_comment where comment_id = #{commentId} |
| 125 | </delete> |
| 126 | |
| 127 | <delete id="deletePostCommentByIds" parameterType="Long"> |
| 128 | delete from post_comment where comment_id in |
| 129 | <foreach collection="array" item="commentId" open="(" separator="," close=")"> |
| 130 | #{commentId} |
| 131 | </foreach> |
| 132 | </delete> |
| 133 | |
| 134 | <delete id="deletePostCommentByPostId" parameterType="Long"> |
| 135 | delete from post_comment where post_id = #{postId} |
| 136 | </delete> |
| 137 | |
| 138 | <update id="updateCommentLikes" parameterType="PostComment"> |
| 139 | update post_comment set likes = likes + #{likes} where comment_id = #{commentId} |
| 140 | </update> |
| 141 | |
| 142 | </mapper> |