deving
This commit is contained in:
+82
-51
@@ -117,14 +117,56 @@ 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:
|
||||
# 先从内存查找
|
||||
if task_id in tasks:
|
||||
task = tasks[task_id]
|
||||
logger.info(f"返回任务状态(内存): {task_id} - {task['status']}")
|
||||
return task
|
||||
|
||||
# 内存中没有,从数据库查找
|
||||
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 ""
|
||||
}
|
||||
|
||||
# 尝试获取快照中的 key_info
|
||||
from models.database import AnalysisResultSnapshot
|
||||
snapshot_result = await db_session.execute(
|
||||
select(AnalysisResultSnapshot)
|
||||
.where(AnalysisResultSnapshot.stp_file_id == stp_file.id)
|
||||
.order_by(AnalysisResultSnapshot.created_time.desc())
|
||||
.limit(1)
|
||||
)
|
||||
snapshot = snapshot_result.scalar_one_or_none()
|
||||
|
||||
if snapshot and snapshot.key_info:
|
||||
task_data["key_info"] = snapshot.key_info
|
||||
|
||||
logger.info(f"返回任务状态(数据库): {task_id} - {task['status']}")
|
||||
return task_data
|
||||
|
||||
|
||||
@router.get("/debug/tasks")
|
||||
@@ -317,60 +359,20 @@ async def result_page(request: Request, task_id: str, db_session: AsyncSession =
|
||||
from sqlalchemy import select
|
||||
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)
|
||||
# 先查询任务记录
|
||||
task_result = await db_session.execute(
|
||||
select(ProcessingTask, STPFile)
|
||||
.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(
|
||||
select(ProcessingTask, STPFile, GeometryData, MoldCavityData, HTMLFile)
|
||||
.join(STPFile, ProcessingTask.stp_file_id == STPFile.id)
|
||||
.outerjoin(GeometryData, STPFile.id == GeometryData.stp_file_id)
|
||||
.outerjoin(MoldCavityData, STPFile.id == MoldCavityData.stp_file_id)
|
||||
.outerjoin(HTMLFile, STPFile.id == HTMLFile.stp_file_id)
|
||||
.where(ProcessingTask.task_id == task_id)
|
||||
)
|
||||
|
||||
task_record = result.first()
|
||||
task_record = task_result.first()
|
||||
|
||||
if not task_record:
|
||||
raise HTTPException(404, "任务不存在")
|
||||
|
||||
task, stp_file, geometry_data, mold_cavity_data, html_file = task_record
|
||||
task, stp_file = task_record
|
||||
|
||||
# 构建任务详情数据
|
||||
task_data = {
|
||||
"task_id": task.task_id,
|
||||
"filename": stp_file.original_filename if stp_file else "",
|
||||
@@ -383,6 +385,35 @@ async def result_page(request: Request, task_id: str, db_session: AsyncSession =
|
||||
"error": task.error_message if task.error_message else ""
|
||||
}
|
||||
|
||||
# 尝试从分析结果快照获取数据
|
||||
snapshot_result = await db_session.execute(
|
||||
select(AnalysisResultSnapshot)
|
||||
.where(AnalysisResultSnapshot.stp_file_id == stp_file.id)
|
||||
.order_by(AnalysisResultSnapshot.created_time.desc())
|
||||
.limit(1)
|
||||
)
|
||||
snapshot = snapshot_result.scalar_one_or_none()
|
||||
|
||||
if snapshot:
|
||||
# 从快照获取完整的数据
|
||||
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(
|
||||
select(GeometryData, MoldCavityData, HTMLFile)
|
||||
.outerjoin(MoldCavityData, GeometryData.stp_file_id == MoldCavityData.stp_file_id)
|
||||
.outerjoin(HTMLFile, GeometryData.stp_file_id == HTMLFile.stp_file_id)
|
||||
.where(GeometryData.stp_file_id == stp_file.id)
|
||||
)
|
||||
|
||||
other_data = result.first()
|
||||
|
||||
if other_data:
|
||||
geometry_data, mold_cavity_data, html_file = other_data
|
||||
|
||||
# 如果有几何数据,添加到返回结果
|
||||
if geometry_data:
|
||||
task_data["geometry_data"] = {
|
||||
|
||||
+1
-23
@@ -147,30 +147,8 @@ async function toggleFileRecords(filename) {
|
||||
}
|
||||
|
||||
async function viewRecordDetails(taskId) {
|
||||
// 先检查任务状态,如果数据不完整,提示用户重新分析
|
||||
try {
|
||||
const response = await fetch(`/status/${taskId}`);
|
||||
if (response.ok) {
|
||||
const task = await response.json();
|
||||
if (task.status === 'completed' && task.key_info) {
|
||||
// 数据完整,跳转到结果页面
|
||||
// 直接跳转到结果页面,由后端从数据库加载完整数据
|
||||
window.location.href = `/result/${taskId}`;
|
||||
} else {
|
||||
// 数据不完整,提示用户重新分析
|
||||
if (confirm('该历史记录的分析数据不完整,是否重新分析?')) {
|
||||
// 重新分析逻辑
|
||||
await reanalyzeTask(taskId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 任务不存在或无法访问,跳转到结果页面尝试显示
|
||||
window.location.href = `/result/${taskId}`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('检查任务状态失败:', error);
|
||||
// 出错时直接跳转
|
||||
window.location.href = `/result/${taskId}`;
|
||||
}
|
||||
}
|
||||
|
||||
async function reanalyzeTask(taskId) {
|
||||
|
||||
+8
-3
@@ -174,12 +174,18 @@ body {
|
||||
}
|
||||
|
||||
.key-info-categories {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
display: grid !important;
|
||||
grid-template-columns: repeat(3, 1fr) !important;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.data-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.category-section {
|
||||
background: #f8f9fa;
|
||||
border-radius: 10px;
|
||||
@@ -509,4 +515,3 @@ body {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-31
@@ -5,7 +5,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>分析结果 - STP文件几何分析工具</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
<link rel="stylesheet" href="/static/style.css?v=10">
|
||||
<style>
|
||||
.result-container {
|
||||
max-width: 1200px;
|
||||
@@ -107,14 +107,6 @@
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.data-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid #f5f5f5;
|
||||
}
|
||||
|
||||
.data-label {
|
||||
font-weight: bold;
|
||||
color: #666;
|
||||
@@ -181,38 +173,23 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// 从URL获取任务ID
|
||||
const pathParts = window.location.pathname.split('/');
|
||||
const taskId = pathParts[pathParts.length - 1];
|
||||
// 从模板获取任务数据
|
||||
const task = {{ task | tojson | safe }};
|
||||
|
||||
// 页面加载完成后获取任务数据
|
||||
// 页面加载完成后显示任务数据
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadTaskData(taskId);
|
||||
});
|
||||
|
||||
async function loadTaskData(taskId) {
|
||||
try {
|
||||
const response = await fetch(`/status/${taskId}`);
|
||||
if (!response.ok) {
|
||||
throw new Error('获取任务数据失败');
|
||||
}
|
||||
|
||||
const task = await response.json();
|
||||
if (task && task.task_id) {
|
||||
displayTaskInfo(task);
|
||||
displayResults(task);
|
||||
|
||||
} catch (error) {
|
||||
} else {
|
||||
document.getElementById('taskInfo').innerHTML = `
|
||||
<div class="error-message">
|
||||
<h3>❌ 加载失败</h3>
|
||||
<p>${error.message}</p>
|
||||
<button class="upload-btn" onclick="loadTaskData('${taskId}')">
|
||||
重试
|
||||
</button>
|
||||
<p>无法获取任务数据</p>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function displayTaskInfo(task) {
|
||||
const taskInfo = document.getElementById('taskInfo');
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>分析结果快照 - STP文件几何分析工具</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
<link rel="stylesheet" href="/static/style.css?v=10">
|
||||
<style>
|
||||
.snapshot-container {
|
||||
max-width: 1200px;
|
||||
@@ -85,14 +85,6 @@
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.data-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid #f5f5f5;
|
||||
}
|
||||
|
||||
.data-label {
|
||||
font-weight: bold;
|
||||
color: #666;
|
||||
|
||||
Reference in New Issue
Block a user