fix(shipping-notice,admin-schedule,frontend): 修复发货通知与后台排程的业务bug并优化各模块功能

1.  后端发货通知模块:
    清空重试任务旧状态避免残留,新增RPA进度回调接口
    优化库存匹配性能,修复人工确认校验逻辑与登录弹窗遮挡问题
    新增排程worker启动脚本,清理冗余环境配置与缓存查询开销
2.  前端后台排程模块:
    新增任务key归一化工具兼容历史格式,修复参数表单隐藏问题
    添加加载错误处理,更新多语言文案替换裸JSON占位符
This commit is contained in:
hugo committed 2026-08-26 22:05:25 +08:00
1 parent 1e5aedb9ed
commit 06c18b3c7c
81 files changed
+3301 -424

No files matched your search

+96
View File
@@ -263,6 +263,65 @@ def test_batch_invalid_trigger_rejection_preserves_batch_callback_id(monkeypatch
assert callbacks[0][1]["identity_errors"] == ["inventory_sources[0].expected_warehouse_id"]
def test_batch_scheduled_trigger_skips_per_source_task_identity(monkeypatch, tmp_path):
"""定时排程 batch 按 run 计价:无逐源任务身份也应执行并按 run 回调,而非拒绝。"""
worker = _load_freight_rpa_worker()
trigger_dir = tmp_path / "triggers"
drop_dir = tmp_path / "drop"
processed_dir = trigger_dir / "processed"
failed_dir = trigger_dir / "failed"
trigger_dir.mkdir()
drop_dir.mkdir()
trigger_path = trigger_dir / "inventory_export_batch_scheduled.json"
# 与 run_shipping_inventory_rpa_schedule 写入的 trigger 形状一致:
# batch 级无 task_no,逐源无 task_no/source_run_no/lease_token/candidate_set_id/execution_id/gate_id。
trigger_path.write_text(json.dumps({
"action": "inventory_export_batch",
"schema_version": "shipping_inventory_rpa.v2",
"callback_id": "RUN-SCHEDULED:batch:C1",
"batch_run_no": "RUN-SCHEDULED",
"run_no": "RUN-SCHEDULED",
"trigger_type": "scheduled",
"schedule_run_id": 713,
"requested_at": "2026-08-26T04:47:05.323691",
"inventory_sources": [{
"source_code": "DSV360_AWSDU",
"connector_type": "dbs",
"worker_connector_type": "dsv360",
"warehouse_id": "AWSDU",
"login_url": "https://s360.dbschenker.com/",
"entry_url": "https://s360.dbschenker.com/",
"navigation": {},
"parameters": [],
"query": {},
"credential_envelope": {},
"validation_run_no": None,
}],
}), encoding="utf-8")
callbacks: list[tuple[str, dict]] = []
monkeypatch.setenv("SHIPPING_NOTICE_RPA_WORKER_MOCK", "true")
monkeypatch.setattr(worker, "_post_callback", lambda path, body: callbacks.append((path, body)))
worker._handle_inventory_batch_trigger(trigger_path, drop_dir, processed_dir)
completed = next(body for path, body in callbacks if path.endswith("/inventory-batch-ready"))
assert completed["schedule_run_id"] == 713
assert completed["trigger_type"] == "scheduled"
result = completed["results"][0]
assert result["source_code"] == "DSV360_AWSDU"
assert result["warehouse_id"] == "AWSDU"
assert result["status"] == "success"
# 每完成一个站点应回传一次累计进度,供后端实时回写排程 run 笔数。
progress = next(body for path, body in callbacks if path.endswith("/inventory-batch-progress"))
assert progress["schedule_run_id"] == 713
assert progress["batch_run_no"] == "RUN-SCHEDULED"
assert progress["success_count"] == 1
assert progress["skipped_count"] == 0
assert progress["failed_count"] == 0
assert (processed_dir / trigger_path.name).is_file()
assert not (failed_dir / trigger_path.name).exists()
def test_batch_interrupt_keeps_trigger_and_completes_best_effort_browser_cleanup(monkeypatch, tmp_path):
"""Ctrl+C 中断导出时不回调或移动 trigger,且清理异常不能阻止停止 Playwright。"""
worker = _load_freight_rpa_worker()
@@ -1766,6 +1825,43 @@ def test_fill_dsv_owner_filter_defaults_to_reportviewer_owner_input():
assert filled == {"#ReportViewerMain_ctl08_ctl03_txtValue": "CADU-0000000100"}
def test_fill_dsv_filter_if_needed_accepts_report_name_kwarg():
"""_fill_dsv_filter_if_needed 包装层必须透传 report_name(报表控件模板依赖)。"""
worker = _load_freight_rpa_worker()
filled: dict[str, str] = {}
class _FakeText:
first = None
def __init__(self) -> None:
self.first = self
def is_visible(self, timeout: int | None = None) -> bool:
return False
class _FakeFrame:
def evaluate(self, script: str, payload: dict[str, str], timeout: int | None = None) -> bool:
assert "disabled = false" in script
filled[payload["selector"]] = payload["value"]
return True
class _FakePage:
frames = [_FakeFrame()]
def get_by_text(self, text: str, exact: bool = False) -> _FakeText:
return _FakeText()
worker._fill_dsv_filter_if_needed(
_FakePage(),
"SHIPPING_NOTICE_RPA_WORKER_DSV_OWNER_SELECTOR",
"Owner",
"CADU-0000000100",
report_name="On Hand Inventory by Location",
)
assert filled == {"#ReportViewerMain_ctl08_ctl03_txtValue": "CADU-0000000100"}
def test_validate_inventory_excel_accepts_real_report_shape(tmp_path):
"""下载完成后必须能打开 Excel,并包含库存报表标题和关键表头。"""
worker = _load_freight_rpa_worker()