"""1 号药城支付落表班次。""" from __future__ import annotations from dataclasses import dataclass from typing import Any from settle import MallLine, attach_detail_ids, match_pay_lines @dataclass class PaySummary: source_lines: int = 0 inserted: int = 0 skipped_status: int = 0 skipped_dup: int = 0 unmatched: int = 0 unmatched_reasons: dict[str, int] | None = None def __post_init__(self) -> None: if self.unmatched_reasons is None: self.unmatched_reasons = {} def run_yaoex_pay( repo, lines: list[MallLine], details: dict[str, dict[str, Any]], *, dry_run: bool = False, ) -> PaySummary: attached = attach_detail_ids(lines, details) result = match_pay_lines(attached, repo.load_existing_pay_keys()) if result.rows and not dry_run: repo.save_pay_rows(result.rows) reasons: dict[str, int] = {} for _line, reason in result.unmatched: reasons[reason] = reasons.get(reason, 0) + 1 return PaySummary( source_lines=len(lines), inserted=len(result.rows), skipped_status=len(result.skipped_status), skipped_dup=len(result.skipped_dup), unmatched=len(result.unmatched), unmatched_reasons=reasons, )