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
@@ -2,8 +2,9 @@
"""重庆社保系统增减员办理(增员/减员系统导入)—— import_add.py / import_stop.py 移植。
统一引擎 ImportEngine(kind):
- kind='add':城保参保单位人员增加,消费《新参保-增员》目录《XX增员导入名单.xls》,
回写「办理状态」列(参保失败),审核结论回写「办理状态」
- kind='add':城保参保单位人员增加,消费《新参保-增员》/《转移参保-增员》目录
《XX增员导入名单.xls》(按参保类型分目录),回写「办理状态」列(参保失败),
审核结论回写「办理状态」
- kind='stop':城保参保单位人员减少,消费《停保-减员》目录《XX减员导入名单.xls》,
回写「办理停保」列(停保失败),审核结论回写「办理停保」
@@ -281,7 +282,9 @@ def _upload_import(tab, xls_path, close_tip, max_rounds=3):
failed = int(m_fail.group(1)) if m_fail else 0
config.log(f" 导入完成:成功 {total} 人,失败 {failed} 人")
if total == 0:
raise RuntimeError(f"导入完成但成功人数为 0,提示:{text.strip()[:120]}")
# 全员未通过:不在此中止,交给上层读「校验未通过人员」回写参保失败并跳过申报
# (若此处 raise,失败人员不会落账,下次运行会重复申报)
config.log(f" 导入完成但成功人数为 0,提示:{text.strip()[:120]}")
for t in ('确 定', '确定'):
try:
btn = tab.ele(f'tag:button@@text()={t}', timeout=2)
@@ -540,32 +543,43 @@ class ImportEngine:
self.kind = kind
if kind == 'add':
self.business_item = "城保参保单位人员增加"
self.import_dir_name = config.OUTPUT_DIR_ADD_NEW
# 名单产出目录:按参保类型分文件夹(新参保-增员 / 转移参保-增员)
self.import_dir_names = {
"新参保": config.OUTPUT_DIR_ADD_NEW,
"转移参保": config.OUTPUT_DIR_ADD_TRANS,
}
self.file_suffix = "增员导入名单.xls"
self.fail_status = "参保失败"
self.close_tip = False
self.operation_type = config.WEB_ADD_TYPE
self.operation_type = config.WEB_ADD_TYPES
else:
self.business_item = "城保参保单位人员减少"
self.import_dir_name = config.OUTPUT_DIR_STOP
self.import_dir_names = {}
self.file_suffix = "减员导入名单.xls"
self.fail_status = "停保失败"
self.close_tip = True
self.operation_type = None
self.import_dir_name = config.OUTPUT_DIR_STOP if kind != 'add' else config.OUTPUT_DIR_ADD_NEW
self.writeback = Writeback(kind)
def _import_dir(self, op_type):
"""按参保类型取名单产出子目录(增员);减员固定「停保-减员」。"""
if self.kind == 'add':
return self.import_dir_names.get(op_type, config.OUTPUT_DIR_ADD_NEW)
return self.import_dir_name
# ---------------- 预检 ----------------
def precheck(self, units, accounts):
"""预检:核对每个单位的导入文件与账号。返回待办列表。"""
import_dir = config.roster_output_dir(self.import_dir_name)
"""预检:核对每个(类型+单位)的导入文件与账号。返回待办列表。"""
tasks, errors = [], []
config.log("\n========== 预检 ==========")
for unit, count in units:
for op_type, unit, count in units:
import_dir = config.roster_output_dir(self._import_dir(op_type))
file_path = os.path.join(import_dir, f"{config._safe_name(unit)}{self.file_suffix}")
acc = accounts.get(unit)
problems = []
if not os.path.isfile(file_path):
problems.append(f"缺导入文件({self.import_dir_name}\\{os.path.basename(file_path)})")
problems.append(f"缺导入文件({self._import_dir(op_type)}\\{os.path.basename(file_path)})")
if acc is None:
problems.append("台账未匹配(检查户头名/城市=重庆/是否在用=是)")
else:
@@ -573,20 +587,21 @@ class ImportEngine:
problems.append("账号缺失(I列信用代码与K列平台用户名均为空)")
if not acc["password"]:
problems.append("密码缺失(L列平台密码为空)")
tag = f"{unit}({op_type or '停保'},{count}人)"
if problems:
errors.append(f"[{unit}] " + ";".join(problems))
config.log(f" ✗ {unit}({count}人):{';'.join(problems)}")
errors.append(f"[{unit} {op_type or ''}] " + ";".join(problems))
config.log(f" ✗ {tag}:{';'.join(problems)}")
else:
tasks.append({"unit": unit, "count": count, "file": file_path,
tasks.append({"type": op_type, "unit": unit, "count": count, "file": file_path,
"username": acc["username"], "password": acc["password"]})
config.log(f" ✓ {unit}({count}人)账号={acc['username']}"
config.log(f" ✓ {tag} 账号={acc['username']}"
f"({acc['username_src']})文件={os.path.basename(file_path)}")
if errors:
config.log(f"\n预检未通过,共 {len(errors)} 个问题,请先修正后重跑:")
for e in errors:
config.log(f" - {e}")
return None
config.log(f"预检通过:{len(tasks)} 个单位待办理\n")
config.log(f"预检通过:{len(tasks)} 个待办理\n")
return tasks
# ---------------- 单个单位网页办理 ----------------
@@ -651,7 +666,8 @@ class ImportEngine:
span_start, span_end = progress_span
results = []
for i, task in enumerate(tasks, 1):
config.log(f"\n========== [{i}/{len(tasks)}] {task['unit']}({task['count']}人)==========")
config.log(f"\n========== [{i}/{len(tasks)}] {task['unit']}"
f"({task.get('type') or '停保'},{task['count']}人)==========")
config.log(f"导入文件:{task['file']}")
if len(tasks) > 1:
config.progress(span_start + int((span_end - span_start) * (i - 1) / len(tasks)))
@@ -691,7 +707,7 @@ class ImportEngine:
if not units:
return {"success": True, "message": "无待办数据", "total": 0, "done": 0}
accounts = source_reader.load_accounts([u for u, _ in units])
accounts = source_reader.load_accounts([u for _, u, _ in units])
tasks = self.precheck(units, accounts)
if tasks is None:
return {"success": False, "message": "预检未通过,详见日志",
@@ -708,6 +724,6 @@ class ImportEngine:
config.log(f"\n========== 汇总 ==========")
config.log(f"成功 {len(ok)} 家,失败 {len(fail)} 家")
for r in fail:
config.log(f" ✗ {r['unit']}:{r.get('message', '')}")
config.log(f" ✗ {r['unit']}({r.get('type') or ''}):{r.get('message', '')}")
return {"success": not fail, "message": f"成功{len(ok)}/失败{len(fail)}",
"total": len(results), "done": len(ok)}