-- 模拟数据脚本：考试成绩和错题记录
-- 创建时间：2025-10-12
-- 说明：为成绩报告和错题本页面添加演示数据
-- 场景：轻医美连锁品牌员工培训考试

USE kaopeilian;

-- ========================================
-- 一、插入考试记录（包含三轮得分）
-- ========================================

-- 用户5（consultant_001）的考试记录
-- 考试1：皮肤生理学基础（完成三轮）
INSERT INTO exams (
    user_id, course_id, exam_name, question_count, total_score, pass_score,
    start_time, end_time, duration_minutes,
    round1_score, round2_score, round3_score, score, is_passed, status
) VALUES (
    5, 1, '皮肤生理学基础 - 动态考试', 10, 100.0, 60.0,
    '2025-10-05 09:00:00', '2025-10-05 10:30:00', 60,
    70, 85, 100, 100, TRUE, 'submitted'
);

-- 考试2：医美产品知识与应用（完成三轮）
INSERT INTO exams (
    user_id, course_id, exam_name, question_count, total_score, pass_score,
    start_time, end_time, duration_minutes,
    round1_score, round2_score, round3_score, score, is_passed, status
) VALUES (
    5, 2, '医美产品知识与应用 - 动态考试', 10, 100.0, 60.0,
    '2025-10-06 14:00:00', '2025-10-06 15:20:00', 60,
    65, 80, 90, 90, TRUE, 'submitted'
);

-- 考试3：美容仪器操作与维护（完成两轮）
INSERT INTO exams (
    user_id, course_id, exam_name, question_count, total_score, pass_score,
    start_time, end_time, duration_minutes,
    round1_score, round2_score, round3_score, score, is_passed, status
) VALUES (
    5, 3, '美容仪器操作与维护 - 动态考试', 10, 100.0, 60.0,
    '2025-10-07 10:00:00', '2025-10-07 11:15:00', 60,
    80, 95, NULL, 95, TRUE, 'submitted'
);

-- 考试4：医美项目介绍与咨询（完成一轮）
INSERT INTO exams (
    user_id, course_id, exam_name, question_count, total_score, pass_score,
    start_time, end_time, duration_minutes,
    round1_score, round2_score, round3_score, score, is_passed, status
) VALUES (
    5, 4, '医美项目介绍与咨询 - 动态考试', 10, 100.0, 60.0,
    '2025-10-08 15:00:00', '2025-10-08 15:45:00', 60,
    55, NULL, NULL, 55, FALSE, 'submitted'
);

-- 考试5：轻医美销售技巧（完成三轮）
INSERT INTO exams (
    user_id, course_id, exam_name, question_count, total_score, pass_score,
    start_time, end_time, duration_minutes,
    round1_score, round2_score, round3_score, score, is_passed, status
) VALUES (
    5, 5, '轻医美销售技巧 - 动态考试', 10, 100.0, 60.0,
    '2025-10-09 09:30:00', '2025-10-09 11:00:00', 60,
    75, 90, 100, 100, TRUE, 'submitted'
);

-- 考试6：客户服务与投诉处理（完成三轮）
INSERT INTO exams (
    user_id, course_id, exam_name, question_count, total_score, pass_score,
    start_time, end_time, duration_minutes,
    round1_score, round2_score, round3_score, score, is_passed, status
) VALUES (
    5, 6, '客户服务与投诉处理 - 动态考试', 10, 100.0, 60.0,
    '2025-10-10 14:00:00', '2025-10-10 15:30:00', 60,
    85, 95, 100, 100, TRUE, 'submitted'
);

-- 考试7：社媒营销与私域运营（完成两轮）
INSERT INTO exams (
    user_id, course_id, exam_name, question_count, total_score, pass_score,
    start_time, end_time, duration_minutes,
    round1_score, round2_score, round3_score, score, is_passed, status
) VALUES (
    5, 7, '社媒营销与私域运营 - 动态考试', 10, 100.0, 60.0,
    '2025-10-11 10:00:00', '2025-10-11 11:10:00', 60,
    60, 75, NULL, 75, TRUE, 'submitted'
);

-- 考试8：卫生消毒与感染控制（完成三轮，最近的考试）
INSERT INTO exams (
    user_id, course_id, exam_name, question_count, total_score, pass_score,
    start_time, end_time, duration_minutes,
    round1_score, round2_score, round3_score, score, is_passed, status
) VALUES (
    5, 9, '卫生消毒与感染控制 - 动态考试', 10, 100.0, 60.0,
    '2025-10-12 09:00:00', '2025-10-12 10:20:00', 60,
    90, 100, 100, 100, TRUE, 'submitted'
);

-- ========================================
-- 二、插入错题记录
-- ========================================

-- 获取刚插入的考试ID（使用最后8条记录）
SET @exam1_id = (SELECT id FROM exams WHERE user_id=5 AND course_id=1 ORDER BY id DESC LIMIT 1);
SET @exam2_id = (SELECT id FROM exams WHERE user_id=5 AND course_id=2 ORDER BY id DESC LIMIT 1);
SET @exam4_id = (SELECT id FROM exams WHERE user_id=5 AND course_id=4 ORDER BY id DESC LIMIT 1);
SET @exam5_id = (SELECT id FROM exams WHERE user_id=5 AND course_id=5 ORDER BY id DESC LIMIT 1);
SET @exam7_id = (SELECT id FROM exams WHERE user_id=5 AND course_id=7 ORDER BY id DESC LIMIT 1);

-- 考试1的错题（皮肤生理学基础 - 第一轮3道错题）
INSERT INTO exam_mistakes (
    user_id, exam_id, question_content, correct_answer, user_answer, question_type, created_at
) VALUES 
(5, @exam1_id, '人体皮肤分为哪几层？', '表皮层、真皮层、皮下组织三层', '表皮和真皮两层', 'essay', '2025-10-05 09:15:00'),
(5, @exam1_id, '关于玻尿酸的作用，以下哪项描述是正确的？\nA. 只能用于填充\nB. 具有保湿和填充双重作用\nC. 不能用于面部\nD. 只适合年轻人使用', 'B', 'A', 'single', '2025-10-05 09:25:00'),
(5, @exam1_id, '敏感肌肤的客户可以使用含酒精的护肤品', '错误', '正确', 'judge', '2025-10-05 09:35:00');

-- 考试2的错题（医美产品知识与应用 - 第一轮4道错题）
INSERT INTO exam_mistakes (
    user_id, exam_id, question_content, correct_answer, user_answer, question_type, created_at
) VALUES 
(5, @exam2_id, '光子嫩肤的主要功效包括哪些？（多选）\nA. 美白淡斑\nB. 收缩毛孔\nC. 去除皱纹\nD. 改善红血丝', 'A,B,D', 'A,B,C', 'multiple', '2025-10-06 14:10:00'),
(5, @exam2_id, '水光针的主要成分是___', '透明质酸（玻尿酸）', '胶原蛋白', 'blank', '2025-10-06 14:20:00'),
(5, @exam2_id, '热玛吉适用于所有肤质', '正确', '错误', 'judge', '2025-10-06 14:30:00'),
(5, @exam2_id, '超声刀的作用原理是什么？', '通过高强度聚焦超声波能量作用于筋膜层，促进胶原蛋白再生，达到紧致提拉效果', '利用超声波震动按摩皮肤', 'essay', '2025-10-06 14:40:00');

-- 考试4的错题（医美项目介绍与咨询 - 第一轮5道错题，未通过）
INSERT INTO exam_mistakes (
    user_id, exam_id, question_content, correct_answer, user_answer, question_type, created_at
) VALUES 
(5, @exam4_id, '面部提升项目适合的年龄段是？\nA. 25岁以下\nB. 25-35岁\nC. 35岁以上\nD. 所有年龄段', 'C', 'B', 'single', '2025-10-08 15:10:00'),
(5, @exam4_id, '皮秒激光可以治疗哪些皮肤问题？（多选）\nA. 色斑\nB. 痘印\nC. 毛孔粗大\nD. 皮肤松弛', 'A,B,C', 'A,B', 'multiple', '2025-10-08 15:15:00'),
(5, @exam4_id, '果酸焕肤后需要严格防晒', '正确', '错误', 'judge', '2025-10-08 15:20:00'),
(5, @exam4_id, '光子嫩肤一个疗程通常需要___次治疗，间隔___周', '3-5次，3-4周', '5-8次，2周', 'blank', '2025-10-08 15:25:00'),
(5, @exam4_id, '请简述如何向客户介绍肉毒素除皱项目的优势和注意事项', '优势：快速见效、微创无痕、可逆性强、针对性强。注意事项：需选择正规品牌、术后避免按摩、孕妇和哺乳期禁用、过敏体质需提前告知', '肉毒素可以除皱，效果很好，没有副作用', 'essay', '2025-10-08 15:30:00');

-- 考试5的错题（轻医美销售技巧 - 第一轮3道错题）
INSERT INTO exam_mistakes (
    user_id, exam_id, question_content, correct_answer, user_answer, question_type, created_at
) VALUES 
(5, @exam5_id, '在销售咨询中，FABE销售法则中的F代表？\nA. Features（特征）\nB. Functions（功能）\nC. Facts（事实）\nD. Feelings（感受）', 'A', 'C', 'single', '2025-10-09 09:45:00'),
(5, @exam5_id, '有效的销售话术应该具备哪些特点？（多选）\nA. 专业准确\nB. 简单易懂\nC. 夸大效果\nD. 针对性强', 'A,B,D', 'A,B', 'multiple', '2025-10-09 09:55:00'),
(5, @exam5_id, '客户提出价格异议时，第一步应该是___客户的关注点', '倾听和理解', '立即降价', 'blank', '2025-10-09 10:05:00');

-- 考试7的错题（社媒营销与私域运营 - 第一轮4道错题）
INSERT INTO exam_mistakes (
    user_id, exam_id, question_content, correct_answer, user_answer, question_type, created_at
) VALUES 
(5, @exam7_id, '私域流量运营的核心是？\nA. 大量加粉\nB. 建立信任关系\nC. 频繁推销\nD. 打折促销', 'B', 'A', 'single', '2025-10-11 10:15:00'),
(5, @exam7_id, '短视频内容策划应遵循哪些原则？（多选）\nA. 垂直专业\nB. 持续更新\nC. 互动性强\nD. 纯广告推广', 'A,B,C', 'A,B', 'multiple', '2025-10-11 10:25:00'),
(5, @exam7_id, '企业微信的客户标签管理可以提升运营效率', '正确', '错误', 'judge', '2025-10-11 10:35:00'),
(5, @exam7_id, '请简述如何设计一个有效的会员转化路径', '步骤：1.引流获客（短视频/直播）2.建立信任（专业内容分享）3.激活需求（案例展示/体验活动）4.促成转化（限时优惠/专属福利）5.持续运营（定期回访/会员权益）', '做活动、发优惠券', 'essay', '2025-10-11 10:45:00');

-- ========================================
-- 三、插入更多用户的考试数据（丰富数据）
-- ========================================

-- 用户6（其他美容顾问）的考试记录
INSERT INTO exams (
    user_id, course_id, exam_name, question_count, total_score, pass_score,
    start_time, end_time, duration_minutes,
    round1_score, round2_score, round3_score, score, is_passed, status
) VALUES 
(6, 1, '皮肤生理学基础 - 动态考试', 10, 100.0, 60.0,
    '2025-10-03 10:00:00', '2025-10-03 11:20:00', 60,
    88, 95, 100, 100, TRUE, 'submitted'),
(6, 2, '医美产品知识与应用 - 动态考试', 10, 100.0, 60.0,
    '2025-10-04 14:30:00', '2025-10-04 15:40:00', 60,
    92, 100, NULL, 100, TRUE, 'submitted'),
(6, 6, '客户服务与投诉处理 - 动态考试', 10, 100.0, 60.0,
    '2025-10-07 09:00:00', '2025-10-07 10:15:00', 60,
    78, 90, 95, 95, TRUE, 'submitted');

-- 用户7的考试记录
INSERT INTO exams (
    user_id, course_id, exam_name, question_count, total_score, pass_score,
    start_time, end_time, duration_minutes,
    round1_score, round2_score, round3_score, score, is_passed, status
) VALUES 
(7, 3, '美容仪器操作与维护 - 动态考试', 10, 100.0, 60.0,
    '2025-10-05 11:00:00', '2025-10-05 12:10:00', 60,
    82, 90, 100, 100, TRUE, 'submitted'),
(7, 5, '轻医美销售技巧 - 动态考试', 10, 100.0, 60.0,
    '2025-10-09 15:00:00', '2025-10-09 16:15:00', 60,
    70, 85, 90, 90, TRUE, 'submitted');

-- ========================================
-- 四、为新增考试添加对应的错题记录
-- ========================================

-- 用户6的错题（皮肤生理学基础 - 第一轮1道错题）
SET @exam6_1 = (SELECT id FROM exams WHERE user_id=6 AND course_id=1 ORDER BY id DESC LIMIT 1);
INSERT INTO exam_mistakes (
    user_id, exam_id, question_content, correct_answer, user_answer, question_type, created_at
) VALUES 
(6, @exam6_1, '皮肤的PH值正常范围是？\nA. 3.5-4.5\nB. 4.5-6.5\nC. 6.5-7.5\nD. 7.5-8.5', 'B', 'C', 'single', '2025-10-03 10:20:00');

-- 用户6的错题（医美产品知识与应用 - 第一轮1道错题）
SET @exam6_2 = (SELECT id FROM exams WHERE user_id=6 AND course_id=2 ORDER BY id DESC LIMIT 1);
INSERT INTO exam_mistakes (
    user_id, exam_id, question_content, correct_answer, user_answer, question_type, created_at
) VALUES 
(6, @exam6_2, '玻尿酸注射后___小时内不能沾水', '24', '12', 'blank', '2025-10-04 14:50:00');

-- 用户6的错题（客户服务与投诉处理 - 第一轮2道错题）
SET @exam6_3 = (SELECT id FROM exams WHERE user_id=6 AND course_id=6 ORDER BY id DESC LIMIT 1);
INSERT INTO exam_mistakes (
    user_id, exam_id, question_content, correct_answer, user_answer, question_type, created_at
) VALUES 
(6, @exam6_3, '处理客户投诉的黄金原则是？（多选）\nA. 及时回应\nB. 真诚道歉\nC. 快速解决\nD. 推卸责任', 'A,B,C', 'A,B', 'multiple', '2025-10-07 09:20:00'),
(6, @exam6_3, '客户投诉时，应该先___，再___', '倾听，解决', '解释，辩解', 'blank', '2025-10-07 09:30:00');

-- 用户7的错题（美容仪器操作与维护 - 第一轮2道错题）
SET @exam7_1 = (SELECT id FROM exams WHERE user_id=7 AND course_id=3 ORDER BY id DESC LIMIT 1);
INSERT INTO exam_mistakes (
    user_id, exam_id, question_content, correct_answer, user_answer, question_type, created_at
) VALUES 
(7, @exam7_1, '射频仪器的工作原理是？\nA. 激光热效应\nB. 电磁波热效应\nC. 超声波振动\nD. 机械摩擦', 'B', 'A', 'single', '2025-10-05 11:20:00'),
(7, @exam7_1, '仪器消毒应该在每次使用___进行', '前后', '前', 'blank', '2025-10-05 11:35:00');

-- 用户7的错题（轻医美销售技巧 - 第一轮3道错题）
SET @exam7_2 = (SELECT id FROM exams WHERE user_id=7 AND course_id=5 ORDER BY id DESC LIMIT 1);
INSERT INTO exam_mistakes (
    user_id, exam_id, question_content, correct_answer, user_answer, question_type, created_at
) VALUES 
(7, @exam7_2, '成交话术中，假设成交法的核心是？\nA. 直接要求客户付款\nB. 假设客户已经同意购买\nC. 给客户压力\nD. 降价促销', 'B', 'A', 'single', '2025-10-09 15:25:00'),
(7, @exam7_2, '顾客异议处理时应避免的做法包括？（多选）\nA. 打断顾客说话\nB. 否认顾客观点\nC. 耐心倾听\nD. 与顾客争辩', 'A,B,D', 'A,B', 'multiple', '2025-10-09 15:35:00'),
(7, @exam7_2, '请列举3种常用的促成交易的方法', '1.假设成交法 2.二选一法 3.优惠刺激法 4.紧迫感营造法（任选3种）', '降价、送礼品', 'essay', '2025-10-09 15:45:00');

-- ========================================
-- 五、验证插入结果
-- ========================================

-- 统计考试记录
SELECT 
    '考试记录统计' as category,
    COUNT(*) as total,
    COUNT(round1_score) as has_round1,
    COUNT(round2_score) as has_round2,
    COUNT(round3_score) as has_round3,
    AVG(round1_score) as avg_round1_score
FROM exams 
WHERE user_id IN (5, 6, 7);

-- 统计错题记录
SELECT 
    '错题记录统计' as category,
    COUNT(*) as total,
    COUNT(DISTINCT exam_id) as distinct_exams,
    COUNT(DISTINCT question_type) as distinct_types
FROM exam_mistakes 
WHERE user_id IN (5, 6, 7);

-- 按课程统计错题
SELECT 
    c.name as course_name,
    COUNT(em.id) as mistake_count
FROM exam_mistakes em
JOIN exams e ON em.exam_id = e.id
JOIN courses c ON e.course_id = c.id
WHERE em.user_id IN (5, 6, 7)
GROUP BY c.id, c.name
ORDER BY mistake_count DESC;

-- 按题型统计错题
SELECT 
    question_type,
    COUNT(*) as count
FROM exam_mistakes
WHERE user_id IN (5, 6, 7) AND question_type IS NOT NULL
GROUP BY question_type
ORDER BY count DESC;

-- 显示最近5条考试记录（包含三轮得分）
SELECT 
    id,
    exam_name,
    round1_score,
    round2_score,
    round3_score,
    score,
    is_passed,
    DATE_FORMAT(start_time, '%Y-%m-%d %H:%i') as start_time
FROM exams 
WHERE user_id = 5
ORDER BY start_time DESC
LIMIT 5;

