# -*- coding: utf-8 -*- """处理动作判定:按花名册「职位序列」限定范围并映射工资账套。 规则: - 只处理 门店服务序列 / 门店技师序列 / 门店管理序列(现网「经营系管理序列」等同门店管理序列); - 序列 → 账套:服务账套 / 技师账套 / 管理账套; - 异动类型=离职 → 跳过;星级为高级/资深(标准表未定义档位)→ 跳过;入职类 → 起薪;其他 → 调薪(已起薪才可调); - 调薪时新账套与现有账套不一致 → 换账套。 """ from __future__ import annotations from typing import Optional from .. import config ACTION_START = "起薪" ACTION_CHANGE = "调薪" ACTION_SKIP = "跳过" ACTION_PENDING = "待核对" def _account_name(account_id: str, accounts: dict) -> str: for name, info in accounts.items(): if info.get("id") == account_id: return name return "" def decide(row: dict, started: Optional[dict], accounts: dict, sequence: str = "", star: str = "") -> dict: """返回 {action, reason, account, account_id, switch_account, change_wage_type}。""" unit = config.text(row.get("BELONG_UNIT_ORG_NAME")) change_type = config.text(row.get("CHANGE_TYPE")) change_name = config.CHANGE_TYPE_NAMES.get(change_type, change_type) result = {"action": ACTION_SKIP, "reason": "", "account": "", "account_id": "", "switch_account": False, "change_wage_type": 0, "change_type_name": change_name, "sequence": config.text(sequence)} if unit not in config.BELONG_UNITS: result["reason"] = f"单位不符({unit or '空'}),不在金色印象/金色湖畔事业部" return result if change_type in config.SKIP_TYPES: result["reason"] = "异动类型=离职,按要求不处理" return result seq = config.text(sequence) account = config.sequence_account(seq) if not seq: result["action"] = ACTION_PENDING result["reason"] = "花名册未查到职位序列,需人工确认" return result if not account: result["reason"] = f"职位序列「{seq}」不在门店服务/技师/管理序列,跳过" return result if config.text(star) in config.UNSUPPORTED_STARS: result["reason"] = (f"星级「{config.text(star)}」不在标准表档位内" "(只处理表里有的星级),跳过") return result result["account"] = account result["account_id"] = accounts.get(account, {}).get("id", "") is_start_type = change_type in config.START_TYPES if is_start_type: if started: result["action"] = ACTION_PENDING result["reason"] = "入职类但已有起薪记录,需人工确认(可能二次入职)" return result result["action"] = ACTION_START return result if not started: result["action"] = ACTION_PENDING result["reason"] = "待办显示已起薪但未查到起薪记录(可能需先停薪再起薪),需人工处理" return result wage_type = config.change_wage_type(change_type, change_name) if not wage_type: result["action"] = ACTION_PENDING result["reason"] = f"异动类型「{change_name}」未映射到调薪类型,需人工确认" return result result["change_wage_type"] = wage_type cur_account = _account_name(config.text(started.get("accountId")), accounts) result["switch_account"] = bool(cur_account and cur_account != account) result["action"] = ACTION_CHANGE return result