<?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.younike.system.mapper.ServerUserFollowMapper">

    <resultMap type="com.younike.system.domain.ServerUserFollow" id="ServerUserFollowResult">
        <result property="serverUserId"    column="server_user_id"    />
        <result property="categoryId"    column="category_id"    />
    </resultMap>

    <sql id="selectServerUserFollowVo">
        select server_user_id, category_id from server_user_follow
    </sql>

    <select id="selectServerUserFollowList" parameterType="com.younike.system.domain.ServerUserFollow" resultMap="ServerUserFollowResult">
        <include refid="selectServerUserFollowVo"/>
        <where>
            <if test="serverUserId != null ">and server_user_id = #{serverUserId}</if>
            <if test="categoryId != null ">and category_id = #{categoryId}</if>
        </where>
    </select>

    <select id="selectServerUserFollowByServerUserId" parameterType="Long" resultMap="ServerUserFollowResult">
        <include refid="selectServerUserFollowVo"/>
        where server_user_id = #{serverUserId}
    </select>

    <insert id="insertServerUserFollow" parameterType="ServerUserFollow">
        insert into server_user_follow
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="serverUserId != null">server_user_id,</if>
            <if test="categoryId != null">category_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="serverUserId != null">#{serverUserId},</if>
            <if test="categoryId != null">#{categoryId},</if>
         </trim>
    </insert>

    <update id="updateServerUserFollow" parameterType="ServerUserFollow">
        update server_user_follow
        <trim prefix="SET" suffixOverrides=",">
            <if test="categoryId != null">category_id = #{categoryId},</if>
        </trim>
        where server_user_id = #{serverUserId}
    </update>

    <delete id="deleteServerUserFollowByServerUserId" parameterType="Long">
        delete from server_user_follow where server_user_id = #{serverUserId}
    </delete>

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

<!--    删除数据-->
    <delete id="cancelAttention" parameterType="ServerUserFollow">
        delete from server_user_follow
        where server_user_id =  #{serverUserId}
         and category_id=#{categoryId}
    </delete>
<!--   批量添加数据-->
    <insert id="insertServerUserFollowList" parameterType="List">
        <foreach collection="list" item="item" index="index" separator=";">
            INSERT INTO server_user_follow (`server_user_id`, `category_id`)
            VALUES (#{item.serverUserId}, #{item.categoryId})
        </foreach>
    </insert>
<!--    批量删除数据-->
    <delete id="deleteServerUserFollowList" parameterType="List">
        <foreach collection="list" item="item" index="index" separator=";">
            delete from server_user_follow where server_user_id = #{item.serverUserId} and category_id = #{item.categoryId}
        </foreach>
    </delete>
</mapper>
