feat(xq0002): 新增钉钉群通知推送功能,优化雇主险增减操作流程

This commit is contained in:
2026-10-05 09:42:56 +08:00
parent 26d4125798
commit 41bcb44e34
83 changed files with 11419 additions and 180 deletions
+55 -11
View File
@@ -443,19 +443,23 @@ def _import_file_path(category, menu_label):
return category_import_sub_file(category)
def _import_one(page, category, menu_label):
def _import_one(page, category, menu_label, expected_total=None):
"""对单个类别执行一次导入(选菜单 -> 上传 -> 下一步 -> 下一步 -> 关闭)。
自第一个「下一步」之前即开启 getTmpDataPage.mc 监听(结果接口可能在格式校验或
真正导入时触发,提前监听避免漏捕);异常仅记录上报,不中断导入流程。
Args:
expected_total: 需导入条数(由 import_all 预检传入,避免重复读文件;None 时自行统计)。
Returns:
dict: 导入结果(含 expected_total 需导入条数、exceptions 异常明细等)。
"""
file_path = _import_file_path(category, menu_label)
if not os.path.isfile(file_path):
raise FileNotFoundError(f"导入文件不存在:{file_path}")
expected_total = _count_import_rows(file_path)
if expected_total is None:
expected_total = _count_import_rows(file_path)
logger.info("===== 类别[%s] 开始%s,文件:%s(需导入 %d 条) =====",
category["name"], menu_label, file_path, expected_total)
@@ -517,19 +521,36 @@ def _import_one(page, category, menu_label):
# ==================== 对外入口:先减员后增员,全程共用一个浏览器 ====================
def _skipped_result(category, menu, reason):
"""构造「无待导入条目」的跳过单元结果(无 error,不计流程失败)。"""
return {
"category": category["name"], "menu": menu,
"captured": False, "state": "", "meg": "", "exceptions": [],
"listen_ok": True, "expected_total": 0,
"success_count": 0, "total_count": 0,
"skipped": True, "skip_reason": reason,
}
def import_all(categories, on_progress=None):
"""对指定类别执行 HR 导入(★先全部类别【减员】再【增员】,顺序不可换)。
预检:仅「导入文件存在且实际有待导入条目」的单元才会启动浏览器执行导入;
需导入 0 条(无增员/减员变动)的单元直接跳过——本就没有需要导入的内容,
不启动浏览器、也不报"流程失败"。
Args:
categories: 类别配置列表(config.CATEGORIES 项,须为本次调度成功的类别,
只导入本次新生成的导入文件,避免误传历史文件)。
on_progress: 可选回调 on_progress(done, total),每个「类别×菜单」单元完成后调用,
供 __init__.py 上报进度。
on_progress: 可选回调 on_progress(done, total),每个实际执行导入的
「类别×菜单」单元完成后调用,供 __init__.py 上报进度。
Returns:
list[dict]: 每单元结果:{category, menu, captured, state, meg, exceptions,
listen_ok, expected_total, success_count, total_count,
assumed_all_success?, error?, error_type?}
assumed_all_success?, error?, error_type?, skipped?}
skipped=True 表示该单元导入文件无待导入条目(需导入 0 条),未启动浏览器导入,
不视为流程失败(无 error 字段)。
Raises:
LoginRequiredError: HR 登录态缺失/失效(整个导入未开始,无部分导入风险)。
@@ -541,10 +562,32 @@ def import_all(categories, on_progress=None):
logger.info("无待导入类别,跳过 HR 导入")
return []
units = [(c, menu) for menu in (MENU_SUB, MENU_ADD) for c in categories]
# ---- 预检:按导入文件实际条数过滤出真正需要导入的单元(类别×菜单) ----
results = []
units = []
for c in categories:
for menu in (MENU_SUB, MENU_ADD):
label = "减员" if menu == MENU_SUB else "增员"
file_path = _import_file_path(c, menu)
if not os.path.isfile(file_path):
logger.warning("类别[%s] %s导入文件不存在,视为无需导入:%s",
c["name"], label, file_path)
results.append(_skipped_result(c, menu, "导入文件不存在"))
continue
expected_total = _count_import_rows(file_path)
if expected_total <= 0:
logger.info("类别[%s] %s导入文件无待导入条目,跳过导入:%s",
c["name"], label, file_path)
results.append(_skipped_result(c, menu, "无待导入条目"))
continue
units.append((c, menu, expected_total))
if not units:
logger.info("各类别增/减员导入文件均无待导入条目,跳过 HR 自动导入(未启动浏览器)")
return results
total_units = len(units)
done = 0
results = []
page = _create_page()
logger.info("浏览器已启动(导入全程共用)")
@@ -553,9 +596,9 @@ def import_all(categories, on_progress=None):
page.set.cookies(cookies)
_ensure_logged_in(page)
for category, menu_label in units:
for category, menu_label, expected_total in units:
try:
res = dict(_import_one(page, category, menu_label))
res = dict(_import_one(page, category, menu_label, expected_total=expected_total))
res["category"] = category["name"]
res["menu"] = menu_label
results.append(res)
@@ -587,7 +630,8 @@ def summarize_results(results):
口径与影刀版一致:需导入条数取自导入文件(expected_total,与接口是否捕获无关);
成功/失败取接口返回的业务结果(全部成功时 HR 不返回接口,按文件条数推定成功);
流程失败(登录/元素/文件缺失)的单元不纳入条数统计,仅报失败。
流程失败(登录/元素/文件缺失)的单元不纳入条数统计,仅报失败;
跳过单元(skipped,无待导入条目)正常纳入统计(需导入 0 条),不报失败/待确认。
"""
lines = []
for menu, label in ((MENU_SUB, "减员"), (MENU_ADD, "增员")):
@@ -600,7 +644,7 @@ def summarize_results(results):
flow_failed = [r["category"] for r in rs if r.get("error")]
unconfirmed = [r["category"] for r in rs
if not r.get("error") and not r.get("exceptions")
and not r.get("assumed_all_success")
and not r.get("assumed_all_success") and not r.get("skipped")
and (not r.get("captured") or r.get("state") != TMP_DATA_STATE_OK)]
line = f"{label}:需导入 {total} 条,成功 {success} 条,异常 {fail} 条"
extras = []