Some checks failed
continuous-integration/drone/push Build is failing
1. 课程学习进度追踪
- 新增 UserCourseProgress 和 UserMaterialProgress 模型
- 新增 /api/v1/progress/* 进度追踪 API
- 更新 admin.py 使用真实课程完成率数据
2. 路由权限检查完善
- 新增前端 permissionChecker.ts 权限检查工具
- 更新 router/guard.ts 实现团队和课程权限验证
- 新增后端 permission_service.py
3. AI 陪练音频转文本
- 新增 speech_recognition.py 语音识别服务
- 新增 /api/v1/speech/* API
- 更新 ai-practice-coze.vue 支持语音输入
4. 双人对练报告生成
- 更新 practice_room_service.py 添加报告生成功能
- 新增 /rooms/{room_code}/report API
- 更新 duo-practice-report.vue 调用真实 API
5. 学习提醒推送
- 新增 notification_service.py 通知服务
- 新增 scheduler_service.py 定时任务服务
- 支持钉钉、企微、站内消息推送
6. 智能学习推荐
- 新增 recommendation_service.py 推荐服务
- 新增 /api/v1/recommendations/* API
- 支持错题、能力、进度、热门多维度推荐
7. 安全问题修复
- DEBUG 默认值改为 False
- 添加 SECRET_KEY 安全警告
- 新增 check_security_settings() 检查函数
8. 证书 PDF 生成
- 更新 certificate_service.py 添加 PDF 生成
- 添加 weasyprint、Pillow、qrcode 依赖
- 更新下载 API 支持 PDF 和 PNG 格式
202 lines
5.3 KiB
Python
202 lines
5.3 KiB
Python
"""
|
||
用户课程学习进度数据库模型
|
||
"""
|
||
from enum import Enum
|
||
from typing import Optional
|
||
from datetime import datetime
|
||
|
||
from sqlalchemy import (
|
||
String,
|
||
Integer,
|
||
Boolean,
|
||
ForeignKey,
|
||
Float,
|
||
DateTime,
|
||
UniqueConstraint,
|
||
Index,
|
||
)
|
||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||
|
||
from app.models.base import BaseModel
|
||
|
||
|
||
class ProgressStatus(str, Enum):
|
||
"""学习进度状态枚举"""
|
||
NOT_STARTED = "not_started" # 未开始
|
||
IN_PROGRESS = "in_progress" # 学习中
|
||
COMPLETED = "completed" # 已完成
|
||
|
||
|
||
class UserCourseProgress(BaseModel):
|
||
"""
|
||
用户课程进度表
|
||
记录用户对每门课程的整体学习进度
|
||
"""
|
||
|
||
__tablename__ = "user_course_progress"
|
||
__table_args__ = (
|
||
UniqueConstraint("user_id", "course_id", name="uq_user_course"),
|
||
Index("idx_user_course_progress_user", "user_id"),
|
||
Index("idx_user_course_progress_course", "course_id"),
|
||
Index("idx_user_course_progress_status", "status"),
|
||
)
|
||
|
||
user_id: Mapped[int] = mapped_column(
|
||
Integer,
|
||
ForeignKey("users.id", ondelete="CASCADE"),
|
||
nullable=False,
|
||
comment="用户ID",
|
||
)
|
||
course_id: Mapped[int] = mapped_column(
|
||
Integer,
|
||
ForeignKey("courses.id", ondelete="CASCADE"),
|
||
nullable=False,
|
||
comment="课程ID",
|
||
)
|
||
|
||
# 进度信息
|
||
status: Mapped[ProgressStatus] = mapped_column(
|
||
String(20),
|
||
default=ProgressStatus.NOT_STARTED.value,
|
||
nullable=False,
|
||
comment="学习状态:not_started/in_progress/completed",
|
||
)
|
||
progress_percent: Mapped[float] = mapped_column(
|
||
Float,
|
||
default=0.0,
|
||
nullable=False,
|
||
comment="完成百分比(0-100)",
|
||
)
|
||
completed_materials: Mapped[int] = mapped_column(
|
||
Integer,
|
||
default=0,
|
||
nullable=False,
|
||
comment="已完成资料数",
|
||
)
|
||
total_materials: Mapped[int] = mapped_column(
|
||
Integer,
|
||
default=0,
|
||
nullable=False,
|
||
comment="总资料数",
|
||
)
|
||
|
||
# 学习时长统计
|
||
total_study_time: Mapped[int] = mapped_column(
|
||
Integer,
|
||
default=0,
|
||
nullable=False,
|
||
comment="总学习时长(秒)",
|
||
)
|
||
|
||
# 时间记录
|
||
first_accessed_at: Mapped[Optional[datetime]] = mapped_column(
|
||
DateTime,
|
||
nullable=True,
|
||
comment="首次访问时间",
|
||
)
|
||
last_accessed_at: Mapped[Optional[datetime]] = mapped_column(
|
||
DateTime,
|
||
nullable=True,
|
||
comment="最后访问时间",
|
||
)
|
||
completed_at: Mapped[Optional[datetime]] = mapped_column(
|
||
DateTime,
|
||
nullable=True,
|
||
comment="完成时间",
|
||
)
|
||
|
||
# 关联关系
|
||
user = relationship("User", backref="course_progress")
|
||
course = relationship("Course", backref="user_progress")
|
||
|
||
|
||
class UserMaterialProgress(BaseModel):
|
||
"""
|
||
用户资料进度表
|
||
记录用户对每个课程资料的学习进度
|
||
"""
|
||
|
||
__tablename__ = "user_material_progress"
|
||
__table_args__ = (
|
||
UniqueConstraint("user_id", "material_id", name="uq_user_material"),
|
||
Index("idx_user_material_progress_user", "user_id"),
|
||
Index("idx_user_material_progress_material", "material_id"),
|
||
)
|
||
|
||
user_id: Mapped[int] = mapped_column(
|
||
Integer,
|
||
ForeignKey("users.id", ondelete="CASCADE"),
|
||
nullable=False,
|
||
comment="用户ID",
|
||
)
|
||
material_id: Mapped[int] = mapped_column(
|
||
Integer,
|
||
ForeignKey("course_materials.id", ondelete="CASCADE"),
|
||
nullable=False,
|
||
comment="资料ID",
|
||
)
|
||
course_id: Mapped[int] = mapped_column(
|
||
Integer,
|
||
ForeignKey("courses.id", ondelete="CASCADE"),
|
||
nullable=False,
|
||
comment="课程ID(冗余字段,便于查询)",
|
||
)
|
||
|
||
# 进度信息
|
||
is_completed: Mapped[bool] = mapped_column(
|
||
Boolean,
|
||
default=False,
|
||
nullable=False,
|
||
comment="是否已完成",
|
||
)
|
||
progress_percent: Mapped[float] = mapped_column(
|
||
Float,
|
||
default=0.0,
|
||
nullable=False,
|
||
comment="阅读/播放进度百分比(0-100)",
|
||
)
|
||
|
||
# 视频/音频特有字段
|
||
last_position: Mapped[int] = mapped_column(
|
||
Integer,
|
||
default=0,
|
||
nullable=False,
|
||
comment="上次播放位置(秒)",
|
||
)
|
||
total_duration: Mapped[int] = mapped_column(
|
||
Integer,
|
||
default=0,
|
||
nullable=False,
|
||
comment="媒体总时长(秒)",
|
||
)
|
||
|
||
# 学习时长
|
||
study_time: Mapped[int] = mapped_column(
|
||
Integer,
|
||
default=0,
|
||
nullable=False,
|
||
comment="学习时长(秒)",
|
||
)
|
||
|
||
# 时间记录
|
||
first_accessed_at: Mapped[Optional[datetime]] = mapped_column(
|
||
DateTime,
|
||
nullable=True,
|
||
comment="首次访问时间",
|
||
)
|
||
last_accessed_at: Mapped[Optional[datetime]] = mapped_column(
|
||
DateTime,
|
||
nullable=True,
|
||
comment="最后访问时间",
|
||
)
|
||
completed_at: Mapped[Optional[datetime]] = mapped_column(
|
||
DateTime,
|
||
nullable=True,
|
||
comment="完成时间",
|
||
)
|
||
|
||
# 关联关系
|
||
user = relationship("User", backref="material_progress")
|
||
material = relationship("CourseMaterial", backref="user_progress")
|
||
course = relationship("Course", backref="material_user_progress")
|