Files
37duAutomation/plugins/XQ0001-0100/XQ0007 OA系统社保增减名单梳理/__init__.py
T
puddy 296e71ccc3 feat(xq0007): 新增 OA 社保增减名单梳理插件(v1.0.1)
从 OA 导出员工参保/停保申请名单(申请日期筛选、去废弃、同工号取最新),清洗后按 15 个/批与 HR 参保记录逐工号核对,输出标红核对表;支持单文件直传/多文件打包 zip、按份数留档、钉钉摘要推送。
2026-11-26 09:28:42 +08:00

120 lines
5.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""XQ0007 OA系统社保增减名单梳理 插件入口(由影刀版 workflows/XQ0001-0100 同名脚本移植)。
流程编排:
1) 登录态预检:HR 参保查询接口探测 + OA 会话校验(失效提示重新登录,不自动补登);
2) 取 OA 门户菜单 fdId(浏览器监听首页菜单请求,仅此一步用浏览器);
3) 逐类(参保 / 停保):按菜单名取 searchId → 查总数 → 导出名单 xls;
4) 清洗去重:去「废弃」、同工号保留申请日期最新一条;
5) HR 按工号分批(15 个/批)查参保记录 → 追加「社保记录查询结果」列并标红异常行;
6) 汇总文本 + 打包(单文件直传,多文件 zip)+ 可选钉钉群机器人摘要推送 + 历史留档清理。
运行上下文:platform = oa(导出主平台),permissions 额外声明 hr(参保记录核对)。
字段由 plugin.json 权威定义:save_dir / change_type / query_date / keep_files /
push_webhook / push_secret。
"""
from webhost.backend.plugins.base import ScenePlugin, PLUGINS
from . import config
from .report.social_change_report import run_social_change
def _try_session(ctx, platform):
"""取底座注入的平台会话(缺失/异常时返回 None,由业务层给「请先登录」提示)。"""
try:
return ctx.get_session(platform)
except Exception as e:
ctx.log(f"{platform.upper()} 登录态不可用:{e}", "WARN")
return None
class SocialChangeRosterPlugin(ScenePlugin):
"""OA系统社保增减名单梳理(需求 XQ0007)。"""
id = "xq0007"
name = "OA系统社保增减名单梳理"
version = "1.0.1"
description = ("从 OA 导出员工参保/停保申请名单(按申请日期筛选),清洗去重后用 HR 参保记录逐工号核对,"
"输出带「社保记录查询结果」标记的核对表(异常行标红),自动打包留档,"
"可选推送核对摘要到钉钉群机器人")
platform = "oa"
uses_month = False
capabilities = ["xq0007"]
permissions = {"platforms": ["oa", "hr"]}
fields = {
"save_dir": {
"type": "string", "title": "输出目录",
"default": r"D:\资料\人资\员工社保增减名单",
"description": "核对表与打包产物输出目录;文件名带运行时间戳,历史留档不覆盖",
},
"change_type": {
"type": "string", "title": "变更类型", "default": "全部",
"enum": ["全部", "参保", "停保"],
"description": "全部=参保表+停保表都梳理;也可只跑其中一类",
},
"query_date": {
"type": "string", "title": "查询起始日期", "default": "",
"description": "按 OA 申请日期筛选(≥ 该日期);留空 = 当月 1 号,补跑历史月份时手填 YYYY-MM-DD",
},
"keep_files": {
"type": "integer", "title": "结果留档份数", "default": 30,
"description": "输出目录最多保留最近 N 份本插件产物(含本次);0 = 不清理",
},
"push_webhook": {
"type": "string", "title": "钉钉群机器人 Webhook", "default": "",
"description": "留空=只导出不推送;填写后推送核对摘要(文本,附件需到输出目录自取)",
},
"push_secret": {
"type": "string", "title": "钉钉机器人加签密钥", "format": "password", "default": "",
"description": "机器人安全设置为「加签」时填写,未配置加签则留空",
},
}
def run(self, fields: dict, ctx):
# ---- 注入运行上下文:日志 / 进度 / 登录态 ----
config.set_log(ctx.log)
config.set_progress(ctx.progress)
config.set_oa_session(_try_session(ctx, "oa"))
config.set_hr_session(_try_session(ctx, "hr"))
save_dir = (fields.get("save_dir") or "").strip().strip('"') or config.DEFAULT_SAVE_DIR
config.set_save_dir(save_dir)
config.set_keep_files(fields.get("keep_files"))
change_type = (fields.get("change_type") or "全部").strip()
if change_type not in config.CHANGE_TYPES:
change_type = "全部"
query_date = (fields.get("query_date") or "").strip()
push_webhook = (fields.get("push_webhook") or "").strip()
push_secret = fields.get("push_secret") or ""
ctx.log(f"===== OA系统社保增减名单梳理启动:输出目录 {config.get_save_dir()}"
f"(变更类型 {change_type},留档 {config.get_keep_files()} 份)=====", "INFO")
result = run_social_change(
save_dir=save_dir,
change_type=change_type,
query_date=query_date,
push_webhook=push_webhook,
push_secret=push_secret,
keep_files=config.get_keep_files(),
progress=ctx.progress,
)
items = result["items"]
parts = [f"{it['label']}表 {it['total']} 条(异常 {len(it['abnormal'])} 条)" for it in items]
summary = "社保增减名单核对完成:" + ",".join(parts) + f"。结果文件:{result['path']}"
if result["notes"]:
summary += "\n注意事项:\n- " + "\n- ".join(result["notes"])
push = result["push"]
detail = {it["label"] + "表": {"总数": it["total"], "异常": len(it["abnormal"]),
"文件": it["path"] or "(无)"} for it in items}
detail["清理历史留档"] = result["cleaned"]
detail["推送"] = "成功" if push.get("success") else (push.get("message") or "未推送")
return {"summary": summary, "detail": detail, "path": result["path"],
"notes": result["notes"]}
PLUGINS.append(SocialChangeRosterPlugin())