Files
37duAutomation/app/service/hrbp/oa/work_overtime/parser.py
T
puddy 8c97d48382 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审批报告生成逻辑优化,支持分组统计与详细清单输出
2026-08-07 00:18:49 +08:00

102 lines
3.3 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
"""
from typing import Any, Dict
from app.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 app.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)