feat(in-transit-transfer): 落地证据流重解析并纳入货代与排程配套改动
外部单号进入异动档自然键,圈档按 T-2 成熟封顶,当前归档可单独重解析。同批带上 Crane 禁整页刷新、ODM 白名单降级、排程抽屉与执行记录日期窗,以及 YAML 库存源下线。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
911afa0f73
commit
4c2a7e2a23
145 files changed
+11695
-4214
No files matched your search
@@ -3,10 +3,10 @@ scripts/freight_rpa/dsv_report_parameters.py
|
||||
|
||||
用途:填充 DSV 360 SSRS ReportViewer 报表参数(Owner / PutawayZone / Warehouse)。
|
||||
依赖:Playwright Page/Frame;由 dsv_report_export.fill_report_parameters 委托调用。
|
||||
逻辑:识别 multi-value checkbox 与 ValidValue select,在 report iframe 内操作并等待控件启用;
|
||||
控件 ID 按报表名模板解析(含库存 3lv/JDA 与收料 Receipt Detail);
|
||||
同名报表可用 `报表名@program_label` 覆盖站点差异(如 Receipt Detail@AWSRTM → ctl29 multi_value);
|
||||
模板命中时整表替换默认控件,禁止默认 ctl17_ddValue 污染 multi_value 回退路径。
|
||||
逻辑:优先按 ParamLabelCell + label[for] / 行内控件形态现场派生(select 或 multi_value),
|
||||
ctlNN 禁止当主键;报表名模板仅作结构性解析失败时的回退;
|
||||
同名报表可用 `报表名@program_label` 覆盖站点差异(如 Receipt Detail@AWSRTM);
|
||||
Warehouse 禁止把过期 ctl*_txtValue 当文本兜底(会写进漂移后的 Project ID)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -79,6 +79,22 @@ _DSV_REPORT_PARAM_TEMPLATES: dict[str, dict[str, dict[str, str]]] = {
|
||||
"dropdown": "#ReportViewerMain_ctl08_ctl29_divDropDown",
|
||||
},
|
||||
},
|
||||
# Shipment Order Detail(AWS/Bison/AWSBI,2026-10-19 实机):Owner、Warehouse 均为
|
||||
# readonly txtValue + 下拉,不是库存默认 select。ctl 会漂移,填参时结构性解析优先,本表只作回退。
|
||||
"shipment order detail": {
|
||||
"Owner": {
|
||||
"control": "multi_value",
|
||||
"text": "#ReportViewerMain_ctl08_ctl15_txtValue",
|
||||
"toggle": "#ReportViewerMain_ctl08_ctl15_ctl01",
|
||||
"dropdown": "#ReportViewerMain_ctl08_ctl15_divDropDown",
|
||||
},
|
||||
"Warehouse": {
|
||||
"control": "multi_value",
|
||||
"text": "#ReportViewerMain_ctl08_ctl31_txtValue",
|
||||
"toggle": "#ReportViewerMain_ctl08_ctl31_ctl01",
|
||||
"dropdown": "#ReportViewerMain_ctl08_ctl31_divDropDown",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -115,8 +131,10 @@ def resolve_parameter_controls(
|
||||
|
||||
|
||||
# 结构性解析脚本:在 SSRS 参数网格(ParametersGrid)中按 ParamLabelCell 标签定位参数行,
|
||||
# 从行内 _txtValue 的 id 基座派生 multi_value 三件套(_txtValue/_ctl01/_divDropDown)。
|
||||
# 再按 label[for] / 行内真实控件形态派生选择器(select 或 multi_value)。
|
||||
# 控件位(ctlNN)是随报表实例变化的实现细节,禁止在代码/配置中写死——一律由此派生。
|
||||
# [2026-10-20] Cincinnati CVG611:Warehouse=label[for]=ctl19_ddValue(原生 select),
|
||||
# 旧模板写死 ctl17_txtValue 已漂移为 Project ID,必须靠 for/行内 select 现场映射。
|
||||
_STRUCTURAL_CONTROLS_JS = """(label) => {
|
||||
const wanted = String(label || "").trim().toLowerCase();
|
||||
const rows = Array.from(document.querySelectorAll(
|
||||
@@ -126,35 +144,63 @@ _STRUCTURAL_CONTROLS_JS = """(label) => {
|
||||
if (!cell) continue;
|
||||
const text = (cell.innerText || cell.textContent || "").trim().toLowerCase();
|
||||
if (text !== wanted) continue;
|
||||
|
||||
// [STEP 1] label[for] → 真实控件(截图:Warehouse for=..._ctl19_ddValue)
|
||||
const labelEl = cell.querySelector("label[for]");
|
||||
const forId = labelEl && labelEl.getAttribute("for");
|
||||
if (forId) {
|
||||
const target = document.getElementById(forId);
|
||||
if (target) {
|
||||
const tag = String(target.tagName || "").toLowerCase();
|
||||
if (tag === "select" || forId.endsWith("_ddValue")) {
|
||||
return { control: "select", selector: "#" + forId };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [STEP 2] 行内 ParamEntryCell 的原生 select(无 for 或 for 指向其它节点时)
|
||||
const entry = row.querySelector(".ParamEntryCell") || row;
|
||||
const select = entry.querySelector("select[id$='_ddValue'], select[id]");
|
||||
if (select && select.id) {
|
||||
return { control: "select", selector: "#" + select.id };
|
||||
}
|
||||
|
||||
// [STEP 3] multi_value:行内 _txtValue + _ctl01 + _divDropDown 三件套
|
||||
const txt = row.querySelector("[id$='_txtValue']");
|
||||
if (!txt || !txt.id) continue;
|
||||
const base = txt.id.replace(/_txtValue$/, "");
|
||||
const toggle = document.getElementById(base + "_ctl01");
|
||||
const dropdown = document.getElementById(base + "_divDropDown");
|
||||
if (!toggle || !dropdown) return null;
|
||||
return { text: "#" + base + "_txtValue", toggle: "#" + base + "_ctl01", dropdown: "#" + base + "_divDropDown" };
|
||||
if (toggle && dropdown) {
|
||||
return {
|
||||
control: "multi_value",
|
||||
text: "#" + base + "_txtValue",
|
||||
toggle: "#" + base + "_ctl01",
|
||||
dropdown: "#" + base + "_divDropDown",
|
||||
};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}"""
|
||||
|
||||
|
||||
def resolve_parameter_controls_structural(page: Any, label: str) -> dict[str, str] | None:
|
||||
"""按参数标签在 SSRS 参数网格中结构性解析 multi_value 控件三件套(免硬编码/免发版)。
|
||||
"""按参数标签在 SSRS 参数网格中结构性解析控件(select 或 multi_value,免硬编码 ctl)。
|
||||
|
||||
【AI 触发时机】:报表/站点的控件位未登记注册表模板时调用(如 Owner@Receipt
|
||||
Detail@AWSRTM);SSRS 参数行自带 ParamLabelCell 标签与 _txtValue/_ctl01/_divDropDown
|
||||
控件族,按标签定位行即可派生控件位,适配任意站点/报表,无需为每个站点改代码。
|
||||
【AI 触发时机】:填 Owner / Warehouse / PutawayZone 时优先调用;SSRS 参数行自带
|
||||
ParamLabelCell、label[for]、可选 data-parametername,按标签定位后映射真实控件,
|
||||
适配 ctl 编号漂移(如 Warehouse 从 ctl17 漂到 ctl19,旧 ctl17 变成 Project ID)。
|
||||
|
||||
核心逻辑:逐 frame 在 ParametersGrid 中找标签匹配的参数行 → 行内 _txtValue 的 id
|
||||
基座 → 校验 _ctl01/_divDropDown 存在 → 返回三件套;任一 frame 命中即返回,
|
||||
全部未命中(或命中但非 multi_value 形态)返回 None,由调用方回退默认/通用路径。
|
||||
核心逻辑:逐 frame 在 ParametersGrid 找标签匹配行 → 优先 label[for]/行内 select
|
||||
判为 select → 否则校验 multi_value 三件套 → 任一 frame 命中即返回;
|
||||
全部未命中返回 None,由调用方回退报表模板。
|
||||
|
||||
Args:
|
||||
page: Playwright Page(跨主文档与全部 frame 探测)。
|
||||
label: 参数名(与页面 ParamLabelCell 展示文本一致,如 Owner)。
|
||||
label: 参数名(与页面 ParamLabelCell 展示文本一致,如 Warehouse)。
|
||||
|
||||
Returns:
|
||||
dict[str, str]: {text, toggle, dropdown} 三件套选择器;未命中为 None。
|
||||
dict[str, str]: 含 control=select|multi_value 及对应选择器;未命中为 None。
|
||||
"""
|
||||
wanted = str(label or "").strip()
|
||||
if not wanted or page is None:
|
||||
@@ -164,11 +210,71 @@ def resolve_parameter_controls_structural(page: Any, label: str) -> dict[str, st
|
||||
found = frame.evaluate(_STRUCTURAL_CONTROLS_JS, wanted)
|
||||
except Exception:
|
||||
continue # 跨域/已销毁帧等探测失败:换下一 frame
|
||||
if isinstance(found, dict) and found.get("text"):
|
||||
return {key: str(found[key]) for key in ("text", "toggle", "dropdown")}
|
||||
if not isinstance(found, dict):
|
||||
continue
|
||||
control = str(found.get("control") or "").strip()
|
||||
if control == "select" and found.get("selector"):
|
||||
return {"control": "select", "selector": str(found["selector"])}
|
||||
if control == "multi_value" and found.get("text"):
|
||||
return {
|
||||
"control": "multi_value",
|
||||
"text": str(found["text"]),
|
||||
"toggle": str(found.get("toggle") or ""),
|
||||
"dropdown": str(found.get("dropdown") or ""),
|
||||
}
|
||||
# 兼容旧脚本只返回三件套、无 control 字段的探测结果
|
||||
if found.get("text") and found.get("toggle") and found.get("dropdown"):
|
||||
return {
|
||||
"control": "multi_value",
|
||||
"text": str(found["text"]),
|
||||
"toggle": str(found["toggle"]),
|
||||
"dropdown": str(found["dropdown"]),
|
||||
}
|
||||
return None
|
||||
|
||||
|
||||
def _apply_structural_parameter_fill(
|
||||
page: Any,
|
||||
label: str,
|
||||
text: str,
|
||||
values: list[str],
|
||||
*,
|
||||
timeout_ms: int,
|
||||
structural: dict[str, str],
|
||||
) -> bool:
|
||||
"""按结构性解析结果填充参数:select 走 ddValue,multi_value 走 checkbox 下拉。
|
||||
|
||||
Args:
|
||||
page: Playwright Page。
|
||||
label: 参数名。
|
||||
text: 原始填充文本(select 用)。
|
||||
values: 拆分后的目标值列表(multi_value 用)。
|
||||
timeout_ms: 操作超时。
|
||||
structural: resolve_parameter_controls_structural 的返回值。
|
||||
|
||||
Returns:
|
||||
bool: 是否填充成功。
|
||||
"""
|
||||
control = str(structural.get("control") or "").strip()
|
||||
if control == "select":
|
||||
selector = str(structural.get("selector") or "").strip()
|
||||
return bool(
|
||||
selector
|
||||
and _fill_select_parameter(page, label, text, selector, timeout_ms=timeout_ms)
|
||||
)
|
||||
if control == "multi_value" or all(structural.get(k) for k in ("text", "toggle", "dropdown")):
|
||||
return _fill_multi_value_parameter(
|
||||
page,
|
||||
label,
|
||||
values,
|
||||
timeout_ms=timeout_ms,
|
||||
config_override={"control": "multi_value", **{
|
||||
k: structural[k] for k in ("text", "toggle", "dropdown") if structural.get(k)
|
||||
}},
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
def _iter_dsv_report_roots(page: Any) -> list[Any]:
|
||||
"""返回包含 ReportViewerMain 的 frame;找不到时回退到全部 roots。"""
|
||||
matched: list[Any] = []
|
||||
@@ -630,9 +736,9 @@ def fill_dsv_filter_if_needed(
|
||||
"""
|
||||
按 ReportViewer 控件类型填充 DSV 报表参数。
|
||||
|
||||
核心逻辑:报表模板(report_name + program_label)命中时整表替换默认控件;
|
||||
multi_value(如 Receipt Detail@AWSRTM Warehouse=ctl29)优先勾选 checkbox,
|
||||
失败时只回退同模板 txtValue,禁止残留默认 ctl17_ddValue 误走库存 select。
|
||||
核心逻辑:Owner/Warehouse/PutawayZone 先按 ParamLabelCell + label[for] 现场派生
|
||||
(select 或 multi_value);失败再回退报表模板。Warehouse 禁止用写死 ctl*_txtValue
|
||||
做文本兜底——ctl 漂移后会写进 Project ID(2026-10-20 Cincinnati CVG611)。
|
||||
|
||||
Returns:
|
||||
bool: True 表示已填充或合法跳过(值为空/未配置控件);False 表示配置了值
|
||||
@@ -660,7 +766,17 @@ def fill_dsv_filter_if_needed(
|
||||
pass
|
||||
|
||||
timeout_ms = browser_timeout_ms()
|
||||
# 报表模板优先:同一参数名在不同报表/站点的控件长相不同(3lv select vs JDA/AWSRTM multi_value)。
|
||||
values = [part.strip() for part in text.split(",") if part.strip()] if label == "PutawayZone" else [text]
|
||||
# [STEP 0] Owner / Warehouse / PutawayZone:按标签 + label[for] 现场派生控件类型与选择器。
|
||||
# Cincinnati CVG611 实机 Warehouse=ctl19_ddValue(select),旧 JDA 模板 ctl17 已是 Project ID。
|
||||
if label in {"Owner", "Warehouse", "PutawayZone"}:
|
||||
structural = resolve_parameter_controls_structural(page, label)
|
||||
if structural and _apply_structural_parameter_fill(
|
||||
page, label, text, values, timeout_ms=timeout_ms, structural=structural,
|
||||
):
|
||||
_debug(f"filter-filled-{label.lower()}", text)
|
||||
return True
|
||||
# 报表模板回退:同一参数名在不同报表/站点的控件长相不同(3lv select vs JDA/AWSRTM multi_value)。
|
||||
# [STEP] 模板命中时整表替换默认控件,禁止 update 残留默认 Warehouse.selector=ctl17_ddValue;
|
||||
# 否则 multi_value 偶发未就绪时会误走库存默认 select(AWSRTM Receipt Detail 2026-09-29)。
|
||||
template_controls = resolve_parameter_controls(
|
||||
@@ -682,8 +798,6 @@ def fill_dsv_filter_if_needed(
|
||||
_debug(f"filter-no-selector-{label.lower()}", text)
|
||||
return True
|
||||
|
||||
values = [part.strip() for part in text.split(",") if part.strip()] if label == "PutawayZone" else [text]
|
||||
|
||||
# [STEP 1] 模板登记为 multi_value(或 Owner/PutawayZone 固有多选)时,优先走 checkbox 下拉填充。
|
||||
if defaults.get("control") == "multi_value" or label in {"Owner", "PutawayZone"}:
|
||||
if _fill_multi_value_parameter(
|
||||
@@ -692,7 +806,7 @@ def fill_dsv_filter_if_needed(
|
||||
_debug(f"filter-filled-{label.lower()}", text)
|
||||
return True
|
||||
|
||||
# [STEP 2] 仅当控件类型确认为 select 时走 ddValue;禁止用 endswith(ddValue) 盖过 multi_value。
|
||||
# [STEP 2] 模板确认为 select,或结构性已确认是 select 但 STEP 0 未就绪时再试 ddValue。
|
||||
if defaults.get("control") == "select":
|
||||
select_selector = custom_selector or defaults.get("selector", "")
|
||||
if select_selector and _fill_select_parameter(
|
||||
@@ -700,8 +814,33 @@ def fill_dsv_filter_if_needed(
|
||||
):
|
||||
_debug(f"filter-filled-{label.lower()}", text)
|
||||
return True
|
||||
# 模板误判为 multi_value(如 JDA 模板套到 Cincinnati select 页)时:再做一次结构性 select。
|
||||
if label == "Warehouse":
|
||||
structural_retry = resolve_parameter_controls_structural(page, label)
|
||||
if (
|
||||
structural_retry
|
||||
and structural_retry.get("control") == "select"
|
||||
and _apply_structural_parameter_fill(
|
||||
page, label, text, values, timeout_ms=timeout_ms, structural=structural_retry,
|
||||
)
|
||||
):
|
||||
_debug(f"filter-filled-{label.lower()}", text)
|
||||
return True
|
||||
# [STEP 3 禁区] Warehouse 禁止用写死/漂移的 *_txtValue 文本兜底(会写进 Project ID)。
|
||||
print(
|
||||
f"[dsv-filter] {label} control probe: "
|
||||
f"{json.dumps(_probe_report_parameter_controls(page), ensure_ascii=False)[:1500]}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(
|
||||
f"[dsv] failed to fill {label} filter text={text!r}; "
|
||||
"refusing stale txtValue fallback",
|
||||
file=sys.stderr,
|
||||
)
|
||||
_debug(f"filter-failed-{label.lower()}", text)
|
||||
return False
|
||||
|
||||
# [STEP 3] 文本输入/脚本兜底:适用于普通文本参数与多选控件的输入框。
|
||||
# [STEP 3] 文本输入/脚本兜底:仅用于非 Warehouse 的普通文本参数与多选输入框。
|
||||
if not selector:
|
||||
print(
|
||||
f"[dsv-filter] {label} control probe: "
|
||||
@@ -757,14 +896,19 @@ def fill_dsv_multi_select_parameter(
|
||||
核心逻辑:selectors 缺省时**优先按参数标签结构性解析控件位**——SSRS 参数控件的
|
||||
ctl 编号每次渲染都会漂移(2026-10-08 实测:昨夜登记的 ctl29 今日漂移为 Project ID,
|
||||
RTM 被写进错误栏位),任何 ctl 编号注册条目都不可靠;结构性解析失败才回退
|
||||
报表模板/默认表。两者都没有则返回 False。
|
||||
报表模板/默认表。结构性命中但形态是 select(非 multi_value)时返回 False,
|
||||
由调用方走 fill_dsv_filter_if_needed 的 select 路径。
|
||||
"""
|
||||
config_override = {"control": "multi_value"}
|
||||
effective_selectors = selectors or (
|
||||
resolve_parameter_controls_structural(page, label)
|
||||
or resolve_parameter_controls(report_name, label, program_label=program_label)
|
||||
or None
|
||||
)
|
||||
effective_selectors = selectors
|
||||
if not effective_selectors:
|
||||
structural = resolve_parameter_controls_structural(page, label)
|
||||
if structural and structural.get("control") == "select":
|
||||
return False
|
||||
effective_selectors = structural or (
|
||||
resolve_parameter_controls(report_name, label, program_label=program_label)
|
||||
or None
|
||||
)
|
||||
if effective_selectors:
|
||||
for key in ("text", "toggle", "dropdown"):
|
||||
value = str(effective_selectors.get(key) or "").strip()
|
||||
|
||||
Reference in new issue
Block a user