-- =====================================================
-- 诊断"我的记录"不显示数据问题
-- =====================================================

-- 1. 查看所有用户，找到"道玄"用户的真实ID
SELECT id, uid, nickname, phone, avatar, create_time 
FROM eb_user 
WHERE nickname LIKE '%道玄%' 
   OR uid = 24187196 
   OR id = 121
ORDER BY id DESC;

-- 2. 检查 eb_view_history 表是否存在
SHOW TABLES LIKE 'eb_view_history';

-- 3. 查看表结构
DESC eb_view_history;

-- 4. 查看所有观看历史数据
SELECT * FROM eb_view_history ORDER BY update_time DESC LIMIT 30;

-- 5. 按用户分组统计观看历史
SELECT user_id, COUNT(*) as count 
FROM eb_view_history 
GROUP BY user_id 
ORDER BY count DESC;

-- 6. 查看直播间列表
SELECT id, title, streamer_id, is_live, cover_image 
FROM eb_live_room 
ORDER BY id 
LIMIT 10;

-- =====================================================
-- 为用户121（道玄）添加测试数据
-- =====================================================

-- 先检查用户121是否存在
SELECT id, nickname FROM eb_user WHERE id = 121;

-- 删除旧的测试数据（可选）
-- DELETE FROM eb_view_history WHERE user_id = 121;

-- 插入观看历史测试数据
INSERT INTO eb_view_history (user_id, target_type, target_id, target_title, view_duration, create_time, update_time) 
SELECT 121, 'room', id, title, FLOOR(RAND() * 3600) + 300, 
       NOW() - INTERVAL FLOOR(RAND() * 24) HOUR, 
       NOW() - INTERVAL FLOOR(RAND() * 24) HOUR
FROM eb_live_room 
WHERE id <= 10
ON DUPLICATE KEY UPDATE 
    view_duration = view_duration + VALUES(view_duration),
    update_time = NOW();

-- 验证插入结果
SELECT '=== 用户121的观看历史 ===' as info;
SELECT * FROM eb_view_history WHERE user_id = 121 ORDER BY update_time DESC;

-- =====================================================
-- 检查点赞记录
-- =====================================================
SELECT '=== 用户121的直播间点赞 ===' as info;
SELECT * FROM eb_live_room_like WHERE user_id = 121;

-- 如果没有点赞记录，添加一些
INSERT IGNORE INTO eb_live_room_like (user_id, room_id, create_time)
SELECT 121, id, NOW() - INTERVAL FLOOR(RAND() * 48) HOUR
FROM eb_live_room 
WHERE id <= 5;

SELECT * FROM eb_live_room_like WHERE user_id = 121;

-- =====================================================
-- 检查关注记录
-- =====================================================
SELECT '=== 用户121的关注记录 ===' as info;
SELECT * FROM eb_follow_record WHERE follower_id = 121;

-- =====================================================
-- 汇总统计
-- =====================================================
SELECT '=== 用户121数据汇总 ===' as info;
SELECT 
    (SELECT COUNT(*) FROM eb_view_history WHERE user_id = 121) as 观看历史数,
    (SELECT COUNT(*) FROM eb_live_room_like WHERE user_id = 121) as 直播间点赞数,
    (SELECT COUNT(*) FROM eb_follow_record WHERE follower_id = 121) as 关注数;
