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

    <resultMap type="FsUserVideoView" id="FsUserVideoViewResult">
        <result property="viewId"    column="view_id"    />
        <result property="userId"    column="user_id"    />
        <result property="duration"    column="duration"    />
        <result property="videoId"    column="video_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectFsUserVideoViewVo">
        select view_id, user_id, duration, video_id, create_time, update_time from fs_user_video_view
    </sql>

    <select id="selectFsUserVideoViewList" parameterType="FsUserVideoView" resultMap="FsUserVideoViewResult">
        <include refid="selectFsUserVideoViewVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="duration != null "> and duration = #{duration}</if>
            <if test="videoId != null "> and video_id = #{videoId}</if>
        </where>
    </select>

    <select id="selectFsUserVideoViewByViewId" parameterType="Long" resultMap="FsUserVideoViewResult">
        <include refid="selectFsUserVideoViewVo"/>
        where view_id = #{viewId}
    </select>

    <insert id="insertFsUserVideoView" parameterType="FsUserVideoView" useGeneratedKeys="true" keyProperty="viewId">
        insert into fs_user_video_view
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="duration != null">duration,</if>
            <if test="videoId != null">video_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="duration != null">#{duration},</if>
            <if test="videoId != null">#{videoId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateFsUserVideoView" parameterType="FsUserVideoView">
        update fs_user_video_view
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="videoId != null">video_id = #{videoId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where view_id = #{viewId}
    </update>

    <delete id="deleteFsUserVideoViewByViewId" parameterType="Long">
        delete from fs_user_video_view where view_id = #{viewId}
    </delete>

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