- 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/(含员工证件照,禁止入库)
75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""XQ0084 数据层:AI 表格读取与影像下载。"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from dingtalk_sdk.aitable import AiTable, attachment_items, flatten
|
|
|
|
from .. import config
|
|
|
|
|
|
def open_client():
|
|
"""创建 AI 表格客户端(凭证内置,不依赖执行机 .env)。"""
|
|
return AiTable(
|
|
app_key=config.DINGTALK_APP_KEY,
|
|
app_secret=config.DINGTALK_APP_SECRET,
|
|
operator=config.AITABLE_OPERATOR_UNIONID,
|
|
log=lambda m: config.logger.debug(m),
|
|
)
|
|
|
|
|
|
def list_pending(cli):
|
|
"""拉全表并按「是否更新HR系统 / 收到纸质资料 / 登记日期 任一为空」筛选。"""
|
|
records = cli.records(config.AI_BASE, config.AI_SHEET)
|
|
items = []
|
|
for rec in records:
|
|
fields = rec.get("fields") or {}
|
|
triggers = [name for name in config.PENDING_FIELDS if config.blank(fields.get(name))]
|
|
if not triggers:
|
|
continue
|
|
row = flatten(rec)
|
|
holder = config.text(row.get(config.F_HOLDER)) or config.text(row.get(config.F_EMP_NAME))
|
|
items.append({
|
|
"record_id": rec.get("id") or rec.get("recordId") or "",
|
|
"fields": fields,
|
|
"row": row,
|
|
"triggers": triggers,
|
|
"reason": config.text(row.get(config.F_REASON)),
|
|
"holder": holder,
|
|
"emp_no": config.text(row.get(config.F_EMP_NO)),
|
|
"errors": [],
|
|
"images": [],
|
|
})
|
|
return items
|
|
|
|
|
|
def download_images(cli, item, batch_dir):
|
|
"""下载一条记录的银行卡/身份证照片到批次目录,返回本地路径列表。"""
|
|
fields = item["fields"]
|
|
folder = os.path.join(
|
|
batch_dir,
|
|
config.safe_name(f"{item.get('emp_no') or '无工号'}_{item.get('holder') or '无姓名'}"),
|
|
)
|
|
saved = []
|
|
expected = 0
|
|
for field, prefix in ((config.F_CARD_IMG, "银行卡"), (config.F_ID_IMG, "身份证")):
|
|
attachments = attachment_items(fields.get(field))
|
|
expected += len(attachments)
|
|
if not attachments:
|
|
continue
|
|
try:
|
|
got = cli.download_attachments(fields.get(field), folder,
|
|
prefix=f"{prefix}_", col=field)
|
|
except Exception as e: # 预签名过期/网络异常 → 转人工
|
|
item["errors"].append(f"{field}下载失败:{e}")
|
|
config.logger.warning("%s %s 下载失败:%s", item.get("emp_no"), field, e)
|
|
continue
|
|
for g in got:
|
|
if g.get("path"):
|
|
saved.append(g["path"])
|
|
item["images"] = saved
|
|
item["expected_images"] = expected
|
|
item["image_dir"] = folder if saved else ""
|
|
return saved
|