deving
This commit is contained in:
+48
-17
@@ -138,15 +138,34 @@ async def debug_tasks():
|
||||
|
||||
@router.get("/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 = {}
|
||||
for task_id, task in tasks.items():
|
||||
filename = task.get("filename", "unknown")
|
||||
for task, stp_file in tasks:
|
||||
filename = stp_file.original_filename
|
||||
if filename not in file_groups:
|
||||
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 = []
|
||||
@@ -178,20 +197,32 @@ async def get_file_records(filename: str):
|
||||
import urllib.parse
|
||||
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 = []
|
||||
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")
|
||||
})
|
||||
for task, stp_file in tasks:
|
||||
file_records.append({
|
||||
"task_id": task.task_id,
|
||||
"filename": stp_file.original_filename,
|
||||
"file_size": stp_file.file_size,
|
||||
"upload_time": task.created_at.isoformat() if task.created_at else "",
|
||||
"status": task.status,
|
||||
"completed_at": task.completed_at.isoformat() if task.completed_at else "",
|
||||
"geometry_data": task.geometry_data,
|
||||
"cavity_data": task.cavity_data
|
||||
})
|
||||
|
||||
# 按上传时间排序(最新的在前)
|
||||
file_records.sort(key=lambda x: x.get("upload_time", ""), reverse=True)
|
||||
|
||||
Reference in New Issue
Block a user