feat: add public h5 dashboard and publish traceability

This commit is contained in:
Wyndham ARR
2026-08-03 13:04:41 +08:00
parent 7e7470821b
commit 2107f00e32
29 changed files with 1047 additions and 71 deletions

View File

@@ -122,7 +122,13 @@ class ProgramCompanyReportExecutor:
class CompanyReportCoordinator(Protocol):
def create(self, report_month: str, period: str) -> Dict[str, Any]:
def create(
self,
report_month: str,
period: str,
*,
source: Optional[Mapping[str, Any]] = None,
) -> Dict[str, Any]:
...
def list_jobs(
@@ -152,7 +158,14 @@ class UnavailableCompanyReportCoordinator:
503,
)
def create(self, report_month: str, period: str) -> Dict[str, Any]:
def create(
self,
report_month: str,
period: str,
*,
source: Optional[Mapping[str, Any]] = None,
) -> Dict[str, Any]:
_ = source
raise self._unavailable()
def list_jobs(
@@ -220,8 +233,87 @@ class PersistentCompanyReportCoordinator:
self._condition.notify_all()
self._thread.join(timeout=10)
def create(self, report_month: str, period: str) -> Dict[str, Any]:
@staticmethod
def _source_metadata(
source: Optional[Mapping[str, Any]],
) -> Optional[Dict[str, Any]]:
if source is None:
return None
if not isinstance(source, Mapping):
raise PortalError(
"COMPANY_REPORT_SOURCE_INVALID",
"当前 Excel 数据源信息无效",
409,
)
source_batch_id = source.get("source_batch_id")
source_type = source.get("source_type")
filename = source.get("filename")
activated_at = source.get("activated_at")
disposition = source.get("disposition")
if (
isinstance(source_batch_id, bool)
or not isinstance(source_batch_id, int)
or source_batch_id <= 0
or not isinstance(source_type, str)
or source_type not in {"excel", "historical"}
or (
filename is not None
and (
not isinstance(filename, str)
or not filename
or len(filename) > 255
or PurePosixPath(filename).name != filename
)
)
or (
activated_at is not None
and (not isinstance(activated_at, str) or len(activated_at) > 80)
)
or not isinstance(disposition, str)
or not disposition
or len(disposition) > 40
):
raise PortalError(
"COMPANY_REPORT_SOURCE_INVALID",
"当前 Excel 数据源信息无效",
409,
)
counts: Dict[str, int] = {}
for key in (
"source_rows",
"worksheet_count",
"distinct_group_codes",
"room_quantity",
):
value = source.get(key)
if isinstance(value, bool) or not isinstance(value, int) or value < 0:
raise PortalError(
"COMPANY_REPORT_SOURCE_INVALID",
"当前 Excel 数据源信息无效",
409,
)
counts[key] = value
return {
"source_batch_id": source_batch_id,
"source_type": source_type,
"filename": filename,
**counts,
"activated_at": activated_at,
"disposition": disposition,
}
def create(
self,
report_month: str,
period: str,
*,
source: Optional[Mapping[str, Any]] = None,
) -> Dict[str, Any]:
as_of_date = period_to_as_of(report_month, period)
source_metadata = self._source_metadata(source)
current = self._now()
if current.tzinfo is None:
current = current.replace(tzinfo=COMPANY_REPORT_TIME_ZONE)
@@ -258,6 +350,7 @@ class PersistentCompanyReportCoordinator:
"period_label": period_label(report_month, period),
"as_of_date": as_of_date.isoformat(),
"requested_companies": list(COMPANY_NAMES),
"source": source_metadata,
"created_at": _utc_now(),
"started_at": None,
"finished_at": None,
@@ -452,6 +545,11 @@ class PersistentCompanyReportCoordinator:
"period_label": state.get("period_label"),
"as_of_date": state.get("as_of_date"),
"requested_companies": list(COMPANY_NAMES),
"source": (
dict(state["source"])
if isinstance(state.get("source"), Mapping)
else None
),
"created_at": state.get("created_at"),
"started_at": state.get("started_at"),
"finished_at": state.get("finished_at"),