feat(shipping-notice): 完善订单模板解析与库存 RPA 调度流程
- 新增行字段补充合并与订单模板匹配能力 - 优化运行时解析策略、签名校验及资料验证 - 完善库存 RPA 归档、收尾与 Worker 启动流程 - 补充前后端测试、多语言文案及功能文档
This commit is contained in:
1 parent
8f2f568f92
commit
dabf140e41
45 files changed
+2007
-151
No files matched your search
@@ -844,7 +844,10 @@ python -m pip install playwright openpyxl pyyaml
|
||||
python -m playwright install chromium
|
||||
```
|
||||
|
||||
若 Worker 复用项目完整依赖,也可执行 `python -m pip install -r <项目仓库>\backend\requirements.txt playwright`。使用本机 Edge 时设置 `SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL=msedge`。
|
||||
若 Worker 复用项目完整依赖,也可执行 `python -m pip install -r <项目仓库>\backend\requirements.txt playwright`。
|
||||
**默认使用 Playwright 捆绑 Chromium**(`python -m playwright install chromium`)。
|
||||
勿默认设置 `SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL=msedge`:Edge 152 + 持久 Profile
|
||||
在 Excel 下载时会原生崩溃(`Download.save_as: TargetClosed` / 残留 `.crdownload`)。
|
||||
|
||||
### 1.5 Windows RPA 临时变量、登录测试与心跳
|
||||
|
||||
@@ -859,7 +862,7 @@ $env:SHIPPING_NOTICE_TOOL_API_KEY = "请替换为测试环境Key"
|
||||
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_MOCK = "false"
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_HEADLESS = "false"
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL = "msedge"
|
||||
# 不设 BROWSER_CHANNEL → Playwright Chromium;勿设 msedge。
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_POLL_SECONDS = "3"
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_HEARTBEAT_SECONDS = "20"
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_ENVIRONMENT = "test"
|
||||
@@ -1095,7 +1098,9 @@ python -m pip install playwright
|
||||
python -m playwright install chromium
|
||||
```
|
||||
|
||||
如使用本机 Edge,可设置 `SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL=msedge`,无需让 Worker 下载 Chromium;仍建议保留 Playwright Python 包。
|
||||
**默认使用 Playwright 捆绑 Chromium**(上一步 `playwright install chromium`)。
|
||||
勿设置 `SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL=msedge`:Edge 152 + 持久 Profile
|
||||
下载会原生崩溃(`TargetClosed` / `.crdownload`)。
|
||||
|
||||
#### 3. 配置当前 PowerShell 会话并启动 Worker
|
||||
|
||||
@@ -1114,7 +1119,7 @@ $env:SHIPPING_NOTICE_RPA_CREDENTIAL_KEY = "<本地 RPA 凭据主密钥>"
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_ENVIRONMENT = "dev"
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_MOCK = "false"
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_HEADLESS = "false"
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL = "msedge"
|
||||
# 不设 BROWSER_CHANNEL → Playwright Chromium;勿设 msedge。
|
||||
$env:SHIPPING_NOTICE_RPA_WORKER_POLL_SECONDS = "3"
|
||||
|
||||
$env:SHIPPING_NOTICE_RPA_SHARED_INVENTORY_TRIGGER_DIR = Join-Path $rpaDataRoot "inventory_triggers"
|
||||
|
||||
@@ -37,8 +37,7 @@ def main() -> int:
|
||||
"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:未设置 CHANNEL 时走 Playwright 捆绑 Chromium(需先 playwright install chromium)。
|
||||
|
||||
worker = _load_worker()
|
||||
username = worker._env("SHIPPING_NOTICE_RPA_WORKER_CRANE_USERNAME")
|
||||
|
||||
@@ -37,9 +37,7 @@ def main() -> int:
|
||||
"SHIPPING_NOTICE_RPA_WORKER_BROWSER_PROFILE_DIR",
|
||||
"backend/data/shipping_notice/freight_rpa/browser_profile",
|
||||
)
|
||||
# Playwright 自带 Chromium 未安装时,回退到本机 Edge(Windows 开发机常见情况)。
|
||||
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:未设置 CHANNEL 时走 Playwright 捆绑 Chromium(需先 playwright install chromium)。
|
||||
|
||||
worker = _load_worker()
|
||||
username = worker._env("SHIPPING_NOTICE_RPA_WORKER_DSV_USERNAME")
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -40,7 +40,7 @@ $processVars = [ordered]@{
|
||||
SHIPPING_NOTICE_RPA_WORKER_ENVIRONMENT = $Environment
|
||||
SHIPPING_NOTICE_RPA_WORKER_MOCK = $(if ($Mock) { 'true' } else { 'false' })
|
||||
SHIPPING_NOTICE_RPA_WORKER_HEADLESS = $(if ($Headless) { 'true' } else { 'false' })
|
||||
SHIPPING_NOTICE_RPA_WORKER_BROWSER_CHANNEL = 'msedge'
|
||||
# 不设 BROWSER_CHANNEL:默认 Playwright 捆绑 Chromium(禁止默认 msedge,见库存 Worker 同因)。
|
||||
SHIPPING_NOTICE_RPA_WORKER_POLL_SECONDS = '3'
|
||||
SHIPPING_NOTICE_RPA_SHARED_RECEIPT_TRIGGER_DIR = Join-Path $dataRoot 'receipt_triggers'
|
||||
SHIPPING_NOTICE_RPA_SHARED_RECEIPT_DROP_DIR = Join-Path $dataRoot 'receipt_drop'
|
||||
|
||||
Reference in new issue
Block a user