feat: sync latest ARR implementation
This commit is contained in:
@@ -62,7 +62,7 @@ def period_label(report_month: str, period: str) -> str:
|
||||
return f"21-{as_of.day:02d}"
|
||||
|
||||
|
||||
def period_release_at(report_month: str, period: str) -> datetime:
|
||||
def period_complete_at(report_month: str, period: str) -> datetime:
|
||||
period_to_as_of(report_month, period)
|
||||
year, month = (int(part) for part in report_month.split("-"))
|
||||
if period == "01-10":
|
||||
@@ -76,6 +76,12 @@ def period_release_at(report_month: str, period: str) -> datetime:
|
||||
return datetime.combine(released, datetime_time.min, COMPANY_REPORT_TIME_ZONE)
|
||||
|
||||
|
||||
def period_release_at(report_month: str, period: str) -> datetime:
|
||||
"""Backward-compatible alias for the period completion boundary."""
|
||||
|
||||
return period_complete_at(report_month, period)
|
||||
|
||||
|
||||
def _utc_now() -> str:
|
||||
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
||||
|
||||
@@ -122,8 +128,9 @@ class CompanyReportCoordinator(Protocol):
|
||||
def list_jobs(
|
||||
self,
|
||||
report_month: Optional[str] = None,
|
||||
limit: int = 100,
|
||||
) -> List[Dict[str, Any]]:
|
||||
limit: int = 50,
|
||||
offset: int = 0,
|
||||
) -> tuple[List[Dict[str, Any]], int]:
|
||||
...
|
||||
|
||||
def get_job(self, job_id: str) -> Dict[str, Any]:
|
||||
@@ -148,8 +155,9 @@ class UnavailableCompanyReportCoordinator:
|
||||
def list_jobs(
|
||||
self,
|
||||
report_month: Optional[str] = None,
|
||||
limit: int = 100,
|
||||
) -> List[Dict[str, Any]]:
|
||||
limit: int = 50,
|
||||
offset: int = 0,
|
||||
) -> tuple[List[Dict[str, Any]], int]:
|
||||
raise self._unavailable()
|
||||
|
||||
def get_job(self, job_id: str) -> Dict[str, Any]:
|
||||
@@ -212,11 +220,13 @@ class PersistentCompanyReportCoordinator:
|
||||
if current.tzinfo is None:
|
||||
current = current.replace(tzinfo=COMPANY_REPORT_TIME_ZONE)
|
||||
current = current.astimezone(COMPANY_REPORT_TIME_ZONE)
|
||||
released = period_release_at(report_month, period)
|
||||
if current < released:
|
||||
report_year, report_month_number = (
|
||||
int(part) for part in report_month.split("-")
|
||||
)
|
||||
if (report_year, report_month_number) > (current.year, current.month):
|
||||
raise PortalError(
|
||||
"COMPANY_REPORT_PERIOD_NOT_OPEN",
|
||||
f"该期间将于曼谷时间 {released.strftime('%Y-%m-%d %H:%M')} 开放",
|
||||
"COMPANY_REPORT_MONTH_IN_FUTURE",
|
||||
"未来报表月份暂不可生成",
|
||||
409,
|
||||
)
|
||||
with self._condition:
|
||||
@@ -260,11 +270,17 @@ class PersistentCompanyReportCoordinator:
|
||||
def list_jobs(
|
||||
self,
|
||||
report_month: Optional[str] = None,
|
||||
limit: int = 100,
|
||||
) -> List[Dict[str, Any]]:
|
||||
limit: int = 50,
|
||||
offset: int = 0,
|
||||
) -> tuple[List[Dict[str, Any]], int]:
|
||||
if report_month is not None:
|
||||
validate_month(report_month)
|
||||
if not 1 <= limit <= 200:
|
||||
if (
|
||||
isinstance(limit, bool)
|
||||
or isinstance(offset, bool)
|
||||
or not 1 <= limit <= 200
|
||||
or not 0 <= offset <= 10_000_000
|
||||
):
|
||||
raise PortalError("QUERY_INVALID", "查询参数无效")
|
||||
with self._condition:
|
||||
states = self._states_locked()
|
||||
@@ -272,7 +288,9 @@ class PersistentCompanyReportCoordinator:
|
||||
states = [
|
||||
state for state in states if state.get("report_month") == report_month
|
||||
]
|
||||
return [self._public_locked(state) for state in states[:limit]]
|
||||
total = len(states)
|
||||
page = states[offset : offset + limit]
|
||||
return [self._public_locked(state) for state in page], total
|
||||
|
||||
def get_job(self, job_id: str) -> Dict[str, Any]:
|
||||
with self._condition:
|
||||
@@ -667,7 +685,7 @@ class PersistentCompanyReportCoordinator:
|
||||
message = {
|
||||
"succeeded": "5 家公司渠道明细表已生成。",
|
||||
"partial_failure": "部分公司已生成,失败公司可按错误代码复核后重跑。",
|
||||
"failed": "本次未生成正式渠道明细表,请按错误代码复核后重跑。",
|
||||
"failed": None,
|
||||
}[job_state]
|
||||
with self._condition:
|
||||
self._update_locked(
|
||||
|
||||
Reference in New Issue
Block a user