feat(plugin): 新增 XQ0036 门店员工起调薪处理(0.1.0,依赖 hr_sdk ^0.2);XQ0001 放宽 hr_sdk 兼容范围
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""花名册查询:职位序列(决定是否处理与工资账套)与星级(标准表匹配用)。
|
||||
|
||||
优先读取传入的花名册路径;未传入时用 hr_sdk.roster 导出在职花名册(30 分钟缓存)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
import pandas as pd
|
||||
|
||||
from .. import config
|
||||
|
||||
COL_CODE = ("工号", "base_code")
|
||||
COL_STAR = ("星级", "ext_star_level")
|
||||
COL_SEQ = ("职位序列", "ext_sequence_name", "sequence")
|
||||
DEFAULT_TTL = 1800
|
||||
|
||||
|
||||
def _col(columns, aliases) -> str:
|
||||
for alias in aliases:
|
||||
if alias in columns:
|
||||
return alias
|
||||
return ""
|
||||
|
||||
|
||||
def load(path: str, log=None) -> dict:
|
||||
"""读取花名册 → {工号: {"star": 星级, "sequence": 职位序列}}。"""
|
||||
path = config.text(path)
|
||||
if not path or not os.path.exists(path):
|
||||
return {}
|
||||
frame = pd.read_excel(path, dtype=str)
|
||||
if not _col(frame.columns, COL_CODE):
|
||||
frame = pd.read_excel(path, dtype=str, header=1)
|
||||
col_code = _col(frame.columns, COL_CODE)
|
||||
col_star = _col(frame.columns, COL_STAR)
|
||||
col_seq = _col(frame.columns, COL_SEQ)
|
||||
if not col_code:
|
||||
if log:
|
||||
log(f"[WARN] 花名册缺少「工号」列:{list(frame.columns)}", "WARNING")
|
||||
return {}
|
||||
result = {}
|
||||
for _, row in frame.iterrows():
|
||||
code = config.text(row.get(col_code))
|
||||
if not code:
|
||||
continue
|
||||
result[code] = {
|
||||
"star": config.text(row.get(col_star)) if col_star else "",
|
||||
"sequence": config.text(row.get(col_seq)) if col_seq else "",
|
||||
}
|
||||
if log:
|
||||
log(f"[INFO] 花名册载入 {len(result)} 人(职位序列/星级):{os.path.basename(path)}")
|
||||
return result
|
||||
|
||||
|
||||
def ensure(client, roster_path: str, save_dir: str, log=None) -> dict:
|
||||
"""返回花名册索引:显式路径优先;否则自动导出在职花名册。"""
|
||||
if roster_path:
|
||||
return load(roster_path, log)
|
||||
try:
|
||||
from hr_sdk import roster as roster_sdk
|
||||
target = os.path.join(save_dir, "花名册_在职.xlsx")
|
||||
path = roster_sdk.export(client, statuses=["在职"], output=target, ttl=DEFAULT_TTL)
|
||||
return load(path, log)
|
||||
except Exception as exc: # noqa: BLE001 - 查询失败不阻断,后续按待核对
|
||||
if log:
|
||||
log(f"[WARN] 自动导出花名册失败,职位序列/星级将缺失:{exc}", "WARNING")
|
||||
return {}
|
||||
Reference in New Issue
Block a user