Files
akmon/doc_zhipao/test_data_complete_fixed.sql
2026-01-20 08:04:15 +08:00

132 lines
15 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 智跑平台真实用户ID测试数据补充修复所有表结构问题
-- 生成日期: 2025-06-17
-- 用途: 修复所有表结构问题和外键约束问题
-- 学生用户ID: 7bf7378e-a027-473e-97ac-3460ed3f170a
-- 教师用户ID: eed3824b-bba1-4309-8048-19d17367c084
-- ===============================
-- 0. 先创建必需的基础数据(避免外键约束错误)
-- ===============================
-- 0.1. 创建学校记录
INSERT INTO public.ak_schools (id, name, region_id, type, created_at) VALUES
('11111111-2222-1111-1111-111111111111', '测试高中', NULL, '高中', now());
-- 0.2. 创建年级记录
INSERT INTO public.ak_grades (id, school_id, name, created_at) VALUES
('11111111-3333-1111-1111-111111111111', '11111111-2222-1111-1111-111111111111', '高一年级', now());
-- 0.3. 创建班级记录
INSERT INTO public.ak_classes (id, grade_id, name, created_at) VALUES
('11111111-4444-1111-1111-111111111111', '11111111-3333-1111-1111-111111111111', '高一(1)班', now()),
('11111111-4444-1111-1111-111111111112', '11111111-3333-1111-1111-111111111111', '高一(2)班', now());
-- ===============================
-- 针对真实学生用户的专门测试数据
-- ===============================
-- 1. 先创建训练计划(避免外键约束错误)
INSERT INTO public.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 public.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"}');
-- 3. 创建训练计划项目
INSERT INTO public.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());
-- 4. 学生用户的训练记录
INSERT INTO public.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());
-- 5. 学生用户的体征数据
INSERT INTO public.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%"}');
-- 6. 学生用户的AI分析报告修复列名问题
INSERT INTO public.ak_ai_reports (id, user_id, report_type, analysis_data, created_at) VALUES
('550e8400-e29b-41d4-a716-446655440021', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'weekly_summary', '{"period_start": "2025-06-10", "period_end": "2025-06-16", "total_activities": 6, "total_distance": 13.7, "total_calories": 980, "avg_heart_rate": 127, "fitness_score": 82, "improvement_areas": ["力量训练", "柔韧性"], "achievements": ["完成本周所有训练目标", "跑步配速稳步提升"]}', now()),
('550e8400-e29b-41d4-a716-446655440022', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'technique_analysis', '{"period_start": "2025-06-10", "period_end": "2025-06-10", "activity_type": "跑步", "technique_score": 87, "strengths": ["步频稳定", "呼吸节奏好", "姿态端正"], "weaknesses": ["步幅可以更大", "摆臂需要更有力"]}', now());
-- 7. 学生用户的通知记录
INSERT INTO public.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());
-- 8. 学生用户的积分记录
INSERT INTO public.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 public.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, '获得训练达人成就', '11111111-aaaa-bbbb-cccc-111111111001', now()),
('b8c9d0e1-f2a3-4b5c-9d8e-7f6a5b4c3d25', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'earn', 100, '完成周训练目标', '11111111-aaaa-bbbb-cccc-111111111002', now()),
('b8c9d0e1-f2a3-4b5c-9d8e-7f6a5b4c3d26', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'spend', -180, '兑换运动T恤', '11111111-aaaa-bbbb-cccc-111111111003', now());
-- ===============================
-- 针对真实教师用户的专门测试数据
-- ===============================
-- 9. 教师用户的教学资源
INSERT INTO public.ak_teaching_resources (id, teacher_id, type, title, description, content_url, tags, is_public, created_at) VALUES
('c9d0e1f2-a3b4-4c5d-9e8f-7a6b5c4d3e21', 'eed3824b-bba1-4309-8048-19d17367c084', 'video', '青少年体能训练指导', '针对中学生的体能训练方法和注意事项', 'https://example.com/videos/youth_fitness_guide.mp4', '["青少年", "体能训练", "指导视频"]', true, now()),
('c9d0e1f2-a3b4-4c5d-9e8f-7a6b5c4d3e22', 'eed3824b-bba1-4309-8048-19d17367c084', 'document', '运动损伤预防手册', '常见运动损伤的预防和处理方法', 'https://example.com/docs/injury_prevention.pdf', '["运动损伤", "预防", "处理"]', true, now()),
('c9d0e1f2-a3b4-4c5d-9e8f-7a6b5c4d3e23', 'eed3824b-bba1-4309-8048-19d17367c084', 'plan', '春季训练计划模板', '适合高中生的春季体能训练计划模板', 'https://example.com/templates/spring_training.json', '["训练计划", "高中生", "春季"]', false, now()),
('c9d0e1f2-a3b4-4c5d-9e8f-7a6b5c4d3e24', 'eed3824b-bba1-4309-8048-19d17367c084', 'video', '跑步技术动作示范', '标准跑步动作的分解示范和常见错误纠正', 'https://example.com/videos/running_technique_demo.mp4', '["跑步技术", "动作示范", "纠错"]', true, now());
-- 10. 教师用户布置的作业
INSERT INTO public.ak_assignments (id, teacher_id, school_id, class_id, title, description, requirements, due_date, status, created_at) VALUES
('d0e1f2a3-b4c5-4d6e-9f8a-7b6c5d4e3f21', 'eed3824b-bba1-4309-8048-19d17367c084', '11111111-2222-1111-1111-111111111111', '11111111-4444-1111-1111-111111111111', '期中体能测试准备', '为期中体能测试做准备,包含多项基础体能训练', '{"duration": "2周", "activities": [{"type": "50米冲刺", "target": "每日3次"}]}', '2025-06-30', 'active', now()),
('d0e1f2a3-b4c5-4d6e-9f8a-7b6c5d4e3f22', 'eed3824b-bba1-4309-8048-19d17367c084', '11111111-2222-1111-1111-111111111111', '11111111-4444-1111-1111-111111111111', '跑步技术改进训练', '根据AI分析结果针对性改进跑步技术', '{"duration": "1周", "focus_areas": ["步频控制", "摆臂动作"]}', '2025-06-23', 'active', now());
-- 11. 学生提交的作业
INSERT INTO public.ak_assignment_submissions (id, assignment_id, student_id, submission_data, submission_time, status, score, teacher_feedback) VALUES
('e1f2a3b4-c5d6-4e7f-9a8b-7c6d5e4f3a21', 'd0e1f2a3-b4c5-4d6e-9f8a-7b6c5d4e3f21', '7bf7378e-a027-473e-97ac-3460ed3f170a', '{"training_log": [{"date": "2025-06-14", "50m_sprint": ["8.1s", "7.9s", "8.0s"]}]}', now(), 'submitted', 92, '训练记录详细,进步明显。'),
('e1f2a3b4-c5d6-4e7f-9a8b-7c6d5e4f3a22', 'd0e1f2a3-b4c5-4d6e-9f8a-7b6c5d4e3f22', '7bf7378e-a027-473e-97ac-3460ed3f170a', '{"video_submissions": ["running_technique_day1.mp4"]}', now(), 'graded', 88, 'AI分析显示跑步技术有明显改善。');
-- 12. 教师的课程安排
INSERT INTO public.ak_class_schedules (id, teacher_id, school_id, class_id, subject, day_of_week, start_time, end_time, location, created_at) VALUES
('f2a3b4c5-d6e7-4f8a-9b8c-7d6e5f4a3b21', 'eed3824b-bba1-4309-8048-19d17367c084', '11111111-2222-1111-1111-111111111111', '11111111-4444-1111-1111-111111111111', '体育', 1, '08:00:00', '08:45:00', '学校操场', now()),
('f2a3b4c5-d6e7-4f8a-9b8c-7d6e5f4a3b22', 'eed3824b-bba1-4309-8048-19d17367c084', '11111111-2222-1111-1111-111111111111', '11111111-4444-1111-1111-111111111111', '体育', 3, '09:55:00', '10:40:00', '体育馆', now()),
('f2a3b4c5-d6e7-4f8a-9b8c-7d6e5f4a3b23', 'eed3824b-bba1-4309-8048-19d17367c084', '11111111-2222-1111-1111-111111111111', '11111111-4444-1111-1111-111111111112', '体育', 2, '14:00:00', '14:45:00', '操场', now()),
('f2a3b4c5-d6e7-4f8a-9b8c-7d6e5f4a3b24', 'eed3824b-bba1-4309-8048-19d17367c084', '11111111-2222-1111-1111-111111111111', '11111111-4444-1111-1111-111111111112', '体育', 4, '15:30:00', '16:15:00', '体育馆', now());
-- 13. 学生的体育成绩报告 (教师生成) - 修复title和content_md字段
INSERT INTO public.ak_sport_reports (id, user_id, title, content_md, school_id, class_id, semester, report_type, content, status, created_at, updated_at) VALUES
('a3b4c5d6-e7f8-4a9b-9c8d-7e6f5a4b3c21', '7bf7378e-a027-473e-97ac-3460ed3f170a', '张小明同学2025年6月AI监测月度报告', '# 张小明同学AI监测月度报告\n\n## 基本信息\n- 学生:张小明\n- 班级:高一(1)班\n- 学期2024-2025学年第二学期\n- 月份2025年06月\n\n## 训练总结\n本月完成18天训练训练完成率89%,各项体能指标显著提升。\n\n## 综合评分A级', '11111111-2222-1111-1111-111111111111', '11111111-4444-1111-1111-111111111111', '2024-2025学年第二学期', 'monthly', '{"student_name": "张小明", "class_name": "高一(1)班", "grade": "A", "points_earned": 95}', 'published', now(), now());
-- 14. 师生互动记录
INSERT INTO public.ak_interactions (id, user_id, target_type, target_id, interaction_type, content, created_at) VALUES
('b4c5d6e7-f8a9-4b0c-9d8e-7f6a5b4c3d21', 'eed3824b-bba1-4309-8048-19d17367c084', 'training_record', '550e8400-e29b-41d4-a716-446655440003', 'comment', '跑步节奏控制得很好,继续保持!', now()),
('b4c5d6e7-f8a9-4b0c-9d8e-7f6a5b4c3d22', 'eed3824b-bba1-4309-8048-19d17367c084', 'assignment_submission', 'e1f2a3b4-c5d6-4e7f-9a8b-7c6d5e4f3a21', 'comment', '训练记录非常详细,进步幅度令人满意。', now()),
('b4c5d6e7-f8a9-4b0c-9d8e-7f6a5b4c3d23', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'teaching_resource', 'c9d0e1f2-a3b4-4c5d-9e8f-7a6b5c4d3e21', 'like', NULL, now()),
('b4c5d6e7-f8a9-4b0c-9d8e-7f6a5b4c3d24', '7bf7378e-a027-473e-97ac-3460ed3f170a', 'teaching_resource', 'c9d0e1f2-a3b4-4c5d-9e8f-7a6b5c4d3e24', 'comment', '老师的跑步技术示范视频很有帮助!', now());
-- ===============================
-- 修复说明
-- ===============================
-- 本文件修复了以下问题:
-- 1. 添加了缺失的学校、年级、班级基础数据
-- 2. 修复了ak_ai_reports表的列名问题移除period_start和period_end
-- 3. 修复了ak_point_transactions表的UUID格式问题
-- 4. 添加了缺失的ak_teaching_resources、ak_class_schedules、ak_interactions表
-- 5. 修复了ak_sport_reports表的title和content_md NOT NULL约束问题
-- 6. 简化了JSON数据以避免语法错误
-- 7. 移除了ON CONFLICT子句以确保兼容性
-- 8. 所有UUID都遵循标准格式