# -*- coding: utf-8 -*- """XQ0010 EHR系统月考勤异常处理 插件入口。 流程编排(由影刀版 attendance_abnormal_monthly.py 移植,登录态改由底座注入): 1) 会话准备:底座注入 HR session/userId → getCurUserInfo 校验(失效抛错提示重新登录); 2) 拉取基础数据:考勤异常(已确认 is_adjusted=2 / 未调整 is_adjusted=0)、全部请假、 休息日加班(类型=3,仅保留已备案 BPM_STATUS=002); 3) 保存过程数据 JSON(与报告同目录,追溯复核); 4) 依次执行检查1/2/3(检查2 休息日半天加班×打卡校验 / 检查3 整日请假×残留异常, 内部按工号实时拉取打卡/排班); 5) 多 Sheet Excel 输出(汇总 + 检查1/2/3,无数据保留表头)。 运行上下文:底座注入 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, ) class AttendanceAbnormalMonthlyPlugin(ScenePlugin): """EHR系统月考勤异常处理(需求 XQ0010)。""" id = "xq0010" name = "EHR系统月考勤异常处理" version = "1.1.0" description = ("对上月考勤异常做三重复核:检查1 已确认异常日期是否存在请假流程(提前确认后请假);" "检查2 休息日半天加班当日打卡是否按考勤班段正常打卡;" "检查3 整日请假当日是否残留考勤异常。" "结合考勤异常/请假/加班/打卡/排班五类 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 统一输出目录", }, } 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 session = config.require_session() user_id = config.require_user_id() ctx.log(f"===== 月考勤异常三查启动:月份 {month},输出目录 {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) ctx.progress(45) # ---- 步骤3:保存过程数据(45% ~ 50%) ---- process_path = save_process_data(data, save_dir, month) ctx.progress(50) # ---- 步骤4:依次执行检查1/2/3(50% ~ 95%) ---- results = run_all_checks(session, user_id, treecode, data, begin, end) ctx.progress(95) # ---- 步骤5:多 Sheet 导出(95% ~ 100%) ---- save_path = write_workbook(results, save_dir, month) ctx.progress(100) detail = {key: len(rows) for key, rows in results.items()} total = sum(detail.values()) summary = ("月考勤异常三查完成({ym}),检查1={c1} 条、检查2={c2} 条、检查3={c3} 条。" "报告:{path};过程数据:{proc}").format( ym=month, c1=detail.get("check1", 0), c2=detail.get("check2", 0), c3=detail.get("check3", 0), path=save_path, proc=process_path) return {"summary": summary, "detail": detail, "path": save_path, "process_path": process_path, "ym": month} PLUGINS.append(AttendanceAbnormalMonthlyPlugin())