diff --git a/src/api/routes.py b/src/api/routes.py index 946c3cc..c2c2155 100644 --- a/src/api/routes.py +++ b/src/api/routes.py @@ -116,14 +116,40 @@ async def upload_stp( @router.get("/status/{task_id}") @router.post("/status/{task_id}") -async def get_status(task_id: str): +async def get_status(task_id: str, db_session: AsyncSession = Depends(get_db_session)): """获取任务状态""" - if task_id not in tasks: + from sqlalchemy import select + from models.database import ProcessingTask, STPFile + + # 从数据库查询任务详情 + result = await db_session.execute( + select(ProcessingTask, STPFile) + .join(STPFile, ProcessingTask.stp_file_id == STPFile.id) + .where(ProcessingTask.task_id == task_id) + ) + + task_record = result.first() + + if not task_record: raise HTTPException(404, "任务不存在") - - task = tasks[task_id] - logger.info(f"返回任务状态: {task_id} - {task['status']}") - return task + + task, stp_file = task_record + + # 构建任务详情数据 + task_data = { + "task_id": task.task_id, + "filename": stp_file.original_filename if stp_file else "", + "file_size": stp_file.file_size if stp_file else 0, + "status": task.status, + "progress": task.progress, + "current_step": task.current_step, + "upload_time": task.created_time.isoformat() if task.created_time else "", + "completed_at": task.completed_time.isoformat() if task.completed_time else "", + "error": task.error_message if task.error_message else "" + } + + logger.info(f"返回任务状态: {task_id} - {task.status}") + return task_data @router.get("/debug/tasks") diff --git a/templates/result.html b/templates/result.html index 8b9a7e0..5a4c367 100644 --- a/templates/result.html +++ b/templates/result.html @@ -152,8 +152,8 @@
-

📊 分析结果详情

-

查看STP文件的详细分析结果

+

📊 历史记录 - 分析结果详情

+

查看历史记录中STP文件的详细分析结果