# -*- coding: utf-8 -*- """XQ0010 EHR系统月考勤异常处理 插件入口。 流程编排(由影刀版 attendance_abnormal_monthly.py 移植,登录态改由底座注入): 1) 会话准备:底座注入 HR session/userId → getCurUserInfo 校验(失效抛错提示重新登录); 2) 拉取基础数据:考勤异常(已确认 is_adjusted=2 / 未调整 is_adjusted=0)、全部请假、 休息日加班(类型=3)与延时加班(类型=1),仅保留已备案 BPM_STATUS=002; 3) 保存过程数据 JSON(与报告同目录,追溯复核); 4) 按勾选执行检查1/2/3/4(检查2 休息日半天加班×打卡校验 / 检查3 整日请假×残留异常, 内部按工号实时拉取打卡/排班;检查4 延时加班系统判断时间×加班时间核对); 5) 多 Sheet Excel 输出(汇总 + 勾选的检查,无数据保留表头)。 运行上下文:底座注入 HR 会话与 userId(config 全局钩子),platform = hr,uses_month = True (前端页眉月份选择器经 payload.ref_month 注入)。 """ from webhost.backend.plugins.base import ScenePlugin, PLUGINS from . import config from .data import hr_api from .report.abnormal_report import ( collect_data, save_process_data, run_all_checks, write_workbook, resolve_month, month_begin_end, normalize_checks, CHECK_META, ) class AttendanceAbnormalMonthlyPlugin(ScenePlugin): """EHR系统月考勤异常处理(需求 XQ0010)。""" id = "xq0010" name = "EHR系统月考勤异常处理" version = "1.2.12" description = ("对上月考勤异常做四重复核:检查1 已确认异常日期是否存在请假流程(提前确认后请假);" "检查2 休息日半天加班当日打卡是否按考勤班段正常打卡;" "检查3 整日请假当日是否残留考勤异常;" "检查4 延时加班的系统判断开始/结束时间与加班开始/结束时间是否一致。" "结合考勤异常/请假/加班/打卡/排班五类 HR 接口,输出多 Sheet Excel 报告。") platform = "hr" uses_month = True capabilities = ["xq0010"] permissions = {"platforms": ["hr"]} fields = { "ref_month": { "type": "string", "title": "执行月份", "default": "", "description": "留空=上月;格式 YYYY-MM", }, "save_dir": { "type": "string", "title": "输出目录", "default": r"D:\资料\人资\考勤异常", "description": "多 Sheet 报告与过程数据 JSON 统一输出目录", }, "checks": { "type": "array", "title": "检查项(可多选)", "default": ["检查1", "检查2", "检查3", "检查4"], "description": "勾选需要执行的检查项;留空=全部执行", }, } 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 = resolve_month(fields.get("ref_month") or fields.get("month") or "") save_dir = (fields.get("save_dir") or "").strip() or config.DEFAULT_SAVE_DIR checks = normalize_checks(fields.get("checks")) session = config.require_session() user_id = config.require_user_id() ctx.log(f"===== 月考勤异常核对启动:月份 {month},检查项 " f"{'、'.join(checks)},输出目录 {save_dir} =====", "INFO") # ---- 步骤1:会话校验(5%) ---- ctx.progress(5) session, user_id, treecode = hr_api.validate_session(session, user_id) ctx.progress(8) # ---- 步骤2:按勾选项拉取基础数据(8% ~ 45%) ---- begin, end = month_begin_end(month) data = collect_data(session, user_id, treecode, begin, end, checks) ctx.progress(45) # ---- 步骤3:保存过程数据(45% ~ 50%) ---- process_path = save_process_data(data, save_dir, month) ctx.progress(50) # ---- 步骤4:依次执行勾选的检查(50% ~ 95%) ---- results = run_all_checks(session, user_id, treecode, data, begin, end, checks) ctx.progress(95) # ---- 步骤5:多 Sheet 导出(95% ~ 100%) ---- save_path = write_workbook(results, save_dir, month, checks) ctx.progress(100) detail = {key: len(rows) for key, rows in results.items()} summary = ("月考勤异常核对完成({ym}),{items}。报告:{path};过程数据:{proc}").format( ym=month, items="、".join(f"{name}={detail.get(key, 0)} 条" for name, key in CHECK_META if key in detail), path=save_path, proc=process_path) return {"summary": summary, "detail": detail, "path": save_path, "process_path": process_path, "ym": month} PLUGINS.append(AttendanceAbnormalMonthlyPlugin())