<?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.FsUserCourseNoteMapper">

    <resultMap type="FsUserCourseNote" id="FsUserCourseNoteResult">
        <result property="noteId"    column="note_id"    />
        <result property="userId"    column="user_id"    />
        <result property="courseId"    column="course_id"    />
        <result property="noteCateId"    column="note_cate_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isHot"    column="is_hot"    />
        <result property="likes"    column="likes"    />
        <result property="status"    column="status"    />
        <result property="isShow"    column="is_show"    />
        <result property="content"    column="content"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectFsUserCourseNoteVo">
        select note_id,content, user_id,is_del, course_id, note_cate_id, create_time, update_time, is_hot, likes, status, is_show from fs_user_course_note
    </sql>

    <select id="selectFsUserCourseNoteList" parameterType="FsUserCourseNote" resultMap="FsUserCourseNoteResult">
        <include refid="selectFsUserCourseNoteVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="courseId != null "> and course_id = #{courseId}</if>
            <if test="noteCateId != null "> and note_cate_id = #{noteCateId}</if>
            <if test="isHot != null "> and is_hot = #{isHot}</if>
            <if test="likes != null "> and likes = #{likes}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="isShow != null "> and is_show = #{isShow}</if>
        </where>
    </select>

    <select id="selectFsUserCourseNoteByNoteId" parameterType="Long" resultMap="FsUserCourseNoteResult">
        <include refid="selectFsUserCourseNoteVo"/>
        where note_id = #{noteId}
    </select>

    <insert id="insertFsUserCourseNote" parameterType="FsUserCourseNote" useGeneratedKeys="true" keyProperty="noteId">
        insert into fs_user_course_note
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="courseId != null">course_id,</if>
            <if test="noteCateId != null">note_cate_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isHot != null">is_hot,</if>
            <if test="likes != null">likes,</if>
            <if test="status != null">status,</if>
            <if test="isShow != null">is_show,</if>
            <if test="content != null">content,</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="noteCateId != null">#{noteCateId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isHot != null">#{isHot},</if>
            <if test="likes != null">#{likes},</if>
            <if test="status != null">#{status},</if>
            <if test="isShow != null">#{isShow},</if>
            <if test="content != null">#{content},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateFsUserCourseNote" parameterType="FsUserCourseNote">
        update fs_user_course_note
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="noteCateId != null">note_cate_id = #{noteCateId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isHot != null">is_hot = #{isHot},</if>
            <if test="likes != null">likes = #{likes},</if>
            <if test="status != null">status = #{status},</if>
            <if test="isShow != null">is_show = #{isShow},</if>
            <if test="content != null">content = #{content},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where note_id = #{noteId}
    </update>

    <update id="deleteFsUserCourseNoteByNoteId" parameterType="Long">
        update fs_user_course_note set is_del = 1 where note_id = #{noteId}
    </update>

    <update id="deleteFsUserCourseNoteByNoteIds" parameterType="String">
        update fs_user_course_note set is_del = 1 where note_id in
        <foreach item="noteId" collection="array" open="(" separator="," close=")">
            #{noteId}
        </foreach>
    </update>
</mapper>
