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

+117 -5
View File
@@ -34,6 +34,51 @@ _DSV_REPORT_PARAM_DEFAULTS: dict[str, dict[str, str]] = {
}
def _normalize_report_name(report_name: str) -> str:
"""报表名归一化:去首尾空白并折叠连续空白、统一小写,用于模板精确匹配。"""
return " ".join(str(report_name or "").strip().lower().split())
# 报表名 → 参数控件模板。同名的 SSRS 参数在不同报表里的控件长相不同:
# - 3lv 版(On Hand Inventory By Location 3lv,Bison/AWSBI):Warehouse 是原生 select(ddValue);
# - JDA 版(On Hand Inventory by Location,Moerdijk 等):Warehouse 是 txtValue + toggle + divDropDown
# 组成的多选框下拉(multi_value),历史 YAML 为该源配置的 selectors 即源于此。
# 模板按"归一化报表名"精确匹配;未命中时回退 _DSV_REPORT_PARAM_DEFAULTS(保持旧行为)。
_DSV_REPORT_PARAM_TEMPLATES: dict[str, dict[str, dict[str, str]]] = {
"on hand inventory by location 3lv": {
"Warehouse": {
"control": "select",
"selector": "#ReportViewerMain_ctl08_ctl17_ddValue",
},
},
"on hand inventory by location": {
"Warehouse": {
"control": "multi_value",
"text": "#ReportViewerMain_ctl08_ctl17_txtValue",
"toggle": "#ReportViewerMain_ctl08_ctl17_ctl01",
"dropdown": "#ReportViewerMain_ctl08_ctl17_divDropDown",
},
},
}
def resolve_parameter_controls(report_name: str | None, label: str) -> dict[str, str]:
"""
按(报表名, 参数名)解析 SSRS 控件配置;报表模板优先,未命中返回空 dict。
Args:
report_name: 当前报表名(如 navigation.report_name),允许为空。
label: 参数名(Owner / PutawayZone / Warehouse)。
Returns:
dict[str, str]: 控件配置(control/selector 或 control/text/toggle/dropdown);
报表未登记时为空 dict,由调用方回退参数名默认值。
"""
key = _normalize_report_name(report_name)
template = _DSV_REPORT_PARAM_TEMPLATES.get(key) or {}
return dict(template.get(str(label or "").strip()) or {})
def _iter_dsv_report_roots(page: Any) -> list[Any]:
"""返回包含 ReportViewerMain 的 frame;找不到时回退到全部 roots。"""
matched: list[Any] = []
@@ -370,6 +415,52 @@ def _fill_select_parameter(page: Any, label: str, value: str, selector: str, *,
return False
def _probe_report_parameter_controls(page: Any) -> dict[str, Any]:
"""
枚举报表参数区(ReportViewerMain_ctl08)的实际控件,用于填参失败时定位控件类型漂移。
核心逻辑:SSRS 对同一参数名在不同报表里可能渲染成原生 select、文本框或多选框下拉;
失败日志带上本探针后,无需人工开浏览器即可判断目标控件是否存在、option 数是否为空。
"""
roots = _iter_dsv_report_roots(page)
probe: dict[str, Any] = {"roots": len(roots), "controls": []}
for root in roots:
try:
items = root.evaluate(
"""
() => {
const normalize = (text) => ((text || '') + '').replace(/\\s+/g, ' ').trim();
const nodes = Array.from(document.querySelectorAll(
'#ReportViewerMain_ctl08 select, #ReportViewerMain_ctl08 input, ' +
'#ReportViewerMain_ctl08 [id$="_divDropDown"]'
));
return nodes.slice(0, 60).map((node) => {
const table = node.tagName.toLowerCase() === 'select'
? Array.from(node.options || []).map((item) => normalize(item.textContent)).filter(Boolean)
: [];
const dropdown = node.getAttribute('id') || '';
return {
id: dropdown,
tag: node.tagName.toLowerCase(),
type: node.getAttribute('type') || '',
hidden: node.getAttribute('type') === 'hidden',
optionCount: table.length,
firstOptions: table.slice(0, 12),
labelText: normalize(
(node.closest('td') || {}).innerText || ''
).slice(0, 120),
};
});
}
""",
)
if isinstance(items, list):
probe["controls"].extend(items)
except Exception as exc:
probe["controls"].append({"probe_error": str(exc)[:120]})
return probe
def fill_dsv_filter_if_needed(
page: Any,
selector_env: str,
@@ -379,10 +470,13 @@ def fill_dsv_filter_if_needed(
env: Callable[[str, str], str],
browser_timeout_ms: Callable[[], int],
debug_stage: Callable[..., None] | None = None,
report_name: str | None = None,
) -> None:
"""
按 ReportViewer 控件类型填充 DSV 报表参数。
核心逻辑:优先使用 JSON/页面默认 selector;Warehouse 走 select_option,Owner/PutawayZone 走 checkbox。
报表模板(_DSV_REPORT_PARAM_TEMPLATES)登记了同类报表的控件差异:传入 report_name 时,
先按模板选择 multi_value/select;未命中的报表回退参数名默认值(旧行为)。
"""
text = str(value or "").strip()
if not text:
@@ -401,7 +495,11 @@ def fill_dsv_filter_if_needed(
pass
timeout_ms = browser_timeout_ms()
defaults = _DSV_REPORT_PARAM_DEFAULTS.get(label, {})
defaults = dict(_DSV_REPORT_PARAM_DEFAULTS.get(label, {}))
# 报表模板优先:同一参数名在不同报表的控件长相不同(3lv select vs JDA multi_value)。
template_controls = resolve_parameter_controls(report_name, label)
if template_controls:
defaults.update(template_controls)
custom_selector = str(env(selector_env) or "").strip()
selector = custom_selector or defaults.get("selector") or defaults.get("text")
@@ -412,17 +510,22 @@ def fill_dsv_filter_if_needed(
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(page, label, values, timeout_ms=timeout_ms):
if _fill_multi_value_parameter(
page, label, values, timeout_ms=timeout_ms, config_override=defaults,
):
_debug(f"filter-filled-{label.lower()}", text)
return
# [STEP 2] 原生 select 路径:模板为 select 或未登记时继续旧行为(ddValue + 选项等待/脚本赋值)。
select_selector = custom_selector or defaults.get("selector", "")
if defaults.get("control") == "select" or label == "Warehouse" or select_selector.endswith("ddValue"):
if select_selector and (defaults.get("control") == "select" or select_selector.endswith("ddValue")):
if _fill_select_parameter(page, label, text, select_selector, timeout_ms=timeout_ms):
_debug(f"filter-filled-{label.lower()}", text)
return
# [STEP 3] 文本输入/脚本兜底:适用于普通文本参数与多选控件的输入框。
print(f"[dsv-filter] filling {label} text={text!r} selector={selector!r}")
for root in _iter_dsv_report_roots(page):
if _fill_input_via_script(root, selector, text):
@@ -440,6 +543,12 @@ def fill_dsv_filter_if_needed(
except Exception as exc:
print(f"[dsv-filter] {label} fill fallback failed: {exc}", file=sys.stderr)
# 全部路径失败:输出参数区控件探针,便于下轮直接定位控件 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}", file=sys.stderr)
_debug(f"filter-failed-{label.lower()}", text)
@@ -452,16 +561,19 @@ def fill_dsv_multi_select_parameter(
selectors: dict[str, str] | None = None,
select_all: bool = False,
browser_timeout_ms: Callable[[], int],
report_name: str | None = None,
) -> bool:
"""
填充由 YAML `mode: multi_select` 显式声明的 SSRS checkbox 下拉参数。
【AI 触发时机】:当 DSV 报表参数不是原生 select,而是 `txtValue + divDropDown + checkbox`
组合控件时调用;例如 AWSAMS 的 Warehouse 下拉需要全选。
核心逻辑:selectors 缺省时按报表模板(report_name)解析控件;两者都没有则返回 False。
"""
config_override = {"control": "multi_value"}
if selectors:
effective_selectors = selectors or (resolve_parameter_controls(report_name, label) or None)
if effective_selectors:
for key in ("text", "toggle", "dropdown"):
value = str(selectors.get(key) or "").strip()
value = str(effective_selectors.get(key) or "").strip()
if value:
config_override[key] = value
if not all(config_override.get(key) for key in ("text", "toggle", "dropdown")):