feat: 新增EHR系统花名册检查插件及多个插件版本更新

This commit is contained in:
2026-10-30 16:38:18 +08:00
parent 210de5b68b
commit 62de24eb4d
93 changed files with 9195 additions and 2277 deletions
@@ -44,16 +44,19 @@ def _import_issues(import_results):
def _build_messages(total, filtered, scheduled, import_on, import_lines,
import_results, notes):
import_results, notes, only_import=False):
"""构建待推送消息列表(汇总 + 异常名单),块格式交由 dingtalk_robot 分批发送。"""
issues = _import_issues(import_results)
issue_total = sum(len(v) for v in issues.values())
# ---- 1. 汇总消息 ----
summary_lines = [
"**处理类别 {} 个:筛选复制成功 {} 个、调度成功 {} 个**".format(
total, filtered, scheduled),
]
if only_import:
summary_lines = ["**仅导入模式:处理类别 {} 个(未执行筛选复制/名额调度)**".format(total)]
else:
summary_lines = [
"**处理类别 {} 个:筛选复制成功 {} 个、调度成功 {} 个**".format(
total, filtered, scheduled),
]
if import_on:
summary_lines.extend(import_lines or ["HR 导入未执行(登录态缺失或整体失败,详见注意事项与日志)"])
else:
@@ -98,7 +101,7 @@ def _build_messages(total, filtered, scheduled, import_on, import_lines,
def push_run_result(total, filtered, scheduled, import_on, import_lines,
import_results, notes):
import_results, notes, only_import=False):
"""把本次运行结果推送到钉钉群(环境取 config.DINGTALK_ENV),失败不影响主流程。
Args:
@@ -107,10 +110,12 @@ def push_run_result(total, filtered, scheduled, import_on, import_lines,
import_lines: hr_import.summarize_results 的可读文本行(未执行时传 [])
import_results: hr_import.import_all 的逐单元结果(未执行时传 [])
notes: 本次运行的注意事项列表
only_import: 仅导入模式(汇总文案不展示筛选复制/调度数量)
"""
try:
messages = _build_messages(total, filtered, scheduled, import_on,
import_lines, import_results, notes)
import_lines, import_results, notes,
only_import=only_import)
result = dingtalk_robot.main(messages, env=DINGTALK_ENV)
if result.get("success"):
log(f"钉钉群通知已推送:{result.get('message', '')}", "INFO")
@@ -4,7 +4,8 @@ export_change_sheet.py 合并移植)。
包含:
- output_results:更新「手动维护-在参名单」(第17行起B~N列)+ 精细更新「变更清单」
(清空并重写 B/M/N/四级部门/P~S 列)+ 姓名修正记录 + 备份新在参名单;
(清空并重写 B/M/N/P~S 列,M列备注=「新增」标记本次全新名额)+ 姓名修正记录
+ 备份新在参名单;
- export_add_sub_import:按「人+投保方案」记录级集合差生成 增员/减员 导入文件;
- export_change_sheet_workbook:将类别目标文件「变更清单」sheet 复制为独立工作簿
(值+样式,公式转缓存结果,避免 #REF!)。
@@ -32,12 +33,14 @@ from ..logic.schedule import _find_special_slots, scheme_with_suffix
def output_results(final_records, change_log, reused_source_employees, biz_df,
in_param_df, column_names, target_file, output_backup,
change_sheet_name, change_sheet_prefix, in_param_sheet,
name_corrections=None):
name_corrections=None, skipped_downgrades=None):
"""输出四部分内容:
1. 更新"手动维护-在参名单"(第17行起B~N列)
2. 精细更新"变更清单"(仅清空并重写B/M/N/P~S列数据)
2. 精细更新"变更清单"(仅清空并重写B/M/N/P~S列数据;M列备注标记「新增」= 本次全新名额)
3. 备份新在参名单
4. 姓名修正记录写入变更清单(批改标志=修改,备注写明「修正姓名,原xx修正为xx」)
skipped_downgrades:降档但目标档无空闲名额、本次不处理的人员(在参名单保留原行不变)
"""
# ---------- 1. 构建需要清空的员工ID集合 ----------
emp_ids_to_clear = set()
@@ -71,10 +74,20 @@ def output_results(final_records, change_log, reused_source_employees, biz_df,
# ---------- 2. 保留的行 ----------
handle_col = column_names[17]
emp_id_col = column_names[10]
# 降档名额不足被跳过的人员(R列多为「档次替换」):本次不处理,原样保留在参名单
skipped_ids = set()
for _s in (skipped_downgrades or []):
_sid = _s.get("证件号")
if _sid is not None and not pd.isna(_sid):
skipped_ids.add(_sid)
if skipped_ids:
logger.warning("以下 %d 人降档因目标档无空闲名额本次不处理,在参名单保持原方案:%s",
len(skipped_ids), " / ".join(str(x) for x in skipped_ids))
keep_mask = (
((in_param_df[handle_col] == "无需") & (~in_param_df[emp_id_col].isin(emp_ids_to_clear))) |
((in_param_df[handle_col].isin(["离职减少", "参保减少"])) & (~in_param_df[emp_id_col].isin(reused_source_employees))) |
(in_param_df[emp_id_col].isin(special_source_ids)) # 特殊情况源员工保留(改M列为老员工旧方案)
(in_param_df[emp_id_col].isin(special_source_ids)) | # 特殊情况源员工保留(改M列为老员工旧方案)
(in_param_df[emp_id_col].isin(skipped_ids)) # 降档跳过:保持原方案不动
)
kept_df = in_param_df[keep_mask].copy()
kept_emp_ids = set(kept_df[emp_id_col].tolist())
@@ -318,7 +331,9 @@ def output_results(final_records, change_log, reused_source_employees, biz_df,
else:
ws_change = wb[change_sheet_name]
# ---------- 定位 O列(费用会馆/四级部门列)----------
# ---------- 定位 O列(新增费用会馆列,仅用于清空历史值)----------
# 该列已不再由插件填写(原先把花名册四级部门写进来,现改为 M列备注标「新增」),
# 但变更清单多由历史模板复制而来,需清掉上一版遗留的四级部门值。
# 表头名不固定(如「新增费用会馆\n(自留后续划成本用)」),按"包含「费用会馆」"模糊匹配
DEPT_COL_MARK = "费用会馆"
dept_col = 15
@@ -327,19 +342,16 @@ def output_results(final_records, change_log, reused_source_employees, biz_df,
for _row in (1, 2)):
dept_col = _col
break
logger.info("变更清单四级部门列定位:%s(第%d列)", dept_col, dept_col)
logger.info("变更清单费用会馆列定位:第%d列(不再填写,仅清空历史值)", dept_col)
# 花名册表四级部门列名(按"包含「四级部门」"模糊匹配表头,兜底固定名)
biz_dept_col = next((c for c in biz_df.columns if "四级部门" in str(c)), "四级部门")
# 清空B列、M列备注、N列、四级部门列、P~S列 从第3行开始
# 清空B列、M列备注、N列、费用会馆列、P~S列 从第3行开始
max_row_change = ws_change.max_row
if max_row_change >= 3:
for row in range(3, max_row_change + 1):
ws_change.cell(row=row, column=2).value = None # B列
ws_change.cell(row=row, column=13).value = None # M列 备注
ws_change.cell(row=row, column=14).value = None # N列
ws_change.cell(row=row, column=dept_col).value = None # 四级部门列
ws_change.cell(row=row, column=dept_col).value = None # 新增费用会馆列(历史值)
for col in range(16, 20): # P~S列
ws_change.cell(row=row, column=col).value = None
@@ -373,6 +385,11 @@ def output_results(final_records, change_log, reused_source_employees, biz_df,
_sid = _rec.get("来源员工ID")
if _sid is not None and not pd.isna(_sid) and str(_sid).strip():
reused_by_others.add(_sid)
def _new_slot_remark(rec):
"""本次拿到全新名额(名额来源=全新新增)→ M列备注「新增」,用于成本归集。"""
return "新增" if rec.get("名额来源") == "全新新增" else None
for rec in final_records:
emp_id = rec["证件号"]
if emp_id in biz_dict:
@@ -393,32 +410,22 @@ def output_results(final_records, change_log, reused_source_employees, biz_df,
if not row_match.empty:
old_scheme = row_match.iloc[0].iloc[12]
if pure_self_replace:
remark = None
if old_scheme is not None and str(old_scheme).strip() != "" and \
scheme is not None and str(scheme).strip() != "":
remark = f"由{old_scheme}替换为{scheme}"
# 删除自己的旧名额 + 自己拿到全新名额:备注同样标「新增」
records.append({"op": "修改", "name": name, "emp_id": emp_id,
"category": category, "scheme": scheme, "remark": remark})
"category": category, "scheme": scheme,
"remark": _new_slot_remark(rec)})
else:
# 涉及其他人的档次替换:正常两条(删除旧方案 + 增加新方案)
records.append({"op": "删除", "name": name, "emp_id": emp_id,
"category": category, "scheme": old_scheme})
records.append({"op": "增加", "name": name, "emp_id": emp_id,
"category": category, "scheme": scheme})
"category": category, "scheme": scheme,
"remark": _new_slot_remark(rec)})
else:
# 新参保人员:仅「全新新增」名额(纯新增,当日名额净增加)在 O列 填四级部门
new_rec = {"op": "增加", "name": name, "emp_id": emp_id,
"category": category, "scheme": scheme}
if rec.get("名额来源") == "全新新增":
biz_row_dept = biz_dict.get(emp_id)
dept = clean_text(biz_row_dept.get(biz_dept_col)) if biz_row_dept is not None else None
if dept is None:
# 四级部门为空:回退填所属单位,并记录日志供人工核对
dept = clean_text(biz_row_dept.get("所属单位")) if biz_row_dept is not None else None
logger.warning("员工 %s(%s) 花名册四级部门为空,O列回退填所属单位:%s",
name, emp_id, dept)
new_rec["dept"] = dept
records.append(new_rec)
# 新参保人员:全新新增名额的「增加」行 M列备注「新增」
records.append({"op": "增加", "name": name, "emp_id": emp_id,
"category": category, "scheme": scheme,
"remark": _new_slot_remark(rec)})
# 写入新记录
current_row_change = 3
@@ -434,9 +441,6 @@ def output_results(final_records, change_log, reused_source_employees, biz_df,
ws_change.cell(row=current_row_change, column=2).value = op # B列
ws_change.cell(row=current_row_change, column=13).value = rec.get("remark") # M列 备注
ws_change.cell(row=current_row_change, column=14).value = today_date() # N列
# 四级部门列:仅纯新增名额(全新新增)的「增加」记录才填
if op == "增加" and rec.get("dept") is not None:
ws_change.cell(row=current_row_change, column=dept_col).value = rec.get("dept")
ws_change.cell(row=current_row_change, column=16).value = name # P列
ws_change.cell(row=current_row_change, column=17).value = emp_id # Q列
ws_change.cell(row=current_row_change, column=18).value = category # R列