feat(shipping): 实现订单批处理聊天聚合展示与优化后端逻辑
This commit is contained in:
1 parent
11cef575b4
commit
523b791c92
38 files changed
+2868
-414
No files matched your search
@@ -613,6 +613,94 @@ describe('conversationProcessingProjection', () => {
|
||||
expect(projection?.summary.total_files).toBe(1);
|
||||
});
|
||||
|
||||
it('aggregates mixed order tasks from one EML intake into one card', () => {
|
||||
const base = {
|
||||
sourceType: 'eml' as const,
|
||||
rootOrderTaskNo: null,
|
||||
shippingNoticeNo: null,
|
||||
conversationId: 'conv-eml',
|
||||
submissionNo: 'SOS-EML',
|
||||
intakeNo: 'INTAKE-EML-1',
|
||||
progressVersion: 1,
|
||||
currentGate: null,
|
||||
childOrderTasks: [],
|
||||
};
|
||||
const items: ShippingProcessingProjection[] = [
|
||||
{
|
||||
...base, workItemType: 'order_task', workItemNo: 'OT-DONE', status: 'completed', stage: 'completed',
|
||||
userStatus: 'completed', userStage: 'completed', lastActivityAt: '2026-08-06T00:00:00Z', availableActions: [],
|
||||
sourceSummary: { emailSubject: 'Shipment', filename: 'a.pdf', documentCount: 1, parsedDocumentCount: 1, candidateCount: 1, customerName: null, poNumber: null },
|
||||
},
|
||||
{
|
||||
...base, workItemType: 'order_task', workItemNo: 'OT-RUN', status: 'processing', stage: 'inventory_matching',
|
||||
userStatus: 'running', userStage: 'inventory_match', lastActivityAt: '2026-08-06T00:00:01Z', availableActions: [],
|
||||
sourceSummary: { emailSubject: 'Shipment', filename: 'b.pdf', documentCount: 1, parsedDocumentCount: 1, candidateCount: 1, customerName: null, poNumber: null },
|
||||
},
|
||||
{
|
||||
...base, workItemType: 'order_task', workItemNo: 'OT-FAIL', status: 'failed', stage: 'freight_uploading',
|
||||
userStatus: 'failed', userStage: 'freight_upload', lastActivityAt: '2026-08-06T00:00:02Z', availableActions: [],
|
||||
blockingReason: { code: 'upload_rpa_failed' },
|
||||
sourceSummary: { emailSubject: 'Shipment', filename: 'c.pdf', documentCount: 1, parsedDocumentCount: 1, candidateCount: 1, customerName: null, poNumber: null },
|
||||
},
|
||||
];
|
||||
const projection = projectConversationProcessingFromWorkItems(items);
|
||||
expect(projection?.needs_action).toHaveLength(1);
|
||||
expect(projection?.processing).toHaveLength(0);
|
||||
expect(projection?.completed).toHaveLength(0);
|
||||
expect(projection?.needs_action[0]?.aggregateSummary).toEqual(expect.objectContaining({
|
||||
intakeNo: 'INTAKE-EML-1', total: 3, completed: 1, processing: 1, needsAction: 1, failed: 1,
|
||||
}));
|
||||
expect(projection?.needs_action[0]?.file_count).toBe(3);
|
||||
expect(projection?.needs_action[0]?.aggregateSummary?.reasonCodes).toContain('upload_rpa_failed');
|
||||
});
|
||||
|
||||
it('does not reuse an empty EML task when a later poll returns aggregate children', () => {
|
||||
const base = {
|
||||
workItemType: 'order_task' as const, sourceType: 'eml' as const, rootOrderTaskNo: 'OT-ROOT',
|
||||
shippingNoticeNo: null, conversationId: 'conv-stable', submissionNo: 'SOS-1', intakeNo: 'SNI-STABLE',
|
||||
progressVersion: 1, currentGate: null, availableActions: [], status: 'processing' as const,
|
||||
stage: 'document_parsing' as const, userStatus: 'running' as const, userStage: 'document_parsing' as const,
|
||||
lastActivityAt: '2026-08-06T00:00:00Z',
|
||||
sourceSummary: { emailSubject: 'mail', filename: 'stable.eml', documentCount: 1, parsedDocumentCount: 1, candidateCount: 0, customerName: null, poNumber: null },
|
||||
};
|
||||
const first = projectConversationProcessingFromWorkItems([{ ...base, workItemNo: 'INTAKE:SNI-STABLE', aggregateSummary: { intakeNo: 'SNI-STABLE', total: 1, completed: 0, processing: 1, needsAction: 0, failed: 0, stages: [], reasonCodes: [] }, aggregateChildren: [] }]);
|
||||
const child = { ...base, workItemNo: 'OT-CHILD', sourceSummary: { ...base.sourceSummary, filename: 'attachment.pdf' } };
|
||||
const second = projectConversationProcessingFromWorkItems([{ ...base, workItemNo: 'INTAKE:SNI-STABLE', aggregateSummary: { intakeNo: 'SNI-STABLE', total: 1, completed: 0, processing: 1, needsAction: 0, failed: 0, stages: [], reasonCodes: [] }, aggregateChildren: [child] }], first);
|
||||
expect(second?.processing[0]?.aggregateChildren?.map((item) => item.sourceSummary.filename)).toEqual(['attachment.pdf']);
|
||||
expect(second?.processing[0]).not.toBe(first?.processing[0]);
|
||||
});
|
||||
|
||||
it('puts an EML with review-required children into needs_action even when parent says processing', () => {
|
||||
const parent = {
|
||||
workItemType: 'order_task' as const, workItemNo: 'INTAKE:SNI-STATUS', sourceType: 'eml' as const,
|
||||
rootOrderTaskNo: null, shippingNoticeNo: null, conversationId: 'conv-status', submissionNo: 'SOS-1', intakeNo: 'SNI-STATUS',
|
||||
status: 'processing' as const, stage: 'document_parsing' as const, userStatus: 'running' as const, userGroup: 'processing' as const,
|
||||
userStage: 'document_parsing' as const, progressVersion: 1, lastActivityAt: '', currentGate: null, availableActions: [],
|
||||
sourceSummary: { emailSubject: null, filename: 'mail.eml', documentCount: 2, parsedDocumentCount: 2, candidateCount: 0, customerName: null, poNumber: null },
|
||||
aggregateChildren: [
|
||||
{ workItemType: 'order_task', workItemNo: 'OT-1', sourceType: 'eml', rootOrderTaskNo: null, shippingNoticeNo: null, conversationId: 'conv-status', submissionNo: 'SOS-1', intakeNo: 'SNI-STATUS', status: 'review_required', stage: 'review_required', userStatus: 'waiting_human', userStage: 'review_required', progressVersion: 1, lastActivityAt: '', currentGate: null, availableActions: [], sourceSummary: { emailSubject: null, filename: 'a.pdf', documentCount: 1, parsedDocumentCount: 1, candidateCount: 0, customerName: null, poNumber: null }, childOrderTasks: [], facts: { uploadState: 'not_created' } },
|
||||
{ workItemType: 'order_task', workItemNo: 'OT-2', sourceType: 'eml', rootOrderTaskNo: null, shippingNoticeNo: null, conversationId: 'conv-status', submissionNo: 'SOS-1', intakeNo: 'SNI-STATUS', status: 'processing', stage: 'document_parsing', userStatus: 'running', userStage: 'document_parsing', progressVersion: 1, lastActivityAt: '', currentGate: null, availableActions: [], sourceSummary: { emailSubject: null, filename: 'b.pdf', documentCount: 1, parsedDocumentCount: 1, candidateCount: 0, customerName: null, poNumber: null }, childOrderTasks: [], facts: { uploadState: 'not_created' } },
|
||||
],
|
||||
} as any;
|
||||
const projection = projectConversationProcessingFromWorkItems([parent]);
|
||||
expect(projection?.needs_action).toHaveLength(1);
|
||||
expect(projection?.processing).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('does not aggregate direct PDFs with matching intake numbers', () => {
|
||||
const common = {
|
||||
workItemType: 'order_task' as const, rootOrderTaskNo: null, shippingNoticeNo: null,
|
||||
conversationId: 'conv-pdf', submissionNo: 'SOS-PDF', intakeNo: 'INTAKE-SAME', progressVersion: 1,
|
||||
currentGate: null, childOrderTasks: [], status: 'processing' as const, stage: 'document_parsing' as const,
|
||||
userStatus: 'running' as const, userStage: 'document_parsing' as const, lastActivityAt: '2026-08-06T00:00:00Z', availableActions: [],
|
||||
};
|
||||
const projection = projectConversationProcessingFromWorkItems([
|
||||
{ ...common, workItemNo: 'OT-1', sourceType: 'direct_pdf', sourceSummary: { emailSubject: null, filename: 'a.pdf', documentCount: 1, parsedDocumentCount: 0, candidateCount: 0, customerName: null, poNumber: null } },
|
||||
{ ...common, workItemNo: 'OT-2', sourceType: 'direct_pdf', sourceSummary: { emailSubject: null, filename: 'b.pdf', documentCount: 1, parsedDocumentCount: 0, candidateCount: 0, customerName: null, poNumber: null } },
|
||||
]);
|
||||
expect(projection?.processing).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('prefers work_items task lists over embedded conversation_processing when both exist', () => {
|
||||
const workItems: ShippingProcessingProjection[] = [
|
||||
{
|
||||
@@ -693,7 +781,10 @@ describe('conversationProcessingProjection', () => {
|
||||
const projection = resolveConversationProcessingFromUnified(workItems, embedded);
|
||||
// 关键断言:兄弟 OT 仅出现在 work_items;embedded 缺 sibling 时不得覆盖任务列表。
|
||||
expect(projection?.needs_action.map((t) => t.user_task_no)).toEqual(['OT-ROOT']);
|
||||
expect(projection?.processing.map((t) => t.user_task_no)).toEqual(['OT-SIBLING']);
|
||||
expect(projection?.processing).toEqual([]);
|
||||
expect(projection?.needs_action[0]?.aggregateSummary).toEqual(expect.objectContaining({
|
||||
intakeNo: 'SNI-1', total: 2, completed: 0, processing: 1, needsAction: 1,
|
||||
}));
|
||||
expect(projection?.focused_task_no).toBe('OT-ROOT');
|
||||
expect(projection?.recent_task_no).toBe('OT-SIBLING');
|
||||
});
|
||||
@@ -1006,7 +1097,7 @@ describe('conversationProcessingProjection — normalize & semantic & stabilize'
|
||||
expect(result!.needs_action[0]!.title).toBe('b.pdf');
|
||||
});
|
||||
|
||||
it('resolveConversationProcessingFromUnified: work_items 仅含 order_intake 时,仍走 embedded normalize 路径(过渡窗口不跳状态)', () => {
|
||||
it('resolveConversationProcessingFromUnified: 仅含 EML order_intake 时,派生统一 processing 投影而非回退 embedded', () => {
|
||||
const embedded: ConversationProcessingProjection = {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 1, needs_action: 0, completed: 0, history: 0 },
|
||||
focused_task_no: 'OT-LEG3',
|
||||
@@ -1035,7 +1126,7 @@ describe('conversationProcessingProjection — normalize & semantic & stabilize'
|
||||
{
|
||||
workItemType: 'order_intake',
|
||||
workItemNo: 'SNI-1',
|
||||
sourceType: 'direct_pdf',
|
||||
sourceType: 'eml',
|
||||
rootOrderTaskNo: null,
|
||||
shippingNoticeNo: null,
|
||||
conversationId: 'conv-1',
|
||||
@@ -1061,13 +1152,16 @@ describe('conversationProcessingProjection — normalize & semantic & stabilize'
|
||||
];
|
||||
const result = resolveConversationProcessingFromUnified(workItems, embedded);
|
||||
expect(result).not.toBeNull();
|
||||
// 过渡阶段:order_intake 不触发统一投影派生;embedded waiting_human 必须 normalize 成 waiting_review/needs_action
|
||||
// EML 尚未创建 OT 时,也必须作为一张 EML 卡进入统一“系统处理中”区。
|
||||
expect(result!.focused_task_no).toBe('OT-LEG3');
|
||||
expect(result!.processing.length).toBe(0);
|
||||
expect(result!.needs_action.length).toBe(1);
|
||||
expect(result!.needs_action[0]!.status_label).toBe('waiting_review');
|
||||
expect(result!.needs_action[0]!.title).toBe('c.pdf');
|
||||
expect(result!.needs_action[0]!.group).toBe('needs_action');
|
||||
expect(result!.needs_action).toHaveLength(0);
|
||||
expect(result!.processing).toHaveLength(1);
|
||||
expect(result!.processing[0]).toMatchObject({
|
||||
user_task_no: 'SNI-1',
|
||||
title: 'c.pdf',
|
||||
group: 'processing',
|
||||
status_label: 'processing',
|
||||
});
|
||||
});
|
||||
|
||||
it('resolveConversationProcessingFromUnified + IntakeOtStabilizer: 看到 order_task 后 2s 内暂缺 OT 保持 previousProjection(避免轮询抖动)', () => {
|
||||
|
||||
Reference in new issue
Block a user