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 格式
This commit is contained in:
@@ -11,6 +11,7 @@ from sqlalchemy import select, func
|
||||
from app.core.deps import get_current_active_user as get_current_user, get_db
|
||||
from app.models.user import User
|
||||
from app.models.course import Course, CourseStatus
|
||||
from app.models.user_course_progress import UserCourseProgress, ProgressStatus
|
||||
from app.schemas.base import ResponseModel
|
||||
|
||||
router = APIRouter(prefix="/admin")
|
||||
@@ -61,18 +62,32 @@ async def get_dashboard_stats(
|
||||
.where(Course.status == CourseStatus.PUBLISHED)
|
||||
)
|
||||
|
||||
# TODO: 完成的课程数需要根据用户课程进度表计算
|
||||
completed_courses = 0 # 暂时设为0
|
||||
# 根据用户课程进度表计算完成的课程学习记录数
|
||||
completed_courses = await db.scalar(
|
||||
select(func.count(UserCourseProgress.id))
|
||||
.where(UserCourseProgress.status == ProgressStatus.COMPLETED.value)
|
||||
) or 0
|
||||
|
||||
# 考试统计(如果有考试表的话)
|
||||
total_exams = 0
|
||||
avg_score = 0.0
|
||||
pass_rate = "0%"
|
||||
|
||||
# 学习时长统计(如果有学习记录表的话)
|
||||
total_learning_hours = 0
|
||||
avg_learning_hours = 0.0
|
||||
active_rate = "0%"
|
||||
# 学习时长统计 - 从用户课程进度表获取
|
||||
total_study_seconds = await db.scalar(
|
||||
select(func.coalesce(func.sum(UserCourseProgress.total_study_time), 0))
|
||||
) or 0
|
||||
total_learning_hours = round(total_study_seconds / 3600)
|
||||
|
||||
# 平均学习时长(每个活跃用户)
|
||||
active_learners = await db.scalar(
|
||||
select(func.count(func.distinct(UserCourseProgress.user_id)))
|
||||
.where(UserCourseProgress.status != ProgressStatus.NOT_STARTED.value)
|
||||
) or 0
|
||||
avg_learning_hours = round(total_study_seconds / 3600 / max(active_learners, 1), 1)
|
||||
|
||||
# 活跃率 = 有学习记录的用户 / 总用户
|
||||
active_rate = f"{round(active_learners / max(total_users, 1) * 100)}%"
|
||||
|
||||
# 构建响应数据
|
||||
stats = {
|
||||
@@ -195,10 +210,28 @@ async def get_course_completion_data(
|
||||
for course_name, course_id in courses:
|
||||
course_names.append(course_name)
|
||||
|
||||
# TODO: 根据用户课程进度表计算完成率
|
||||
# 这里暂时生成模拟数据
|
||||
import random
|
||||
completion_rate = random.randint(60, 95)
|
||||
# 根据用户课程进度表计算完成率
|
||||
# 统计该课程的完成用户数和总学习用户数
|
||||
stats_result = await db.execute(
|
||||
select(
|
||||
func.count(UserCourseProgress.id).label('total'),
|
||||
func.sum(
|
||||
func.case(
|
||||
(UserCourseProgress.status == ProgressStatus.COMPLETED.value, 1),
|
||||
else_=0
|
||||
)
|
||||
).label('completed')
|
||||
).where(UserCourseProgress.course_id == course_id)
|
||||
)
|
||||
stats = stats_result.one()
|
||||
total_learners = stats.total or 0
|
||||
completed_learners = stats.completed or 0
|
||||
|
||||
# 计算完成率
|
||||
if total_learners > 0:
|
||||
completion_rate = round(completed_learners / total_learners * 100)
|
||||
else:
|
||||
completion_rate = 0
|
||||
completion_rates.append(completion_rate)
|
||||
|
||||
return ResponseModel(
|
||||
|
||||
Reference in New Issue
Block a user