This commit is contained in:
cjw
2026-02-16 00:52:29 +08:00
parent 074c1ec993
commit 28a30736ae
3 changed files with 112 additions and 4 deletions
+96 -1
View File
@@ -132,6 +132,101 @@ async def debug_tasks():
} }
@router.get("/api/history")
async def get_file_history():
"""获取按文件名分组的文件历史记录"""
# 按文件名分组
file_groups = {}
for task_id, task in tasks.items():
filename = task.get("filename", "unknown")
if filename not in file_groups:
file_groups[filename] = []
file_groups[filename].append(task)
# 构建返回数据
files = []
for filename, file_tasks in file_groups.items():
# 按上传时间排序
file_tasks.sort(key=lambda x: x.get("upload_time", ""), reverse=True)
files.append({
"filename": filename,
"record_count": len(file_tasks),
"last_upload": file_tasks[0].get("upload_time", ""),
"first_upload": file_tasks[-1].get("upload_time", "") if len(file_tasks) > 1 else ""
})
# 按最后上传时间排序
files.sort(key=lambda x: x["last_upload"], reverse=True)
return {
"total_files": len(files),
"files": files
}
@router.get("/api/history/{filename}")
async def get_file_records(filename: str):
"""获取指定文件名的所有记录"""
# URL解码文件名
import urllib.parse
decoded_filename = urllib.parse.unquote(filename)
# 查找匹配的文件记录
file_records = []
for task_id, task in tasks.items():
if task.get("filename", "") == decoded_filename:
file_records.append({
"task_id": task_id,
"filename": task.get("filename", ""),
"file_size": task.get("file_size", 0),
"upload_time": task.get("upload_time", ""),
"status": task.get("status", "unknown"),
"completed_at": task.get("completed_at", ""),
"geometry_data": task.get("geometry_data"),
"cavity_data": task.get("cavity_data")
})
# 按上传时间排序(最新的在前)
file_records.sort(key=lambda x: x.get("upload_time", ""), reverse=True)
return file_records
@router.get("/history")
async def history_page(request: Request):
"""历史记录页面"""
from fastapi.templating import Jinja2Templates
import os
templates_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "templates")
templates = Jinja2Templates(directory=templates_dir)
return templates.TemplateResponse("history.html", {
"request": request,
"pythonocc_available": True,
"version": "3.0.0"
})
@router.get("/result/{task_id}")
async def result_page(request: Request, task_id: str):
"""结果详情页面"""
if task_id not in tasks:
raise HTTPException(404, "任务不存在")
task = tasks[task_id]
from fastapi.templating import Jinja2Templates
import os
templates_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "templates")
templates = Jinja2Templates(directory=templates_dir)
return templates.TemplateResponse("result.html", {
"request": request,
"task": task,
"pythonocc_available": True,
"version": "3.0.0"
})
async def process_file_with_storage( async def process_file_with_storage(
task_id: str, task_id: str,
file_path: str, file_path: str,
@@ -289,7 +384,7 @@ async def process_file_core(
"width": int(mold_width), "width": int(mold_width),
"height": int(mold_height) "height": int(mold_height)
}, },
"mold_material": "Aluminum Alloy 7075", "mold_material": "铝合金7075",
"mold_hardness": "HB 150-170", "mold_hardness": "HB 150-170",
"surface_finish": "Ra 0.8 μm", "surface_finish": "Ra 0.8 μm",
"parting_line_length": f"{parting_line_length:.2f} mm", "parting_line_length": f"{parting_line_length:.2f} mm",
+8 -2
View File
@@ -513,11 +513,17 @@ function getPriorityText(priority) {
} }
function formatParameters(parameters) { function formatParameters(parameters) {
const parameterMap = {
'min_angle': '最小角度',
'preferred_angle': '推荐角度'
};
return Object.entries(parameters).map(([key, value]) => { return Object.entries(parameters).map(([key, value]) => {
const displayKey = parameterMap[key] || key;
if (typeof value === 'number') { if (typeof value === 'number') {
return `${key}: ${value.toFixed(2)}`; return `${displayKey}: ${value.toFixed(2)}`;
} }
return `${key}: ${value}`; return `${displayKey}: ${value}`;
}).join('; '); }).join('; ');
} }
+8 -1
View File
@@ -114,7 +114,14 @@
</div> </div>
<div class="system-info"> <div class="system-info">
<p>PythonOCC 可用: {{ pythonocc_available }} | 服务版本: 2.0.0</p> <div style="display: flex; justify-content: space-between; align-items: center;">
<p>PythonOCC 可用: {{ pythonocc_available }} | 服务版本: 3.0.0</p>
<div>
<button class="upload-btn" onclick="location.href='/history'" style="background: #666; margin-left: 10px;">
📋 查看历史记录
</button>
</div>
</div>
</div> </div>
</div> </div>