Files
37duAutomation/plugins/sb_person_change/mode_make_stop.py
T
puddy 1e533dd1b3 refactor: 完成项目目录重构与代码迁移
本次提交完成了整体项目的目录梳理与代码迁移:
1.  将根级controlplane、webhost等目录的代码迁移至desktop/对应子目录,统一桌面端架构
2.  移动并整理了插件目录结构,将插件统一放入根级plugins/
3.  调整了前端项目的路径与配置,统一前后端开发构建流程
4.  清理了废弃的旧版app/目录与冗余的构建中间文件
5.  更新了.gitignore与README.md,适配新的项目结构
2026-09-14 17:46:09 +08:00

67 lines
2.8 KiB
Python

# -*- 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": []}