-- 修复关注状态字段值不一致的问题
-- 将字符串"关注"统一为数字"1"

-- 1. 先查看当前的状态值分布
SELECT 
    follow_status,
    COUNT(*) as count,
    GROUP_CONCAT(DISTINCT CONCAT(follower_nickname, '->', followed_nickname) SEPARATOR '; ') as examples
FROM eb_follow_record
GROUP BY follow_status;

-- 2. 备份当前数据（可选，建议先备份）
-- CREATE TABLE eb_follow_record_backup AS SELECT * FROM eb_follow_record;

-- 3. 将字符串"关注"统一为数字"1"
UPDATE eb_follow_record 
SET follow_status = '1' 
WHERE follow_status = '关注';

-- 4. 将字符串"取消关注"统一为数字"0"
UPDATE eb_follow_record 
SET follow_status = '0' 
WHERE follow_status IN ('取消关注', '未关注');

-- 5. 验证修复结果
SELECT 
    follow_status,
    COUNT(*) as count,
    GROUP_CONCAT(DISTINCT CONCAT(follower_nickname, '->', followed_nickname) SEPARATOR '; ') as examples
FROM eb_follow_record
GROUP BY follow_status;

-- 6. 查看修复后用户 43 的关注列表
SELECT 
    fr.followed_id,
    fr.followed_nickname,
    u.is_streamer,
    fr.follow_status,
    fr.create_time
FROM eb_follow_record fr
LEFT JOIN eb_user u ON fr.followed_id = u.uid
WHERE fr.follower_id = 43 
    AND fr.follow_status = '1'
    AND fr.is_deleted = 0;

-- 7. 查看修复后用户 43 应该看到的直播间
SELECT 
    u.uid as streamer_id,
    u.nickname as streamer_name,
    lr.id as room_id,
    lr.title as room_title,
    lr.is_live,
    lr.view_count,
    lr.online_count
FROM eb_follow_record fr
INNER JOIN eb_user u ON fr.followed_id = u.uid AND u.is_streamer = 1
INNER JOIN eb_live_room lr ON u.uid = lr.uid
WHERE fr.follower_id = 43 
    AND fr.follow_status = '1'
    AND fr.is_deleted = 0
ORDER BY lr.is_live DESC;
