- hr_sdk.wage_import:DrissionPage 注入 cookie 打开 HR 门户,页面内 WS 订阅 + fetch 上传,解析 over: 结果;build_xlsx 第 9 列卡号强制数值(修复「卡号必须是数字」) - 纯 HTTP 导入不可用:服务端异步任务与浏览器会话强绑定,且前端无轮询接口(已核实),结果通道只能用浏览器上下文 - desktopauto 0.5.0 新增 cardocr:身份证/银行卡 OCR、号码纠错、Luhn 与模 11-2 校验、交叉核对 - 新增插件 XQ0084 银行卡更新EHR系统:AI 表格待处理行 → 影像识别 → 一致性核对/异常名单 - .gitignore 忽略 tests/aitable_probe/_out/(含员工证件照,禁止入库)
109 lines
4.6 KiB
Python
109 lines
4.6 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""XQ0084 流程编排:拉取待处理行 → 下载影像 → 识别 → 判定 → 输出/提醒。"""
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
import time
|
||
|
||
from .. import config
|
||
from ..data.ai_table import download_images, list_pending, open_client
|
||
from ..report.notify import send_markdown
|
||
from ..report.workbook import write_workbook
|
||
from .recognize import recognize
|
||
from .verify import verify
|
||
|
||
|
||
def _push_text(rows, stats, path):
|
||
lines = [
|
||
"### 银行卡变更影像核对(XQ0084)",
|
||
f"- 待处理:**{stats['total']}** 条;通过 **{stats['passed']}**、"
|
||
f"需人工 **{stats['manual']}**、现金发放 **{stats['cash']}**",
|
||
"- 触发原因:未更新HR系统 {0} / 未收纸质资料 {1} / 缺登记日期 {2}".format(
|
||
stats["trigger"][config.F_DONE],
|
||
stats["trigger"][config.F_PAPER],
|
||
stats["trigger"][config.F_REG_DATE],
|
||
),
|
||
]
|
||
manual = [r for r in rows if r["conclusion"] == "需人工核实"]
|
||
if manual:
|
||
lines.append(f"#### 需人工核实({len(manual)})")
|
||
for r in manual[:20]:
|
||
lines.append(f"- {r['holder']}({r['emp_no']}):{r['notes'][:120]}")
|
||
if len(manual) > 20:
|
||
lines.append(f"- …… 其余 {len(manual) - 20} 条见结果文件")
|
||
lines.append(f"- 结果文件:{path}")
|
||
return "\n".join(lines)
|
||
|
||
|
||
def run_verify(save_dir, keep_files=config.DEFAULT_KEEP_FILES, push_webhook="",
|
||
push_secret="", limit_rows=0, progress=None):
|
||
p = progress or (lambda _pct: None)
|
||
stamp = time.strftime("%Y%m%d_%H%M%S")
|
||
image_batch = os.path.join(save_dir, config.IMAGE_DIR_NAME, stamp)
|
||
os.makedirs(image_batch, exist_ok=True)
|
||
p(3)
|
||
|
||
with open_client() as cli:
|
||
items = list_pending(cli)
|
||
config.logger.info("AI 表格待处理记录:%d 条(筛选:%s 任一为空)",
|
||
len(items), "、".join(config.PENDING_FIELDS))
|
||
if limit_rows and limit_rows > 0:
|
||
items = items[:limit_rows]
|
||
config.logger.info("按配置仅处理前 %d 条", len(items))
|
||
if not items:
|
||
return {"path": "", "rows": [], "stats": _stats([], []),
|
||
"push": {"success": False, "message": "无待处理记录"},
|
||
"cleaned": [], "batch_dir": image_batch}
|
||
|
||
# 1) 先集中下载影像(预签名有效期短,避免识别耗时导致后续地址过期)
|
||
for i, item in enumerate(items):
|
||
if config.REASON_CASH_KEYWORD in (item.get("reason") or ""):
|
||
continue
|
||
download_images(cli, item, image_batch)
|
||
p(5 + int(20 * (i + 1) / len(items)))
|
||
|
||
# 2) 逐条识别 + 判定
|
||
rows = []
|
||
for i, item in enumerate(items):
|
||
if config.REASON_CASH_KEYWORD in (item.get("reason") or ""):
|
||
ocr = {}
|
||
else:
|
||
ocr = recognize(item.get("images") or [], expected_name=item.get("holder") or "")
|
||
result = verify(item, ocr)
|
||
rows.append(result)
|
||
config.logger.info("%s %s(%s)→ %s%s",
|
||
result["emp_no"], result["holder"], result["reason"],
|
||
result["conclusion"],
|
||
f":{result['notes']}" if result["notes"] else "")
|
||
p(25 + int(65 * (i + 1) / len(items)))
|
||
|
||
stats = _stats(rows, items)
|
||
path = write_workbook(rows, config.build_result_path(save_dir))
|
||
p(94)
|
||
|
||
cleaned = config.cleanup_old_results(save_dir, keep_files, protect=path)
|
||
config.cleanup_old_images(os.path.join(save_dir, config.IMAGE_DIR_NAME), keep_files,
|
||
protect=image_batch)
|
||
|
||
push = {"success": False, "message": "无需推送(无异常)"}
|
||
if stats["manual"] and push_webhook:
|
||
push = send_markdown(push_webhook, push_secret, "银行卡变更影像核对异常",
|
||
_push_text(rows, stats, path))
|
||
p(100)
|
||
return {"path": path, "rows": rows, "stats": stats, "push": push,
|
||
"cleaned": cleaned, "batch_dir": image_batch}
|
||
|
||
|
||
def _stats(rows, items):
|
||
trigger = {name: 0 for name in config.PENDING_FIELDS}
|
||
for item in items:
|
||
for name in item.get("triggers") or []:
|
||
trigger[name] = trigger.get(name, 0) + 1
|
||
return {
|
||
"total": len(rows),
|
||
"passed": sum(1 for r in rows if r.get("conclusion") == "通过"),
|
||
"manual": sum(1 for r in rows if r.get("conclusion") == "需人工核实"),
|
||
"cash": sum(1 for r in rows if str(r.get("conclusion", "")).startswith("现金发放")),
|
||
"trigger": trigger,
|
||
}
|