<?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.FsUserVideoFavoriteMapper">
    
    <resultMap type="FsUserVideoFavorite" id="FsUserVideoFavoriteResult">
        <result property="favoriteId"    column="favorite_id"    />
        <result property="userId"    column="user_id"    />
        <result property="videoId"    column="video_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectFsUserVideoFavoriteVo">
        select favorite_id, user_id, video_id, create_time, update_time from fs_user_video_favorite
    </sql>

    <select id="selectFsUserVideoFavoriteList" parameterType="FsUserVideoFavorite" resultMap="FsUserVideoFavoriteResult">
        <include refid="selectFsUserVideoFavoriteVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="videoId != null "> and video_id = #{videoId}</if>
        </where>
    </select>
    
    <select id="selectFsUserVideoFavoriteByFavoriteId" parameterType="Long" resultMap="FsUserVideoFavoriteResult">
        <include refid="selectFsUserVideoFavoriteVo"/>
        where favorite_id = #{favoriteId}
    </select>
        
    <insert id="insertFsUserVideoFavorite" parameterType="FsUserVideoFavorite" useGeneratedKeys="true" keyProperty="favoriteId">
        insert into fs_user_video_favorite
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</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="videoId != null">#{videoId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateFsUserVideoFavorite" parameterType="FsUserVideoFavorite">
        update fs_user_video_favorite
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</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 favorite_id = #{favoriteId}
    </update>

    <delete id="deleteFsUserVideoFavoriteByFavoriteId" parameterType="Long">
        delete from fs_user_video_favorite where favorite_id = #{favoriteId}
    </delete>

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