Files
37duAutomation/app/service/hrbp/oa/work_overtime/parser.py
T
puddy 249088614d feat(hrbp): 完成HRBP加班审批系统全链路开发
新增:
1.  新增依赖包chinese_calendar,完善.gitignore会话存储配置
2.  新增完整测试套件与项目初始化文件
3.  实现延时/休息日/法定假日加班审批规则(参考aa.md文档)
4.  新增排班、打卡、请假数据获取与解析工具
5.  完善会话管理与持久化存储逻辑
6.  实现格式化审批报告生成功能

修改:
1.  调整请假校验函数签名以传入会话对象
2.  更新审批流程调用逻辑适配新校验函数
3.  重构cookie存储路径与目录创建逻辑
4.  优化日志输出级别与调试信息
2026-08-06 21:03:20 +08:00

106 lines
3.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""
@Module: hrbp.oa.work_overtime.parser
@FileName: parser.py
@Author: 小布丁
@CreateTime: 2026-08-06 09:30
@Description: 加班表单解析模块(解析 WorkformEngine 返回的 result,提取关键字段并转换为中文描述)
@Version: 1.0.0
"""
import os
import sys
from typing import Any, Dict
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', '..', '..'))
from utils.logger import get_logger
logger = get_logger(__name__)
# 加班类型映射
OT_TYPE_MAP = {
"1": "延时加班",
"2": "法定假日加班",
"3": "休息日加班",
}
# 补贴类型映射
SUBSIDY_TYPE_MAP = {
"1": "转调休",
"2": "转补贴",
}
def parse_overtime_form(result: Dict[str, Any]) -> Dict[str, Any]:
"""
解析加班表单数据,提取关键字段并将代码转换为中文描述。
注意:入参为 oa_api.get_business_data 返回的 result 字段(state 校验已在
get_business_data 内完成),即审批引擎 doc['formData']。
Args:
result: WorkformEngine 返回的 result 字典(含 ot_type / staff_name 等)
Returns:
包含加班关键字段的字典(中文键名);找不到映射时保留原始代码值
"""
# 获取原始类型代码
ot_type_code = result.get("ot_type")
subsidy_type_code = result.get("subsidy_type")
overtime_info = {
"加班人员ID": result.get("staff_id"),
"加班人员": result.get("staff_name"),
"所属部门": result.get("dept_org_name"),
"加班类型": OT_TYPE_MAP.get(ot_type_code, ot_type_code),
"补贴类型": SUBSIDY_TYPE_MAP.get(subsidy_type_code, subsidy_type_code),
"加班日期": result.get("ot_date"),
"加班开始时间": result.get("start_time"),
"加班结束时间": result.get("end_time"),
"加班时长(小时)": result.get("ot_hour"),
"加班天数(天)": result.get("ot_day"),
"系统判断加班时长(小时)": result.get("judge_ot_hour"),
"系统判断加班天数(天)": result.get("judge_ot_day"),
"附件": result.get("file"),
}
# 拼接系统判定的加班时间段
judge_start = result.get("judge_start_time")
judge_end = result.get("judge_end_time")
if judge_start and judge_end:
overtime_info["系统判定加班时间"] = f"{judge_start} 至 {judge_end}"
else:
overtime_info["系统判定加班时间"] = None
return overtime_info
# ---------- 使用示例(测试用) ----------
if __name__ == "__main__":
from utils.logger import setup_logging
setup_logging()
# 示例 result(WorkformEngine 返回的 result 字段)
sample_result = {
"dept_org_name": "网络项目小组",
"end_time": "2026-08-03 00:00",
"judge_end_time": "2026-08-03 00:00:00",
"judge_ot_hour": 6.0,
"judge_start_time": "2026-08-02 18:00:00",
"ot_date": "2026-08-02",
"ot_hour": 6.0,
"ot_type": "1",
"staff_id": "572e6cce-7a9f-11ec-b449-000c296f9469",
"staff_name": "黄俊林",
"start_time": "2026-08-02 18:00",
"subsidy_type": "2",
"file": "ccc1d3ef-175a-4105-a8a8-0e63ed88d7bd",
}
parsed = parse_overtime_form(sample_result)
logger.info("===== 加班信息解析结果 =====")
for key, value in parsed.items():
logger.info("%s: %s", key, value)