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

    <resultMap type="FsUserCourseStudyLog" id="FsUserCourseStudyLogResult">
        <result property="logId"    column="log_id"    />
        <result property="courseId"    column="course_id"    />
        <result property="courseName"    column="course_name"    />
        <result property="videoId"    column="video_id"    />
        <result property="videoName"    column="video_name"    />
        <result property="userId"    column="user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="studyId"    column="study_id"    />
        <result property="times"    column="times"    />
        <result property="rate"    column="rate"    />
        <result property="isBuy"    column="is_buy"    />
        <result property="status"    column="status"    />
        <result property="currentTimes"    column="current_times"    />
        <result property="totalTimes"    column="total_times"    />
    </resultMap>

    <sql id="selectFsUserCourseStudyLogVo">
        select log_id, total_times,course_id,is_buy,status, course_name, video_id, video_name, user_id, create_time, study_id, times, rate, current_times from fs_user_course_study_log
    </sql>

    <select id="selectFsUserCourseStudyLogList" parameterType="FsUserCourseStudyLog" resultMap="FsUserCourseStudyLogResult">
        <include refid="selectFsUserCourseStudyLogVo"/>
        <where>
            <if test="courseId != null "> and course_id = #{courseId}</if>
            <if test="courseName != null  and courseName != ''"> and course_name = #{courseName}</if>
            <if test="videoId != null "> and video_id = #{videoId}</if>
            <if test="videoName != null  and videoName != ''"> and video_name = #{videoName}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="studyId != null "> and study_id = #{studyId}</if>
            <if test="times != null "> and times = #{times}</if>
            <if test="rate != null "> and rate = #{rate}</if>
            <if test="currentTimes != null "> and current_times = #{currentTimes}</if>
        </where>
    </select>

    <select id="selectFsUserCourseStudyLogByLogId" parameterType="String" resultMap="FsUserCourseStudyLogResult">
        <include refid="selectFsUserCourseStudyLogVo"/>
        where log_id = #{logId}
    </select>

    <insert id="insertFsUserCourseStudyLog" parameterType="FsUserCourseStudyLog" useGeneratedKeys="true" keyProperty="logId">
        insert into fs_user_course_study_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="courseId != null">course_id,</if>
            <if test="courseName != null">course_name,</if>
            <if test="videoId != null">video_id,</if>
            <if test="videoName != null">video_name,</if>
            <if test="userId != null">user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="studyId != null">study_id,</if>
            <if test="times != null">times,</if>
            <if test="rate != null">rate,</if>
            <if test="currentTimes != null">current_times,</if>
            <if test="isBuy != null">is_buy,</if>
            <if test="status != null">status,</if>
            <if test="totalTimes != null">total_times,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="courseId != null">#{courseId},</if>
            <if test="courseName != null">#{courseName},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="videoName != null">#{videoName},</if>
            <if test="userId != null">#{userId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="studyId != null">#{studyId},</if>
            <if test="times != null">#{times},</if>
            <if test="rate != null">#{rate},</if>
            <if test="currentTimes != null">#{currentTimes},</if>
            <if test="isBuy != null">#{isBuy},</if>
            <if test="status != null">#{status},</if>
            <if test="totalTimes != null">#{totalTimes},</if>
         </trim>
    </insert>

    <update id="updateFsUserCourseStudyLog" parameterType="FsUserCourseStudyLog">
        update fs_user_course_study_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="courseId != null">course_id = #{courseId},</if>
            <if test="courseName != null">course_name = #{courseName},</if>
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="videoName != null">video_name = #{videoName},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="studyId != null">study_id = #{studyId},</if>
            <if test="times != null">times = #{times},</if>
            <if test="rate != null">rate = #{rate},</if>
            <if test="currentTimes != null">current_times = #{currentTimes},</if>
            <if test="isBuy != null">is_buy = #{isBuy},</if>
            <if test="status != null">status = #{status},</if>
            <if test="totalTimes != null">total_times = #{totalTimes},</if>
        </trim>
        where log_id = #{logId}
    </update>

    <delete id="deleteFsUserCourseStudyLogByLogId" parameterType="String">
        delete from fs_user_course_study_log where log_id = #{logId}
    </delete>

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