From 02de02d063a84d96cb996e51fd73a7e87c0c25bf Mon Sep 17 00:00:00 2001 From: spudding <1115683088@qq.com> Date: Fri, 13 Nov 2026 13:53:31 +0800 Subject: [PATCH] =?UTF-8?q?fix(plugin):=20XQ0004=201.2.0=20=E5=BD=93?= =?UTF-8?q?=E5=A4=A9=E5=8A=A0=E7=8F=AD=E5=8D=95=E8=B7=B3=E8=BF=87=E4=B8=8D?= =?UTF-8?q?=E5=AE=A1=E6=A0=B8=EF=BC=8C=E5=BE=85=E6=89=93=E5=8D=A1=E9=BD=90?= =?UTF-8?q?=E5=85=A8=E5=90=8E=E5=86=8D=E6=AC=A1=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XQ0004 EHR系统加班流程审核/__init__.py | 19 ++++++- .../XQ0004 EHR系统加班流程审核/_pack.py | 53 +++++++++++++++++++ .../logic/overtime_rules.py | 28 ++++++++++ .../XQ0004 EHR系统加班流程审核/plugin.json | 2 +- .../report/overtime_report.py | 8 +-- 5 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/_pack.py diff --git a/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/__init__.py b/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/__init__.py index 2fddd22..d5f457a 100644 --- a/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/__init__.py +++ b/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/__init__.py @@ -27,7 +27,7 @@ class OvertimeApprovalPlugin(ScenePlugin): id = "xq0004" name = "EHR系统加班流程审核" - version = "1.1.1" + version = "1.2.0" description = ("自动审核 EHR 加班待办:拉取待办与加班表单,按加班类型(延时/法定假日/休息日)" "校验加班日期、时长、排班与打卡区间及弹性到岗兑换;校验通过自动提交审批," "并生成审批报告与钉钉群推送。") @@ -100,6 +100,7 @@ class OvertimeApprovalPlugin(ScenePlugin): browser = None results = [] + skipped = [] try: if docs: for idx, doc in enumerate(docs, 1): @@ -107,6 +108,14 @@ class OvertimeApprovalPlugin(ScenePlugin): detail = hr_api.fetch_doc_detail(doc) result = overtime_rules.validate_doc(detail, session) + # 当天发起当天的加班:本次跳过不审核(不提交、不入报告/推送),后续再审核 + if result.get("decision") == "跳过": + skipped.append(result) + ctx.log(f"已跳过 {idx}/{len(docs)}: {result.get('creator')} - " + f"{result.get('title')} -> {result.get('note')}", "INFO") + ctx.progress(15 + int(75 * idx / len(docs))) + continue + if approve_enabled and result.get("decision") == "通过": if browser is None: browser = hr_browser.build_browser(session) @@ -152,6 +161,9 @@ class OvertimeApprovalPlugin(ScenePlugin): push_message = "" if push_enabled: push_items = overtime_report.build_push_summary(results, subject) + if not push_items and skipped: + push_items = [{"text": f"本次跳过 {len(skipped)} 条当天加班单据(当天打卡未完成)," + f"待打卡完成后再次审核"}] if not push_items: push_items = [{"text": f"暂无待审批的{subject}单据"}] push_res = dingtalk_robot.main( @@ -169,12 +181,15 @@ class OvertimeApprovalPlugin(ScenePlugin): "overdue": sum(1 for r in results if r.get("decision") == "超期"), "abnormal": sum(1 for r in results if r.get("decision") == "异常"), "failed": sum(1 for r in results if r.get("decision") == "失败"), + "skipped": len(skipped), } if not docs: summary = f"暂无待审批的{subject}单据;报告:{report_path}" else: summary = (f"{subject}审批完成,共 {counts['total']} 单:通过 {counts['passed']}," - f"校验不通过未处理 {counts['rejected']},人工复核 {counts['review']}") + f"校验不通过未处理 {counts['rejected']},人工复核 {counts['review']}") + if counts["skipped"]: + summary += f",当天加班跳过 {counts['skipped']}" if counts["overdue"]: summary += f",超期待人资处理 {counts['overdue']}" if counts["abnormal"]: diff --git a/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/_pack.py b/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/_pack.py new file mode 100644 index 0000000..6738cab --- /dev/null +++ b/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/_pack.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +"""XQ0004 EHR系统加班流程审核 插件打包脚本(统一规范版)。 + +打包产物统一输出到仓库根 dist-plugin/_v<版本>.zip(目录不入库), +zip 根含 plugin.json,可被 agent_cli publish 直接发布。 +详见 docs/插件/插件开发规范.md 与 docs/插件/发版规范.md。 + +用法(任意 cwd 均可): + d:\\work\\code\\37duAutomation\\.venv\\Scripts\\python.exe plugins\\XQ0001-0100\\XQ0004 EHR系统加班流程审核\\_pack.py +随后发布: + .venv\\Scripts\\python.exe tools\\agent_cli.py publish \ + dist-plugin\\xq0004_v<版本>.zip --id xq0004 --version <版本> +""" +import json +import sys +import zipfile +from pathlib import Path + +_HERE = Path(__file__).resolve().parent +# 仓库根 = plugins/XQ0001-0100/<插件目录>/ 的 parents[2],统一出包位置 +_REPO_ROOT = _HERE.parents[2] +_OUT_DIR = _REPO_ROOT / "dist-plugin" + +# 排除项:打包脚本自身 / 前端源码与依赖 / 缓存 / 调试文件 +_EXCLUDE_DIRS = {"ui-src", "__pycache__", ".git", ".idea", "debug", ".sessions"} +_EXCLUDE_FILES = {"_pack.py"} +_EXCLUDE_SUFFIXES = (".pyc", ".pyo") + + +def main(): + manifest = json.loads((_HERE / "plugin.json").read_text(encoding="utf-8")) + pid = manifest["id"] + ver = manifest["version"] + # 带 UI 插件必须已构建前端产物(ui/ 由底座 /pui// 托管) + if manifest.get("ui") and not (_HERE / "ui" / "index.html").is_file(): + sys.exit(f"插件 {pid} 声明 ui=true 但缺少 ui/index.html:请先在 ui-src 下执行 npm install && npm run build") + _OUT_DIR.mkdir(exist_ok=True) + out = _OUT_DIR / f"{pid}_v{ver}.zip" + count = 0 + with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED) as zf: + for p in sorted(_HERE.rglob("*")): + rel = p.relative_to(_HERE) + if set(rel.parts) & _EXCLUDE_DIRS or p.name in _EXCLUDE_FILES \ + or p.suffix in _EXCLUDE_SUFFIXES: + continue + if p.is_file(): + zf.write(p, str(rel)) + count += 1 + print(f"已打包: {out}({count} 个文件,{out.stat().st_size / 1024:.0f} KB)") + + +if __name__ == "__main__": + main() diff --git a/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/logic/overtime_rules.py b/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/logic/overtime_rules.py index 5a71ba5..b662b48 100644 --- a/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/logic/overtime_rules.py +++ b/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/logic/overtime_rules.py @@ -526,6 +526,21 @@ def _is_review_period_exempt(post_name): return bool(name) and any(kw in name for kw in OT_REVIEW_EXEMPT_POST_KEYWORDS) +def _is_same_day_ot(ot_date, today=None): + """加班日期是否为当天。 + + 当天发起当天加班时下班卡还没打,打卡校验必然不通过,本次直接跳过不审核, + 等次日打卡齐全后再由后续运行审核。 + """ + if not ot_date: + return False + try: + ot_day = datetime.strptime(str(ot_date).strip()[:10], "%Y-%m-%d").date() + except (TypeError, ValueError): + return False + return ot_day == (today or datetime.now()).date() + + def check_review_period(ot_date, post_name=None, today=None): """ 加班日期有效性前置校验,返回 (是否可审核, 原因)。 @@ -581,6 +596,19 @@ def validate_doc(doc, session): staff_id = overtime_info.get("加班人员ID") ot_date = overtime_info.get("加班日期") + # 当天发起当天的加班:下班卡尚未打,打卡校验必然不通过; + # 本次直接跳过不审核(不提交、不推送),等次日打卡齐全后再由后续运行审核 + if _is_same_day_ot(ot_date): + return { + "title": doc.get("title", ""), + "creator": doc.get("creator", ""), + "time": doc.get("time", ""), + "detail_url": doc.get("detail_url", ""), + "decision": "跳过", + "note": f"加班日期({ot_date})为当天,本次跳过审核,待打卡完成后再次审核", + "overtime_info": overtime_info, + } + attendance_info = _check_attendance(session, staff_id, ot_date) punch_info = _check_punch_records(session, staff_id, ot_date) overtime_info.update(attendance_info) diff --git a/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/plugin.json b/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/plugin.json index ba04d9e..c875819 100644 --- a/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/plugin.json +++ b/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/plugin.json @@ -2,7 +2,7 @@ "schema_version": 1, "id": "xq0004", "name": "EHR系统加班流程审核", - "version": "1.1.1", + "version": "1.2.0", "description": "自动审核 EHR 加班待办:拉取待办与加班表单,按加班类型(延时/法定假日/休息日)校验加班日期、时长、排班与打卡区间及弹性到岗兑换;校验通过自动提交审批,并生成审批报告与钉钉群推送。", "category": "人事考勤", "icon": "", diff --git a/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/report/overtime_report.py b/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/report/overtime_report.py index 7637e0d..ac97abe 100644 --- a/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/report/overtime_report.py +++ b/plugins/XQ0001-0100/XQ0004 EHR系统加班流程审核/report/overtime_report.py @@ -168,12 +168,8 @@ def _format_overtime_block(r): date = info.get("加班日期") if date: lines.append(f"> 加班日期:{date}") - start = info.get("加班开始时间") - end = info.get("加班结束时间") - if start or end: - lines.append(f"> 加班时段:{start or ''} ~ {end or ''}") - for key, label in [("加班时长(小时)", "加班时长"), ("加班天数(天)", "加班天数"), - ("系统判定加班时间", "系统判定时间"), + # 推送不展示:加班时段 / 加班时长 / 系统判定时间(群里只需关键结论与需人工处理明细) + for key, label in [("加班天数(天)", "加班天数"), ("计算加班时长(小时)", "计算时长"), ("有效加班时长(小时)", "有效时长"), ("弹性扣减(小时)", "弹性扣减"),