refactor(shipping-notice): 重构货代发货通知状态管理,移除废弃的process_status字段

统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成
设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程
删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本
替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段
更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
This commit is contained in:
hugo committed 2026-08-15 10:19:10 +08:00
1 parent 6684e7181a
commit 5ef8329bd8
178 files changed
+5091 -1734

No files matched your search

@@ -22,6 +22,8 @@ import {
buildTaskSemanticKey,
buildProcessingSemanticKey,
stabilizeTaskObjects,
flattenBusinessFileProjections,
businessFileKeys,
} from './conversationProcessingProjection';
import type {
ConversationProcessingProjection,
@@ -29,6 +31,28 @@ import type {
ShippingWorkflowItem,
} from '@/features/chat/types/shipping.api.types';
describe('EML business-file projection', () => {
it('excludes the EML container and keeps its PDF/XLSX leaf attachments', () => {
const eml = {
workItemType: 'order_task', workItemNo: 'INTAKE:SNI-1', sourceType: 'eml',
sourceSummary: { filename: 'mail.eml', documentCount: 2 },
aggregateChildren: [
{ workItemType: 'order_task', workItemNo: 'OT-1', sourceType: 'eml', sourceSummary: { filename: 'notice-a.pdf', documentId: 101, documentCount: 1 } },
{ workItemType: 'order_task', workItemNo: 'OT-2', sourceType: 'eml', sourceSummary: { filename: 'items.xlsx', documentId: 102, documentCount: 1 } },
],
} as ShippingProcessingProjection;
const directPdf = {
workItemType: 'order_task', workItemNo: 'OT-3', sourceType: 'direct_pdf',
sourceSummary: { filename: 'direct.pdf', documentId: 103, documentCount: 1 },
} as ShippingProcessingProjection;
// EML 仅为来源分组,3 个业务附件才是唯一文件集合。
expect(flattenBusinessFileProjections([eml, directPdf]).map((row) => row.sourceSummary.filename))
.toEqual(['notice-a.pdf', 'items.xlsx', 'direct.pdf']);
expect(businessFileKeys([eml, directPdf])).toEqual(['document:101', 'document:102', 'document:103']);
});
});
function item(partial: Partial<ShippingWorkflowItem>): ShippingWorkflowItem {
return {
item_no: 'WI-1',
@@ -891,6 +915,43 @@ describe('conversationProcessingProjection — normalize & semantic & stabilize'
expect(t2.available_actions).toEqual(['open_order_review', 'view_details']);
});
it('buildTaskSemanticKey: ui_state 动作变化必须改变签名', () => {
const shared = {
user_task_no: 'INTAKE:SNI-UI', group: 'needs_action' as const,
status_label: 'waiting_human', file_count: 1, can_append: false,
available_actions: ['retry_parse'],
};
const before = {
...shared,
uiState: {
status: 'waiting_human', stage: 'order_review', blocking_reason: null,
primary_action: { code: 'open_order_review', i18nKey: 'action.open_order_review', parameters: {} },
secondary_actions: [],
},
};
const after = {
...before,
uiState: {
...before.uiState,
primary_action: { code: 'retry_parse', i18nKey: 'action.retry_parse', parameters: {} },
},
};
expect(buildTaskSemanticKey(before)).not.toBe(buildTaskSemanticKey(after));
});
it('buildTaskSemanticKey: authoritative ui_state without a primary action ignores stale legacy action', () => {
const shared = {
user_task_no: 'INTAKE:SNI-NO-ACTION', group: 'processing' as const,
status_label: 'processing', file_count: 1, can_append: false,
primary_action: 'retry_parse', available_actions: ['retry_parse'],
uiState: { status: 'processing', stage: 'document_parsing', blocking_reason: null, primary_action: null, secondary_actions: [] },
};
const withoutLegacy = { ...shared, primary_action: null, available_actions: [] };
// 后端 ui_state 已明确“无动作”时,旧字段变动不能让状态卡语义闪烁或伪造 CTA。
expect(buildTaskSemanticKey(shared)).toBe(buildTaskSemanticKey(withoutLegacy));
});
it('stabilizeTaskObjects: 同一 user_task_no 且语义相同,优先复用旧对象引用(避免 DOM 重建)', () => {
const baseTask = (no: string, updatedAt: string) => ({
user_task_no: no,
@@ -1063,6 +1124,55 @@ describe('conversationProcessingProjection — normalize & semantic & stabilize'
expect(normalized.processing.length).toBe(0);
});
it('normalizes backend status-group task UI state and EML children without recalculating batch facts', () => {
const backendProjection = {
// 统计是后端按完整批次裁决的事实,不能由当前返回的局部 EML/附件数组替代。
summary: { total_tasks: 1, total_files: 7, processing: 0, needs_action: 1, completed: 0, history: 0 },
focused_task_no: 'INTAKE:SNI-API',
recent_task_no: 'INTAKE:SNI-API',
needs_action: [], processing: [], completed: [], history: [],
status_groups: {
failed: [{
user_task_no: 'INTAKE:SNI-API', title: 'source.eml', display_kind: 'multi_document_task',
document_names: ['a.pdf', 'b.pdf'], group: 'needs_action', status_label: 'failed', file_count: 2,
can_append: false, available_actions: [], primary_action: null,
ui_state: {
status: 'failed', stage: 'document_parsing',
blocking_reason: { code: 'PARSE_FAILED', i18n_key: 'shipping.parse_failed', details: {} },
primary_action: { code: 'retry', i18n_key: 'shipping.retry', parameters: {} }, secondary_actions: [],
},
aggregate_children: [{
work_item_type: 'order_task', work_item_no: 'OT-API-1', source_type: 'direct_pdf',
root_order_task_no: 'OT-API-1', shipping_notice_no: null, conversation_id: 'conv-api',
submission_no: 'SUB-1', intake_no: 'SNI-API', status: 'failed', stage: 'document_parsing',
progress_version: 1, last_activity_at: '2026-08-14T00:00:00Z', current_gate: null, available_actions: [],
source_summary: { email_subject: 'Subject', filename: 'a.pdf', document_count: 1, parsed_document_count: 0, candidate_count: 0 },
child_order_tasks: [], ui_state: {
status: 'failed', stage: 'document_parsing', blocking_reason: { code: 'PARSE_FAILED', details: {} },
primary_action: { code: 'retry', parameters: {} }, secondary_actions: [],
},
}],
}],
waiting_human: [], processing: [], completed: [], cancelled: [], archived: [],
},
four_stage_nodes: [{ code: 'intake_parse', label_key: 'shipping.stage.intake', status: 'blocked' }],
output_artifacts: [{ order_task_no: 'OT-API-1', filename: 'shipping.xlsx', type: 'excel', status: 'ready', action: { code: 'download_excel', enabled: true } }],
} as unknown as ConversationProcessingProjection;
const normalized = normalizeConversationProcessingProjection(backendProjection);
const eml = normalized.status_groups!.failed[0]!;
// 后端裁决的状态/按钮必须在 EML 与附件层均可直接消费,前端不重新推导。
expect(eml.uiState?.primary_action?.code).toBe('retry');
expect(eml.uiState?.primary_action?.i18nKey).toBe('shipping.retry');
expect(eml.aggregateChildren?.[0]?.uiState?.primary_action?.code).toBe('retry');
expect(eml.aggregateChildren?.[0]?.sourceSummary.filename).toBe('a.pdf');
// 批次统计、四阶段与产物均是后端事实,适配时不得从附件重算或丢失。
expect(normalized.summary.total_files).toBe(7);
expect(normalized.four_stage_nodes).toEqual([{ code: 'intake_parse', label_key: 'shipping.stage.intake', status: 'blocked' }]);
expect(normalized.output_artifacts?.[0]?.action.enabled).toBe(true);
});
it('resolveConversationProcessingFromUnified: work_items 为空时,embedded waiting_human 任务迁入 needs_action 且统一文案', () => {
const embedded: ConversationProcessingProjection = {
summary: { total_tasks: 1, total_files: 1, processing: 1, needs_action: 0, completed: 0, history: 0 },