Files
37duAutomation/plugins/XQ0001-0100/XQ0084 银行卡更新EHR系统/_selftest.py
T
puddy de7eeee08f feat(plugin): XQ0084 0.1.1 插件界面 + 核对通过自动导入 HR 工资卡并回写台账
- 新增 ui-src(Vue3+Element Plus,v3 规范)与构建产物 ui/,plugin.json 开启 ui
- 接入 hr_sdk.wage_import:核对通过记录按身份证匹配导入工资卡,成功后回写「是否更新HR系统=是」
- 委托发放/缺开户银行记录跳过并注明原因,现金发放仍不导入;导入失败不中断出表与推送
- 工作簿新增 HR导入/说明列,推送正文补充导入统计;_pack 排除 ui-src 并校验 ui/index.html
2026-11-18 11:02:25 +08:00

128 lines
4.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""XQ0084 判定规则自测(不联网、只验证纯逻辑)。
运行:python _selftest.py(自带包引导,等价壳子/预检的加载方式)。
插件内部是包(有 `..config` 相对导入),目录名带空格不能直接 import,
所以按 spec 载入插件包后再取 `logic.verify`。打包时 `_` 前缀文件会被 _pack.py 排除。
"""
from __future__ import annotations
import importlib
import importlib.util
import sys
import types
from pathlib import Path
HERE = Path(__file__).resolve().parent
CARD = "6214832377534396"
ID = "500228199001011235"
def _load_verify():
"""按壳子/预检同款方式载入插件包,返回 `logic.verify.verify`。
有宿主运行时(webhost)时正常执行 `__init__.py`;单独跑本文件时宿主可能不存在,
此时退化为只挂包路径的桩(判定逻辑只用到 config 与 SDK,不需要宿主)。
"""
sys.path.insert(0, str(HERE))
package = "plugin_under_test"
try:
spec = importlib.util.spec_from_file_location(
package, str(HERE / "__init__.py"), submodule_search_locations=[str(HERE)])
pkg = importlib.util.module_from_spec(spec)
sys.modules[package] = pkg
spec.loader.exec_module(pkg)
except ModuleNotFoundError:
sys.modules.pop(package, None)
pkg = types.ModuleType(package)
pkg.__path__ = [str(HERE)]
sys.modules[package] = pkg
return importlib.import_module(f"{package}.logic.verify").verify
verify = _load_verify()
def _item(card=CARD, id_no=ID, holder="张三", reason="个人原因换新卡", images=("a.jpg",)):
row = {
"员工姓名.工号": "37000001",
"持卡人姓名": holder,
"变更原因": reason,
"开户银行": "招商银行",
"银行卡号": card,
"持卡人身份证号": id_no,
"是否更新HR系统": "",
}
return {"row": row, "triggers": ["收到纸质资料"], "images": list(images), "errors": []}
def _ocr(id_no=ID, name="张三", card=CARD, bank="招商银行"):
return {"id": {"number": id_no, "name": name},
"bank": {"number": card, "bank": bank},
"runs": [id_no, card], "errors": []}
def _wage_row(**kw):
base = {
"conclusion": "通过", "trust": "", "emp_name": "张三", "holder": "张三",
"table_bank": "招商银行", "table_branch": "深圳分行", "table_card": CARD,
"table_id": ID, "record_id": "rec1", "hr_status": "", "hr_note": "",
}
base.update(kw)
return base
def _wage_cases():
dedup = [
("可导入", _wage_row(), 1, ""),
("委托发放跳过", _wage_row(trust="是"), 0, "跳过"),
("缺开户银行跳过", _wage_row(table_bank=""), 0, "跳过"),
("需人工不导入", _wage_row(conclusion="需人工核实"), 0, ""),
]
return dedup
def main():
cases = [
("全部一致", _item(), _ocr(), "通过"),
("身份证不一致", _item(), _ocr(id_no="500228199002021235"), "需人工核实"),
("卡号读不出", _item(), _ocr(card=""), "需人工核实"),
("姓名不一致", _item(), _ocr(name="李四"), "需人工核实"),
("开户银行不一致", _item(), _ocr(bank="建设银行"), "需人工核实"),
("缺影像", _item(images=()), _ocr(), "需人工核实"),
("表格缺卡号", _item(card=""), _ocr(), "需人工核实"),
("现金发放跳过核对", _item(card="", reason="银行卡收款异常改“现金发放”"),
{}, "现金发放(无需影像核对)"),
("多人一行", _item(holder="张三、李四"), _ocr(), "需人工核实"),
]
failed = 0
for name, item, ocr, expect in cases:
got = verify(item, ocr)["conclusion"]
ok = got == expect
failed += 0 if ok else 1
print(f"{'OK ' if ok else 'FAIL'} {name}: {got}(期望 {expect})")
wage = importlib.import_module(f"{verify.__module__.rsplit('.', 2)[0]}.logic.wage")
for name, row, expect_n, expect_status in _wage_cases():
targets, data_rows = wage.build_wage_rows([row])
guards = [
len(targets) == expect_n,
row["hr_status"] == expect_status,
all(len(d) == 10 for d in data_rows),
]
if expect_n:
d = data_rows[0]
guards += [d[0] == "张三", d[3] == "主卡", d[5] == "工资卡", d[8] == CARD]
ok = all(guards)
failed += 0 if ok else 1
extra = f"{data_rows[0][:6]}…" if expect_n else row["hr_note"]
print(f"{'OK ' if ok else 'FAIL'} 工资卡导入-{name}: 目标 {len(targets)} 条 {extra}")
print(f"完成:{len(cases) + len(_wage_cases()) - failed}/{len(cases) + len(_wage_cases())} 通过")
return failed
if __name__ == "__main__":
raise SystemExit(main())