本次提交包含多项功能更新: 1. 为多个插件(xq0002/0003/0004/0008/0010/0011/0020/0031_xq0032/0033/0035/0037/0045_xq0046/0047/0048)新增 UI 界面及配置支持 2. 新增运行日志集中回传功能,客户端自动上传运行日志到中心机集中存储 3. 新增插件分类字段支持,用于场景库分组管理 4. 优化 xq0034/0037/0048 等插件的功能及描述 5. 修复控制面响应兼容问题,支持新旧版本数据格式 6. 新增 xq0033 插件的状态存储模块,用于历史记录管理 7. 优化 CRM 登录窗口模式,支持全屏置顶
261 lines
7.9 KiB
Python
261 lines
7.9 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""XQ0020 EHR系统离职电子签流程审核 插件 - 配置常量与全局钩子。
|
||
|
||
插件自包含:本包只依赖 Python 标准库 / 第三方库 / 底座注入的 RunContext。
|
||
所有业务模块统一经 config.logger 输出日志、config.require_session() 取登录态。
|
||
登录态由底座注入(hr 平台),插件不自行读 cookies 文件、不做自动补登。
|
||
"""
|
||
import os
|
||
import random
|
||
import time
|
||
from functools import wraps
|
||
|
||
# ==================== 输出配置 ====================
|
||
DEFAULT_SAVE_DIR = r"D:\资料\人资\离职电子签流程审核"
|
||
|
||
# ==================== HR 系统接口 ====================
|
||
HR_BASE_URL = "https://hr.37du.co"
|
||
# 流程待办查询:数据行在响应 jsonList/datas(随服务端版本切换,已兼容),行内自带 taskId/businessKey/processId/formId
|
||
WE_PROCESS_QUERY_URL = f"{HR_BASE_URL}/RedseaPlatform/WeProcess.mc?method=getProcessAndData"
|
||
# 当前登录用户信息(轻量会话校验:返回顶层含 userId 的 JSON)
|
||
GET_CUR_USER_INFO_URL = f"{HR_BASE_URL}/RedseaPlatform/PtUsers.mc?method=getCurUserInfo"
|
||
WF_ACTIVITY_URL = f"{HR_BASE_URL}/RedseaPlatform/WfActivity.mc"
|
||
WORKFORM_ENGINE_URL = f"{HR_BASE_URL}/RedseaPlatform/WorkformEngine.mc"
|
||
# 附件清单查询接口:按 ids(逗号分隔 fileId)查附件元信息(fileName 等)
|
||
FJK_BY_IDS_URL = f"{HR_BASE_URL}/RedseaPlatform/PtFjk.mc?method=getFjkByIds"
|
||
# 附件下载接口:按 fileId 下载(返回 PDF 流 + Content-Disposition);要求有效 EHR 会话
|
||
FILE_DOWNLOAD_URL = f"{HR_BASE_URL}/RedseaPlatform/corePlatformOutUser/fjkFileDownload.mob"
|
||
# 审批提交接口:点击"同意"确认后前端会调用 sendWeTask,监听其响应以区分提交成功/失败(state="1" 成功,"0" 失败)
|
||
SEND_WE_TASK_URL = f"{HR_BASE_URL}/RedseaPlatform/WeTask.mc"
|
||
SEND_WE_TASK_MARK = "WeTask.mc?method=sendWeTask"
|
||
# 流程节点列表查询接口:按 processId 查流程全部节点任务(activityName/createTime/endTime/currentState 等)
|
||
WE_TASK_QUERY_URL = f"{HR_BASE_URL}/RedseaPlatform/WeTask.mc"
|
||
# 电子签真实签署状态查询接口(按合同业务主键 main_id 查询)
|
||
CONTRACT_SIGNATURE_SELECT_URL = (
|
||
f"{HR_BASE_URL}/RedseaPlatform/getContentLinkage/redApi/"
|
||
"rf_hr_staff_contract_signature_select_sp_cq37du/WorkformEngine.mc"
|
||
)
|
||
|
||
DEFAULT_PAGE_SIZE = 100
|
||
DEFAULT_SUBJECT = "改签离职电子签流程"
|
||
|
||
# 超期检查:「完善信息(操作人)」节点 endTime 非空且距今超过该天数 -> 超期提醒
|
||
OVERDUE_ACTIVITY_NAME = "完善信息(操作人)"
|
||
OVERDUE_DAYS = 3
|
||
|
||
# ==================== 审批提交 ====================
|
||
# 仅自动提交"同意"(校验通过);未完成一律不自动提交("不管"),保留待后续流转
|
||
APPROVE_BUTTONS = {
|
||
"通过": ("#chooseSubmit", "同意"),
|
||
}
|
||
|
||
# ==================== 编码 → 名称 ====================
|
||
# 是否已发起电子签字典(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": "退休",
|
||
}
|
||
|
||
# ==================== 全局钩子(run() 启动时注入) ====================
|
||
_log = None
|
||
_progress = None
|
||
_session = None
|
||
_user_id = ""
|
||
_save_dir = DEFAULT_SAVE_DIR
|
||
_debug = False
|
||
|
||
|
||
def set_log(fn):
|
||
"""注入 ctx.log(RunContext.log),各模块经 log()/logger 输出。"""
|
||
global _log
|
||
_log = fn
|
||
|
||
|
||
def log(msg, level="INFO"):
|
||
if _log:
|
||
_log(str(msg), level)
|
||
else:
|
||
print(f"[{level}] {msg}")
|
||
|
||
|
||
class _ModuleLogger:
|
||
"""模块级 logger 适配:保留影刀版 logger.info(...) 调用点,统一转发到 ctx.log。"""
|
||
|
||
@staticmethod
|
||
def debug(msg, *args):
|
||
if args:
|
||
msg = msg % args
|
||
log(msg, "DEBUG")
|
||
|
||
@staticmethod
|
||
def info(msg, *args):
|
||
if args:
|
||
msg = msg % args
|
||
log(msg, "INFO")
|
||
|
||
@staticmethod
|
||
def warning(msg, *args):
|
||
if args:
|
||
msg = msg % args
|
||
log(msg, "WARN")
|
||
|
||
@staticmethod
|
||
def error(msg, *args):
|
||
if args:
|
||
msg = msg % args
|
||
log(msg, "ERROR")
|
||
|
||
|
||
logger = _ModuleLogger()
|
||
|
||
|
||
def set_progress(fn):
|
||
"""注入 ctx.progress,业务层按阶段上报进度。"""
|
||
global _progress
|
||
_progress = fn
|
||
|
||
|
||
def progress(pct):
|
||
if _progress:
|
||
try:
|
||
_progress(int(pct))
|
||
except Exception:
|
||
pass
|
||
|
||
|
||
def set_session(session):
|
||
global _session
|
||
_session = session
|
||
|
||
|
||
def get_session():
|
||
return _session
|
||
|
||
|
||
def require_session():
|
||
"""取插件运行期注入的 HR session(缺失抛错,提示先登录 HR)。"""
|
||
if _session is None:
|
||
raise RuntimeError("未注入 HR 登录态,请先在壳子(工作台)完成 HR 登录")
|
||
return _session
|
||
|
||
|
||
def set_user_id(uid):
|
||
global _user_id
|
||
_user_id = str(uid or "")
|
||
|
||
|
||
def get_user_id():
|
||
return _user_id
|
||
|
||
|
||
def require_user_id():
|
||
if not _user_id:
|
||
raise RuntimeError("获取当前用户 userId 失败,请重新完成 HR 登录")
|
||
return _user_id
|
||
|
||
|
||
def set_save_dir(path):
|
||
global _save_dir
|
||
_save_dir = (path or "").strip() or DEFAULT_SAVE_DIR
|
||
|
||
|
||
def get_save_dir():
|
||
return _save_dir
|
||
|
||
|
||
def get_attachment_dir():
|
||
"""签章附件(解除确认书/报酬支付确认)存放目录 = <save_dir>\\附件。"""
|
||
return os.path.join(get_save_dir(), "附件")
|
||
|
||
|
||
def set_debug(flag):
|
||
global _debug
|
||
_debug = bool(flag)
|
||
|
||
|
||
def is_debug():
|
||
return _debug
|
||
|
||
|
||
# ==================== 重试装饰器(全局最大 3 次) ====================
|
||
class RetryExhaustedError(Exception):
|
||
"""重试次数耗尽。"""
|
||
|
||
|
||
def retry(max_attempts: int = 3, no_retry_on: tuple = ()):
|
||
"""指数退避重试:首次失败后 1s、2s、4s(含抖动);连续失败记录错误并抛出。"""
|
||
|
||
def decorator(func):
|
||
@wraps(func)
|
||
def wrapper(*args, **kwargs):
|
||
last_exc = None
|
||
for attempt in range(1, max_attempts + 1):
|
||
try:
|
||
return func(*args, **kwargs)
|
||
except no_retry_on:
|
||
raise
|
||
except Exception as e: # noqa: BLE001 - 统一重试入口
|
||
last_exc = e
|
||
if attempt >= max_attempts:
|
||
break
|
||
delay = 1.0 * (2 ** (attempt - 1)) * random.uniform(0.5, 1.5)
|
||
logger.warning("%s 第 %d 次失败,%.1fs 后重试: %s",
|
||
func.__name__, attempt, delay, e)
|
||
time.sleep(delay)
|
||
logger.error("%s 连续 %d 次尝试失败,放弃并记录: %s",
|
||
func.__name__, max_attempts, last_exc)
|
||
raise RetryExhaustedError(
|
||
f"{func.__name__} 连续 {max_attempts} 次失败: {last_exc}") from last_exc
|
||
|
||
return wrapper
|
||
|
||
return decorator
|