feat(xq0002): 新增钉钉群通知推送功能,优化雇主险增减操作流程
This commit is contained in:
@@ -70,7 +70,8 @@ REPLAY_PREFIX = "人员增减申请回盘表" # 回盘表文件名前
|
||||
# ==================== 目标区域 / 参保类型 ====================
|
||||
TARGET_REGION = "重庆"
|
||||
ADD_TYPES = ("新参保", "转移参保") # 名单制作覆盖两种参保类型
|
||||
WEB_ADD_TYPE = "新参保" # 系统办理仅办「新参保」(与 import_add.py 一致)
|
||||
WEB_ADD_TYPES = ("新参保", "转移参保") # 增员系统办理覆盖两种参保类型(与 import_add.py 一致)
|
||||
WEB_ADD_TYPE = WEB_ADD_TYPES[0] # 兼容旧引用(web_review 增员核查保持只查新参保)
|
||||
STOP_TYPES = ("停保", "转移停保") # 减员两类都办
|
||||
|
||||
# ==================== 台账「缴费比例」sheet 数据列(0-based,表头占 1-2 行已跳过) ====================
|
||||
|
||||
@@ -49,8 +49,11 @@ def load_records(kind, operation_type=None, status_filter="empty", exclude_ids=f
|
||||
|
||||
if kind == 'add':
|
||||
status_col = "办理状态"
|
||||
# 增员可传单值或元组(如 config.WEB_ADD_TYPES 两类都办)
|
||||
op_types = operation_type if isinstance(operation_type, (tuple, list, set)) \
|
||||
else (operation_type,)
|
||||
mask = (df["区域"].astype(str).str.strip() == config.TARGET_REGION)
|
||||
mask &= (df["参保类型"].astype(str).str.strip() == operation_type)
|
||||
mask &= (df["参保类型"].astype(str).str.strip().isin(op_types))
|
||||
else:
|
||||
status_col = config.STOP_PROCESSED_COL
|
||||
mask = (df["区域"].astype(str).str.strip() == config.TARGET_REGION)
|
||||
@@ -74,21 +77,34 @@ def load_records(kind, operation_type=None, status_filter="empty", exclude_ids=f
|
||||
|
||||
|
||||
def load_units(kind, operation_type=None, status_filter="empty", exclude_ids=frozenset()):
|
||||
"""读取名单并筛选,返回 [(参保单位, 人数), ...](按单位分组,名称排序)。"""
|
||||
"""读取名单并筛选,返回 [(参保类型, 参保单位, 人数), ...](按类型+单位分组,名称排序)。
|
||||
|
||||
减员(kind='stop')参保类型恒为 None(停保/转移停保合并按单位分组)。
|
||||
"""
|
||||
sub, source_file, sheet_name, status_col = load_records(
|
||||
kind, operation_type, status_filter, exclude_ids)
|
||||
print_source = os.path.basename(source_file)
|
||||
if kind == 'add':
|
||||
desc = f"{config.TARGET_REGION} ∩ 参保类型={operation_type}"
|
||||
desc = f"{config.TARGET_REGION} ∩ 参保类型∈{'/'.join(config.WEB_ADD_TYPES)}"
|
||||
else:
|
||||
desc = f"{config.TARGET_REGION} ∩ 类型∈{'/'.join(config.STOP_TYPES)}"
|
||||
config.log(f"源名单:{print_source}(sheet: {sheet_name})")
|
||||
if sub.empty:
|
||||
config.log(f"没有筛选到数据({desc} ∩ {status_col}={'空' if status_filter == 'empty' else status_filter})")
|
||||
return [], source_file, sheet_name
|
||||
grouped = sub.groupby(sub["参保单位"].astype(str).str.strip()).size()
|
||||
units = sorted(grouped.items(), key=lambda t: t[0])
|
||||
config.log(f"筛选结果:共 {sum(n for _, n in units)} 人 / {len(units)} 个参保单位")
|
||||
if kind == 'add':
|
||||
sub["_type"] = sub["参保类型"].astype(str).str.strip()
|
||||
sub["_unit"] = sub["参保单位"].astype(str).str.strip()
|
||||
grouped = sub.groupby(["_type", "_unit"]).size()
|
||||
units = [(t, u, int(n)) for (t, u), n in grouped.items()]
|
||||
units.sort(key=lambda x: (x[0], x[1]))
|
||||
unit_desc = "个(类型+单位)分组"
|
||||
else:
|
||||
grouped = sub.groupby(sub["参保单位"].astype(str).str.strip()).size()
|
||||
units = [(None, u, int(n)) for u, n in grouped.items()]
|
||||
units.sort(key=lambda x: x[1])
|
||||
unit_desc = "个参保单位"
|
||||
config.log(f"筛选结果:共 {sum(n for _, _, n in units)} 人 / {len(units)} {unit_desc}")
|
||||
return units, source_file, sheet_name
|
||||
|
||||
|
||||
|
||||
@@ -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)}
|
||||
|
||||
Reference in New Issue
Block a user