"""Authenticated daily-report retirement, separate from read-only portal access.""" from dataclasses import dataclass from datetime import date from arr_ingestion.contracts import IngestionError from arr_web.contracts import PortalError class UnavailableDailyReports: def retire(self, job_id, business_date, actor): raise PortalError("DAILY_RETIREMENT_UNAVAILABLE", "日报删除服务暂不可用", 503) @dataclass class ProgramDailyReports: repository: object def retire(self, job_id, business_date, actor): try: result = self.repository.retire_daily_job(job_id, date.fromisoformat(business_date), actor) except IngestionError as error: status = 404 if error.code == "DAILY_JOB_NOT_FOUND" else ( 409 if error.code in {"DAILY_DATE_CONFLICT", "DAILY_JOB_BUSY", "REVIEW_STATE_INVALID", "JOB_RETIRED", "DAILY_RETIREMENT_CONFLICT"} else 503) raise PortalError(error.code, "日报记录已变化,请刷新后重试" if status == 409 else "日报删除未完成,请稍后重试", status) from None return {**result, "status": "deleted", "removed_from_month": result["current_removed"]}