-- 智跑平台真实用户ID测试数据补充（最终完整修正版本）
-- 生成日期: 2025-06-17
-- 用途: 为指定的真实用户ID创建完整的测试数据，修复所有外键约束问题
-- 学生用户ID: 7bf7378e-a027-473e-97ac-3460ed3f170a
-- 教师用户ID: eed3824b-bba1-4309-8048-19d17367c084

-- ===============================
-- 针对真实学生用户的专门测试数据
-- ===============================

-- 0. 先创建设备记录（避免外键约束错误）
INSERT INTO ak_devices (id, user_id, device_type, device_name, device_mac, bind_time, status, extra) VALUES
('12345678-1234-5678-9abc-123456789012', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'smartwatch', '华为手表GT3', 'AA:BB:CC:DD:EE:FF', now(), 'active', '{"brand": "华为", "model": "GT3", "firmware": "1.2.3"}');

-- 1. 创建训练计划（避免外键约束错误）
INSERT INTO ak_training_plans (id, user_id, plan_name, description, start_date, end_date, status, created_at) VALUES
('11111111-3333-1111-1111-111111111111', '7bf7378e-a027-473e-97ac-3460ed3f170a', '期中体能训练计划', '为期中体能测试准备的综合训练计划，包含跳绳、俯卧撑、跑步等多项训练内容', '2025-06-11', '2025-06-25', 'active', now());

-- 2. 创建训练计划项目
INSERT INTO ak_training_plan_items (id, plan_id, item_date, activity_type, target_value, unit, description, created_at) VALUES
('47e3bc40-a5d2-4c8e-b9f7-82a1b3c4d5e6', '11111111-3333-1111-1111-111111111111', '2025-06-11', '跳绳', 500, '次', '跳绳训练：分5组完成，每组100次，组间休息30秒', now()),
('47e3bc40-a5d2-4c8e-b9f7-82a1b3c4d5e7', '11111111-3333-1111-1111-111111111111', '2025-06-12', '俯卧撑', 30, '次', '俯卧撑训练：分3组完成，每组10次，组间休息60秒', now()),
('47e3bc40-a5d2-4c8e-b9f7-82a1b3c4d5e8', '11111111-3333-1111-1111-111111111111', '2025-06-13', '跑步', 3.5, '公里', '跑步训练：3.5公里，配速控制在8:30/km左右', now());

-- 3. 学生用户的训练记录
INSERT INTO ak_training_records (id, user_id, plan_item_id, device_id, activity_type, start_time, end_time, duration_sec, distance_km, calories, steps, avg_heart_rate, max_heart_rate, data, created_at) VALUES
('550e8400-e29b-41d4-a716-446655440001', '7bf7378e-a027-473e-97ac-3460ed3f170a', '47e3bc40-a5d2-4c8e-b9f7-82a1b3c4d5e6', '12345678-1234-5678-9abc-123456789012', '跳绳', '2025-06-11 07:00:00+08', '2025-06-11 07:15:00+08', 900, 0, 150, 0, 130, 160, '{"total_jumps": 500, "sets": 5, "rest_between_sets": "30sec"}', now()),
('550e8400-e29b-41d4-a716-446655440002', '7bf7378e-a027-473e-97ac-3460ed3f170a', '47e3bc40-a5d2-4c8e-b9f7-82a1b3c4d5e7', '12345678-1234-5678-9abc-123456789012', '俯卧撑', '2025-06-12 18:00:00+08', '2025-06-12 18:10:00+08', 600, 0, 80, 0, 110, 140, '{"total_pushups": 30, "sets": 3, "reps_per_set": 10}', now()),
('550e8400-e29b-41d4-a716-446655440003', '7bf7378e-a027-473e-97ac-3460ed3f170a', '47e3bc40-a5d2-4c8e-b9f7-82a1b3c4d5e8', '12345678-1234-5678-9abc-123456789012', '跑步', '2025-06-13 06:30:00+08', '2025-06-13 07:00:00+08', 1800, 3.5, 240, 4500, 125, 155, '{"pace": "8:30/km", "route": "公园环路", "weather": "多云"}', now()),
('550e8400-e29b-41d4-a716-446655440004', '7bf7378e-a027-473e-97ac-3460ed3f170a', NULL, '12345678-1234-5678-9abc-123456789012', '自由训练', '2025-06-14 07:00:00+08', '2025-06-14 07:45:00+08', 2700, 4.2, 300, 5200, 135, 165, '{"activity": "晨跑+拉伸", "note": "感觉状态很好"}', now());

-- 4. 学生用户的体征数据
INSERT INTO ak_biometric_data (id, user_id, device_id, data_type, value, unit, measured_at, extra) VALUES
('550e8400-e29b-41d4-a716-446655440011', '7bf7378e-a027-473e-97ac-3460ed3f170a', '12345678-1234-5678-9abc-123456789012', 'heart_rate', 125, 'bpm', '2025-06-11 07:08:00+08', '{"context": "跳绳运动中"}'),
('550e8400-e29b-41d4-a716-446655440012', '7bf7378e-a027-473e-97ac-3460ed3f170a', '12345678-1234-5678-9abc-123456789012', 'heart_rate', 68, 'bpm', '2025-06-11 22:00:00+08', '{"context": "睡前静息"}'),
('550e8400-e29b-41d4-a716-446655440013', '7bf7378e-a027-473e-97ac-3460ed3f170a', '12345678-1234-5678-9abc-123456789012', 'sleep', 8.2, 'hours', '2025-06-12 07:00:00+08', '{"deep_sleep": 3.1, "light_sleep": 4.8, "rem_sleep": 0.3}'),
('550e8400-e29b-41d4-a716-446655440014', '7bf7378e-a027-473e-97ac-3460ed3f170a', '12345678-1234-5678-9abc-123456789012', 'steps', 9200, 'count', '2025-06-12 23:59:00+08', '{"daily_goal": 10000, "goal_completion": "92%"}'),
('550e8400-e29b-41d4-a716-446655440015', '7bf7378e-a027-473e-97ac-3460ed3f170a', '12345678-1234-5678-9abc-123456789012', 'weight', 65.2, 'kg', '2025-06-13 07:00:00+08', '{"bmi": 21.3, "body_fat": "12%"}');

-- 5. 学生用户的AI分析报告
INSERT INTO ak_ai_reports (id, user_id, report_type, period_start, period_end, analysis_data, created_at) VALUES
('550e8400-e29b-41d4-a716-446655440021', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'weekly_summary', '2025-06-10', '2025-06-16', '{"total_activities": 6, "total_distance": 13.7, "total_calories": 980, "avg_heart_rate": 127, "fitness_score": 82, "improvement_areas": ["力量训练", "柔韧性"], "achievements": ["完成本周所有训练目标", "跑步配速稳步提升"], "recommendations": ["建议增加力量训练频次，每周至少2次", "加入瑜伽或拉伸训练提高柔韧性", "保持当前的跑步训练强度"]}', now()),
('550e8400-e29b-41d4-a716-446655440022', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'technique_analysis', '2025-06-10', '2025-06-10', '{"activity_type": "跑步", "technique_score": 87, "strengths": ["步频稳定", "呼吸节奏好", "姿态端正"], "weaknesses": ["步幅可以更大", "摆臂需要更有力"], "detailed_analysis": {"posture": {"score": 85, "comment": "整体姿态良好，头部保持稳定"}, "breathing": {"score": 90, "comment": "呼吸与步频配合很好"}, "stride": {"score": 82, "comment": "步幅适中，建议可以适当增大"}, "arm_swing": {"score": 78, "comment": "摆臂动作需要更有力度"}}, "training_suggestions": ["练习高抬腿增强步幅", "加强核心力量训练", "注意手臂摆动的力度和节奏"]}', now());

-- 6. 学生用户的通知记录
INSERT INTO ak_notifications (id, user_id, type, title, content, data, is_read, created_at) VALUES
('c3e8f2a0-9b4c-4d6e-8f7a-1b2c3d4e5f61', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'training_reminder', '今日训练提醒', '今天的俯卧撑训练还没完成，加油！', '{"plan_item_id": "47e3bc40-a5d2-4c8e-b9f7-82a1b3c4d5e7", "target": "30次"}', false, now()),
('c3e8f2a0-9b4c-4d6e-8f7a-1b2c3d4e5f62', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'achievement', '新成就解锁！', '连续完成训练计划4天，获得"训练达人"称号', '{"achievement_id": "training_master_4days", "points_earned": 80}', false, now()),
('c3e8f2a0-9b4c-4d6e-8f7a-1b2c3d4e5f63', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'report_ready', 'AI分析报告更新', '您的跑步技术分析报告已更新，快来查看详细建议吧！', '{"report_id": "550e8400-e29b-41d4-a716-446655440022"}', true, now()),
('c3e8f2a0-9b4c-4d6e-8f7a-1b2c3d4e5f60', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'social_interaction', '好友互动', '您的好友李小红为您的训练记录点了赞', '{"from_user": "李小红", "action": "like", "target": "训练记录"}', false, now());

-- 7. 学生用户的积分记录
INSERT INTO ak_user_points (id, user_id, total_points, available_points, created_at, updated_at) VALUES
('a7b8c9d0-e1f2-4a3b-9c8d-7e6f5a4b3c21', '7bf7378e-a027-473e-97ac-3460ed3f170a', 1580, 1200, now(), now());

INSERT INTO ak_point_transactions (id, user_id, transaction_type, points, description, reference_id, created_at) VALUES
('b8c9d0e1-f2a3-4b5c-9d8e-7f6a5b4c3d21', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'earn', 50, '完成跑步训练', '550e8400-e29b-41d4-a716-446655440003', now()),
('b8c9d0e1-f2a3-4b5c-9d8e-7f6a5b4c3d22', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'earn', 30, '完成跳绳训练', '550e8400-e29b-41d4-a716-446655440001', now()),
('b8c9d0e1-f2a3-4b5c-9d8e-7f6a5b4c3d23', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'earn', 25, '完成俯卧撑训练', '550e8400-e29b-41d4-a716-446655440002', now()),
('b8c9d0e1-f2a3-4b5c-9d8e-7f6a5b4c3d24', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'earn', 80, '获得训练达人成就', 'training_master_4days', now()),
('b8c9d0e1-f2a3-4b5c-9d8e-7f6a5b4c3d25', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'earn', 100, '完成周训练目标', 'weekly_goal_completed', now()),
('b8c9d0e1-f2a3-4b5c-9d8e-7f6a5b4c3d26', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'spend', -180, '兑换运动T恤', 'reward_tshirt_001', now());

-- ===============================
-- 针对真实教师用户的专门测试数据
-- ===============================

-- 8. 教师用户的教学资源
INSERT INTO ak_teaching_resources (id, teacher_id, title, description, content_type, content_url, tags, visibility, created_at) VALUES
('c9d0e1f2-a3b4-4c5d-9e8f-7a6b5c4d3e21', 'eed3824b-bba1-4309-8048-19d17367c084', '跑步技术教学视频', '专业的跑步姿势和呼吸技巧讲解，适合初学者和进阶学员', 'video', '/resources/videos/running_technique_basics.mp4', '["跑步", "技术", "姿势", "呼吸"]', 'public', now()),
('c9d0e1f2-a3b4-4c5d-9e8f-7a6b5c4d3e22', 'eed3824b-bba1-4309-8048-19d17367c084', '体能训练计划模板', '针对不同体能水平学生的训练计划模板，包含详细的训练内容和进度安排', 'document', '/resources/docs/fitness_plan_template.pdf', '["体能", "训练计划", "模板"]', 'public', now()),
('c9d0e1f2-a3b4-4c5d-9e8f-7a6b5c4d3e23', 'eed3824b-bba1-4309-8048-19d17367c084', '运动伤害预防指南', '常见运动伤害的预防方法和处理建议，帮助学生安全运动', 'document', '/resources/docs/injury_prevention_guide.pdf', '["安全", "伤害预防", "运动医学"]', 'public', now()),
('c9d0e1f2-a3b4-4c5d-9e8f-7a6b5c4d3e24', 'eed3824b-bba1-4309-8048-19d17367c084', '力量训练示范', '各种力量训练动作的标准示范，包含俯卧撑、仰卧起坐等基础动作', 'video', '/resources/videos/strength_training_demo.mp4', '["力量训练", "示范", "基础动作"]', 'public', now());

-- 9. 教师布置的作业
INSERT INTO ak_assignments (id, teacher_id, title, description, assignment_type, due_date, max_score, requirements, created_at) VALUES
('d0e1f2a3-b4c5-4d6e-9f8a-7b6c5d4e3f21', 'eed3824b-bba1-4309-8048-19d17367c084', '期中体能测试准备', '为期中体能测试做准备，完成指定的训练项目', 'fitness_test', '2025-06-20', 100, '{"type": "50米冲刺", "target": "每日3次", "standard": "男生<8秒，女生<9秒"}', now()),
('d0e1f2a3-b4c5-4d6e-9f8a-7b6c5d4e3f22', 'eed3824b-bba1-4309-8048-19d17367c084', '本周跑步训练记录', '记录本周的跑步训练情况，包括距离、时间、心率等数据', 'training_log', '2025-06-18', 50, '{"min_distance": 3, "min_frequency": 3, "required_data": ["distance", "time", "heart_rate"]}', now());

-- 10. 学生作业提交记录
INSERT INTO ak_assignment_submissions (id, assignment_id, student_id, submission_data, score, feedback, status, submitted_at) VALUES
('e1f2a3b4-c5d6-4e7f-9a8b-7c6d5e4f3a21', 'd0e1f2a3-b4c5-4d6e-9f8a-7b6c5d4e3f21', '7bf7378e-a027-473e-97ac-3460ed3f170a', '{"date": "2025-06-17", "50m_sprint": ["7.7s", "7.5s", "7.8s"], "pushups": 35, "situps": 45, "heart_rate_avg": 128}', 85, '50米成绩有明显改善，继续保持！力量训练表现优秀。', 'graded', now()),
('e1f2a3b4-c5d6-4e7f-9a8b-7c6d5e4f3a22', 'd0e1f2a3-b4c5-4d6e-9f8a-7b6c5d4e3f22', '7bf7378e-a027-473e-97ac-3460ed3f170a', '{"week_summary": {"total_runs": 4, "total_distance": 14.2, "avg_pace": "8:15/km", "avg_heart_rate": 132}, "daily_records": [{"date": "2025-06-11", "distance": 3.5, "time": 1800, "heart_rate": 125}, {"date": "2025-06-13", "distance": 4.2, "time": 2100, "heart_rate": 135}]}', 48, '训练记录详细完整，跑步频次和距离都达到要求，继续保持！', 'graded', now());

-- 11. 教师的课程安排
INSERT INTO ak_class_schedules (id, teacher_id, class_name, subject, start_time, end_time, location, description, created_at) VALUES
('f2a3b4c5-d6e7-4f8a-9b8c-7d6e5f4a3b21', 'eed3824b-bba1-4309-8048-19d17367c084', '高一(1)班', '体育课', '2025-06-17 08:00:00+08', '2025-06-17 08:45:00+08', '操场', '50米短跑训练与测试', now()),
('f2a3b4c5-d6e7-4f8a-9b8c-7d6e5f4a3b22', 'eed3824b-bba1-4309-8048-19d17367c084', '高一(2)班', '体育课', '2025-06-17 09:00:00+08', '2025-06-17 09:45:00+08', '体育馆', '力量训练基础动作教学', now()),
('f2a3b4c5-d6e7-4f8a-9b8c-7d6e5f4a3b23', 'eed3824b-bba1-4309-8048-19d17367c084', '高一(1)班', '体育课', '2025-06-19 08:00:00+08', '2025-06-19 08:45:00+08', '操场', '长跑耐力训练', now());

-- 12. 师生互动记录
INSERT INTO ak_user_interactions (id, user_id, target_id, interaction_type, content, created_at) VALUES
('a3b4c5d6-e7f8-4a9b-8c7d-6e5f4a3b2c21', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'eed3824b-bba1-4309-8048-19d17367c084', 'question', '老师，我在跑步时总是很快就气喘吁吁，有什么改善的方法吗？', now()),
('a3b4c5d6-e7f8-4a9b-8c7d-6e5f4a3b2c22', 'eed3824b-bba1-4309-8048-19d17367c084', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'answer', '这说明你的心肺耐力还需要加强。建议你先降低跑步配速，采用慢跑的方式逐步提高，同时注意呼吸节奏。', now()),
('a3b4c5d6-e7f8-4a9b-8c7d-6e5f4a3b2c23', 'eed3824b-bba1-4309-8048-19d17367c084', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'praise', '你这周的训练表现很棒！50米成绩有明显提升，继续保持这个训练强度。', now()),
('a3b4c5d6-e7f8-4a9b-8c7d-6e5f4a3b2c24', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'c9d0e1f2-a3b4-4c5d-9e8f-7a6b5c4d3e24', 'comment', '老师的跑步技术示范视频很有帮助，我按照要求练习后确实有改善！', now());

-- ===============================
-- 数据验证查询
-- ===============================

-- 查询学生用户的训练记录
SELECT 
    tr.activity_type,
    tr.duration_sec,
    tr.distance_km,
    tr.calories,
    tr.created_at
FROM ak_training_records tr 
WHERE tr.user_id = '7bf7378e-a027-473e-97ac-3460ed3f170a'
ORDER BY tr.created_at DESC;

-- 查询学生用户的体征数据
SELECT 
    bd.data_type,
    bd.value,
    bd.unit,
    bd.measured_at
FROM ak_biometric_data bd 
WHERE bd.user_id = '7bf7378e-a027-473e-97ac-3460ed3f170a'
ORDER BY bd.measured_at DESC;

-- 查询学生用户的AI报告
SELECT 
    ar.report_type,
    ar.period_start,
    ar.period_end,
    ar.created_at
FROM ak_ai_reports ar 
WHERE ar.user_id = '7bf7378e-a027-473e-97ac-3460ed3f170a'
ORDER BY ar.created_at DESC;

-- 查询学生用户的通知
SELECT 
    n.type,
    n.title,
    n.content,
    n.is_read,
    n.created_at
FROM ak_notifications n 
WHERE n.user_id = '7bf7378e-a027-473e-97ac-3460ed3f170a'
ORDER BY n.created_at DESC;

-- 查询学生用户的积分情况
SELECT 
    SUM(CASE WHEN pt.transaction_type = 'earn' THEN pt.points ELSE -pt.points END) as total_points
FROM ak_point_transactions pt 
WHERE pt.user_id = '7bf7378e-a027-473e-97ac-3460ed3f170a';

-- 查询教师用户的教学资源
SELECT 
    tr.title,
    tr.description,
    tr.content_type,
    tr.created_at
FROM ak_teaching_resources tr 
WHERE tr.teacher_id = 'eed3824b-bba1-4309-8048-19d17367c084'
ORDER BY tr.created_at DESC;

-- 查询教师用户布置的作业
SELECT 
    a.title,
    a.description,
    a.assignment_type,
    a.due_date,
    a.created_at
FROM ak_assignments a 
WHERE a.teacher_id = 'eed3824b-bba1-4309-8048-19d17367c084'
ORDER BY a.created_at DESC;

-- 查询教师用户的课程安排
SELECT 
    cs.class_name,
    cs.subject,
    cs.start_time,
    cs.end_time,
    cs.location,
    cs.description
FROM ak_class_schedules cs 
WHERE cs.teacher_id = 'eed3824b-bba1-4309-8048-19d17367c084'
ORDER BY cs.start_time DESC;
