<?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.FsUserCoursePeriodDaysMapper">
    
    <resultMap type="FsUserCoursePeriodDays" id="FsUserCoursePeriodDaysResult">
        <result property="id"    column="id"    />
        <result property="periodId"    column="period_id"    />
        <result property="lesson"    column="lesson"    />
        <result property="startDateTime"    column="start_date_time"    />
        <result property="endDateTime"    column="end_date_time"    />
        <result property="courseId"    column="course_id"    />
        <result property="videoId"    column="video_id"    />
        <result property="money"    column="money"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectFsUserCoursePeriodDaysVo">
        select * from fs_user_course_period_days
    </sql>

    <select id="selectFsUserCoursePeriodDaysList" parameterType="FsUserCoursePeriodDays" resultType="FsUserCoursePeriodDays">
        select a.*,b.course_name,c.title videoName from fs_user_course_period_days a
        inner join fs_user_course b on a.course_id = b.course_id
        inner join fs_user_course_video c on a.video_id = c.video_id
        <where>
            <if test="periodId != null "> and period_id = #{periodId}</if>
            <if test="courseId != null "> and course_id = #{courseId}</if>
            <if test="videoId != null "> and video_id = #{videoId}</if>
        </where>
    </select>
    
    <select id="selectFsUserCoursePeriodDaysById" parameterType="Long" resultMap="FsUserCoursePeriodDaysResult">
        <include refid="selectFsUserCoursePeriodDaysVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFsUserCoursePeriodDays" parameterType="FsUserCoursePeriodDays" useGeneratedKeys="true" keyProperty="id">
        insert into fs_user_course_period_days
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="periodId != null">period_id,</if>
            <if test="lesson != null">lesson,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="courseId != null">course_id,</if>
            <if test="videoId != null">video_id,</if>
            <if test="money != null">money,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</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="periodId != null">#{periodId},</if>
            <if test="lesson != null">#{lesson},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="money != null">#{money},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateFsUserCoursePeriodDays" parameterType="FsUserCoursePeriodDays">
        update fs_user_course_period_days
        <trim prefix="SET" suffixOverrides=",">
            <if test="periodId != null">period_id = #{periodId},</if>
            <if test="lesson != null">lesson = #{lesson},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="money != null">money = #{money},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</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 id = #{id}
    </update>

    <delete id="deleteFsUserCoursePeriodDaysById" parameterType="Long">
        delete from fs_user_course_period_days where id = #{id}
    </delete>

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