- 职位序列改取 pt_staff_stru.first_type_id,按 rf_s_Core_Post_pt_post_type_Select_v3_1 字典转名称 - 星级改按 star_level_sp_cq37du 字典解析(ext_1=见习/ext_2=正式/ext_13=代理),实时结果不全时回退全量导出 - 调薪但无起薪记录:与平台同口径「该员工没起薪,无需调薪」,记跳过而非待人工 - 入职/再次入职当天又借调:借调待办调 insertHrWageBaseStaffChange.mc(changeIds[])设置忽略,试算只标记待忽略 - 花名册实时查询补专用角色集、按页拉全
222 lines
10 KiB
Python
222 lines
10 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""单条工资待办的核对与(可选)提交编排。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from typing import List
|
||
|
||
from .. import config
|
||
from ..data.wage_api import WageApi
|
||
from . import classify, plan as plan_mod, standard_table, submit, tax
|
||
|
||
|
||
def _base_record(row: dict, decision: dict) -> dict:
|
||
return {
|
||
"姓名": config.text(row.get("staff_name")),
|
||
"工号": config.text(row.get("base_code")),
|
||
"异动类型": config.text(row.get("CHANGE_TYPE")),
|
||
"异动类型名称": decision.get("change_type_name", ""),
|
||
"异动日期": config.text(row.get("CHANGE_DATE")),
|
||
"所属单位": config.text(row.get("BELONG_UNIT_ORG_NAME")),
|
||
"品牌": "",
|
||
"区域": "",
|
||
"部门": config.text(row.get("DEPT_ORG_NAME")),
|
||
"岗位": config.text(row.get("POST_ORG_NAME")),
|
||
"职衔": config.text(row.get("POST_LEVEL_NAME")),
|
||
"职位序列": "",
|
||
"星级": "",
|
||
"原单位": config.text(row.get("PRE_ORG_NAME")),
|
||
"原职衔": config.text(row.get("PRE_POST_LEVEL_NAME")),
|
||
"处理动作": "",
|
||
"工资账套": decision.get("account", ""),
|
||
"是否换账套": "",
|
||
"调薪类型": "",
|
||
"起薪/调薪时间": config.text(row.get("CHANGE_DATE")),
|
||
"纳税单位": "",
|
||
"固定项总额": "",
|
||
"标准表总额": "",
|
||
"核对结果": "",
|
||
"处理状态": "",
|
||
"说明": "",
|
||
}
|
||
|
||
|
||
def _do_ignore(api: WageApi, row: dict, record: dict, decision: dict,
|
||
fields: dict, log) -> dict:
|
||
"""入职当天借调 → 调 HR「设置忽略」接口(试算模式只记待忽略,不改 HR 数据)。"""
|
||
change_id = config.text(row.get("CHANGE_ID"))
|
||
if bool(fields.get("dry_run", True)):
|
||
record["处理状态"] = config.ST_IGNORE_DRY
|
||
record["说明"] = f"{decision['reason']}(试算未调用忽略接口)"
|
||
log(f"[INFO] {record['姓名']}:试算将设置忽略({decision['reason']})")
|
||
return record
|
||
try:
|
||
api.ignore([change_id])
|
||
except Exception as exc: # noqa: BLE001 - 单条失败不中断整体
|
||
message = getattr(exc, "message", "") or str(exc)
|
||
record["处理状态"] = config.ST_FAIL
|
||
record["说明"] = f"设置忽略失败:{message}"
|
||
log(f"[ERROR] {record['姓名']} 设置忽略失败:{message}", "ERROR")
|
||
return record
|
||
record["处理状态"] = config.ST_IGNORED
|
||
record["说明"] = decision["reason"]
|
||
log(f"[INFO] {record['姓名']}:已设置忽略(CHANGE_ID={change_id[:8]})")
|
||
return record
|
||
|
||
|
||
def evaluate(row: dict, api: WageApi, accounts: dict, std_rows: List[dict],
|
||
fields: dict, log=None, roster_index: dict = None,
|
||
ignore: bool = False) -> dict:
|
||
"""处理单条待办,返回结果行(不抛异常,错误记入「说明」)。
|
||
|
||
Args:
|
||
ignore: 该待办已判定为「入职当天借调」,走 HR「设置忽略」而不是调薪。
|
||
"""
|
||
roster_index = roster_index or {}
|
||
def _log(msg: str, level: str = "INFO") -> None:
|
||
if log:
|
||
log(msg, level)
|
||
|
||
roster_info = roster_index.get(config.text(row.get("base_code")), {}) or {}
|
||
sequence = config.text(roster_info.get("sequence"))
|
||
star = config.text(roster_info.get("star"))
|
||
|
||
started = None if ignore else api.started(config.text(row.get("base_id")))
|
||
decision = classify.decide(row, started, accounts, sequence, star, ignore=ignore)
|
||
record = _base_record(row, decision)
|
||
record["处理动作"] = decision["action"]
|
||
record["职位序列"] = sequence
|
||
record["星级"] = star
|
||
|
||
if decision["action"] == classify.ACTION_IGNORE:
|
||
return _do_ignore(api, row, record, decision, fields, _log)
|
||
if decision["action"] == classify.ACTION_SKIP:
|
||
record["处理状态"] = config.ST_SKIP
|
||
record["说明"] = decision["reason"]
|
||
_log(f"[INFO] {record['姓名']}:跳过({decision['reason']})")
|
||
return record
|
||
if decision["action"] == classify.ACTION_PENDING:
|
||
record["处理状态"] = config.ST_PENDING
|
||
record["说明"] = decision["reason"]
|
||
_log(f"[WARN] {record['姓名']}:待人工核对({decision['reason']})", "WARNING")
|
||
return record
|
||
|
||
account = decision["account"]
|
||
account_id = decision["account_id"]
|
||
if not account_id:
|
||
record["处理状态"] = config.ST_PENDING
|
||
record["说明"] = f"账套「{account}」未取到 ID"
|
||
return record
|
||
|
||
same_account = bool(started) and config.text(started.get("accountId")) == account_id
|
||
base_info_id = config.text(started.get("baseInfoId")) if same_account else ""
|
||
record["是否换账套"] = ("是" if decision.get("switch_account") else "否") if started else "—"
|
||
|
||
brand = config.brand_for_unit(row.get("BELONG_UNIT_ORG_NAME"))
|
||
city = config.city_for_path(row.get("ORG_FULL_PATH"), brand)
|
||
record["品牌"] = brand
|
||
record["区域"] = city
|
||
|
||
check_total = account not in config.NO_TOTAL_CHECK_ACCOUNTS
|
||
std_total, matched, std_reason, parts = None, None, "", None
|
||
if check_total:
|
||
std_total, matched, std_reason = standard_table.match(
|
||
std_rows, sequence=sequence, brand=brand,
|
||
post=config.text(row.get("POST_ORG_NAME")), city=city, star=star)
|
||
if std_total is not None and matched:
|
||
parts, _ = standard_table.expected(matched, city=city, star=star)
|
||
# 按标准表修正固定项:
|
||
# 金色湖畔·门店管理序列 → 绩效奖金;
|
||
# 金色印象·见习主管/见习领班 → 岗位补贴;其余岗位只核对不改值。
|
||
seq_norm = config.SEQUENCE_ALIASES.get(config.norm(sequence), config.norm(sequence))
|
||
fix_items = {}
|
||
if parts:
|
||
standard_posts = config.text((matched or {}).get("post"))
|
||
if (brand in config.PERF_FIX_BRANDS and seq_norm == config.PERF_FIX_SEQUENCE
|
||
and parts.get("kind") == "绩效奖金"):
|
||
fix_items["绩效奖金"] = parts["bonus"]
|
||
elif (brand == "金色印象" and any(
|
||
config.norm(p) in config.norm(standard_posts)
|
||
for p in config.ALLOWANCE_FIX_POSTS)):
|
||
fix_items["岗位补贴"] = parts["allowance"]
|
||
|
||
plan = plan_mod.build_plan(api, row, account_id,
|
||
same_account=same_account, base_info_id=base_info_id,
|
||
brand=brand, city=city, fix_items=fix_items)
|
||
plan["change_wage_type"] = decision["change_wage_type"]
|
||
record["固定项总额"] = ("—" if account in config.NO_TOTAL_CHECK_ACCOUNTS
|
||
else f"{plan['total']:.2f}")
|
||
if decision["change_wage_type"]:
|
||
record["调薪类型"] = config.CHANGE_WAGE_TYPE_NAMES.get(
|
||
decision["change_wage_type"], str(decision["change_wage_type"]))
|
||
|
||
staff_base = api.staff_base(config.text(row.get("base_id"))) \
|
||
if decision["action"] == classify.ACTION_START else {}
|
||
cards = api.wage_cards(config.text(row.get("base_id"))) \
|
||
if decision["action"] == classify.ACTION_START else []
|
||
tax_info = tax.resolve(row, started, staff_base)
|
||
record["纳税单位"] = tax_info["name"] or tax_info["id"] or ""
|
||
if tax_info["name"]:
|
||
_log(f"[INFO] {record['姓名']} 纳税单位:{tax_info['name']}({tax_info['source']})")
|
||
|
||
blockers = list(plan["issues"])
|
||
if not tax_info["id"]:
|
||
blockers.append("未匹配到纳税单位")
|
||
|
||
notes = list(plan.get("warnings") or [])
|
||
notes.extend(plan.get("corrections") or [])
|
||
if decision["action"] == classify.ACTION_START and not cards:
|
||
notes.append("无工资卡信息(起薪提交时不带工资卡)")
|
||
if account in config.NO_TOTAL_CHECK_ACCOUNTS:
|
||
notes.append("技师岗无需核对固定项总额")
|
||
else:
|
||
if std_total is None:
|
||
blockers.append(f"线下标准表核对未通过:{std_reason}")
|
||
else:
|
||
record["标准表总额"] = f"{std_total:.2f}"
|
||
if abs(float(plan["total"]) - float(std_total)) > 0.01:
|
||
blockers.append(
|
||
f"固定项总额 {plan['total']:.2f} 与标准 {std_total:.2f} 不一致")
|
||
else:
|
||
notes.append(f"标准表匹配:{matched.get('post')}/{city}")
|
||
if fix_items and parts:
|
||
expected = {"岗位补贴": parts["allowance"], "薪资小计": parts["salary"]}
|
||
if "绩效奖金" in fix_items:
|
||
expected["绩效奖金"] = parts["bonus"]
|
||
diffs = plan_mod.diff_parts(plan["items"], expected)
|
||
blockers.extend(f"分项核对不通过:{diff}" for diff in diffs)
|
||
if not diffs:
|
||
detail = "、".join(f"{key} {float(value):.2f}"
|
||
for key, value in expected.items())
|
||
notes.append(f"分项核对通过({detail})")
|
||
|
||
record["核对结果"] = "通过" if not blockers else ";".join(blockers)
|
||
if blockers:
|
||
record["处理状态"] = config.ST_PENDING
|
||
record["说明"] = ";".join(notes + blockers)
|
||
_log(f"[WARN] {record['姓名']} 待人工核对:{record['说明']}", "WARNING")
|
||
return record
|
||
|
||
if bool(fields.get("dry_run", True)):
|
||
record["处理状态"] = config.ST_DRY
|
||
record["说明"] = ";".join(notes) or "试算通过,未提交"
|
||
_log(f"[INFO] {record['姓名']} 试算通过(总额 {plan['total']:.2f}),未提交")
|
||
return record
|
||
|
||
try:
|
||
if decision["action"] == classify.ACTION_START:
|
||
payload = submit.start_payload(row, plan, tax_info, account_id, staff_base, cards)
|
||
api.submit_start(payload)
|
||
else:
|
||
payload = submit.change_payload(row, plan, tax_info, account_id, started)
|
||
api.submit_change(payload)
|
||
record["处理状态"] = config.ST_OK
|
||
record["说明"] = ";".join(notes) or "提交成功"
|
||
_log(f"[INFO] {record['姓名']} {decision['action']}提交成功")
|
||
except Exception as exc: # noqa: BLE001 - 单条失败不中断整体
|
||
message = getattr(exc, "message", "") or str(exc)
|
||
record["处理状态"] = config.ST_FAIL
|
||
record["说明"] = f"提交失败:{message}"
|
||
_log(f"[ERROR] {record['姓名']} 提交失败:{message}(已回滚到未处理)", "ERROR")
|
||
return record
|