feat(shipping-notice): 新增库存快照管理与RPA批量导出功能
This commit is contained in:
1 parent
fc694a8f43
commit
d54f51ddc3
48 files changed
+4970
-543
No files matched your search
@@ -96,6 +96,100 @@ def write_inventory_export_trigger(task_no: str, payload: dict[str, Any] | None
|
||||
return str(path)
|
||||
|
||||
|
||||
def write_inventory_export_batch_trigger(
|
||||
run_no: str,
|
||||
sources: list[dict[str, Any]],
|
||||
*,
|
||||
payload: dict[str, Any] | None = None,
|
||||
) -> str | None:
|
||||
"""
|
||||
写入批量库存导出 trigger(DSV/Crane 一次登录多 Warehouse)。
|
||||
【AI 触发时机】:定时排程或后台批量预热库存快照时调用。
|
||||
|
||||
Args:
|
||||
run_no: RPA 批次号,写入回调 audit。
|
||||
sources: build_rpa_inventory_source 构造的源列表。
|
||||
payload: 额外字段(trigger_type、schedule_run_id 等)。
|
||||
|
||||
Returns:
|
||||
str | None: 触发文件绝对路径。
|
||||
"""
|
||||
trigger_dir = inventory_trigger_dir()
|
||||
if not trigger_dir or not sources:
|
||||
return None
|
||||
trigger_dir.mkdir(parents=True, exist_ok=True)
|
||||
inventory_sources = []
|
||||
for source in sources:
|
||||
if not isinstance(source, dict) or not source.get("source_code"):
|
||||
continue
|
||||
inventory_sources.append({
|
||||
"source_code": source.get("source_code"),
|
||||
"source_type": source.get("source_type"),
|
||||
"warehouse_id": source.get("warehouse_id"),
|
||||
"warehouse_code": source.get("warehouse_code"),
|
||||
"entry_url": source.get("entry_url"),
|
||||
"navigation": source.get("navigation") or {},
|
||||
"parameters": source.get("parameters") or [],
|
||||
"query": source.get("query") or {},
|
||||
})
|
||||
if not inventory_sources:
|
||||
return None
|
||||
|
||||
body = {
|
||||
"action": "inventory_export_batch",
|
||||
"run_no": run_no,
|
||||
"trigger_type": "scheduled",
|
||||
"requested_at": datetime.utcnow().isoformat(),
|
||||
"inventory_sources": inventory_sources,
|
||||
**(payload or {}),
|
||||
}
|
||||
safe_run = "".join(ch for ch in run_no if ch.isalnum() or ch in {"-", "_"}) or "batch"
|
||||
path = trigger_dir / f"inventory_export_batch_{safe_run}.json"
|
||||
path.write_text(json.dumps(body, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
return str(path)
|
||||
|
||||
|
||||
def inventory_rpa_batch_enabled() -> bool:
|
||||
"""是否启用按需单票走 batch trigger 统一路径(Flask config 优先于环境变量)。"""
|
||||
raw = current_app.config.get("SHIPPING_NOTICE_INVENTORY_RPA_BATCH_ENABLED")
|
||||
if raw is None:
|
||||
raw = os.getenv("SHIPPING_NOTICE_INVENTORY_RPA_BATCH_ENABLED", "true")
|
||||
return str(raw).strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
def write_inventory_export_trigger_for_task(
|
||||
task_no: str,
|
||||
rpa_source: dict[str, Any],
|
||||
*,
|
||||
payload: dict[str, Any] | None = None,
|
||||
) -> str | None:
|
||||
"""
|
||||
写入按需库存 RPA trigger;batch 开启时包装为单源 batch trigger,与定时导出共用 worker 路径。
|
||||
【AI 触发时机】:ensure_inventory_via_rpa 触发单票 RPA 导出时调用。
|
||||
|
||||
核心逻辑:batch 模式写 inventory_export_batch(含 task_no);否则写 legacy inventory_export。
|
||||
"""
|
||||
body = dict(payload or {})
|
||||
if inventory_rpa_batch_enabled():
|
||||
run_no = f"TASK-{task_no}-{datetime.utcnow().strftime('%Y%m%d%H%M%S')}"
|
||||
return write_inventory_export_batch_trigger(
|
||||
run_no,
|
||||
[rpa_source],
|
||||
payload={
|
||||
"trigger_type": "on_demand",
|
||||
"task_no": task_no,
|
||||
**body,
|
||||
},
|
||||
)
|
||||
return write_inventory_export_trigger(
|
||||
task_no,
|
||||
{
|
||||
"rpa_inventory_source": rpa_source,
|
||||
**body,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def write_upload_trigger(task_no: str, export_file_path: str, payload: dict[str, Any] | None = None) -> tuple[str | None, str | None]:
|
||||
"""
|
||||
复制 Excel 至上传队列并写入 RPA 上传触发 JSON。
|
||||
|
||||
Reference in new issue
Block a user