-- 诊断当前关注页面问题
-- 执行这个脚本来查看具体问题所在

SELECT '========== 1. 检查当前登录用户的关注记录 ==========' as step;

-- 查看所有关注记录
SELECT 
    fr.id,
    fr.follower_id,
    fr.follower_nickname,
    fr.followed_id,
    fr.followed_nickname,
    fr.follow_status,
    fr.is_deleted,
    fr.create_time
FROM eb_follow_record fr
ORDER BY fr.create_time DESC
LIMIT 20;

SELECT '========== 2. 检查关注状态值的分布 ==========' as step;

SELECT 
    follow_status,
    COUNT(*) as count,
    GROUP_CONCAT(DISTINCT CONCAT(follower_id, '->', followed_id) LIMIT 5) as examples
FROM eb_follow_record
GROUP BY follow_status;

SELECT '========== 3. 检查主播用户 ==========' as step;

SELECT 
    u.uid,
    u.nickname,
    u.is_streamer,
    COUNT(DISTINCT lr.id) as room_count,
    SUM(CASE WHEN lr.is_live = 1 THEN 1 ELSE 0 END) as live_count
FROM eb_user u
LEFT JOIN eb_live_room lr ON u.uid = lr.uid
WHERE u.is_streamer = 1
GROUP BY u.uid, u.nickname, u.is_streamer
ORDER BY room_count DESC;

SELECT '========== 4. 检查所有直播间 ==========' as step;

SELECT 
    lr.id,
    lr.uid,
    u.nickname as streamer_name,
    lr.title,
    lr.is_live,
    lr.started_at,
    lr.view_count
FROM eb_live_room lr
LEFT JOIN eb_user u ON lr.uid = u.uid
ORDER BY lr.is_live DESC, lr.id DESC
LIMIT 20;

SELECT '========== 5. 模拟关注页面查询（用户43） ==========' as step;

-- 获取用户43的关注列表
SELECT 
    '用户43的关注列表' as info,
    fr.followed_id,
    fr.followed_nickname,
    fr.follow_status,
    u.is_streamer
FROM eb_follow_record fr
LEFT JOIN eb_user u ON fr.followed_id = u.uid
WHERE fr.follower_id = 43 
    AND fr.is_deleted = 0;

-- 查找这些被关注用户的直播间
SELECT 
    '用户43关注的主播的直播间' as info,
    lr.id as room_id,
    lr.uid as streamer_uid,
    u.nickname as streamer_name,
    lr.title as room_title,
    lr.is_live,
    lr.started_at
FROM eb_live_room lr
INNER JOIN eb_user u ON lr.uid = u.uid
WHERE lr.uid IN (
    SELECT fr.followed_id 
    FROM eb_follow_record fr
    WHERE fr.follower_id = 43 
        AND fr.is_deleted = 0
        AND fr.follow_status IN ('1', '关注')
)
ORDER BY lr.is_live DESC;

SELECT '========== 6. 检查是否有follow_status不是1的记录 ==========' as step;

SELECT 
    follow_status,
    COUNT(*) as count
FROM eb_follow_record
WHERE follow_status != '1'
GROUP BY follow_status;

SELECT '========== 7. 检查用户表中的is_streamer字段 ==========' as step;

SELECT 
    is_streamer,
    COUNT(*) as count
FROM eb_user
GROUP BY is_streamer;
