<?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.ai.da.mapper.primary.UserFollowMapper">
    <select id="getFolloweeListByFollower" resultType="com.ai.da.model.vo.AccountFollowVO">
        SELECT a.id as sender_id, a.user_name AS user_name, a.avatar AS avatar, b.create_time AS create_time
        FROM t_account a
                 INNER JOIN t_user_follow b ON a.id = b.followee_id
        WHERE b.follower_id = #{followerAccountId}
        <if test="order != null and order != ''">
            ORDER BY b.create_time ${order}
        </if>
        LIMIT #{limit} OFFSET #{offset}
    </select>
    <select id="getFollowerListByFollowee" resultType="com.ai.da.model.vo.AccountFollowVO">
        SELECT a.id as sender_id, a.user_name AS user_name, a.avatar AS avatar, b.create_time AS create_time
        FROM t_account a
                 INNER JOIN t_user_follow b ON a.id = b.follower_id
        WHERE b.followee_id = #{followeeAccountId}
        <if test="order != null and order != ''">
            ORDER BY b.create_time ${order}
        </if>
        LIMIT #{limit} OFFSET #{offset}
    </select>

    <select id="getFolloweeListByName" resultType="com.ai.da.model.vo.AccountFollowVO">
        SELECT a.id as sender_id, a.user_name, a.avatar, b.create_time as create_time
        FROM t_account a
                 INNER JOIN t_user_follow b ON a.id = b.followee_id
        WHERE b.follower_id = #{followerId}
          AND b.followee_id in (
            SELECT id
            FROM t_account
            WHERE user_name = #{name} OR user_email = #{name}
        )
        GROUP BY a.user_email;

    </select>

    <select id="getFollowerListByName" resultType="com.ai.da.model.vo.AccountFollowVO">
        SELECT a.id as sender_id, a.user_name, a.avatar, b.create_time as create_time
        FROM t_account a
                 INNER JOIN t_user_follow b ON a.id = b.follower_id
        WHERE b.followee_id = #{followeeId}
          AND b.follower_id in (
            SELECT id
            FROM t_account
            WHERE user_name = #{name} OR user_email = #{name}
        )
        GROUP BY a.user_email;
    </select>




</mapper>
