<?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.fs.course.mapper.FsUserCourseCommentMapper">

    <resultMap type="FsUserCourseComment" id="FsUserCourseCommentResult">
        <result property="commentId"    column="comment_id"    />
        <result property="userId"    column="user_id"    />
        <result property="courseId"    column="course_id"    />
        <result property="type"    column="type"    />
        <result property="parentId"    column="parent_id"    />
        <result property="content"    column="content"    />
        <result property="replyCount"    column="reply_count"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="likes"    column="likes"    />
        <result property="toUserId"    column="to_user_id"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectFsUserCourseCommentVo">
        select comment_id,to_user_id, user_id,is_del, course_id, type, parent_id, content, reply_count, create_time, update_time, likes from fs_user_course_comment
    </sql>

    <select id="selectFsUserCourseCommentList" parameterType="FsUserCourseComment" resultMap="FsUserCourseCommentResult">
        <include refid="selectFsUserCourseCommentVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="courseId != null "> and course_id = #{courseId}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="replyCount != null "> and reply_count = #{replyCount}</if>
            <if test="likes != null "> and likes = #{likes}</if>
        </where>
    </select>

    <select id="selectFsUserCourseCommentByCommentId" parameterType="Long" resultMap="FsUserCourseCommentResult">
        <include refid="selectFsUserCourseCommentVo"/>
        where comment_id = #{commentId}
    </select>

    <insert id="insertFsUserCourseComment" parameterType="FsUserCourseComment" useGeneratedKeys="true" keyProperty="commentId">
        insert into fs_user_course_comment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="courseId != null">course_id,</if>
            <if test="type != null">type,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="content != null">content,</if>
            <if test="replyCount != null">reply_count,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="likes != null">likes,</if>
            <if test="toUserId != null">to_user_id,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="type != null">#{type},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="content != null">#{content},</if>
            <if test="replyCount != null">#{replyCount},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="likes != null">#{likes},</if>
            <if test="toUserId != null">#{toUserId},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateFsUserCourseComment" parameterType="FsUserCourseComment">
        update fs_user_course_comment
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="content != null">content = #{content},</if>
            <if test="replyCount != null">reply_count = #{replyCount},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="likes != null">likes = #{likes},</if>
            <if test="toUserId != null">to_user_id = #{toUserId},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where comment_id = #{commentId}
    </update>

    <update id="deleteFsUserCourseCommentByCommentId" parameterType="Long">
        update fs_user_course_comment set is_del = 1 where comment_id = #{commentId}
    </update>

    <update id="deleteFsUserCourseCommentByCommentIds" parameterType="String">
        update fs_user_course_comment set is_del = 1 where comment_id in
        <foreach item="commentId" collection="array" open="(" separator="," close=")">
            #{commentId}
        </foreach>
    </update>
</mapper>
