feat(plugin): 新增 XQ0036 门店员工起调薪处理(0.1.0,依赖 hr_sdk ^0.2);XQ0001 放宽 hr_sdk 兼容范围
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""XQ0036 门店员工起调薪处理(插件版)。
|
||||
|
||||
流程:
|
||||
1) 拉取工资待办任务(默认本月);
|
||||
2) 按规则判定:入职→起薪、离职→跳过、其他→调薪(并判断换账套/调薪类型);
|
||||
3) 取账套工资项与工资标准,计算固定项总额并核对岗位名称;
|
||||
4) 服务/管理账套对线下标准表(序列+品牌+岗位+城市 → 薪资总额+岗位补贴+奖金)核对总额;技师账套免核对;
|
||||
5) 纳税单位缺省时按部门全路径中的会馆兜底;
|
||||
6) 全部通过才提交(默认试算,不提交),结果导出 xlsx。
|
||||
|
||||
运行上下文:``platform = "hr"``(壳子按账号注入登录态),不使用执行月份。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from webhost.backend.plugins.base import PLUGINS, ScenePlugin
|
||||
|
||||
from hr_sdk import HrClient
|
||||
from hr_sdk.errors import SessionExpiredError
|
||||
|
||||
from . import config
|
||||
from .data.wage_api import WageApi
|
||||
from .logic import evaluate as evaluate_mod
|
||||
from .logic import roster_map, standard_table
|
||||
from .report.excel import export_result
|
||||
|
||||
LOGIN_HINT = "HR 登录态失效,请先在壳子右上角重新登录 HR 后重试"
|
||||
|
||||
|
||||
class WageStartChangePlugin(ScenePlugin):
|
||||
"""门店员工起调薪(停薪)处理(需求 XQ0036)。"""
|
||||
|
||||
id = "xq0036"
|
||||
name = "门店员工起调薪处理"
|
||||
version = "0.1.0"
|
||||
description = ("花名册职位序列过滤(仅门店服务/技师/管理序列):入职起薪、其他调薪"
|
||||
"(自动判断换账套与调薪类型),核对工资项/岗位名称/固定项总额与标准一致后提交;"
|
||||
"离职不处理。默认试算不提交,结果导出 xlsx。")
|
||||
platform = "hr"
|
||||
uses_month = False
|
||||
capabilities = ["xq0036"]
|
||||
permissions = {"platforms": ["hr"]}
|
||||
fields = {
|
||||
"save_dir": {
|
||||
"type": "string", "title": "输出目录",
|
||||
"default": config.DEFAULT_SAVE_DIR,
|
||||
"description": "处理结果 xlsx 输出目录",
|
||||
},
|
||||
"date_start": {
|
||||
"type": "string", "title": "开始日期",
|
||||
"default": "",
|
||||
"description": "YYYY-MM-DD;留空=当前自然月",
|
||||
},
|
||||
"date_end": {
|
||||
"type": "string", "title": "结束日期",
|
||||
"default": "",
|
||||
"description": "YYYY-MM-DD;留空=当前自然月",
|
||||
},
|
||||
"dry_run": {
|
||||
"type": "boolean", "title": "试算模式(不提交)", "default": True,
|
||||
"description": "开启后只核对并输出结果,不调用起薪/调薪提交;验证通过后可关闭",
|
||||
},
|
||||
"standard_path": {
|
||||
"type": "string", "title": "线下标准表路径",
|
||||
"default": r"D:\资料\人资\门店员工起调薪处理\印象 湖畔起调薪薪资标准20261013.xlsx",
|
||||
"description": "线下《起调薪薪资标准》xlsx(工作表「起调薪薪资」);留空=服务/管理账套无法核对总额,按待核对处理",
|
||||
},
|
||||
"roster_path": {
|
||||
"type": "string", "title": "花名册路径(取职位序列/星级)",
|
||||
"default": "",
|
||||
"description": "标准表核对需要员工星级;留空=自动导出在职花名册(30 分钟缓存),同时用于职位序列过滤",
|
||||
},
|
||||
"tax_unit_fallback": {
|
||||
"type": "boolean", "title": "纳税单位兜底", "default": True,
|
||||
"description": "纳税单位缺失时按部门全路径中的 XX 会馆自动选择",
|
||||
},
|
||||
"debug_mode": {
|
||||
"type": "boolean", "title": "调试日志", "default": False,
|
||||
"description": "开启后输出完整调试信息(默认关闭)",
|
||||
},
|
||||
}
|
||||
|
||||
# ---------------- 入口 ----------------
|
||||
def run(self, fields: dict, ctx) -> dict:
|
||||
fields = fields or {}
|
||||
debug = bool(fields.get("debug_mode", False))
|
||||
|
||||
def log(msg: str, level: str = "INFO") -> None:
|
||||
if level == "DEBUG" and not debug:
|
||||
return
|
||||
ctx.log(msg, level)
|
||||
|
||||
save_dir = config.save_dir(fields)
|
||||
os.makedirs(save_dir, exist_ok=True)
|
||||
|
||||
try:
|
||||
session = ctx.get_session("hr")
|
||||
except Exception as exc: # noqa: BLE001
|
||||
raise RuntimeError(f"未获取到 HR 登录态:{exc};请先在壳子登录 HR") from exc
|
||||
|
||||
def hr_log(msg: str) -> None:
|
||||
level = ("WARNING" if "[WARN]" in msg else "ERROR" if "[ERROR]" in msg else "INFO")
|
||||
log(msg, level)
|
||||
|
||||
api = WageApi(HrClient(session, log=hr_log), log=hr_log)
|
||||
try:
|
||||
return self._run(api, fields, save_dir, log, ctx, debug)
|
||||
except SessionExpiredError as exc:
|
||||
raise RuntimeError(f"{LOGIN_HINT}({exc})") from exc
|
||||
|
||||
# ---------------- 主体 ----------------
|
||||
def _run(self, api: WageApi, fields: dict, save_dir: str, log, ctx, debug: bool) -> dict:
|
||||
start_date = config.text(fields.get("date_start"))
|
||||
end_date = config.text(fields.get("date_end"))
|
||||
|
||||
rows = api.tasks(start_date, end_date)
|
||||
log(f"[INFO] 工资待办任务 {len(rows)} 条({start_date or '本月'} ~ {end_date or '本月'})")
|
||||
ctx.progress(15)
|
||||
|
||||
accounts = api.accounts()
|
||||
log("[INFO] 工资账套:" + "、".join(f"{k}({v['id'][:8]})" for k, v in accounts.items()))
|
||||
|
||||
std_rows = standard_table.load(config.text(fields.get("standard_path")), log)
|
||||
if not std_rows:
|
||||
log("[WARN] 未载入线下标准表:服务/管理账套的固定项总额将无法核对(按待人工处理)",
|
||||
"WARNING")
|
||||
roster_index = roster_map.ensure(api.client, config.text(fields.get("roster_path")),
|
||||
save_dir, log)
|
||||
if not roster_index:
|
||||
log("[WARN] 未取到花名册,无法按职位序列限定处理范围(全部按待人工处理)",
|
||||
"WARNING")
|
||||
ctx.progress(25)
|
||||
|
||||
records = []
|
||||
total = max(len(rows), 1)
|
||||
for index, row in enumerate(rows, 1):
|
||||
try:
|
||||
record = evaluate_mod.evaluate(row, api, accounts, std_rows, fields, log,
|
||||
roster_index)
|
||||
except Exception as exc: # noqa: BLE001 - 单条异常不中断
|
||||
record = {
|
||||
"姓名": config.text(row.get("staff_name")),
|
||||
"工号": config.text(row.get("base_code")),
|
||||
"异动类型": config.text(row.get("CHANGE_TYPE")),
|
||||
"处理状态": config.ST_FAIL,
|
||||
"说明": f"处理异常:{exc}",
|
||||
}
|
||||
log(f"[ERROR] {record['姓名']} 处理异常:{exc}", "ERROR")
|
||||
if debug:
|
||||
log(traceback.format_exc(), "DEBUG")
|
||||
record["序号"] = index
|
||||
records.append(record)
|
||||
ctx.progress(25 + int(index / total * 55))
|
||||
|
||||
dry_run = bool(fields.get("dry_run", True))
|
||||
path = ""
|
||||
if dry_run:
|
||||
path = export_result(records, save_dir, log)
|
||||
else:
|
||||
log("[INFO] 正式提交模式:不生成试算结果表")
|
||||
ctx.progress(95)
|
||||
|
||||
counts = {}
|
||||
for record in records:
|
||||
counts[record.get("处理状态") or ""] = counts.get(record.get("处理状态") or "", 0) + 1
|
||||
detail = ",".join(f"{k} {v}" for k, v in counts.items())
|
||||
log(f"[INFO] 处理汇总:{detail}")
|
||||
ctx.progress(100)
|
||||
return {
|
||||
"ok": True,
|
||||
"total": len(records),
|
||||
"dry_run": dry_run,
|
||||
"counts": counts,
|
||||
"path": path,
|
||||
"save_dir": save_dir,
|
||||
"summary": f"共 {len(records)} 条 · {detail or '无数据'}",
|
||||
"detail": records,
|
||||
}
|
||||
|
||||
|
||||
PLUGINS.append(WageStartChangePlugin())
|
||||
Reference in New Issue
Block a user