<?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.FsUserCourseStudyMapper">
    
    <resultMap type="FsUserCourseStudy" id="FsUserCourseStudyResult">
        <result property="studyId"    column="study_id"    />
        <result property="videoId"    column="video_id"    />
        <result property="courseId"    column="course_id"    />
        <result property="userId"    column="user_id"    />
        <result property="periodTotal"    column="period_total"    />
        <result property="periodStudy"    column="period_study"    />
        <result property="status"    column="status"    />
        <result property="sort"    column="sort"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isExam"    column="is_exam"    />
    </resultMap>

    <sql id="selectFsUserCourseStudyVo">
        select study_id, video_id, course_id, user_id, period_total, period_study, status, sort, create_time, update_time, is_exam from fs_user_course_study
    </sql>

    <select id="selectFsUserCourseStudyList" parameterType="FsUserCourseStudy" resultMap="FsUserCourseStudyResult">
        <include refid="selectFsUserCourseStudyVo"/>
        <where>  
            <if test="videoId != null "> and video_id = #{videoId}</if>
            <if test="courseId != null "> and course_id = #{courseId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="periodTotal != null "> and period_total = #{periodTotal}</if>
            <if test="periodStudy != null "> and period_study = #{periodStudy}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="isExam != null "> and is_exam = #{isExam}</if>
        </where>
    </select>
    
    <select id="selectFsUserCourseStudyByStudyId" parameterType="String" resultMap="FsUserCourseStudyResult">
        <include refid="selectFsUserCourseStudyVo"/>
        where study_id = #{studyId}
    </select>
        
    <insert id="insertFsUserCourseStudy" parameterType="FsUserCourseStudy" useGeneratedKeys="true" keyProperty="studyId">
        insert into fs_user_course_study
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="videoId != null">video_id,</if>
            <if test="courseId != null">course_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="periodTotal != null">period_total,</if>
            <if test="periodStudy != null">period_study,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="sort != null">sort,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isExam != null">is_exam,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="videoId != null">#{videoId},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="periodTotal != null">#{periodTotal},</if>
            <if test="periodStudy != null">#{periodStudy},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="sort != null">#{sort},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isExam != null">#{isExam},</if>
         </trim>
    </insert>

    <update id="updateFsUserCourseStudy" parameterType="FsUserCourseStudy">
        update fs_user_course_study
        <trim prefix="SET" suffixOverrides=",">
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="periodTotal != null">period_total = #{periodTotal},</if>
            <if test="periodStudy != null">period_study = #{periodStudy},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isExam != null">is_exam = #{isExam},</if>
        </trim>
        where study_id = #{studyId}
    </update>

    <delete id="deleteFsUserCourseStudyByStudyId" parameterType="String">
        delete from fs_user_course_study where study_id = #{studyId}
    </delete>

    <delete id="deleteFsUserCourseStudyByStudyIds" parameterType="String">
        delete from fs_user_course_study where study_id in 
        <foreach item="studyId" collection="array" open="(" separator="," close=")">
            #{studyId}
        </foreach>
    </delete>
</mapper>