更新内容: - 后端 AI 服务优化(能力分析、知识点解析等) - 前端考试和陪练界面更新 - 修复多个 prompt 和 JSON 解析问题 - 更新 Coze 语音客户端
This commit is contained in:
@@ -141,6 +141,7 @@ async def submit_exam(
|
||||
@router.get("/mistakes", response_model=ResponseModel[GetMistakesResponse])
|
||||
async def get_mistakes(
|
||||
exam_id: int,
|
||||
round: int = Query(None, description="获取指定轮次的错题,不传则获取所有轮次"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
@@ -149,18 +150,31 @@ async def get_mistakes(
|
||||
|
||||
用于第二、三轮考试时获取上一轮的错题记录
|
||||
返回的数据可直接序列化为JSON字符串作为mistake_records参数传给考试生成接口
|
||||
|
||||
参数说明:
|
||||
- exam_id: 考试ID
|
||||
- round: 指定轮次(1/2/3),用于获取特定轮次的错题
|
||||
第2轮考试时传入round=1,获取第1轮的错题
|
||||
第3轮考试时传入round=2,获取第2轮的错题
|
||||
不传则获取该考试的所有错题
|
||||
"""
|
||||
logger.info(f"📋 GET /mistakes 收到请求")
|
||||
try:
|
||||
logger.info(f"📋 获取错题记录 - exam_id: {exam_id}, user_id: {current_user.id}")
|
||||
logger.info(f"📋 获取错题记录 - exam_id: {exam_id}, round: {round}, user_id: {current_user.id}")
|
||||
|
||||
# 查询指定考试的错题记录
|
||||
result = await db.execute(
|
||||
select(ExamMistake).where(
|
||||
ExamMistake.exam_id == exam_id,
|
||||
ExamMistake.user_id == current_user.id,
|
||||
).order_by(ExamMistake.id)
|
||||
# 构建查询条件
|
||||
query = select(ExamMistake).where(
|
||||
ExamMistake.exam_id == exam_id,
|
||||
ExamMistake.user_id == current_user.id,
|
||||
)
|
||||
|
||||
# 如果指定了轮次,只获取该轮次的错题
|
||||
if round is not None:
|
||||
query = query.where(ExamMistake.round == round)
|
||||
|
||||
query = query.order_by(ExamMistake.id)
|
||||
|
||||
result = await db.execute(query)
|
||||
mistakes = result.scalars().all()
|
||||
|
||||
logger.info(f"✅ 查询到错题记录数量: {len(mistakes)}")
|
||||
@@ -262,7 +276,18 @@ async def generate_exam(
|
||||
- 第一轮考试:mistake_records 传空或不传
|
||||
- 第二、三轮错题重考:mistake_records 传入上一轮错题记录的JSON字符串
|
||||
"""
|
||||
from app.models.course import Course
|
||||
|
||||
try:
|
||||
# 验证课程存在性
|
||||
course = await db.get(Course, request.course_id)
|
||||
if not course or course.is_deleted:
|
||||
logger.warning(f"课程不存在或已删除: course_id={request.course_id}")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"无法生成试题:课程ID {request.course_id} 不存在或已被删除"
|
||||
)
|
||||
|
||||
# 从用户信息中自动获取岗位ID(如果未提供)
|
||||
position_id = request.position_id
|
||||
if not position_id:
|
||||
@@ -486,6 +511,7 @@ async def record_mistake(
|
||||
mistake = ExamMistake(
|
||||
user_id=current_user.id,
|
||||
exam_id=request.exam_id,
|
||||
round=request.round, # 记录考试轮次
|
||||
question_id=request.question_id,
|
||||
knowledge_point_id=None, # 暂时设为None,避免外键约束
|
||||
question_content=request.question_content,
|
||||
@@ -503,7 +529,7 @@ async def record_mistake(
|
||||
|
||||
logger.info(
|
||||
f"记录错题成功 - user_id: {current_user.id}, exam_id: {request.exam_id}, "
|
||||
f"mistake_id: {mistake.id}"
|
||||
f"round: {request.round}, mistake_id: {mistake.id}"
|
||||
)
|
||||
|
||||
return ResponseModel(
|
||||
|
||||
Reference in New Issue
Block a user