<?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.system.mapper.CommentContentMapper">
    
    <resultMap type="CommentContent" id="CommentContentResult">
        <result property="contentId"    column="content_id"    />
        <result property="commentId"    column="comment_id"    />
        <result property="userId"    column="user_id"    />
        <result property="commentContent"    column="comment_content"    />
        <result property="status"    column="status"    />
        <result property="type"    column="type"    />
        <result property="likeCount"    column="like_count"    />
        <result property="delFlag"    column="del_flag"    />
        <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="selectCommentContentVo">
        select content_id, comment_id, user_id, comment_content, status, type, like_count, del_flag, create_by, create_time, update_by, update_time, remark from comment_content
    </sql>

    <select id="selectCommentContentList" parameterType="CommentContent" resultMap="CommentContentResult">
        <include refid="selectCommentContentVo"/>
        <where>  
            <if test="commentId != null "> and comment_id = #{commentId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="commentContent != null  and commentContent != ''"> and comment_content = #{commentContent}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="likeCount != null "> and like_count = #{likeCount}</if>
        </where>
    </select>
    
    <select id="selectCommentContentByContentId" parameterType="Long" resultMap="CommentContentResult">
        <include refid="selectCommentContentVo"/>
        where content_id = #{contentId}
    </select>

    <insert id="insertCommentContent" parameterType="CommentContent" useGeneratedKeys="true" keyProperty="contentId">
        insert into comment_content
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="contentId != null">content_id,</if>
            <if test="commentId != null">comment_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="commentContent != null">comment_content,</if>
            <if test="status != null">status,</if>
            <if test="type != null">type,</if>
            <if test="likeCount != null">like_count,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="contentId != null">#{contentId},</if>
            <if test="commentId != null">#{commentId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="commentContent != null">#{commentContent},</if>
            <if test="status != null">#{status},</if>
            <if test="type != null">#{type},</if>
            <if test="likeCount != null">#{likeCount},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCommentContent" parameterType="CommentContent">
        update comment_content
        <trim prefix="SET" suffixOverrides=",">
            <if test="commentId != null">comment_id = #{commentId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="commentContent != null">comment_content = #{commentContent},</if>
            <if test="status != null">status = #{status},</if>
            <if test="type != null">type = #{type},</if>
            <if test="likeCount != null">like_count = #{likeCount},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where content_id = #{contentId}
    </update>
    <update id="updateCommentContentByContentId" parameterType="CommentContent">
        update comment_content set del_flag = 'Y' where comment_id = #{commentId}
    </update>
    <update id="deleteCommentContentByCommentId" parameterType="CommentContent">
        update comment_content set del_flag = 'Y' where comment_id in(select comment_id from comment_index where parent_id = #{commentId})
    </update>
    <update id="updateCommentContentByCommentId" parameterType="CommentContent">
        update comment_content
        <trim prefix="SET" suffixOverrides=",">
            <if test="likeCount != null">like_count = #{likeCount},</if>
        </trim>
        where comment_id = #{commentId}
    </update>

    <delete id="deleteCommentContentByContentId" parameterType="Long">
        delete from comment_content where content_id = #{contentId}
    </delete>

    <delete id="deleteCommentContentByContentIds" parameterType="String">
        delete from comment_content where content_id in 
        <foreach item="contentId" collection="array" open="(" separator="," close=")">
            #{contentId}
        </foreach>
    </delete>
</mapper>