Files
akmon/doc_zhipao/TRAINING_PREFERENCES_SYSTEM_DOCUMENTATION.md
2026-01-20 08:04:15 +08:00

9.4 KiB

训练偏好与设备管理系统 - 完整实现文档

📋 系统概述

本文档描述了一个完整的训练偏好与设备管理系统,包括用户训练偏好设置、目标管理、提醒系统、设备管理和智能分析功能。

🗄️ 数据库架构

核心表结构

1. 运动类型表 (ak_sport_types)

- id: uuid (主键)
- name: 运动名称
- description: 描述
- category: 分类 (有氧、力量、柔韧等)
- difficulty_level: 难度等级 (1-5)
- calorie_rate: 每分钟消耗卡路里
- icon_url: 图标URL
- is_active: 是否启用

2. 用户训练目标表 (ak_user_training_goals)

- id: uuid (主键)
- user_id: 用户ID
- goal_type: 目标类型 (减肥、增肌、耐力等)
- target_value: 目标数值
- current_value: 当前数值
- unit: 单位
- target_date: 目标日期
- priority: 优先级 (1-5)
- status: 状态 (activecompleted等)

3. 用户运动偏好表 (ak_user_sport_preferences)

- id: uuid (主键)
- user_id: 用户ID
- sport_type_id: 运动类型ID
- preference_level: 喜好程度 (1-5)
- frequency_per_week: 每周频次
- duration_minutes: 每次时长
- intensity_level: 强度等级 (1-5)
- is_favorite: 是否最爱
- notes: 备注

4. 训练提醒表 (ak_training_reminders)

- id: uuid (主键)
- user_id: 用户ID
- reminder_type: 提醒类型 (dailyweeklycustom)
- title: 提醒标题
- message: 提醒内容
- trigger_time: 触发时间
- trigger_days: 触发星期
- is_enabled: 是否启用
- sound_enabled: 是否播放声音
- vibrate_enabled: 是否震动

5. 设备管理表 (ak_device_types, ak_device_status_history, ak_device_settings, ak_device_sync_logs)

支持多种可穿戴设备的管理,包括智能手环、手表、戒指等。

分析扩展表

6. 偏好历史记录表 (ak_user_preference_history)

记录用户偏好的所有变化,用于趋势分析。

7. 目标进度历史表 (ak_goal_progress_history)

追踪目标进度的历史变化。

8. 训练模式分析表 (ak_training_patterns)

自动检测和记录用户的训练模式。

9. 个性化推荐表 (ak_personalized_recommendations)

存储为用户生成的个性化建议。

🎯 核心功能模块

1. 训练目标管理 (goal-settings.uvue)

功能特性:

  • 目标创建与编辑
  • 进度追踪与可视化
  • 目标模板快速设置
  • 优先级管理
  • 完成率统计
  • 目标状态管理

主要功能:

- 添加新目标 (addGoal)
- 编辑目标 (editGoal)
- 删除目标 (deleteGoal)
- 更新进度 (updateProgress)
- 目标完成检查 (checkCompletion)

2. 训练提醒系统 (reminder-settings.uvue)

功能特性:

  • 多种提醒类型 (每日、每周、自定义)
  • 智能提醒调度
  • 提前提醒功能
  • 重复提醒设置
  • 声音和震动控制
  • 全局提醒开关

提醒类型:

enum ReminderType {
  DAILY = 'daily',      // 每日提醒
  WEEKLY = 'weekly',    // 每周提醒
  CUSTOM = 'custom'     // 自定义提醒
}

3. 运动偏好管理 (favorite-exercises.uvue)

功能特性:

  • 运动分类浏览
  • 搜索与筛选
  • 偏好等级设置 (1-5星)
  • 训练频次与时长配置
  • 强度等级选择
  • 最爱运动标记
  • 个性化推荐

数据管理:

interface ExercisePreference {
  sport_type_id: string
  preference_level: number  // 1-5
  frequency_per_week: number
  duration_minutes: number
  intensity_level: number   // 1-5
  is_favorite: boolean
  notes: string
}

4. 设备管理系统 (device-management.uvue)

功能特性:

  • 设备扫描与配对
  • 多设备类型支持
  • 设备状态监控
  • 电池电量显示
  • 同步状态追踪
  • 设备设置管理

支持设备类型:

const DeviceTypes = {
  SMART_BAND: '智能手环',
  SMART_WATCH: '智能手表', 
  SMART_RING: '智能戒指',
  FITNESS_TRACKER: '健身追踪器',
  HEART_RATE_MONITOR: '心率监测器'
}

5. 偏好分析仪表板 (preferences-analytics.uvue)

功能特性:

  • 偏好概览统计
  • 运动类型分布图
  • 训练强度分析
  • 时间安排热力图
  • 目标完成情况
  • 智能推荐系统
  • 趋势分析

分析维度:

interface AnalyticsData {
  favoriteCount: number
  weeklyHours: number
  activeGoals: number
  remindersCount: number
  categoryDistribution: CategoryData[]
  intensityAnalysis: IntensityData[]
  trendMetrics: TrendData[]
}

🔄 数据流与架构

1. 数据获取模式

// 统一的用户ID获取
const getCurrentUserId = (): string => {
  if (state.userProfile?.id) return state.userProfile.id
  const session = supaClient.getSession()
  return session?.user?.id || ''
}

2. CRUD 操作模式

// 标准的数据操作流程
const saveData = async (data: any) => {
  try {
    const result = await supaClient
      .from('table_name')
      .upsert(data)
      .execute()
    
    if (result.error) throw new Error(result.error.message)
    
    uni.showToast({ title: '保存成功', icon: 'success' })
    await loadData() // 重新加载数据
  } catch (error) {
    console.error('保存失败:', error)
    uni.showToast({ title: '保存失败', icon: 'none' })
  }
}

3. 实时数据同步

所有页面都实现了实时数据同步机制,确保用户操作后立即看到最新状态。

🎨 UI/UX 设计原则

1. 一致性设计

  • 统一的色彩方案 (#4CAF50 主色调)
  • 一致的按钮样式和交互反馈
  • 标准化的卡片布局和间距

2. 响应式布局

.responsive-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

@media (max-width: 768px) {
  .responsive-grid {
    grid-template-columns: 1fr;
  }
}

3. 用户体验优化

  • 加载状态提示
  • 错误处理和重试机制
  • 表单验证和即时反馈
  • 手势操作支持

📊 智能分析功能

1. 个性化推荐算法

-- 基于用户行为生成推荐
CREATE FUNCTION generate_personalized_recommendations(user_id uuid)
RETURNS JSONB AS $$
BEGIN
  -- 分析用户偏好模式
  -- 生成个性化建议
  -- 返回推荐结果
END;
$$ LANGUAGE plpgsql;

2. 趋势分析

  • 训练频率变化趋势
  • 目标完成率分析
  • 偏好变化模式识别
  • 运动多样性评估

3. 智能提醒

  • 基于历史数据的最佳训练时间推荐
  • 个性化提醒内容生成
  • 自适应提醒频率调整

🔧 技术实现细节

1. 状态管理

// 使用 Vue 3 Composition API
const { loading, data, error } = useAsyncData(fetchFunction)

// 响应式状态
const preferences = ref<Preference[]>([])
const analytics = computed(() => calculateAnalytics(preferences.value))

2. 数据验证

const validateGoal = (goal: Goal): ValidationResult => {
  const errors = []
  
  if (!goal.target_value || goal.target_value <= 0) {
    errors.push('目标数值必须大于0')
  }
  
  if (!goal.target_date || new Date(goal.target_date) <= new Date()) {
    errors.push('目标日期必须是未来日期')
  }
  
  return { isValid: errors.length === 0, errors }
}

3. 性能优化

  • 分页加载大数据集
  • 数据缓存机制
  • 懒加载非关键组件
  • 图片和资源压缩

🚀 部署与配置

1. 数据库初始化

# 执行主要表结构
psql -d database_name -f training_preferences_tables.sql

# 执行设备管理扩展
psql -d database_name -f wearable_devices_extension.sql

# 执行分析功能扩展
psql -d database_name -f preferences_analytics_extension.sql

2. 页面路由配置

{
  "path": "pages/sport/student/goal-settings",
  "style": {
    "navigationBarTitleText": "训练目标",
    "navigationBarBackgroundColor": "#667eea"
  }
}

3. 权限配置

确保数据库 RLS (Row Level Security) 正确配置,保护用户数据安全。

📈 功能扩展建议

1. 短期扩展

  • 社交分享功能
  • 训练伙伴匹配
  • 成就徽章系统
  • 数据导出功能

2. 中期扩展

  • AI 驱动的训练计划生成
  • 与健康应用集成
  • 语音控制功能
  • AR/VR 训练体验

3. 长期扩展

  • 机器学习优化推荐算法
  • 生物识别集成
  • IoT 设备生态系统
  • 健康数据分析平台

🛠️ 维护与监控

1. 数据质量监控

-- 定期检查数据完整性
SELECT 
  table_name,
  COUNT(*) as record_count,
  MAX(created_at) as last_update
FROM information_schema.tables t
JOIN various_tables ON table condition
GROUP BY table_name;

2. 性能监控

  • 数据库查询性能
  • API 响应时间
  • 用户行为分析
  • 错误率监控

3. 备份策略

  • 每日自动数据备份
  • 增量备份机制
  • 灾难恢复计划
  • 数据同步验证

📋 总结

这个训练偏好与设备管理系统提供了完整的用户体验,从基础的偏好设置到高级的数据分析,涵盖了现代健身应用的所有核心功能。系统采用模块化设计,易于扩展和维护,为用户提供个性化的训练体验。

核心优势: 完整的数据模型设计 直观的用户界面 智能分析与推荐 多设备支持 可扩展的架构 数据安全保障

系统已准备好投入使用,并可根据用户反馈持续优化和改进。