feat(shipping-notice): 新增临时库存管理功能,支持创建会话、获取分析结果及字段映射建议
This commit is contained in:
1 parent
46eb63f5bb
commit
e9bdd81f1a
320 files changed
+28361
-10487
No files matched your search
@@ -9,7 +9,6 @@ services/shipping_notice/rpa.py
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
@@ -35,7 +34,7 @@ def rpa_runtime_mode(runtime: dict[str, Any] | None = None) -> dict[str, str | b
|
||||
mode = str(runtime.get("mode") or runtime.get("rpa_mode") or "").strip().lower()
|
||||
if mode in {"browser", "mock"}:
|
||||
return _runtime_summary(mode)
|
||||
raw = str(os.getenv("FREIGHT_RPA_MOCK", current_app.config.get("FREIGHT_RPA_MOCK", "false")) or "false").strip().lower()
|
||||
raw = str(current_app.config.get("SHIPPING_NOTICE_RPA_WORKER_MOCK", "false") or "false").strip().lower()
|
||||
return _runtime_summary("mock" if raw in {"1", "true", "yes", "on"} else "browser")
|
||||
|
||||
|
||||
@@ -47,8 +46,8 @@ def _path(key: str) -> Path | None:
|
||||
|
||||
|
||||
def inventory_drop_dir() -> Path | None:
|
||||
"""RPA 库存 Excel 落盘目录(FREIGHT_INVENTORY_DROP_DIR)。"""
|
||||
return _path("FREIGHT_INVENTORY_DROP_DIR")
|
||||
"""RPA 库存 Excel 落盘目录(SHIPPING_NOTICE_RPA_SHARED_INVENTORY_DROP_DIR)。"""
|
||||
return _path("SHIPPING_NOTICE_RPA_SHARED_INVENTORY_DROP_DIR")
|
||||
|
||||
|
||||
def inventory_processed_dir() -> Path | None:
|
||||
@@ -61,17 +60,17 @@ def inventory_processed_dir() -> Path | None:
|
||||
|
||||
def inventory_trigger_dir() -> Path | None:
|
||||
"""RPA 库存导出触发 JSON 目录。"""
|
||||
return _path("FREIGHT_RPA_INVENTORY_TRIGGER_DIR")
|
||||
return _path("SHIPPING_NOTICE_RPA_SHARED_INVENTORY_TRIGGER_DIR")
|
||||
|
||||
|
||||
def upload_queue_dir() -> Path | None:
|
||||
"""货代上传 Excel 队列目录(RPA 从此处读取待上传文件)。"""
|
||||
return _path("FREIGHT_UPLOAD_QUEUE_DIR")
|
||||
return _path("SHIPPING_NOTICE_RPA_SHARED_UPLOAD_QUEUE_DIR")
|
||||
|
||||
|
||||
def upload_trigger_dir() -> Path | None:
|
||||
"""RPA 货代上传触发 JSON 目录。"""
|
||||
return _path("FREIGHT_RPA_UPLOAD_TRIGGER_DIR")
|
||||
return _path("SHIPPING_NOTICE_RPA_SHARED_UPLOAD_TRIGGER_DIR")
|
||||
|
||||
|
||||
def write_inventory_export_trigger(task_no: str, payload: dict[str, Any] | None = None) -> str | None:
|
||||
@@ -129,15 +128,27 @@ def write_inventory_export_batch_trigger(
|
||||
for source in sources:
|
||||
if not isinstance(source, dict) or not source.get("source_code"):
|
||||
continue
|
||||
# 调用方只持有非敏感快照;写 trigger 前在服务端按 Source 补入 Profile 密文。
|
||||
from app.services.shipping_notice.inventory_source_repository import get_rpa_trigger_inventory_source
|
||||
configuration_test = str((payload or {}).get('trigger_type') or '') == 'configuration_test'
|
||||
trigger_source = get_rpa_trigger_inventory_source(
|
||||
str(source["source_code"]), enabled_only=not configuration_test,
|
||||
) or source
|
||||
source = {**source, **trigger_source}
|
||||
business_connector = str(source.get("connector_type") or "").strip().lower()
|
||||
worker_connector = {"dbs": "dsv360", "crane": "crane_footprint"}.get(business_connector, business_connector)
|
||||
inventory_sources.append({
|
||||
"source_code": source.get("source_code"),
|
||||
"connector_type": source.get("connector_type"),
|
||||
"site_id": source.get("site_id"),
|
||||
"warehouse_id": source.get("warehouse_id"),
|
||||
"entry_url": source.get("entry_url"),
|
||||
"connector_type": business_connector,
|
||||
"worker_connector_type": worker_connector,
|
||||
"rpa_profile_code": source.get("rpa_profile_code"),
|
||||
"warehouse_id": source.get("fixed_warehouse_id") or source.get("warehouse_id"),
|
||||
"login_url": source.get("login_url"),
|
||||
"entry_url": source.get("login_url"),
|
||||
"navigation": source.get("navigation") or {},
|
||||
"parameters": source.get("parameters") or [],
|
||||
"query": source.get("query") or {},
|
||||
"credential_envelope": source.get("credential_envelope") or {},
|
||||
})
|
||||
if not inventory_sources:
|
||||
return None
|
||||
@@ -176,6 +187,16 @@ def write_inventory_export_trigger_for_task(
|
||||
|
||||
核心逻辑:batch 模式写 inventory_export_batch(含 task_no);否则写 legacy inventory_export。
|
||||
"""
|
||||
from app.services.shipping_notice.inventory_source_repository import get_rpa_trigger_inventory_source
|
||||
|
||||
source_code = str(rpa_source.get('source_code') or '').strip()
|
||||
rpa_source = get_rpa_trigger_inventory_source(source_code) or rpa_source
|
||||
# Legacy 单票 trigger 与 batch trigger 必须共享 worker 输入契约。
|
||||
rpa_source = dict(rpa_source)
|
||||
business_connector = str(rpa_source.get('connector_type') or '').strip().lower()
|
||||
rpa_source.setdefault('worker_connector_type', {'dbs': 'dsv360', 'crane': 'crane_footprint'}.get(business_connector, business_connector))
|
||||
rpa_source.setdefault('entry_url', rpa_source.get('login_url'))
|
||||
rpa_source.setdefault('credential_envelope', {})
|
||||
body = dict(payload or {})
|
||||
if inventory_rpa_batch_enabled():
|
||||
run_no = f"TASK-{task_no}-{datetime.utcnow().strftime('%Y%m%d%H%M%S%f')}"
|
||||
|
||||
Reference in new issue
Block a user