feat(shipping-notice): 增强订单抽取与审计功能,支持取消与保留策略
- 在环境配置中新增进度细化、订单提取取消与审计导出相关的开关 - 实现订单抽取运行的取消功能,允许管理员在运行中进行操作 - 引入审计事件的保留策略,支持三年保留期的自动清理 - 更新相关模型与服务,确保新功能的完整性与可追溯性 - 增强文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
1 parent
c85997884b
commit
95cdfe66b0
158 files changed
+19005
-1201
No files matched your search
@@ -82,9 +82,21 @@ export type ShippingOrderExtractionDiagnosticAutoFreezePolicy = {
|
||||
|
||||
export type ShippingOrderExtractionDiagnosticRun = {
|
||||
run_no: string; status: string; phase: string; conversation_id: string;
|
||||
attempt_count: number; current_event_code?: string | null; created_at?: string | null; started_at?: string | null;
|
||||
candidate_materialized_at?: string | null; finished_at?: string | null; error_code?: string | null; durations_ms: Record<string, number | null>;
|
||||
user_id?: number | null;
|
||||
attempt_count: number; progress_version?: number | null;
|
||||
current_event_code?: string | null; created_at?: string | null; started_at?: string | null;
|
||||
candidate_materialized_at?: string | null; finished_at?: string | null; last_activity_at?: string | null;
|
||||
error_code?: string | null; durations_ms: Record<string, number | null>;
|
||||
result_counts: Record<string, number>;
|
||||
cancellation?: {
|
||||
requested: boolean;
|
||||
completed: boolean;
|
||||
in_flight: boolean;
|
||||
requested_at?: string | null;
|
||||
completed_at?: string | null;
|
||||
actor_type?: string | null;
|
||||
reason_code?: string | null;
|
||||
} | null;
|
||||
auto_freeze_policy: ShippingOrderExtractionDiagnosticAutoFreezePolicy;
|
||||
};
|
||||
export type ShippingOrderExtractionDiagnosticDetail = {
|
||||
@@ -93,13 +105,50 @@ export type ShippingOrderExtractionDiagnosticDetail = {
|
||||
units: Array<{ unit_id: number; position: number; unit_type: string; document_type: string; status: string; attempt_count: number; duration_ms?: number | null; error_code?: string | null; route_decisions: Array<{ attempt_no: number; execution_mode: 'deterministic' | 'review_required' | 'skipped'; match_status: string; selected_profile_code?: string | null; selected_profile_version?: number | null; auto_create_approved?: boolean | null; candidate_count: number; table_count: number; approved_table_count: number; candidates: Array<{ profile_code: string; version: number; score: number; hard_match: boolean; reason_codes: string[]; missing_required_anchor_ids?: string[] }>; fallback_reason_codes: string[] }> }>;
|
||||
progress_events: Array<{ sequence_no: number; visibility: 'workspace' | 'admin'; event_code: string; status?: string | null; unit_id?: number | null; document_id?: number | null; reason_code?: string | null; summary?: Record<string, unknown> | null; occurred_at?: string | null }>;
|
||||
};
|
||||
export const listShippingOrderExtractionDiagnosticRuns = (page = 1, pageSize = 25, status = '') => {
|
||||
export type ShippingOrderExtractionHealth = {
|
||||
generated_at: string;
|
||||
health_status: 'healthy' | 'degraded' | string;
|
||||
window_hours: number;
|
||||
thresholds: Record<string, number>;
|
||||
counts: Record<string, number>;
|
||||
status_counts: Record<string, number>;
|
||||
phase_counts: Record<string, number>;
|
||||
error_code_counts: Record<string, number>;
|
||||
failure_rate: number;
|
||||
latency: Record<string, { count: number; avg_ms?: number | null; p50_ms?: number | null; p95_ms?: number | null; max_ms?: number | null }>;
|
||||
stale_run_nos: string[];
|
||||
};
|
||||
export const listShippingOrderExtractionDiagnosticRuns = (
|
||||
page = 1,
|
||||
pageSize = 25,
|
||||
status = '',
|
||||
options?: { staleOnly?: boolean; cancellationInFlight?: boolean },
|
||||
) => {
|
||||
const params = new URLSearchParams({ page: String(page), page_size: String(pageSize) });
|
||||
if (status) params.set('status', status);
|
||||
if (options?.staleOnly) params.set('stale_only', 'true');
|
||||
if (options?.cancellationInFlight) params.set('cancellation_in_flight', 'true');
|
||||
return requestJson<{ items: ShippingOrderExtractionDiagnosticRun[]; total: number; page: number; page_size: number }>(`/api/admin/shipping-notice/order-extraction-runs?${params}`, auth());
|
||||
};
|
||||
export const getShippingOrderExtractionDiagnosticRun = (runNo: string) =>
|
||||
requestJson<ShippingOrderExtractionDiagnosticDetail>(`/api/admin/shipping-notice/order-extraction-runs/${encodeURIComponent(runNo)}`, auth());
|
||||
/** 管理员取消任意活跃订单抽取 Run;代取消必须提供 reason。 */
|
||||
export const cancelShippingOrderExtractionRun = (
|
||||
runNo: string,
|
||||
payload: { reason?: string | null; reason_code?: string | null } = {},
|
||||
) => requestJson<{ run: ShippingOrderExtractionDiagnosticRun }>(
|
||||
`/api/admin/shipping-notice/order-extraction-runs/${encodeURIComponent(runNo)}/cancel`,
|
||||
{ method: 'POST', body: JSON.stringify(payload), ...jsonAuth() },
|
||||
);
|
||||
|
||||
/** 管理员健康聚合:积压、失败率、P50/P95 时延与卡住 Run 编号。 */
|
||||
export const getShippingOrderExtractionHealth = (windowHours = 24) => {
|
||||
const params = new URLSearchParams({ window_hours: String(windowHours) });
|
||||
return requestJson<ShippingOrderExtractionHealth>(
|
||||
`/api/admin/shipping-notice/order-extraction-runs/health?${params}`,
|
||||
auth(),
|
||||
);
|
||||
};
|
||||
|
||||
/** 下载管理员可访问的库存快照,并保留服务端指定的原始文件名。 */
|
||||
export const downloadShippingInventorySnapshot = async (snapshotId: number, fallbackName: string): Promise<void> => {
|
||||
|
||||
Reference in new issue
Block a user