Files
37duAutomation/app/service/hrbp/oa/work_overtime/parser.py
T

104 lines
3.6 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") or result.get("expect_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")
# 接口对未判定场景返回字符串"无数据",需过滤,避免拼出"10:00:00 至 无数据"
if (judge_start and judge_end
and "无" not in str(judge_start) and "无" not in str(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)