<?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.live.mapper.LiveUserFollowMapper">

    <resultMap type="LiveUserFollow" id="LiveUserFollowResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="liveId"    column="live_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectLiveUserFollowVo">
        select id, user_id, live_id, create_time, update_time from live_user_follow
    </sql>

    <select id="selectLiveUserFollowList" parameterType="LiveUserFollow" resultMap="LiveUserFollowResult">
        <include refid="selectLiveUserFollowVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="liveId != null "> and live_id = #{liveId}</if>
        </where>
    </select>

    <select id="selectLiveUserFollowById" parameterType="Long" resultMap="LiveUserFollowResult">
        <include refid="selectLiveUserFollowVo"/>
        where id = #{id}
    </select>

    <insert id="insertLiveUserFollow" parameterType="LiveUserFollow" useGeneratedKeys="true" keyProperty="id">
        insert into live_user_follow
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="liveId != null">live_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="liveId != null">#{liveId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateLiveUserFollow" parameterType="LiveUserFollow">
        update live_user_follow
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="liveId != null">live_id = #{liveId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLiveUserFollowById" parameterType="Long">
        delete from live_user_follow where id = #{id}
    </delete>

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

    <select id="selectLiveUserFollowByLiveIdAndUserId" parameterType="LiveUserFollow" resultMap="LiveUserFollowResult">
        <include refid="selectLiveUserFollowVo"/>
        where live_id = #{liveId} and user_id = #{userId}
    </select>

    <delete id="deleteLiveUserFollowByLiveIdAndUserId" parameterType="LiveUserFollow">
        delete from live_user_follow where live_id = #{liveId} and user_id = #{userId}
    </delete>

</mapper>
