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

142 lines
4.8 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"
# 离职类型字典(hr_staff_contract.leaveoffice_type 编码 -> 展示文本)
LEAVEOFFICE_TYPE_MAP = {
"": "请选择",
"0": "辞职",
"1": "辞退",
"4": "合同期内辞职",
"9": "其他",
"2": "进修学习",
"3": "参军",
"5": "除名",
"6": "开除",
"7": "死亡",
"8": "失踪",
"11": "协商一致解除",
"12": "主动离职",
"13": "非主动离职",
"14": "自动离职(未办理离职手续)",
"15": "开除人员",
"16": "调出",
"17": "合同到期未续签",
"18": "解除合同",
"ext_8": "个人申请辞职",
"ext_1": "主动辞职",
"ext_2": "到期个人不愿续签",
"ext_3": "单位不续签",
"ext_4": "劝退无证明",
"ext_5": "劝退有证明",
"ext_6": "自动离职",
"ext_7": "双方协商一致解除",
"10": "退休",
}
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("leaveoffice_type"),
"离职类型": _sign_name(LEAVEOFFICE_TYPE_MAP, result.get("leaveoffice_type")),
"手机号": 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",
"leaveoffice_type": "ext_8",
"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)