Files
37duAutomation/plugins/XQ0001-0100/XQ0011 考勤月报封存检查/config/__init__.py
T
puddy d1af551eac chore: 清理废弃插件与冗余文档,重构项目目录结构
1.  删除旧版xq0031_xq0032插件的冗余UI源码与配置文件
2.  迁移并标准化XQ0001-0100系列需求的插件、文档与工作流目录
3.  清理过期的需求列表、评分文档与流程底稿
4.  更新.gitignore匹配规则,适配新的目录结构
2026-09-21 16:59:05 +08:00

153 lines
4.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 -*-
"""XQ0011 考勤月报封存检查 插件 - 配置常量与全局钩子。
插件自包含:本包只依赖 Python 标准库 / 第三方库 / 底座注入的 RunContext。
所有业务模块统一经 config.log() 输出日志、config.get_session()/get_user_id() 取登录态。
"""
import os
# ==================== 共享目录(登录态/缓存,与影刀版同路径) ====================
_APP_DATA_DIR = os.path.join(
os.getenv('LOCALAPPDATA') or os.getenv('APPDATA') or os.path.expanduser('~'),
'37duAutomation')
SESSIONS_DIR = os.path.join(_APP_DATA_DIR, '.sessions')
CACHE_DIR = os.path.join(_APP_DATA_DIR, 'cache') # 应勤天方案 1 天文件缓存
# ==================== HR 接口 ====================
HR_BASE_URL = "https://hr.37du.co"
GET_CUR_USER_INFO_URL = f"{HR_BASE_URL}/RedseaPlatform/PtUsers.mc?method=getCurUserInfo"
SEAL_URL = f"{HR_BASE_URL}/RedseaPlatform/kqController/getPageAjaxList.mc"
SEAL_SQL_ID = "kq_count_leave_wage_SelectV2"
STAT_URL = f"{HR_BASE_URL}/RedseaPlatform/getPageAjax/kq_count_leave_StatV2/CoreRequest.mc"
SHIFT_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_p_kq_count_SelectBanci/getExecutePageResult.mc"
TEAM_LIST_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_p_kq_team_ajax_list/redApiExec.mc"
TEAM_EXTEND_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_s_kq_team_extend_table_select/redApiExec.mc"
TEAM_PLAN_URL = f"{HR_BASE_URL}/RedseaPlatform/redmagicapi/rf_s_kq_team_minyq_plan_up_query_all/redApiExec.mc"
PAGE_MAX_SIZE = 500
# ==================== 输出目录与文件(默认与影刀版一致) ====================
DEFAULT_SAVE_DIR = r"D:\资料\人资\考勤月报封存检查"
def _default_roster(save_dir):
return os.path.join(save_dir, "员工花名册.xlsx")
def _default_transfer(save_dir):
return os.path.join(save_dir, "调动台账.xlsx")
# ==================== 口径常量 ====================
# 所属单位白名单(预处理口径:封存表仅保留以下单位员工)
SEAL_UNIT_WHITELIST = (
"财务管理部",
"集团管理中心",
"集团营建中心",
"金色印象事业部",
"金色湖畔事业部",
)
# 封存记录工号字段
SEAL_CODE_FIELDS = ("base_code", "seal_base_code")
# 花名册剔除口径
EXCLUDE_FIRST_DEPT = "职业技术培训学校" # 一级部门等于该值不参与检查
EXCLUDE_EMPTY_FIRST_DEPT = True # 一级部门为空(直属根节点高管)不参与检查
ROSTER_DEPT_COLS = ("一级部门", "二级部门", "三级部门", "四级部门", "五级部门")
ROSTER_CODE_COL = "工号"
ROSTER_NAME_COL = "姓名"
ROSTER_UNIT_COL = "所属单位"
ROSTER_JOIN_COL = "入职时间"
ROSTER_LEAVE_COL = "离职时间"
ROSTER_SEQ_COL = "职位序列"
# ==================== 全局钩子(run() 启动时注入) ====================
_log = None
_session = None
_user_id = ""
_roster_path = ""
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_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():
uid = _user_id
if not uid:
raise RuntimeError("获取当前用户 userId 失败")
return uid
def set_roster_path(path):
"""花名册路径全局配置(run() 解析后注入,部门回填/剔除默认使用)。"""
global _roster_path
_roster_path = str(path or "")
def get_roster_path():
return _roster_path or _default_roster(DEFAULT_SAVE_DIR)