Files
37duAutomation/app/service/hrbp/oa/resign_e_sign/parser.py
T
puddy 1553a2de28 feat(hrbp.oa): 新增离职电子签流程审核模块
完成离职电子签全流程开发,包括:
1. 新增模块目录与基础初始化文件
2. 实现表单解析、校验逻辑、审批入口与报告生成
3. 扩展通知模块兼容离职电子签场景,新增未完成待跟进统计
4. 补充接口文档与示例代码
2026-08-20 23:28:05 +08:00

107 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.resign_e_sign.parser
@FileName: parser.py
@Author: 小布丁
@CreateTime: 2026-08-20
@Description: 离职电子签流程表单解析模块(解析 WorkformEngine 返回的 result,提取电子签三状态及员工信息)
@Version: 1.0.0
"""
from typing import Any, Dict
from app.utils.logger import get_logger
logger = get_logger(__name__)
# 是否已发起电子签字典(hr_staff_contract.is_initiate_sign)
INITIATE_SIGN_MAP = {
"0": "未发起",
"1": "已发起",
"2": "已完成",
"3": "已撤销",
"5": "已过期",
"7": "已拒签",
"8": "已作废",
}
# 员工/企业签署状态字典(esign_sigin_state)
SIGN_STATE_MAP = {
"1": "签署中",
"2": "已完成",
"3": "未完成",
"4": "已作废",
}
# 电子签三状态均须等于该编码(已完成)才同意
SIGN_DONE_CODE = "2"
def _sign_name(mapping: Dict[str, str], code: Any) -> str:
"""将状态编码转换为名称;空值返回空串,未知编码原样返回。"""
if code is None or str(code).strip() == "":
return ""
return mapping.get(str(code).strip(), str(code))
def parse_resign_e_sign_form(result: Dict[str, Any]) -> Dict[str, Any]:
"""
解析离职电子签表单数据,提取关键字段。
Args:
result: WorkformEngine 返回的 result 字典(即 doc['formData'])
Returns:
包含离职电子签关键字段的字典(中文键名),三个电子签状态同时保留编码与名称
"""
is_initiate = result.get("ext_is_initiate_sign")
staff_state = result.get("ext_staff_sign_status")
org_state = result.get("ext_org_sign_status")
return {
"员工姓名": result.get("staff_name"),
"工号": result.get("base_code"),
"身份证号": result.get("idcard"),
"所属事业部": result.get("belong_unit_org_name"),
"组织架构": result.get("org_full_path"),
"岗位": result.get("post_name"),
"离职日期": result.get("leaveoffice_time"),
"手机号": result.get("mobile_phone"),
"合同类型": result.get("contract_type"),
"合同开始日期": result.get("contract_start_date"),
"合同结束日期": result.get("contract_end_date"),
"是否已发起电子签编码": is_initiate,
"是否已发起电子签": _sign_name(INITIATE_SIGN_MAP, is_initiate),
"员工签署状态编码": staff_state,
"员工签署状态": _sign_name(SIGN_STATE_MAP, staff_state),
"企业签署状态编码": org_state,
"企业签署状态": _sign_name(SIGN_STATE_MAP, org_state),
}
# ---------- 使用示例(测试用) ----------
if __name__ == "__main__":
from app.utils.logger import setup_logging
setup_logging()
# 示例 result(WorkformEngine 返回的 result 字段,见 aa.md)
sample_result = {
"base_code": "37022119",
"belong_unit_org_name": "金色印象事业部",
"ext_is_initiate_sign": "2",
"ext_org_sign_status": "2",
"ext_staff_sign_status": "2",
"idcard": "511623200311056533",
"leaveoffice_time": "2026-07-31",
"mobile_phone": "19950986716",
"org_full_path": "集团-金色印象事业部-第一大区-金色印象重庆第一经营中心-第四片区-石油路PLUS会馆-接待组",
"post_name": "接待员",
"staff_name": "夏礼广",
}
parsed = parse_resign_e_sign_form(sample_result)
logger.info("===== 离职电子签信息解析结果 =====")
for key, value in parsed.items():
logger.info("%s: %s", key, value)