"""1 号药城支付落表班次。""" from __future__ import annotations from dataclasses import dataclass from settle import MallLine, 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], *, dry_run: bool = False, ) -> PaySummary: result = match_pay_lines(lines, repo.load_existing_pay_order_nos()) 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, )