feat(shipping-notice): 增强订单抽取与审计功能,支持取消与保留策略

- 在环境配置中新增进度细化、订单提取取消与审计导出相关的开关
- 实现订单抽取运行的取消功能,允许管理员在运行中进行操作
- 引入审计事件的保留策略,支持三年保留期的自动清理
- 更新相关模型与服务,确保新功能的完整性与可追溯性
- 增强文档与代码注释,反映新的业务逻辑与审计要求
This commit is contained in:
hugo committed 2026-07-30 14:52:21 +08:00
1 parent c85997884b
commit 95cdfe66b0
158 files changed
+19005 -1201

No files matched your search

@@ -0,0 +1,126 @@
/**
* features/admin/api/shipping-audit.api.ts
* 用途:货代统一审计查询/详情/导出 HTTP 客户端。
* 依赖:shared/api/client、getAuthHeaders。
* 逻辑:由 ShippingAuditCenterPage 调用;导出走 blob 下载并保留服务端文件名。
*/
import { requestJson } from '@/shared/api/client';
import { getAuthHeaders } from '@/shared/utils/auth';
export type ShippingAuditEventSummary = {
id: number;
event_type: string;
aggregate_type: string;
aggregate_id: string;
run_no?: string | null;
task_no?: string | null;
document_id?: string | null;
conversation_id?: string | null;
session_item_id?: string | null;
review_case_no?: string | null;
owner_user_id?: string | null;
actor_type: string;
actor_id?: string | null;
request_id?: string | null;
operation_id?: string | null;
result?: string | null;
action?: string | null;
reason_code?: string | null;
error_code?: string | null;
has_snapshots: boolean;
created_at?: string | null;
};
export type ShippingAuditDiffRow = {
key: string;
change: 'added' | 'removed' | 'changed' | string;
before: unknown;
after: unknown;
};
export type ShippingAuditEventDetail = ShippingAuditEventSummary & {
before_snapshot?: Record<string, unknown> | null;
after_snapshot?: Record<string, unknown> | null;
diff?: ShippingAuditDiffRow[];
metadata?: Record<string, unknown>;
evidence_refs?: Array<Record<string, unknown>>;
artifact_refs?: Array<Record<string, unknown>>;
};
export type ShippingAuditFilters = {
event_type?: string;
actor_type?: string;
/** 操作者用户 ID;与后端 audit_query_service.actor_id 对齐 */
actor_id?: string;
run_no?: string;
task_no?: string;
document_id?: string;
operation_id?: string;
request_id?: string;
/** 会话 ID;与后端 conversation_id 筛选对齐 */
conversation_id?: string;
/** 会话 PDF 工作项编号 */
session_item_id?: string;
/** 人工复核 Case 编号 */
review_case_no?: string;
/** 工作项属主用户 ID */
owner_user_id?: string;
result?: string;
created_from?: string;
created_to?: string;
q?: string;
};
const auth = () => ({ headers: getAuthHeaders() });
/**
* 分页查询审计事件列表(无快照全文)。
*/
export function listShippingAuditEvents(page = 1, pageSize = 25, filters: ShippingAuditFilters = {}) {
const params = new URLSearchParams({ page: String(page), page_size: String(pageSize) });
Object.entries(filters).forEach(([key, value]) => {
if (value) params.set(key, String(value));
});
return requestJson<{ items: ShippingAuditEventSummary[]; total: number; page: number; page_size: number }>(
`/api/admin/shipping-notice/audit-events?${params}`,
auth(),
);
}
/**
* 读取单条审计详情(含白名单快照与 diff)。
*/
export function getShippingAuditEvent(eventId: number) {
return requestJson<ShippingAuditEventDetail>(
`/api/admin/shipping-notice/audit-events/${encodeURIComponent(String(eventId))}`,
auth(),
);
}
/**
* 受控导出审计 CSV/JSON,并触发浏览器下载。
*/
export async function exportShippingAuditEvents(
filters: ShippingAuditFilters = {},
format: 'csv' | 'json' = 'csv',
): Promise<void> {
const response = await fetch('/api/admin/shipping-notice/audit-events/export', {
method: 'POST',
headers: {
...getAuthHeaders(),
'Content-Type': 'application/json',
},
body: JSON.stringify({ ...filters, format, limit: 2000 }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const blob = await response.blob();
const disposition = response.headers.get('Content-Disposition') || '';
const filename = disposition.match(/filename="?([^";]+)"?/i)?.[1]
|| `shipping-audit.${format}`;
const objectUrl = URL.createObjectURL(blob);
const anchor = document.createElement('a');
anchor.href = objectUrl;
anchor.download = filename;
anchor.click();
URL.revokeObjectURL(objectUrl);
}