Files
37duAutomation/plugins/xq0003/config/__init__.py
T
puddy 843ff244a6 feat: 新增多插件 UI 支持及运行日志集中回传功能
本次提交包含多项功能更新:
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 登录窗口模式,支持全屏置顶
2026-10-26 15:42:50 +08:00

204 lines
5.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 -*-
"""XQ0003 EHR系统请假流程审核 插件 - 配置常量与全局钩子。
插件自包含:本包只依赖 Python 标准库 / 第三方库 / 底座注入的 RunContext。
所有业务模块统一经 config.logger 输出日志、config.require_session()/require_user_id() 取登录态。
登录态由底座注入(hr 平台),插件不自行读 cookies 文件、不做自动补登。
"""
import os
import random
import time
from functools import wraps
# ==================== 输出配置 ====================
DEFAULT_SAVE_DIR = r"D:\资料\人资\请假流程审批"
ATTACHMENT_DIR_NAME = "附件"
# ==================== HR 系统接口 ====================
HR_BASE_URL = "https://hr.37du.co"
WE_PROCESS_QUERY_URL = f"{HR_BASE_URL}/RedseaPlatform/WeProcess.mc?method=getProcessAndData"
WF_ACTIVITY_URL = f"{HR_BASE_URL}/RedseaPlatform/WfActivity.mc"
WORKFORM_ENGINE_URL = f"{HR_BASE_URL}/RedseaPlatform/WorkformEngine.mc"
GET_CUR_USER_INFO_URL = f"{HR_BASE_URL}/RedseaPlatform/PtUsers.mc?method=getCurUserInfo"
SHIFT_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_p_kq_count_SelectBanci/getExecutePageResult.mc"
ATTACHMENT_URL = f"{HR_BASE_URL}/RedseaPlatform/corePlatformOutUser/fjkFileDownload.mob"
DEFAULT_PAGE_SIZE = 100
PAGE_MAX_SIZE = 500
DEFAULT_TREE_CODE = "cq37du"
DEFAULT_SUBJECT = "请假"
# 审批按钮:决策 -> (选择器, 按钮文案);仅「通过」会自动提交
APPROVE_BUTTONS = {"通过": ("#chooseSubmit", "同意")}
# ==================== 假期类型编码 → 名称 ====================
VACATION_TYPE_MAP = {
"04": "病假",
"05": "产假",
"09": "事假",
"11": "调休假",
"15": "普通事假",
"17": "特殊事假",
"18": "小时特假",
"19": "普通事假(晚/高峰)",
"20": "普通事假(早/中)",
"22": "半天休(仅限人资专用)",
"23": "特别福利假",
"24": "年度福利假",
}
# ==================== 全局钩子(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(_save_dir, ATTACHMENT_DIR_NAME)
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