-- ============================================
-- 为 superadmin 和 admin 添加学习记录
-- ============================================

USE `kaopeilian`;

-- 设置用户ID
SET @superadmin_id = 4;
SET @admin_id = 2;

-- 获取训练场景ID
SET @scene1_id = (SELECT id FROM training_scenes WHERE name = 'Python编程助手' LIMIT 1);
SET @scene2_id = (SELECT id FROM training_scenes WHERE name = '面试模拟' LIMIT 1);
SET @scene3_id = (SELECT id FROM training_scenes WHERE name = '项目讨论' LIMIT 1);

-- 获取课程ID
SET @course_id = 4;

-- ============================================
-- 1. 为 superadmin 添加训练会话记录（高级管理员，学习记录较多）
-- ============================================
INSERT INTO training_sessions (
    user_id, 
    scene_id, 
    start_time, 
    end_time, 
    duration_seconds, 
    status, 
    total_score,
    evaluation_result,
    created_by
) VALUES
-- 30天的丰富学习记录
(@superadmin_id, @scene1_id, '2025-08-23 09:00:00', '2025-08-23 10:30:00', 5400, 'COMPLETED', 95, '{"feedback": "架构设计优秀"}', @superadmin_id),
(@superadmin_id, @scene3_id, '2025-08-25 14:00:00', '2025-08-25 16:00:00', 7200, 'COMPLETED', 98, '{"feedback": "系统设计能力出色"}', @superadmin_id),
(@superadmin_id, @scene2_id, '2025-08-28 10:00:00', '2025-08-28 11:30:00', 5400, 'COMPLETED', 96, '{"feedback": "技术面试官水平"}', @superadmin_id),
(@superadmin_id, @scene1_id, '2025-09-01 09:00:00', '2025-09-01 10:00:00', 3600, 'COMPLETED', 94, '{"feedback": "代码审查能力强"}', @superadmin_id),
(@superadmin_id, @scene3_id, '2025-09-03 13:30:00', '2025-09-03 15:30:00', 7200, 'COMPLETED', 97, '{"feedback": "技术决策合理"}', @superadmin_id),
(@superadmin_id, @scene1_id, '2025-09-05 10:00:00', '2025-09-05 11:00:00', 3600, 'COMPLETED', 95, '{"feedback": "性能优化出色"}', @superadmin_id),
(@superadmin_id, @scene2_id, '2025-09-08 14:00:00', '2025-09-08 15:30:00', 5400, 'COMPLETED', 93, '{"feedback": "面试策略成熟"}', @superadmin_id),
(@superadmin_id, @scene3_id, '2025-09-10 09:00:00', '2025-09-10 11:00:00', 7200, 'COMPLETED', 96, '{"feedback": "项目管理经验丰富"}', @superadmin_id),
(@superadmin_id, @scene1_id, '2025-09-12 10:00:00', '2025-09-12 11:30:00', 5400, 'COMPLETED', 98, '{"feedback": "技术深度令人印象深刻"}', @superadmin_id),
(@superadmin_id, @scene2_id, '2025-09-14 14:00:00', '2025-09-14 15:00:00', 3600, 'COMPLETED', 95, '{"feedback": "团队管理能力优秀"}', @superadmin_id),
(@superadmin_id, @scene3_id, '2025-09-16 09:30:00', '2025-09-16 11:30:00', 7200, 'COMPLETED', 97, '{"feedback": "架构视野开阔"}', @superadmin_id),
(@superadmin_id, @scene1_id, '2025-09-18 10:00:00', '2025-09-18 11:00:00', 3600, 'COMPLETED', 96, '{"feedback": "最佳实践掌握透彻"}', @superadmin_id),
(@superadmin_id, @scene2_id, '2025-09-20 14:00:00', '2025-09-20 15:30:00', 5400, 'COMPLETED', 94, '{"feedback": "人才评估准确"}', @superadmin_id),
(@superadmin_id, @scene3_id, '2025-09-21 09:00:00', '2025-09-21 11:00:00', 7200, 'COMPLETED', 98, '{"feedback": "技术方案完善"}', @superadmin_id),
(@superadmin_id, @scene1_id, '2025-09-22 10:00:00', '2025-09-22 11:30:00', 5400, 'COMPLETED', 97, '{"feedback": "持续学习精神可嘉"}', @superadmin_id);

-- ============================================
-- 2. 为 admin 添加训练会话记录（普通管理员，学习记录适中）
-- ============================================
INSERT INTO training_sessions (
    user_id, 
    scene_id, 
    start_time, 
    end_time, 
    duration_seconds, 
    status, 
    total_score,
    evaluation_result,
    created_by
) VALUES
-- 20天的学习记录
(@admin_id, @scene1_id, '2025-09-03 09:00:00', '2025-09-03 10:00:00', 3600, 'COMPLETED', 88, '{"feedback": "基础扎实"}', @admin_id),
(@admin_id, @scene2_id, '2025-09-05 14:00:00', '2025-09-05 15:00:00', 3600, 'COMPLETED', 85, '{"feedback": "面试技巧良好"}', @admin_id),
(@admin_id, @scene3_id, '2025-09-08 10:00:00', '2025-09-08 11:30:00', 5400, 'COMPLETED', 90, '{"feedback": "项目理解到位"}', @admin_id),
(@admin_id, @scene1_id, '2025-09-10 09:30:00', '2025-09-10 10:30:00', 3600, 'COMPLETED', 87, '{"feedback": "进步明显"}', @admin_id),
(@admin_id, @scene2_id, '2025-09-12 14:00:00', '2025-09-12 15:00:00', 3600, 'COMPLETED', 89, '{"feedback": "沟通能力提升"}', @admin_id),
(@admin_id, @scene3_id, '2025-09-15 10:00:00', '2025-09-15 11:30:00', 5400, 'COMPLETED', 91, '{"feedback": "方案设计合理"}', @admin_id),
(@admin_id, @scene1_id, '2025-09-17 09:00:00', '2025-09-17 10:00:00', 3600, 'COMPLETED', 86, '{"feedback": "代码质量不错"}', @admin_id),
(@admin_id, @scene2_id, '2025-09-19 14:00:00', '2025-09-19 15:00:00', 3600, 'COMPLETED', 88, '{"feedback": "表达清晰"}', @admin_id),
(@admin_id, @scene3_id, '2025-09-21 10:00:00', '2025-09-21 11:30:00', 5400, 'COMPLETED', 92, '{"feedback": "项目管理有进步"}', @admin_id),
(@admin_id, @scene1_id, '2025-09-22 09:00:00', '2025-09-22 10:00:00', 3600, 'COMPLETED', 90, '{"feedback": "技术理解深入"}', @admin_id);

-- ============================================
-- 3. 为管理员添加考试记录
-- ============================================

-- superadmin 的考试记录（成绩优秀）
INSERT INTO exams (
    user_id, 
    course_id, 
    exam_name, 
    question_count, 
    total_score, 
    pass_score, 
    start_time, 
    end_time, 
    duration_minutes, 
    score, 
    is_passed, 
    status,
    questions,
    answers
) VALUES
-- superadmin 的考试（高分）
(@superadmin_id, @course_id, 'Python高级特性测试', 40, 100, 80, 
 '2025-09-01 09:00:00', '2025-09-01 10:00:00', 60, 98, 1, 'completed',
 '[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40]',
 '{}'),

(@superadmin_id, @course_id, 'Python架构设计测试', 50, 100, 85, 
 '2025-09-10 10:00:00', '2025-09-10 11:30:00', 90, 96, 1, 'completed',
 '[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50]',
 '{}'),

(@superadmin_id, @course_id, 'Python性能优化测试', 35, 100, 80, 
 '2025-09-20 14:00:00', '2025-09-20 15:15:00', 75, 95, 1, 'completed',
 '[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35]',
 '{}'),

-- admin 的考试记录（成绩良好）
(@admin_id, @course_id, 'Python基础测试', 30, 100, 60, 
 '2025-09-05 14:00:00', '2025-09-05 15:00:00', 60, 85, 1, 'completed',
 '[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]',
 '{}'),

(@admin_id, @course_id, 'Python进阶测试', 35, 100, 70, 
 '2025-09-15 10:00:00', '2025-09-15 11:15:00', 75, 88, 1, 'completed',
 '[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35]',
 '{}');

-- ============================================
-- 查询验证
-- ============================================

-- superadmin 的统计
SELECT 
    'superadmin训练统计' as type,
    COUNT(DISTINCT DATE(start_time)) as learning_days,
    ROUND(SUM(duration_seconds) / 3600, 1) as total_hours,
    COUNT(*) as session_count,
    ROUND(AVG(total_score), 1) as avg_score
FROM training_sessions 
WHERE user_id = @superadmin_id;

SELECT 
    'superadmin考试统计' as type,
    COUNT(*) as exam_count,
    SUM(question_count) as total_questions,
    ROUND(AVG(score), 1) as avg_score
FROM exams 
WHERE user_id = @superadmin_id AND status = 'completed';

-- admin 的统计
SELECT 
    'admin训练统计' as type,
    COUNT(DISTINCT DATE(start_time)) as learning_days,
    ROUND(SUM(duration_seconds) / 3600, 1) as total_hours,
    COUNT(*) as session_count,
    ROUND(AVG(total_score), 1) as avg_score
FROM training_sessions 
WHERE user_id = @admin_id;

SELECT 
    'admin考试统计' as type,
    COUNT(*) as exam_count,
    SUM(question_count) as total_questions,
    ROUND(AVG(score), 1) as avg_score
FROM exams 
WHERE user_id = @admin_id AND status = 'completed';

SELECT '管理员学习数据添加完成！' as message;
