Files
37duAutomation/plugins/XQ0001-0100/XQ0036 门店员工起调薪处理/__init__.py
T
puddy a1610fb32c feat(plugin): XQ0036 0.1.1 配置收敛为工作目录、星级按工号实时查询
- 配置由 save_dir / standard_path / roster_path 收敛为 work_dir:线下标准表在
  该目录内按文件名关键词(起调薪薪资标准/薪资标准)与日期自动取最新,
  处理结果 xlsx 同目录输出
- 星级改为按待办工号实时查询,失败再回退全量花名册导出
- 处理窗口留空=全部待办(原先默认当前自然月);界面、规则说明、README 同步
2026-11-16 11:27:56 +08:00

175 lines
7.2 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 -*-
"""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.1"
description = ("花名册职位序列过滤(仅门店服务/技师/管理序列):入职起薪、其他调薪"
"(自动判断换账套与调薪类型),核对工资项/岗位名称/固定项总额与标准一致后提交;"
"离职不处理。默认试算不提交,结果导出 xlsx。")
platform = "hr"
uses_month = False
capabilities = ["xq0036"]
permissions = {"platforms": ["hr"]}
fields = {
"work_dir": {
"type": "string", "title": "工作目录(标准表 + 处理结果)",
"default": config.DEFAULT_WORK_DIR,
"description": ("线下《起调薪薪资标准》xlsx 所在目录:按文件名关键词(起调薪薪资标准/薪资标准)"
"与文件名日期自动取最新一个;处理结果 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": "开启后只核对并输出结果,不调用起薪/调薪提交;验证通过后可关闭",
},
"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)
scope = f"{start_date} ~ {end_date}" if start_date and end_date else "全部待办"
log(f"[INFO] 工资待办任务 {len(rows)} 条({scope})")
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(save_dir, log)
if not std_rows:
log(f"[WARN] 未载入线下标准表(目录内无匹配的「起调薪薪资标准」xlsx):"
f"服务/管理账套的固定项总额将无法核对(按待人工处理)", "WARNING")
roster_index = roster_map.ensure(
api.client, save_dir, log,
base_codes=[config.text(row.get("base_code")) for row in rows])
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())