Files
37duAutomation/plugins/XQ0001-0100/XQ0011 考勤月报封存检查/__init__.py
T
puddy d1af551eac chore: 清理废弃插件与冗余文档,重构项目目录结构
1.  删除旧版xq0031_xq0032插件的冗余UI源码与配置文件
2.  迁移并标准化XQ0001-0100系列需求的插件、文档与工作流目录
3.  清理过期的需求列表、评分文档与流程底稿
4.  更新.gitignore匹配规则,适配新的目录结构
2026-09-21 16:59:05 +08:00

114 lines
5.1 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 -*-
"""XQ0011 考勤月报封存检查 插件入口。
流程编排:
1) 封存数据导出与预处理(全集团 → 白名单单位 → 学校剔除 → 固定路径封存表);
2) 花名册导出(TTL 15 分钟缓存复用)、调动台账导出(自动);
3) 依次执行检查1~6(在职天数/出勤排休/封存最新值/全勤验证/未封存/延时加班);
4) 单工作簿输出(汇总 + 检查1~6 共 7 个 sheet)。
运行上下文:底座注入 HR 会话与 userId(config 全局钩子),平台 = hr,uses_month = True
(前端页眉月份选择器经 payload.ref_month 注入)。
"""
import os
from webhost.backend.plugins.base import ScenePlugin, PLUGINS
from . import config
from .data.seal_data_export import export_seal_data
from .data.roster_export_api import export_roster
from .data.transfer_roster_export_api import export_transfer_roster
from .report.monthly_report_check import run_all_checks, write_workbook, _normalize_month
class KqSealCheckPlugin(ScenePlugin):
"""考勤月报封存检查(需求 XQ0011)。"""
id = "xq0011"
name = "考勤月报封存检查"
version = "1.0.0"
description = ("考勤月报封存后自动检查:拉取当月全集团封存数据并按白名单单位预处理,"
"自动导出花名册/调动台账,依次执行 6 项检查(在职天数排班/出勤及排休/"
"封存最新值/全勤验证/未封存名单/延时加班),输出单工作簿异常名单")
platform = "hr"
uses_month = True
capabilities = ["xq0011"]
permissions = {"platforms": ["hr"]}
fields = {
"save_dir": {
"type": "string", "title": "输出目录",
"default": r"D:\资料\人资\考勤月报封存检查",
"description": "封存表/花名册/调动台账/汇总工作簿统一输出目录",
},
"roster_path": {
"type": "string", "title": "花名册路径", "default": "",
"description": "留空=输出目录/员工花名册.xlsx(自动导出,15 分钟内复用)",
},
"transfer_path": {
"type": "string", "title": "调动台账路径", "default": "",
"description": "留空=输出目录/调动台账.xlsx(自动导出,15 分钟内复用)",
},
}
def run(self, fields: dict, ctx):
# ---- 注入运行上下文:日志 / HR 会话 / userId ----
config.set_log(ctx.log)
config.set_session(ctx.get_session("hr"))
config.set_user_id(ctx.get_user_id("hr"))
month = _normalize_month(fields.get("ref_month") or fields.get("month") or "")
save_dir = (fields.get("save_dir") or "").strip() or config.DEFAULT_SAVE_DIR
roster_path = (fields.get("roster_path") or "").strip() or os.path.join(save_dir, "员工花名册.xlsx")
transfer_path = (fields.get("transfer_path") or "").strip() or os.path.join(save_dir, "调动台账.xlsx")
config.set_roster_path(roster_path)
session = config.get_session()
ctx.log(f"===== 考勤月报封存检查启动:月份 {month},输出目录 {save_dir} =====", "INFO")
notes: list = []
# ---- 步骤1:封存数据导出与预处理(5% ~ 30%) ----
ctx.progress(5)
export_seal_data(month, save_dir)
ctx.progress(30)
# ---- 步骤2:花名册导出(TTL 15 分钟缓存复用,30% ~ 45%) ----
ctx.progress(30)
try:
export_roster(output_path=roster_path,
download_dir=os.path.join(config.CACHE_DIR, "roster_tmp"),
session=session)
except Exception as e:
notes.append(f"花名册导出失败(检查5/6 与部门回填将受影响):{e}")
ctx.log(f"花名册导出失败:{e}", "WARN")
ctx.progress(45)
# ---- 步骤3:调动台账导出(45% ~ 55%) ----
try:
export_transfer_roster(output_path=transfer_path, session=session)
except Exception as e:
notes.append(f"调动台账导出失败(检查4 将受影响):{e}")
ctx.log(f"调动台账导出失败:{e}", "WARN")
ctx.progress(55)
# ---- 步骤4:依次执行检查1~6(55% ~ 90%) ----
result = run_all_checks(month, save_dir, roster_path, transfer_path)
ctx.progress(90)
# ---- 步骤5:单工作簿输出(90% ~ 100%) ----
save_path = write_workbook(result, save_dir)
ctx.progress(100)
detail = {it["no"]: len(it["rows"]) for it in result["results"]}
summary = ("考勤月报封存检查完成({ym}),异常合计 {total} 人:{detail}。"
"汇总工作簿:{path}").format(
ym=result["ym"], total=result["total"],
detail="、".join(f"{k}:{v}" for k, v in detail.items()),
path=save_path)
if notes:
summary += "\n注意事项:\n- " + "\n- ".join(notes)
return {"summary": summary, "notes": notes,
"detail": detail, "path": save_path, "ym": result["ym"]}
PLUGINS.append(KqSealCheckPlugin())