feat(shipping-notice): 新增货代客户管理功能,支持客户导入、识别证据管理与客户确认
This commit is contained in:
1 parent
b595e157e9
commit
4fbaed2b4c
176 files changed
+14011
-994
No files matched your search
@@ -6,7 +6,7 @@ Hxops 与货代系统之间通过 **目录 + JSON 触发文件** 解耦,RPA
|
||||
|
||||
| 文件 | 职责 |
|
||||
|------|------|
|
||||
| `freight_rpa_worker.py` | 轮询 trigger、打开浏览器、按 `source_type` 分发、HTTP 回调(~900 行) |
|
||||
| `freight_rpa_worker.py` | 轮询 trigger、打开浏览器、按 `connector_type` 分发、HTTP 回调(~900 行) |
|
||||
| `rpa_common.py` | 环境变量、通用 Playwright 点击/填充工具 |
|
||||
| `dsv_driver.py` | DSV 对外入口:`download_dsv360_inventory` |
|
||||
| `dsv_auth.py` | DSV PingID 分步登录(表单/探测辅助) |
|
||||
@@ -102,9 +102,9 @@ backend\venv\Scripts\python.exe scripts\rpa\crane_login_smoke.py
|
||||
|
||||
若页面出现 MFA、验证码或 SSO 二次确认,worker 会失败并回调错误,需要人工处理后重试。
|
||||
|
||||
库存 trigger 需要包含 `rpa_inventory_source`,worker 会按 `source_type` 分发:
|
||||
库存 trigger 需要包含 `rpa_inventory_source`,worker 会按 `connector_type` 分发:
|
||||
|
||||
| source_type | Driver |
|
||||
| connector_type | Driver |
|
||||
|-------------|--------|
|
||||
| `dsv360` | 打开 DSV 360,进入 Reports / Program / Inventory 报表并下载 |
|
||||
| `crane_footprint` | 打开 On Hand Details Query → Run Report → Schedule Report → Scheduled Reports 下载 |
|
||||
@@ -118,11 +118,11 @@ backend\venv\Scripts\python.exe scripts\rpa\crane_login_smoke.py
|
||||
"action": "inventory_export_batch",
|
||||
"run_no": "RUN20260707030000",
|
||||
"trigger_type": "scheduled",
|
||||
"inventory_sources": [{ "source_code": "DSV360_AWSBI_BYAWSATL01", "source_type": "dsv360", "site_id": "AWSBI", "warehouse_id": "BYAWSATL01" }]
|
||||
"inventory_sources": [{ "source_code": "DSV360_AWSBI_BYAWSATL01", "connector_type": "dsv360", "site_id": "AWSBI", "warehouse_id": "BYAWSATL01" }]
|
||||
}
|
||||
```
|
||||
|
||||
Worker 按 `source_type` 分组:**DSV 一次登录**循环各 Warehouse,DSV source 必须包含 `site_id`(如 `AWSBI` / `AWSDBU`),部分站点还需要具体 `warehouse_id`;**Crane 一次登录**循环导出,Crane 不要求 `site_id` 或 `warehouse_id`。无 `site_id` 时,后端会从实际库存 Excel 的 Warehouse ID 列提取发货 Excel 要写入的 Warehouse ID。完成后回调 `POST /api/shipping-notice/rpa/inventory-batch-ready`。
|
||||
Worker 按 `connector_type` 分组:**DSV 一次登录**循环各 Warehouse,DSV source 必须包含 `site_id`(如 `AWSBI` / `AWSDBU`),部分站点还需要具体 `warehouse_id`;**Crane 一次登录**循环导出,Crane 不要求 `site_id` 或 `warehouse_id`。无 `site_id` 时,后端会从实际库存 Excel 的 Warehouse ID 列提取发货 Excel 要写入的 Warehouse ID。完成后回调 `POST /api/shipping-notice/rpa/inventory-batch-ready`。
|
||||
|
||||
库存源定义见 `backend/config/shipping_inventory_sources.yaml`(新增 Warehouse 只改 YAML)。
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ def _build_source_from_config(source_code: str = "CRANE") -> dict:
|
||||
|
||||
return {
|
||||
"source_code": str(raw.get("source_code") or source_code).upper(),
|
||||
"source_type": str(raw.get("source_type") or "crane_footprint").strip().lower(),
|
||||
"connector_type": str(raw.get("connector_type") or "crane_footprint").strip().lower(),
|
||||
"display_name": str(raw.get("display_name") or source_code),
|
||||
"enabled": bool(raw.get("enabled", True)),
|
||||
"entry_url": str(raw.get("entry_url") or "https://wms-portal.craneww.com/#/on-hand-details-query"),
|
||||
|
||||
@@ -3,7 +3,7 @@ scripts/rpa/dsv_driver.py
|
||||
|
||||
用途:DSV 360 库存 RPA 对外编排入口(session → 导航 → 导出)。
|
||||
依赖:dsv_report_export。
|
||||
逻辑:freight_rpa_worker 在 source_type=dsv360 时仅调用本模块公开函数。
|
||||
逻辑:freight_rpa_worker 在 connector_type=dsv360 时仅调用本模块公开函数。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -52,11 +52,11 @@ def _build_source_from_config(source_code: str) -> dict:
|
||||
|
||||
navigation = dict(raw.get("navigation") or {})
|
||||
parameters = [dict(item) for item in (raw.get("parameters") or []) if isinstance(item, dict)]
|
||||
source_type = str(raw.get("source_type") or "dsv360").strip().lower()
|
||||
connector_type = str(raw.get("connector_type") or "dsv360").strip().lower()
|
||||
warehouse_id = str(raw.get("warehouse_id") or "").strip()
|
||||
|
||||
query: dict[str, object] = {}
|
||||
if source_type == "dsv360":
|
||||
if connector_type == "dsv360":
|
||||
for key in ("program_group", "program_label", "report_group", "report_name"):
|
||||
if navigation.get(key):
|
||||
query[key] = navigation[key]
|
||||
@@ -88,7 +88,7 @@ def _build_source_from_config(source_code: str) -> dict:
|
||||
|
||||
return {
|
||||
"source_code": str(raw.get("source_code") or source_code).upper(),
|
||||
"source_type": source_type,
|
||||
"connector_type": connector_type,
|
||||
"site_id": str(raw.get("site_id") or "").strip().upper(),
|
||||
"display_name": str(raw.get("display_name") or source_code),
|
||||
"enabled": bool(raw.get("enabled", True)),
|
||||
|
||||
@@ -3,7 +3,7 @@ scripts/rpa/dsv_report_export.py
|
||||
|
||||
用途:DSV 360 填参、View Report、Excel 导出与 batch 编排。
|
||||
依赖:rpa_common、dsv_debug、dsv_navigation、dsv_session、dsv_report_parameters。
|
||||
逻辑:worker source_type=dsv360 时委托本模块。
|
||||
逻辑:worker connector_type=dsv360 时委托本模块。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Freight RPA worker (PoC).
|
||||
|
||||
轮询 trigger JSON → 按 source_type 调用 DSV/Crane driver → 回调 hxops Tool API。
|
||||
轮询 trigger JSON → 按 connector_type 调用 DSV/Crane driver → 回调 hxops Tool API。
|
||||
DSV 逻辑见 dsv_driver / dsv_session / dsv_navigation / dsv_report_export;Crane 见 crane_*。
|
||||
|
||||
Usage:
|
||||
@@ -570,14 +570,16 @@ def _save_batch_download(download: Any, drop_dir: Path, run_no: str, source: dic
|
||||
def _validate_inventory_source_for_rpa(source: dict[str, Any]) -> None:
|
||||
"""
|
||||
校验单个库存 RPA source 的最小定位条件。
|
||||
核心逻辑:DSV 必须有 site_id;Crane 只需要 source_type 即可分发,warehouse id 由库存 Excel 结果决定。
|
||||
核心逻辑:DSV 必须有 site_id;Crane 只需要 connector_type 即可分发,warehouse id 由库存 Excel 结果决定。
|
||||
"""
|
||||
source_type = str(source.get("source_type") or "").strip()
|
||||
connector_type = str(source.get("connector_type") or "").strip()
|
||||
source_code = str(source.get("source_code") or "").strip() or "UNKNOWN"
|
||||
site_id = str(source.get("site_id") or "").strip()
|
||||
if source_type not in {"dsv360", "crane_footprint"}:
|
||||
raise RuntimeError(f"{source_code}: source_type must be dsv360 or crane_footprint")
|
||||
if source_type == "dsv360" and not site_id:
|
||||
if connector_type not in {"dsv360", "crane_footprint"}:
|
||||
raise RuntimeError(
|
||||
f"{source_code}: connector_type must be dsv360 or crane_footprint"
|
||||
)
|
||||
if connector_type == "dsv360" and not site_id:
|
||||
raise RuntimeError(f"{source_code}: site_id is required for dsv360")
|
||||
|
||||
|
||||
@@ -752,8 +754,8 @@ def _download_inventory_with_browser(trigger: dict[str, Any], drop_dir: Path) ->
|
||||
source = trigger.get("rpa_inventory_source")
|
||||
if not isinstance(source, dict):
|
||||
raise RuntimeError("inventory trigger missing rpa_inventory_source")
|
||||
source_type = str(source.get("source_type") or "").strip()
|
||||
source_code = str(source.get("source_code") or "").strip() or source_type or "UNKNOWN"
|
||||
connector_type = str(source.get("connector_type") or "").strip()
|
||||
source_code = str(source.get("source_code") or "").strip() or connector_type or "UNKNOWN"
|
||||
_validate_inventory_source_for_rpa(source)
|
||||
|
||||
playwright = context = runtime_profile_dir = None
|
||||
@@ -761,12 +763,12 @@ def _download_inventory_with_browser(trigger: dict[str, Any], drop_dir: Path) ->
|
||||
failed = False
|
||||
try:
|
||||
playwright, context, page, runtime_profile_dir = _open_browser(drop_dir)
|
||||
if source_type == "dsv360":
|
||||
if connector_type == "dsv360":
|
||||
download = _download_dsv360_inventory(page, trigger, source)
|
||||
elif source_type == "crane_footprint":
|
||||
elif connector_type == "crane_footprint":
|
||||
download = _download_crane_inventory(page, trigger, source)
|
||||
else:
|
||||
raise RuntimeError(f"unsupported inventory source_type: {source_type}")
|
||||
raise RuntimeError(f"unsupported inventory connector_type: {connector_type}")
|
||||
return _save_download(download, drop_dir, task_no, source_code)
|
||||
except Exception:
|
||||
failed = True
|
||||
@@ -879,7 +881,7 @@ def _handle_inventory_batch_trigger(trigger_path: Path, drop_dir: Path, processe
|
||||
for source in sources:
|
||||
if not isinstance(source, dict):
|
||||
continue
|
||||
site = str(source.get("source_type") or "").strip()
|
||||
site = str(source.get("connector_type") or "").strip()
|
||||
grouped.setdefault(site, []).append(source)
|
||||
|
||||
for site, site_sources in grouped.items():
|
||||
@@ -899,8 +901,8 @@ def _handle_inventory_batch_trigger(trigger_path: Path, drop_dir: Path, processe
|
||||
"warehouse_id": source.get("warehouse_id"),
|
||||
"status": "failed",
|
||||
"success": False,
|
||||
"error_code": "unsupported_source_type",
|
||||
"error_message": f"unsupported source_type: {site}",
|
||||
"error_code": "unsupported_connector_type",
|
||||
"error_message": f"unsupported connector_type: {site}",
|
||||
})
|
||||
continue
|
||||
|
||||
|
||||
@@ -70,10 +70,10 @@ def _build_query_from_yaml(raw: dict[str, Any]) -> dict[str, Any]:
|
||||
"""复用 dsv_export_smoke 口径,从 YAML 构造 worker 兼容 query。"""
|
||||
navigation = dict(raw.get("navigation") or {})
|
||||
parameters = [dict(item) for item in (raw.get("parameters") or []) if isinstance(item, dict)]
|
||||
source_type = str(raw.get("source_type") or "dsv360").strip().lower()
|
||||
connector_type = str(raw.get("connector_type") or "dsv360").strip().lower()
|
||||
warehouse_id = str(raw.get("warehouse_id") or "").strip()
|
||||
query: dict[str, Any] = {}
|
||||
if source_type == "dsv360":
|
||||
if connector_type == "dsv360":
|
||||
for key in ("program_group", "program_label", "report_group", "report_name"):
|
||||
if navigation.get(key):
|
||||
query[key] = navigation[key]
|
||||
@@ -113,7 +113,7 @@ def _build_rpa_source_from_yaml(source_code: str) -> dict[str, Any] | None:
|
||||
parameters = [dict(item) for item in (raw.get("parameters") or []) if isinstance(item, dict)]
|
||||
return {
|
||||
"source_code": str(raw.get("source_code") or source_code).upper(),
|
||||
"source_type": str(raw.get("source_type") or "dsv360").strip().lower(),
|
||||
"connector_type": str(raw.get("connector_type") or "dsv360").strip().lower(),
|
||||
"site_id": str(raw.get("site_id") or "").strip().upper() or None,
|
||||
"warehouse_id": str(raw.get("warehouse_id") or "").strip(),
|
||||
"entry_url": str(raw.get("entry_url") or ""),
|
||||
|
||||
Reference in new issue
Block a user