# -*- coding: utf-8 -*- """纳税单位兜底:优先沿用已显示/花名册值,缺省时按部门全路径中的会馆匹配。""" from __future__ import annotations from .. import config def resolve(row: dict, started: dict = None, staff_base: dict = None) -> dict: """返回 {id, name, source};纳税单位缺失时始终按部门全路径兜底。""" started = started or {} staff_base = staff_base or {} unit_id = config.text(started.get("taxUnitId")) if unit_id: return {"id": unit_id, "name": config.text(started.get("taxUnitName")) or config.TAX_UNITS.get(unit_id, ""), "source": "已显示"} unit_id = config.text(staff_base.get("hsb_field_tax_unit_id")) if unit_id: return {"id": unit_id, "name": config.TAX_UNITS.get(unit_id, ""), "source": "花名册"} unit_id, unit_name = config.tax_unit_by_org_path(row.get("ORG_FULL_PATH")) if unit_id: return {"id": unit_id, "name": unit_name, "source": "部门全路径"} return {"id": "", "name": "", "source": "未匹配"}