feat(hrbp): 完成HRBP加班审批系统全链路开发

新增:
1.  新增依赖包chinese_calendar,完善.gitignore会话存储配置
2.  新增完整测试套件与项目初始化文件
3.  实现延时/休息日/法定假日加班审批规则(参考aa.md文档)
4.  新增排班、打卡、请假数据获取与解析工具
5.  完善会话管理与持久化存储逻辑
6.  实现格式化审批报告生成功能

修改:
1.  调整请假校验函数签名以传入会话对象
2.  更新审批流程调用逻辑适配新校验函数
3.  重构cookie存储路径与目录创建逻辑
4.  优化日志输出级别与调试信息
This commit is contained in:
2026-08-06 21:03:20 +08:00
parent 7d5028c49a
commit 249088614d
28 changed files with 1342 additions and 41 deletions
+94
View File
@@ -0,0 +1,94 @@
# -*- coding: utf-8 -*-
"""
@Module: tests.hrbp.test_04_parsers
@FileName: test_04_parsers.py
@Author: 小布丁
@CreateTime: 2026-08-06 10:50
@Description: 连通性测试④——纯解析函数(无需登录,离线测试)
@Version: 1.0.0
"""
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
from tests.hrbp._helpers import logger # noqa: E402
def test_attendance_html_parse():
"""测试:排班 HTML 解析 + 工作日计算"""
from app.service.hrbp.oa.common.parser import parse_attendance_html, get_work_days_in_range
html = """
<a class='cale_a' data-temp="2026-08-01">休息</a>
<a class='cale_a' data-temp="2026-08-02">正常</a>
<a class='cale_a' data-temp="2026-08-03">休息</a>
"""
result = parse_attendance_html(html)
assert result == {"2026-08-01": "休息", "2026-08-02": "正常", "2026-08-03": "休息"}
work_days = get_work_days_in_range(result, "2026-08-01", "2026-08-03")
assert work_days == ["2026-08-02"], f"工作日计算错误: {work_days}"
logger.info("[通过] 排班 HTML 解析 + 工作日计算")
def test_attendance_summary():
"""测试:打卡明细按日汇总(含跨天凌晨下班)"""
from app.service.hrbp.oa.common.parser import summarize_attendance_records
records = [
{"staff_id": "S001", "staff_name": "张三", "bc_date": "2026-08-02",
"kq_time": "2026-08-02 08:50:00", "status": "1", "time_order": "1",
"DEPT_ORG_NAME": "技术部", "POST_ALIAS_NAME": "工程师"},
{"staff_id": "S001", "staff_name": "张三", "bc_date": "2026-08-02",
"kq_time": "2026-08-02 12:00:00", "status": "5", "time_order": "2",
"DEPT_ORG_NAME": "技术部", "POST_ALIAS_NAME": "工程师"},
{"staff_id": "S001", "staff_name": "张三", "bc_date": "2026-08-02",
"kq_time": "2026-08-03 00:30:00", "status": "5", "time_order": "2",
"DEPT_ORG_NAME": "技术部", "POST_ALIAS_NAME": "工程师"},
{"staff_id": "S001", "staff_name": "张三", "bc_date": "2026-08-02",
"kq_time": "2026-08-02 19:00:00", "status": "6", "time_order": "1",
"DEPT_ORG_NAME": "技术部", "POST_ALIAS_NAME": "工程师"}, # 重复打卡,应过滤
]
summary = summarize_attendance_records(records)
assert len(summary) == 1, f"汇总天数错误: {len(summary)}"
row = summary[0]
assert row["first_check_in"] == "2026-08-02 08:50:00"
assert row["last_check_out"] == "2026-08-03 00:30:00" # 跨天最晚
logger.info("[通过] 打卡汇总(含跨天 + 过滤重复): 最早=%s, 最晚=%s",
row["first_check_in"], row["last_check_out"])
def test_overtime_form_parse():
"""测试:加班表单解析 + 类型映射"""
from app.service.hrbp.oa.work_overtime.parser import parse_overtime_form
form_data = {
"staff_id": "572e6cce-7a9f-11ec-b449-000c296f9469",
"staff_name": "黄俊林",
"dept_org_name": "网络项目小组",
"ot_type": "1", # → 延时加班
"subsidy_type": "2", # → 转补贴
"ot_date": "2026-08-02",
"start_time": "2026-08-02 18:00",
"end_time": "2026-08-03 00:00",
"ot_hour": 6.0,
"judge_ot_hour": 6.0,
"judge_start_time": "2026-08-02 18:00:00",
"judge_end_time": "2026-08-03 00:00:00",
"file": "ccc1d3ef-175a-4105-a8a8-0e63ed88d7bd",
}
info = parse_overtime_form(form_data)
assert info["加班人员ID"] == "572e6cce-7a9f-11ec-b449-000c296f9469"
assert info["加班类型"] == "延时加班", f"类型映射错误: {info['加班类型']}"
assert info["补贴类型"] == "转补贴"
assert info["系统判定加班时间"] == "2026-08-02 18:00:00 至 2026-08-03 00:00:00"
logger.info("[通过] 加班表单解析 + 类型映射: %s", info["加班类型"])
if __name__ == "__main__":
logger.info("========== 测试④:纯解析函数(离线) ==========")
test_attendance_html_parse()
test_attendance_summary()
test_overtime_form_parse()
logger.info("========== 测试④结束 ==========")