# -*- coding: utf-8 -*- """减员名单制作模式(sb_person_change 插件)。 自 workflows/XQ0008 generate_stop.py 迁移:读取【停保名单】sheet,筛选 区域=重庆, 按参保单位分组复制《减员模版.xls》(保留下拉字典),逐单位生成《XX减员导入名单.xls》。 填写标准:减少时间=当天、减少原因=在职人员主动解除劳动合同、 五个险种减少标志=1 减少、失业原因=3 劳动者自愿辞职。 """ from datetime import datetime from . import config from . import excelio from . import source def _log(msg): config.log(msg) def run(ctx): """主流程:读【停保名单】→ 筛选重庆 → 按单位生成减员导入名单。""" ctx.progress(5) source_file, df_filtered = source.load_stop_rows() if df_filtered.empty: ctx.progress(100) return {"summary": f"无【{config.REGION}】区域停保数据", "rows": [], "notes": []} config.check_not_locked(source_file) _log(f"共找到 {len(df_filtered)} 条 {config.REGION} 区域停保记录") today = datetime.now() _log(f"制作日期:{today.strftime('%Y-%m-%d')}(减少时间 = 当天)") cm = config.COLUMN_MAP_STOP template_file = excelio.find_template_file(config.STOP_TEMPLATE_FILE) output_dir = excelio.get_output_dir_stop() _log(f"输出目录:{output_dir}") produced = [] for group_key, group in df_filtered.groupby(config.GROUP_COL_STOP): _log(f" 正在处理:单位【{group_key}】,共 {len(group)} 人") first_row = group.iloc[0] unit_no = first_row[cm['单位社保号']] # 单位社保号 → B1 unit_name = first_row[cm['单位名称']] # 参保单位 → D1 records = [] for _, row in group.iterrows(): rec = {'减少时间': today} for tpl_col in config.TPL_COLS_STOP: if tpl_col == '减少时间': continue if tpl_col in cm: rec[tpl_col] = config._clean_value(row[cm[tpl_col]]) else: rec[tpl_col] = config.DEFAULT_VALUES_STOP[tpl_col] records.append(rec) output_path = f"{output_dir}\\{config._safe_name(group_key)}减员导入名单.xls" excelio.write_template(template_file, output_path, unit_no, unit_name, records, config.TPL_COLS_STOP, config.DATE_COLS_STOP) _log(f" 已生成:{output_path}") produced.append({"unit": str(group_key), "count": len(group), "path": output_path}) _log(f"所有停保导入名单生成完成!共 {len(produced)} 个单位") ctx.progress(100) total = sum(p["count"] for p in produced) return {"summary": f"减员名单制作:{len(produced)} 个单位 / {total} 人", "rows": produced, "notes": []}