refactor: 重构项目代码结构与依赖管理

1.  **依赖与导入路径修正
    - 移除所有本地sys.path插入,统一使用绝对包导入
    - 修复logger导入路径,统一从app.utils导入
    - 重构intelligent_retry.py移除冗余导入
    - 统一hrbp各模块的导入路径

2.  **项目配置与构建
    - 新增pyproject.toml配置文件,规范项目元数据与依赖声明
    - 更新requirements.txt新增pyautogui、pywin32、pyperclip依赖

3.  **业务模块重构
    - 重构请假/加班审批模块的导入路径与内部逻辑
    - 重命名审批结果描述(将"不通过"改为"驳回")
    - 统一代码中的箭头符号(将→改为->)
    - 新增请假表单解析模块、钉钉通知模块
    - 重构加班/请假校验模块的报告生成逻辑,统一报告格式与推送流程

4.  **测试与文档
    - 新增端到端测试脚本与统一测试运行器
    - 完善README.md文档,补充项目结构、功能说明与使用方法
    - 新增钉钉消息推送工具文档
    - 新增测试用例与辅助工具

5.  **其他优化
    - 修复common/parser.py中的正则表达式兼容单引号的HTML属性
    - 新增session_manager.py移除冗余导入与路径修正
    - 新增OA审批报告生成逻辑优化,支持分组统计与详细清单输出
This commit is contained in:
2026-08-07 00:18:49 +08:00
parent 249088614d
commit 724a4f7b77
31 changed files with 4742 additions and 288 deletions
+27 -45
View File
@@ -4,50 +4,31 @@
@FileName: validator.py
@Author: 小布丁
@CreateTime: 2026-08-05 21:35
@Description: 加班流程校验模块(按 aa.md 审批规则:延时加班/休息日加班/法定假日加班,判定通过/不通过)
@Version: 3.0.0
@Description: 加班流程校验模块(按 aa.md 审批规则:延时加班/休息日加班/法定假日加班,判定通过/驳回)
@Version: 3.1.0
"""
import math
import os
import sys
from datetime import datetime, timedelta
from typing import Any, Dict, Optional
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
from utils.logger import get_logger
from app.utils.logger import get_logger
logger = get_logger(__name__)
try:
from .parser import parse_overtime_form
from ..common.oa_api import (
get_attendance_html,
get_attendance_records,
get_leave_records,
)
from ..common.parser import parse_attendance_html, summarize_attendance_records
from ..common.config import (
WORK_START_TIME,
WORK_END_TIME,
FLEX_TRIGGER_TIME,
OT_MIN_HOURS,
)
except ImportError:
from parser import parse_overtime_form
from common.oa_api import (
get_attendance_html,
get_attendance_records,
get_leave_records,
)
from common.parser import parse_attendance_html, summarize_attendance_records
from common.config import (
WORK_START_TIME,
WORK_END_TIME,
FLEX_TRIGGER_TIME,
OT_MIN_HOURS,
)
from app.service.hrbp.oa.work_overtime.parser import parse_overtime_form
from app.service.hrbp.oa.common.oa_api import (
get_attendance_html,
get_attendance_records,
get_leave_records,
)
from app.service.hrbp.oa.common.parser import parse_attendance_html, summarize_attendance_records
from app.service.hrbp.oa.common.config import (
WORK_START_TIME,
WORK_END_TIME,
FLEX_TRIGGER_TIME,
OT_MIN_HOURS,
)
# ---------- 通用工具 ----------
@@ -209,7 +190,7 @@ def _validate_delayed(
2. 时长达标:1小时起算,超1小时按0.5h累加,不足1h驳回;
3. 区间合规:开始时间 >= 规定下班时间(18:00),结束时间 <= 实际下班打卡时间。
(二)弹性到岗兑换(仅影响结算,校验不通过则驳回):
(二)弹性到岗兑换(仅影响结算,校验驳回则驳回):
D 基于实际下班打卡时间计算,>= 23:00 时 D = 1 + floor((打卡-23:00)/0.5)*0.5。
次日休息/请假覆盖09:00/无打卡 -> 不触发兑换。
正常工作日按次日打卡 P 校验:P<=09:00 不扣;09:00<P<=09:00+D 扣 ceil(P-09:00);
@@ -253,7 +234,7 @@ def _validate_delayed(
info["弹性扣减(小时)"] = 0
info["有效加班时长(小时)"] = hours
info["弹性额度D(小时)"] = 0
return "不通过", ";".join(reasons)
return "驳回", ";".join(reasons)
# 4. 弹性到岗兑换(仅影响结算时长)
deduction = 0.0
@@ -291,8 +272,8 @@ def _validate_delayed(
info["弹性扣减(小时)"] = 0
info["有效加班时长(小时)"] = hours
info["弹性额度D(小时)"] = d_hours
return "不通过", (
f"弹性兑换校验不通过:申请加班{hours:g}h + 晚到{late_hours}h "
return "驳回", (
f"弹性兑换校验驳回:申请加班{hours:g}h + 晚到{late_hours}h "
f"> 总自然时长{total_natural:.1f}h"
)
deduction = float(late_hours)
@@ -303,8 +284,8 @@ def _validate_delayed(
info["弹性扣减(小时)"] = 0
info["有效加班时长(小时)"] = hours
info["弹性额度D(小时)"] = d_hours
return "不通过", (
f"弹性兑换校验不通过:申请加班{hours:g}h + 兑换额度{d_hours:g}h "
return "驳回", (
f"弹性兑换校验驳回:申请加班{hours:g}h + 兑换额度{d_hours:g}h "
f"> 总自然时长{total_natural:.1f}h"
)
deduction = float(d_hours)
@@ -335,7 +316,7 @@ def _validate_day_ot(
require_holiday: bool,
) -> tuple:
"""
休息日/法定假日加班审批(任一条件不满足即不通过):
休息日/法定假日加班审批(任一条件不满足即驳回):
- 排班显示为休息;
- 法定假日(仅春节):申请日期必须为春节法定节假日;
- 加班时长 > 0;
@@ -388,14 +369,14 @@ def _validate_day_ot(
info["打卡时间间隔(小时)"] = interval
info["申报天数(天)"] = apply_days
if reasons:
return "不通过", ";".join(reasons)
return "驳回", ";".join(reasons)
return "通过", f"审批通过(申报{apply_days:g}天,打卡间隔{interval:.2f}小时)"
# ---------- 主入口 ----------
def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
"""
校验单张加班单据,返回审批决策(通过 / 不通过)。
校验单张加班单据,返回审批决策(通过 / 驳回)。
按加班类型分派规则:
ot_type=1 延时加班;
@@ -435,12 +416,13 @@ def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
overtime_info, punch_info, session, staff_id, require_holiday=require_holiday
)
else:
decision, note = "不通过", f"无法识别加班类型: {ot_type_code}"
decision, note = "驳回", f"无法识别加班类型: {ot_type_code}"
return {
"title": doc.get("title", ""),
"creator": doc.get("creator", ""),
"time": doc.get("time", ""),
"detail_url": doc.get("detail_url", ""),
"decision": decision,
"note": note,
"overtime_info": overtime_info,