feat(shipping-notice): 新增临时库存管理功能,支持创建会话、获取分析结果及字段映射建议
This commit is contained in:
1 parent
46eb63f5bb
commit
e9bdd81f1a
320 files changed
+28361
-10487
No files matched your search
@@ -188,21 +188,29 @@ def get_task_in_batch(batch_no: str, task_no: str) -> ShippingTask | None:
|
||||
|
||||
|
||||
def resolve_task_export_download(task: ShippingTask | None) -> tuple[Path, str] | None:
|
||||
"""解析任务导出文件路径;文件不存在或路径无效时返回 None。"""
|
||||
"""解析任务当前 ready Artifact;文件不存在或校验元数据无效时返回 None。"""
|
||||
if not task or not task.export_file_path:
|
||||
return None
|
||||
path = Path(task.export_file_path)
|
||||
from app.models import ShippingExportArtifact
|
||||
artifact = ShippingExportArtifact.query.filter_by(
|
||||
task_id=task.id, status='ready', file_path=task.export_file_path,
|
||||
).order_by(
|
||||
ShippingExportArtifact.created_at.desc(), ShippingExportArtifact.id.desc(),
|
||||
).first()
|
||||
if artifact is None:
|
||||
return None
|
||||
path = Path(artifact.file_path)
|
||||
if not path.is_file():
|
||||
return None
|
||||
return path, task.export_file_name or path.name
|
||||
return path, artifact.file_name or path.name
|
||||
|
||||
|
||||
def task_export_error_message(task: ShippingTask | None) -> str:
|
||||
"""导出下载失败时的错误文案(与 Tool / Workspace API 保持一致)。"""
|
||||
if not task or not task.export_file_path:
|
||||
if not task or task.id is None or not task.export_file_path:
|
||||
return "export file not found"
|
||||
path = Path(task.export_file_path)
|
||||
if not path.is_file():
|
||||
resolved = resolve_task_export_download(task)
|
||||
if resolved is None:
|
||||
return "export file missing on disk"
|
||||
return ""
|
||||
|
||||
@@ -536,7 +544,6 @@ def serialize_task(task: ShippingTask, projection: TaskProjection) -> dict[str,
|
||||
"warehouse_hint": task.warehouse_hint,
|
||||
"inventory_source_code": task.inventory_source_code,
|
||||
"inventory_connector_type": task.inventory_connector_type,
|
||||
"inventory_site_id": task.inventory_site_id,
|
||||
"inventory_warehouse_id": task.inventory_warehouse_id,
|
||||
"inventory_source_status": task.inventory_source_status,
|
||||
"inventory_source_method": task.inventory_source_method,
|
||||
@@ -727,7 +734,7 @@ def list_tasks_for_user(
|
||||
process_status: str | None = None,
|
||||
limit: int = 100,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""列出用户可见任务摘要,可按 batch_no / process_status 过滤。"""
|
||||
"""列出用户可见任务摘要,可按批次或工作台用户态状态过滤。"""
|
||||
q = ShippingTask.query.filter(
|
||||
(ShippingTask.user_id == user_id) | (ShippingTask.user_id.is_(None))
|
||||
)
|
||||
@@ -737,7 +744,13 @@ def list_tasks_for_user(
|
||||
return []
|
||||
q = q.filter(ShippingTask.batch_id == batch.id)
|
||||
if process_status:
|
||||
q = q.filter(ShippingTask.process_status == process_status)
|
||||
if process_status == "shortage_review":
|
||||
q = q.filter(
|
||||
(ShippingTask.review_status == "shortage_review")
|
||||
| (ShippingTask.pending_human_reason.in_(("shortage", "shortage_review")))
|
||||
)
|
||||
else:
|
||||
q = q.filter(ShippingTask.process_status == process_status)
|
||||
rows = q.order_by(desc(ShippingTask.created_at)).limit(max(1, min(limit, 500))).all()
|
||||
return [serialize_task_summary(c) for c in rows]
|
||||
|
||||
|
||||
Reference in new issue
Block a user