deving
This commit is contained in:
+41
-11
@@ -315,9 +315,46 @@ async def get_analysis_snapshot(snapshot_id: int, db_session: AsyncSession = Dep
|
|||||||
async def result_page(request: Request, task_id: str, db_session: AsyncSession = Depends(get_db_session)):
|
async def result_page(request: Request, task_id: str, db_session: AsyncSession = Depends(get_db_session)):
|
||||||
"""结果详情页面"""
|
"""结果详情页面"""
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
from models.database import ProcessingTask, STPFile, GeometryData, MoldCavityData, HTMLFile
|
from models.database import ProcessingTask, STPFile, GeometryData, MoldCavityData, HTMLFile, AnalysisResultSnapshot
|
||||||
|
|
||||||
# 从数据库查询任务详情及相关数据
|
# 先尝试从分析结果快照获取数据(包含完整的 key_info)
|
||||||
|
result = await db_session.execute(
|
||||||
|
select(AnalysisResultSnapshot, ProcessingTask, STPFile)
|
||||||
|
.join(ProcessingTask, AnalysisResultSnapshot.stp_file_id == ProcessingTask.stp_file_id)
|
||||||
|
.join(STPFile, ProcessingTask.stp_file_id == STPFile.id)
|
||||||
|
.where(ProcessingTask.task_id == task_id)
|
||||||
|
.order_by(AnalysisResultSnapshot.created_time.desc())
|
||||||
|
.limit(1)
|
||||||
|
)
|
||||||
|
|
||||||
|
snapshot_record = result.first()
|
||||||
|
|
||||||
|
# 构建任务详情数据
|
||||||
|
task_data = {}
|
||||||
|
|
||||||
|
if snapshot_record:
|
||||||
|
# 从快照获取完整数据
|
||||||
|
snapshot, task, stp_file = snapshot_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 ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# 从快照获取完整的数据
|
||||||
|
task_data["geometry_data"] = snapshot.geometry_data if snapshot.geometry_data else None
|
||||||
|
task_data["key_info"] = snapshot.key_info if snapshot.key_info else None
|
||||||
|
task_data["mold_cavity_data"] = snapshot.mold_cavity_data if snapshot.mold_cavity_data else None
|
||||||
|
|
||||||
|
logger.info(f"从快照加载任务数据: {task_id}")
|
||||||
|
else:
|
||||||
|
# 如果没有快照,从各个表分别获取
|
||||||
result = await db_session.execute(
|
result = await db_session.execute(
|
||||||
select(ProcessingTask, STPFile, GeometryData, MoldCavityData, HTMLFile)
|
select(ProcessingTask, STPFile, GeometryData, MoldCavityData, HTMLFile)
|
||||||
.join(STPFile, ProcessingTask.stp_file_id == STPFile.id)
|
.join(STPFile, ProcessingTask.stp_file_id == STPFile.id)
|
||||||
@@ -334,7 +371,6 @@ async def result_page(request: Request, task_id: str, db_session: AsyncSession =
|
|||||||
|
|
||||||
task, stp_file, geometry_data, mold_cavity_data, html_file = task_record
|
task, stp_file, geometry_data, mold_cavity_data, html_file = task_record
|
||||||
|
|
||||||
# 构建任务详情数据
|
|
||||||
task_data = {
|
task_data = {
|
||||||
"task_id": task.task_id,
|
"task_id": task.task_id,
|
||||||
"filename": stp_file.original_filename if stp_file else "",
|
"filename": stp_file.original_filename if stp_file else "",
|
||||||
@@ -342,7 +378,7 @@ async def result_page(request: Request, task_id: str, db_session: AsyncSession =
|
|||||||
"status": task.status,
|
"status": task.status,
|
||||||
"progress": task.progress,
|
"progress": task.progress,
|
||||||
"current_step": task.current_step,
|
"current_step": task.current_step,
|
||||||
"created_at": task.created_time.isoformat() if task.created_time else "",
|
"upload_time": task.created_time.isoformat() if task.created_time else "",
|
||||||
"completed_at": task.completed_time.isoformat() if task.completed_time else "",
|
"completed_at": task.completed_time.isoformat() if task.completed_time else "",
|
||||||
"error": task.error_message if task.error_message else ""
|
"error": task.error_message if task.error_message else ""
|
||||||
}
|
}
|
||||||
@@ -393,13 +429,7 @@ async def result_page(request: Request, task_id: str, db_session: AsyncSession =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# 如果有HTML文件信息,添加到返回结果
|
logger.info(f"从各个表加载任务数据: {task_id}")
|
||||||
if html_file:
|
|
||||||
task_data["html_info"] = {
|
|
||||||
"filename": html_file.filename,
|
|
||||||
"file_path": html_file.file_path,
|
|
||||||
"generated_time": html_file.generated_time.isoformat() if html_file.generated_time else ""
|
|
||||||
}
|
|
||||||
|
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
import os
|
import os
|
||||||
|
|||||||
+2
-2
@@ -505,8 +505,8 @@ body {
|
|||||||
.features-data,
|
.features-data,
|
||||||
.recommendations-data,
|
.recommendations-data,
|
||||||
.metrics-data,
|
.metrics-data,
|
||||||
.analysis-info,
|
.analysis-info {
|
||||||
.key-info-categories {
|
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user