<?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.FsUserCourseFavoriteMapper">
    
    <resultMap type="FsUserCourseFavorite" id="FsUserCourseFavoriteResult">
        <result property="favoriteId"    column="favorite_id"    />
        <result property="userId"    column="user_id"    />
        <result property="courseId"    column="course_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectFsUserCourseFavoriteVo">
        select favorite_id, user_id, course_id, create_time, update_time from fs_user_course_favorite
    </sql>

    <select id="selectFsUserCourseFavoriteList" parameterType="FsUserCourseFavorite" resultMap="FsUserCourseFavoriteResult">
        <include refid="selectFsUserCourseFavoriteVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="courseId != null "> and course_id = #{courseId}</if>
        </where>
    </select>
    
    <select id="selectFsUserCourseFavoriteByFavoriteId" parameterType="Long" resultMap="FsUserCourseFavoriteResult">
        <include refid="selectFsUserCourseFavoriteVo"/>
        where favorite_id = #{favoriteId}
    </select>
        
    <insert id="insertFsUserCourseFavorite" parameterType="FsUserCourseFavorite" useGeneratedKeys="true" keyProperty="favoriteId">
        insert into fs_user_course_favorite
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="courseId != null">course_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="courseId != null">#{courseId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateFsUserCourseFavorite" parameterType="FsUserCourseFavorite">
        update fs_user_course_favorite
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="courseId != null">course_id = #{courseId},</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="deleteFsUserCourseFavoriteByFavoriteId" parameterType="Long">
        delete from fs_user_course_favorite where favorite_id = #{favoriteId}
    </delete>

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