<?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.ruoyi.abuwx.mapper.UserFavoriteMapper">
    
    <resultMap type="UserFavorite" id="UserFavoriteResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="contentType"    column="content_type"    />
        <result property="contentId"    column="content_id"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectUserFavoriteVo">
        select id, user_id, content_type, content_id, remark, create_time, update_time, create_by, update_by from user_favorite
    </sql>

    <select id="selectUserFavoriteList" parameterType="UserFavorite" resultMap="UserFavoriteResult">
        <include refid="selectUserFavoriteVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="contentType != null "> and content_type = #{contentType}</if>
            <if test="contentId != null "> and content_id = #{contentId}</if>
        </where>
    </select>
    
    <select id="selectUserFavoriteById" parameterType="Long" resultMap="UserFavoriteResult">
        <include refid="selectUserFavoriteVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertUserFavorite" parameterType="UserFavorite" useGeneratedKeys="true" keyProperty="id">
        insert into user_favorite
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="contentType != null">content_type,</if>
            <if test="contentId != null">content_id,</if>
            <if test="remark != null">remark,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="contentType != null">#{contentType},</if>
            <if test="contentId != null">#{contentId},</if>
            <if test="remark != null">#{remark},</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>
         </trim>
    </insert>

    <update id="updateUserFavorite" parameterType="UserFavorite">
        update user_favorite
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="contentType != null">content_type = #{contentType},</if>
            <if test="contentId != null">content_id = #{contentId},</if>
            <if test="remark != null">remark = #{remark},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUserFavoriteById" parameterType="Long">
        delete from user_favorite where id = #{id}
    </delete>

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

    <delete id="unFavorite">
        delete from user_favorite where user_id = #{userId} and content_type=#{contentType} and content_id = #{contentId}
    </delete>
</mapper>