<?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.store.mapper.FsUserCourseCountMapper">
    
    <resultMap type="FsUserCourseCount" id="FsUserCourseCountResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="watchCourseCount"    column="watch_course_count"    />
        <result property="missCourseCount"    column="miss_course_count"    />
        <result property="missCourseStatus"    column="miss_course_status"    />
        <result property="missCourseDays"    column="miss_course_days"    />
        <result property="courseId"    column="course_id"    />
        <result property="partCourseCount"    column="part_course_count"    />
        <result property="lastWatchDate"    column="last_watch_date"    />
        <result property="status"    column="status"    />
        <result property="stopWatchDays"    column="stop_watch_days"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="completeWatchDate"    column="complete_watch_date"    />
        <result property="completeWatchCount"    column="complete_watch_count"    />
        <result property="watchTimes"    column="watch_times"    />
    </resultMap>

    <sql id="selectFsUserCourseCountVo">
        select id, user_id, watch_course_count, miss_course_count, miss_course_status, miss_course_days, course_id, part_course_count, last_watch_date, status, stop_watch_days, create_time, update_time, create_by, update_by, complete_watch_date, complete_watch_count, watch_times from fs_user_course_count
    </sql>

    <select id="selectFsUserCourseCountList" parameterType="FsUserCourseCount" resultMap="FsUserCourseCountResult">
        <include refid="selectFsUserCourseCountVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="watchCourseCount != null "> and watch_course_count = #{watchCourseCount}</if>
            <if test="missCourseCount != null "> and miss_course_count = #{missCourseCount}</if>
            <if test="missCourseStatus != null "> and miss_course_status = #{missCourseStatus}</if>
            <if test="missCourseDays != null "> and miss_course_days = #{missCourseDays}</if>
            <if test="courseId != null "> and course_id = #{courseId}</if>
            <if test="partCourseCount != null  and partCourseCount != ''"> and part_course_count = #{partCourseCount}</if>
            <if test="lastWatchDate != null "> and last_watch_date = #{lastWatchDate}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="stopWatchDays != null "> and stop_watch_days = #{stopWatchDays}</if>
            <if test="completeWatchDate != null "> and complete_watch_date = #{completeWatchDate}</if>
            <if test="completeWatchCount != null "> and complete_watch_count = #{completeWatchCount}</if>
            <if test="watchTimes != null "> and watch_times = #{watchTimes}</if>
        </where>
    </select>
    
    <select id="selectFsUserCourseCountById" parameterType="Long" resultMap="FsUserCourseCountResult">
        <include refid="selectFsUserCourseCountVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertFsUserCourseCount" parameterType="FsUserCourseCount">
        insert into fs_user_course_count
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="watchCourseCount != null">watch_course_count,</if>
            <if test="missCourseCount != null">miss_course_count,</if>
            <if test="missCourseStatus != null">miss_course_status,</if>
            <if test="missCourseDays != null">miss_course_days,</if>
            <if test="courseId != null">course_id,</if>
            <if test="partCourseCount != null">part_course_count,</if>
            <if test="lastWatchDate != null">last_watch_date,</if>
            <if test="status != null">status,</if>
            <if test="stopWatchDays != null">stop_watch_days,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="completeWatchDate != null">complete_watch_date,</if>
            <if test="completeWatchCount != null">complete_watch_count,</if>
            <if test="watchTimes != null">watch_times,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userId != null">#{userId},</if>
            <if test="watchCourseCount != null">#{watchCourseCount},</if>
            <if test="missCourseCount != null">#{missCourseCount},</if>
            <if test="missCourseStatus != null">#{missCourseStatus},</if>
            <if test="missCourseDays != null">#{missCourseDays},</if>
            <if test="courseId != null">#{courseId},</if>
            <if test="partCourseCount != null">#{partCourseCount},</if>
            <if test="lastWatchDate != null">#{lastWatchDate},</if>
            <if test="status != null">#{status},</if>
            <if test="stopWatchDays != null">#{stopWatchDays},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="completeWatchDate != null">#{completeWatchDate},</if>
            <if test="completeWatchCount != null">#{completeWatchCount},</if>
            <if test="watchTimes != null">#{watchTimes},</if>
         </trim>
    </insert>

    <update id="updateFsUserCourseCount" parameterType="FsUserCourseCount">
        update fs_user_course_count
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="watchCourseCount != null">watch_course_count = #{watchCourseCount},</if>
            <if test="missCourseCount != null">miss_course_count = #{missCourseCount},</if>
            <if test="missCourseStatus != null">miss_course_status = #{missCourseStatus},</if>
            <if test="missCourseDays != null">miss_course_days = #{missCourseDays},</if>
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="partCourseCount != null">part_course_count = #{partCourseCount},</if>
            <if test="lastWatchDate != null">last_watch_date = #{lastWatchDate},</if>
            <if test="status != null">status = #{status},</if>
            <if test="stopWatchDays != null">stop_watch_days = #{stopWatchDays},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="completeWatchDate != null">complete_watch_date = #{completeWatchDate},</if>
            <if test="completeWatchCount != null">complete_watch_count = #{completeWatchCount},</if>
            <if test="watchTimes != null">watch_times = #{watchTimes},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsUserCourseCountById" parameterType="Long">
        delete from fs_user_course_count where id = #{id}
    </delete>

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