feat(shipping-notice): 完善订单模板解析与库存 RPA 调度流程

- 新增行字段补充合并与订单模板匹配能力
- 优化运行时解析策略、签名校验及资料验证
- 完善库存 RPA 归档、收尾与 Worker 启动流程
- 补充前后端测试、多语言文案及功能文档
This commit is contained in:
hugo committed 2026-09-09 14:32:43 +08:00
1 parent 8f2f568f92
commit dabf140e41
45 files changed
+2007 -151

No files matched your search

+26 -7
View File
@@ -22,7 +22,8 @@ Optional:
SHIPPING_NOTICE_RPA_WORKER_SESSION_REUSE=true
# legacy alias: SHIPPING_NOTICE_RPA_WORKER_DSV_SESSION_REUSE
SHIPPING_NOTICE_RPA_WORKER_HEADLESS=false
SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL=msedge
# 默认不设 CHANNEL → Playwright 捆绑 Chromium;禁止默认 msedge(Edge 152 持久 Profile 下载崩溃)。
# SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL=msedge # 不推荐
SHIPPING_NOTICE_RPA_WORKER_BROWSER_EXECUTABLE_PATH=C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe
SHIPPING_NOTICE_RPA_WORKER_LOG_FILE=C:\\HxopsRpaTest\\data\\logs\\worker.log
SHIPPING_NOTICE_RPA_WORKER_LOG_MAX_BYTES=10485760
@@ -1475,6 +1476,18 @@ def _emit_batch_progress(body: dict[str, Any], run_no: str, results: list[dict[s
def _handle_inventory_batch_trigger(trigger_path: Path, drop_dir: Path, processed_dir: Path) -> None:
"""
消费 inventory_export_batch trigger:按 Profile 分组导出并回调后端。
核心逻辑:先按 trigger_type 做身份门禁——scheduled / configuration_test(_batch)
只校验信封字段;按需单票保持逐源 Attempt/Gate fail-closed。导出后按类型路由到
inventory-batch-ready 或 inventory-configuration-test(-batch)-ready。
Args:
trigger_path: 待处理的 batch trigger JSON 路径。
drop_dir: 下载落盘目录。
processed_dir: 成功处理后的 trigger 归档目录。
"""
body = json.loads(trigger_path.read_text(encoding="utf-8"))
run_no = str(body.get("batch_run_no") or body.get("run_no") or trigger_path.stem).strip()
task_no = str(body.get("task_no") or "").strip()
@@ -1491,17 +1504,23 @@ def _handle_inventory_batch_trigger(trigger_path: Path, drop_dir: Path, processe
identity_errors.append("schema_version")
if body.get("callback_id") is None or (isinstance(body.get("callback_id"), str) and not body.get("callback_id").strip()):
identity_errors.append("callback_id")
# 定时排程批量触发是按 run 计价的:只携带 run_no/schedule_run_id,没有逐源
# Attempt/Gate 身份。身份校验按模式取值:scheduled 只强制信封与站点分发字段,
# 业务终态由后端按 schedule_run_id + DB 配置校验;其余模式保持逐源身份 fail-closed。
is_scheduled_batch = str(body.get("trigger_type") or "").strip() == "scheduled"
# [STEP] 身份校验按 trigger_type 取值:
# - scheduled:按 run 计价,仅 run_no/schedule_run_id,无逐源 Attempt/Gate。
# - configuration_test / configuration_test_batch:管理端停用站点连通性验证,
# 不创建订单 Attempt/Gate,故意不写 task_no/source_run_no 等生产身份;
# 终态走 inventory-configuration-test(-batch)-ready,不得用生产身份 fail-closed。
# - 其余(按需单票/多源准备):保持逐源身份 fail-closed。
trigger_type = str(body.get("trigger_type") or "").strip()
is_run_scoped_batch = trigger_type in {
"scheduled", "configuration_test", "configuration_test_batch",
}
source_required = set(_INVENTORY_V2_REQUIRED_FIELDS) - {"schema_version", "task_no", "callback_id"}
if is_scheduled_batch:
if is_run_scoped_batch:
source_required -= {
"task_no", "source_run_no", "attempt_no", "lease_token", "candidate_set_id",
"execution_id", "gate_id", "callback_id", "expected_warehouse_id",
}
if not is_scheduled_batch and (
if not is_run_scoped_batch and (
body.get("task_no") is None or (isinstance(body.get("task_no"), str) and not body.get("task_no").strip())
):
identity_errors.append("task_no")
@@ -55,8 +55,7 @@ def main() -> int:
os.environ.setdefault("SHIPPING_NOTICE_RPA_WORKER_HEADLESS", "false")
os.environ.setdefault("SHIPPING_NOTICE_RPA_WORKER_KEEP_BROWSER_OPEN_ON_ERROR", "true")
os.environ.setdefault("SHIPPING_NOTICE_RPA_WORKER_BROWSER_PROFILE_DIR", "backend/data/shipping_notice/freight_rpa/browser_profile")
if not os.environ.get("SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL") and not os.environ.get("SHIPPING_NOTICE_RPA_WORKER_BROWSER_EXECUTABLE_PATH"):
os.environ.setdefault("SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL", "msedge")
# 不默认 msedge:Edge 152 + 持久 Profile 下载会原生崩溃;未设置 CHANNEL 时走 Playwright Chromium。
os.environ.setdefault("HXOPS_API_BASE", "http://127.0.0.1:5052")
if not os.environ.get("SHIPPING_NOTICE_TOOL_API_KEY"):
print("[batch-run] SHIPPING_NOTICE_TOOL_API_KEY is required")
@@ -84,7 +84,8 @@ $processVars = [ordered]@{
SHIPPING_NOTICE_RPA_WORKER_MOCK = $(if ($Mock) { "true" } else { "false" })
SHIPPING_NOTICE_RPA_WORKER_HEADLESS = $(if ($Headless) { "true" } else { "false" })
SHIPPING_NOTICE_RPA_WORKER_SESSION_REUSE = $sessionReuse
SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL = "msedge"
# 不设 BROWSER_CHANNEL:默认 Playwright 捆绑 Chromium。
# Edge 152 + 持久 Profile 下载会原生崩溃(TargetClosed / .crdownload),禁止默认 msedge。
SHIPPING_NOTICE_RPA_WORKER_POLL_SECONDS = "3"
SHIPPING_NOTICE_RPA_SHARED_INVENTORY_TRIGGER_DIR = Join-Path $dataRoot "inventory_triggers"
SHIPPING_NOTICE_RPA_SHARED_INVENTORY_DROP_DIR = Join-Path $dataRoot "inventory_drop"