feat(plugin XQ0008): 支持增员按参保类型分目录存储回盘文件

更新插件版本至1.0.2,调整增员核查逻辑按参保类型分组,回盘文件按类型分目录存储,适配不同参保类型的办理需求
This commit is contained in:
2026-10-08 11:46:09 +08:00
parent 2ff550368d
commit 4b7c5b8b12
6 changed files with 51 additions and 30 deletions
@@ -48,7 +48,7 @@ class ChongqingSocialChangePlugin(ScenePlugin):
id = "xq0008"
name = "重庆社保增减员办理"
version = "1.0.0"
version = "1.0.2"
description = ("重庆社保增减员全流程(XQ0008 名单制作 + XQ0014 系统办理/核查回盘 + "
"XQ0015/XQ0016 告知书制作下发):目录预检、增/减员名单制作、增/减员系统办理、"
"增/减员核查回盘、告知书制作与 OA 推送八阶段可选串行。逐参保单位读取台账账号"
@@ -70,8 +70,7 @@ REPLAY_PREFIX = "人员增减申请回盘表" # 回盘表文件名前
# ==================== 目标区域 / 参保类型 ====================
TARGET_REGION = "重庆"
ADD_TYPES = ("新参保", "转移参保") # 名单制作覆盖两种参保类型
WEB_ADD_TYPES = ("新参保", "转移参保") # 增员系统办理覆盖两种参保类型(与 import_add.py 一致)
WEB_ADD_TYPE = WEB_ADD_TYPES[0] # 兼容旧引用(web_review 增员核查保持只查新参保)
WEB_ADD_TYPES = ("新参保", "转移参保") # 增员系统办理/核查覆盖两种参保类型(与 import_add.py 一致)
STOP_TYPES = ("停保", "转移停保") # 减员两类都办
# ==================== 台账「缴费比例」sheet 数据列(0-based,表头占 1-2 行已跳过) ====================
@@ -109,11 +109,12 @@ def load_units(kind, operation_type=None, status_filter="empty", exclude_ids=fro
def load_check_tasks(kind, status_filter=config.CHECK_STATUS, exclude_ids=frozenset()):
"""读取名单筛选 办理状态/办理停保=待审核 的行,按参保单位分组。
"""读取名单筛选 办理状态/办理停保=待审核 的行,分组。
返回 [{unit, count, cids(set)}],供核查流程使用。
增员按参保类型+单位分组(回盘文件按类型分目录),减员按单位分组。
返回 [{unit, type, count, cids(set)}],供核查流程使用。
"""
operation_type = config.WEB_ADD_TYPE if kind == 'add' else None
operation_type = config.WEB_ADD_TYPES if kind == 'add' else None
sub, source_file, sheet_name, status_col = load_records(
kind, operation_type, status_filter, exclude_ids)
print_source = os.path.basename(source_file)
@@ -121,14 +122,26 @@ def load_check_tasks(kind, status_filter=config.CHECK_STATUS, exclude_ids=frozen
if sub.empty:
config.log(f"没有筛选到数据({status_col}={status_filter})")
return [], source_file, sheet_name
sub = sub.copy()
sub["_unit"] = sub["参保单位"].astype(str).str.strip()
tasks = []
for unit, g in sub.groupby(sub["参保单位"].astype(str).str.strip()):
cids = {config._norm_id(v) for v in g['身份证号码']}
cids.discard('')
tasks.append({"unit": unit, "count": len(cids), "cids": cids})
tasks.sort(key=lambda t: t['unit'])
if kind == 'add':
sub["_type"] = sub["参保类型"].astype(str).str.strip()
for (unit, t), g in sub.groupby(["_unit", "_type"]):
cids = {config._norm_id(v) for v in g['身份证号码']}
cids.discard('')
tasks.append({"unit": unit, "type": t, "count": len(cids), "cids": cids})
tasks.sort(key=lambda x: (x['unit'], x['type']))
unit_desc = "个(类型+单位)分组"
else:
for unit, g in sub.groupby("_unit"):
cids = {config._norm_id(v) for v in g['身份证号码']}
cids.discard('')
tasks.append({"unit": unit, "type": None, "count": len(cids), "cids": cids})
tasks.sort(key=lambda x: x['unit'])
unit_desc = "个参保单位"
config.log(f"核查范围:共 {sum(t['count'] for t in tasks)} 人 / "
f"{len(tasks)} 个参保单位({status_col}={status_filter})")
f"{len(tasks)} {unit_desc}({status_col}={status_filter})")
return tasks, source_file, sheet_name
@@ -453,7 +453,7 @@ class ReviewEngine:
self.pass_status = "参保成功"
self.fail_status = "参保失败"
self.status_label = "办理状态"
self.operation_type = config.WEB_ADD_TYPE
self.operation_type = config.WEB_ADD_TYPES
else:
self.business_item = "城保参保单位人员减少"
self.pass_status = "停保成功"
@@ -461,8 +461,9 @@ class ReviewEngine:
self.status_label = config.STOP_PROCESSED_COL
self.operation_type = None
self.writeback = Writeback(kind)
self._huipan_sub = (config.OUTPUT_DIR_ADD_NEW if kind == 'add'
else config.OUTPUT_DIR_STOP)
# 回盘子目录:减员固定「停保-减员」;增员按参保类型分(新参保-增员 / 转移参保-增员)
self._huipan_subs = {"新参保": config.OUTPUT_DIR_ADD_NEW,
"转移参保": config.OUTPUT_DIR_ADD_TRANS}
# ---------------- 单个单位完整核查 ----------------
def do_unit_check(self, task):
@@ -536,7 +537,9 @@ class ReviewEngine:
if unit_full and unit_full != task['unit']:
config.log(f" 使用平台单位全称命名:{unit_full}")
config.log(" 开始回盘打印下载...")
save_dir = Path(config.replay_dir(self._huipan_sub))
sub = (self._huipan_subs.get(task.get('type'), config.OUTPUT_DIR_ADD_NEW)
if self.kind == 'add' else config.OUTPUT_DIR_STOP)
save_dir = Path(config.replay_dir(sub))
hp_file = _download_huipan(page, biz_tab, name_for_file,
self.business_item, save_dir)
config.log(f" 回盘文件已保存:{hp_file}")
@@ -2,7 +2,7 @@
"schema_version": 1,
"id": "xq0008",
"name": "重庆社保增减员办理",
"version": "1.0.0",
"version": "1.0.2",
"description": "重庆社保增减员全流程(XQ0008 名单制作 + XQ0014 系统办理/核查回盘 + XQ0015/XQ0016 告知书制作下发):目录预检、增/减员名单制作、增/减员系统办理、增/减员核查回盘、告知书制作与 OA 推送八阶段可选串行。逐参保单位读取台账账号登录重庆人社政务平台(法人用户+图形验证码识别)完成导入申报、审核结论核查与回盘表核对,回写源名单办理状态/办理停保及备注;生成三类告知书并构造 OA 工作沟通推送,全程 JSON 缓存防崩溃、结束统一落盘。",
"category": "社保",
"icon": "",
@@ -68,7 +68,8 @@ CHECK_LIMIT = None # 每次运行最多核查的单位数(No
RUN_400_CLEAR = True # 400系统错误:True=运行结束后统一清空办理状态回待办(重新走8号+增员)
# ---- 回盘打印下载与核对 ----
DISK_DIR = r"D:\资料\人资\重庆社保增减员办理\回盘打印\新参保-增员" # 回盘文件保存目录
DISK_DIR = r"D:\资料\人资\重庆社保增减员办理\回盘打印" # 回盘文件根目录(按参保类型分子目录)
HUIPAN_SUBS = {"新参保": "新参保-增员", "转移参保": "转移参保-增员"} # 参保类型 → 回盘子目录
REPLAY_PREFIX = "人员增减申请回盘表" # 保存文件名:前缀_单位_日期.xlsx
INS_STATUSES = ["养老参保状态", "失业参保状态", "医疗参保状态",
"工伤参保状态", "生育参保状态"] # 需核对的三险五项状态列
@@ -77,9 +78,10 @@ INS_OK = "参保缴费" # 正
# ==================== 2. 核查任务读取 ====================
def load_check_tasks(exclude_ids=frozenset()):
"""读取源名单,筛选 办理状态=待审核 的行,按参保单位分组。
"""读取源名单,筛选 办理状态=待审核 的行,按参保类型+参保单位分组。
返回 [{unit, count, cids(set)}];同时把源文件信息写回 import_add 全局
返回 [{unit, type, count, cids(set)}](type=参保类型,回盘文件按类型分目录存放);
同时把源文件信息写回 import_add 全局
(flush_writeback 依赖 SOURCE_FILE_USED / SOURCE_SHEET_USED)。
exclude_ids:上次运行已回写的人员身份证号(防重复核查)。
"""
@@ -94,7 +96,7 @@ def load_check_tasks(exclude_ids=frozenset()):
status = df[import_add.STATUS_COL].astype(str).str.strip()
mask = (
(df[import_add.REGION_COL].astype(str).str.strip() == import_add.REGION)
& (df[import_add.TYPE_COL].astype(str).str.strip() == import_add.OPERATION_TYPE)
& (df[import_add.TYPE_COL].astype(str).str.strip().isin(import_add.OPERATION_TYPES))
& (status == CHECK_STATUS)
)
sub = df[mask].copy()
@@ -106,16 +108,20 @@ def load_check_tasks(exclude_ids=frozenset()):
if dropped:
print(f" 已排除 {dropped} 行上次运行已回写的人员(防重复核查)")
if sub.empty:
print(f"没有筛选到数据({import_add.REGION} ∩ {import_add.OPERATION_TYPE} ∩ 办理状态={CHECK_STATUS})")
print(f"没有筛选到数据({import_add.REGION} ∩ {'/'.join(import_add.OPERATION_TYPES)} "
f"∩ 办理状态={CHECK_STATUS})")
return []
tasks = []
for unit, g in sub.groupby(sub[import_add.UNIT_COL].astype(str).str.strip()):
sub["_unit"] = sub[import_add.UNIT_COL].astype(str).str.strip()
sub["_type"] = sub[import_add.TYPE_COL].astype(str).str.strip()
for (unit, t), g in sub.groupby(["_unit", "_type"]):
cids = {import_add._norm_id(v) for v in g['身份证号码']}
cids.discard('')
tasks.append({"unit": unit, "count": len(cids), "cids": cids})
tasks.sort(key=lambda t: t['unit'])
print(f"核查范围:共 {sum(t['count'] for t in tasks)} 人 / {len(tasks)} 个参保单位(办理状态={CHECK_STATUS})")
tasks.append({"unit": unit, "type": t, "count": len(cids), "cids": cids})
tasks.sort(key=lambda x: (x['unit'], x['type']))
print(f"核查范围:共 {sum(t['count'] for t in tasks)} 人 / "
f"{len(tasks)} 个(参保类型+单位)分组(办理状态={CHECK_STATUS})")
return tasks
@@ -322,10 +328,10 @@ def _clean_cell(v):
return str(v).strip()
def _download_huipan(page, biz_tab, unit):
def _download_huipan(page, biz_tab, unit, op_type):
"""左侧菜单「回盘打印」→ 页内「回盘打印」按钮,等下载完成后重命名为规范文件名。
返回保存的文件 Path。"""
save_dir = Path(DISK_DIR)
按参保类型存入 回盘打印/<类型>-增员/ 子目录。返回保存的文件 Path。"""
save_dir = Path(DISK_DIR) / HUIPAN_SUBS.get(op_type, "新参保-增员")
save_dir.mkdir(parents=True, exist_ok=True)
target = save_dir / f"{REPLAY_PREFIX}_{unit}_{datetime.now():%Y%m%d}.xlsx"
menu_sel = ['tag:li@@text()=回盘打印', 'text=回盘打印']
@@ -439,7 +445,7 @@ def _do_huipan(page, biz_tab, task, res, unit_full="", fail_cids=()):
if unit_full and unit_full != task['unit']:
print(f" 使用平台单位全称命名:{unit_full}")
print(" 开始回盘打印下载...")
hp_file = _download_huipan(page, biz_tab, name_for_file)
hp_file = _download_huipan(page, biz_tab, name_for_file, task.get('type'))
print(f" 回盘文件已保存:{hp_file}")
hp_remarks, hp_logs = _verify_huipan(hp_file, task['cids'])
for line in hp_logs: