This commit is contained in:
cjw
2026-02-16 02:00:10 +08:00
parent c6f52b9849
commit 6dc538e754
2 changed files with 52 additions and 21 deletions
+48 -17
View File
@@ -138,15 +138,34 @@ async def debug_tasks():
@router.get("/api/history") @router.get("/api/history")
@router.post("/api/history") @router.post("/api/history")
async def get_file_history(): async def get_file_history(db_session: AsyncSession = Depends(get_db_session)):
"""获取按文件名分组的文件历史记录""" """获取按文件名分组的文件历史记录"""
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)
.order_by(ProcessingTask.created_at.desc())
)
tasks = result.all()
# 按文件名分组 # 按文件名分组
file_groups = {} file_groups = {}
for task_id, task in tasks.items(): for task, stp_file in tasks:
filename = task.get("filename", "unknown") filename = stp_file.original_filename
if filename not in file_groups: if filename not in file_groups:
file_groups[filename] = [] file_groups[filename] = []
file_groups[filename].append(task)
file_groups[filename].append({
"task_id": task.task_id,
"filename": filename,
"upload_time": task.created_at.isoformat() if task.created_at else "",
"status": task.status,
"file_size": stp_file.file_size
})
# 构建返回数据 # 构建返回数据
files = [] files = []
@@ -178,20 +197,32 @@ async def get_file_records(filename: str):
import urllib.parse import urllib.parse
decoded_filename = urllib.parse.unquote(filename) decoded_filename = urllib.parse.unquote(filename)
# 查找匹配的文件记录 # 从数据库查询指定文件名的所有处理任务
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(STPFile.original_filename == decoded_filename)
.order_by(ProcessingTask.created_at.desc())
)
tasks = result.all()
# 构建返回数据
file_records = [] file_records = []
for task_id, task in tasks.items(): for task, stp_file in tasks:
if task.get("filename", "") == decoded_filename: file_records.append({
file_records.append({ "task_id": task.task_id,
"task_id": task_id, "filename": stp_file.original_filename,
"filename": task.get("filename", ""), "file_size": stp_file.file_size,
"file_size": task.get("file_size", 0), "upload_time": task.created_at.isoformat() if task.created_at else "",
"upload_time": task.get("upload_time", ""), "status": task.status,
"status": task.get("status", "unknown"), "completed_at": task.completed_at.isoformat() if task.completed_at else "",
"completed_at": task.get("completed_at", ""), "geometry_data": task.geometry_data,
"geometry_data": task.get("geometry_data"), "cavity_data": task.cavity_data
"cavity_data": task.get("cavity_data") })
})
# 按上传时间排序(最新的在前) # 按上传时间排序(最新的在前)
file_records.sort(key=lambda x: x.get("upload_time", ""), reverse=True) file_records.sort(key=lambda x: x.get("upload_time", ""), reverse=True)
+4 -4
View File
@@ -185,12 +185,12 @@
<p>查看所有上传的STP文件分析记录</p> <p>查看所有上传的STP文件分析记录</p>
</div> </div>
<div class="nav-buttons"> <div class="nav-buttons">
<button class="upload-btn" onclick="goToUpload()"> <a href="/" class="upload-btn" style="text-decoration: none; display: inline-block; text-align: center;">
📁 上传新文件 📁 上传新文件
</button> </a>
<button class="upload-btn" onclick="goToHome()"> <a href="/" class="upload-btn" style="text-decoration: none; display: inline-block; text-align: center;">
🔄 返回主页 🔄 返回主页
</button> </a>
</div> </div>
</div> </div>