feat(shipping): 实现订单批处理聊天聚合展示与优化后端逻辑

This commit is contained in:
hugo committed 2026-08-13 17:40:43 +08:00
1 parent 11cef575b4
commit 523b791c92
38 files changed
+2868 -414

No files matched your search

@@ -5,11 +5,13 @@
* 逻辑:断言不再渲染进度列表/刷新取消/完整 handling 卡片;失败重试与需处理继续处理互斥。
*/
import { mount } from '@vue/test-utils';
import { ref } from 'vue';
import { describe, expect, it } from 'vitest';
import { createI18n } from 'vue-i18n';
import chatZhCn from '@/locales/zh-CN/chat.json';
import ShippingOrderExtractionCard from './ShippingOrderExtractionCard.vue';
import type { ShippingOrderExtractionState } from '../../types/chat.types';
import { SHIPPING_WORKFLOW_KEY } from '../../shipping/useShippingNoticeWorkflow';
const i18n = createI18n({
legacy: false,
@@ -51,6 +53,288 @@ const buildState = (patch: Partial<ShippingOrderExtractionState> = {}): Shipping
});
describe('ShippingOrderExtractionCard', () => {
it('uses unified EML aggregation and keeps candidate creation out of completed', async () => {
const aggregate = {
workItemType: 'order_task', workItemNo: 'INTAKE:SNI-1', sourceType: 'eml', rootOrderTaskNo: 'OT-1',
shippingNoticeNo: null, runNo: 'SNER-EML', caseNo: null, conversationId: 'conv-1', submissionNo: 'SOS-1', intakeNo: 'SNI-1',
status: 'processing', stage: 'candidate_creating', progressVersion: 1, lastActivityAt: '', currentGate: null, availableActions: [],
sourceSummary: { emailSubject: null, filename: 'forwarder.eml', documentCount: 3, parsedDocumentCount: 3, candidateCount: 2, customerName: null, poNumber: null }, childOrderTasks: [],
userStatus: 'running', userStage: 'candidate_creating', facts: { uploadState: 'not_created' },
aggregateSummary: { intakeNo: 'SNI-1', total: 3, completed: 1, processing: 1, needsAction: 0, failed: 1, stages: ['completed', 'candidate_creating'], reasonCodes: ['upload_rpa_failed'] },
aggregateChildren: [
{ workItemType: 'order_task', workItemNo: 'OT-1', sourceType: 'eml', rootOrderTaskNo: 'OT-1', shippingNoticeNo: null, runNo: 'SNER-EML', caseNo: null, conversationId: 'conv-1', submissionNo: 'SOS-1', intakeNo: 'SNI-1', status: 'completed', stage: 'completed', progressVersion: 1, lastActivityAt: '', currentGate: null, availableActions: [], sourceSummary: { emailSubject: null, filename: 'done.pdf', documentCount: 1, parsedDocumentCount: 1, candidateCount: 1, customerName: null, poNumber: null }, childOrderTasks: [], userStatus: 'completed', userStage: 'completed', facts: { uploadState: 'succeeded' } },
{ workItemType: 'order_task', workItemNo: 'OT-2', sourceType: 'eml', rootOrderTaskNo: 'OT-1', shippingNoticeNo: null, runNo: 'SNER-EML', caseNo: null, conversationId: 'conv-1', submissionNo: 'SOS-1', intakeNo: 'SNI-1', status: 'processing', stage: 'candidate_creating', progressVersion: 1, lastActivityAt: '', currentGate: null, availableActions: [], sourceSummary: { emailSubject: null, filename: 'candidate.pdf', documentCount: 1, parsedDocumentCount: 1, candidateCount: 1, customerName: null, poNumber: null }, childOrderTasks: [], userStatus: 'running', userStage: 'candidate_creating', facts: { uploadState: 'not_created' } },
],
} as any;
const wrapper = mount(ShippingOrderExtractionCard, {
props: { state: buildState(), runNo: 'SNER-EML' },
global: { plugins: [i18n], provide: { [SHIPPING_WORKFLOW_KEY as symbol]: { processingWorkItems: ref([aggregate]) } } },
});
expect(wrapper.get('[data-testid="shipping-order-extraction-eml-aggregate"]').text()).toContain('已上传完成 1 · 处理中 1 · 异常 1');
expect(wrapper.text()).not.toContain('已生成候选 3 个文件');
await wrapper.get('[data-testid="shipping-order-extraction-eml-aggregate"] button').trigger('click');
expect(wrapper.text()).toContain('candidate.pdf');
expect(wrapper.text()).toContain('处理中 1');
});
it('keeps its matched EML card when the side-panel poll temporarily omits the intake', async () => {
const workItems = ref<any[]>([{
workItemType: 'order_task', workItemNo: 'INTAKE:SNI-STABLE', sourceType: 'eml', rootOrderTaskNo: 'OT-STABLE',
shippingNoticeNo: null, runNo: 'SNER-STABLE', caseNo: null, conversationId: 'conv-1', submissionNo: 'SOS-1', intakeNo: 'SNI-STABLE',
status: 'processing', stage: 'candidate_creating', progressVersion: 1, lastActivityAt: '', currentGate: null, availableActions: [],
sourceSummary: { emailSubject: null, filename: 'stable.eml', documentCount: 2, parsedDocumentCount: 2, candidateCount: 0, customerName: null, poNumber: null },
childOrderTasks: [], userStatus: 'running', userStage: 'candidate_creating', facts: { uploadState: 'not_created' },
aggregateSummary: { intakeNo: 'SNI-STABLE', total: 2, completed: 0, processing: 2, needsAction: 0, failed: 0, stages: ['candidate_creating'], reasonCodes: [] },
aggregateChildren: [],
}]);
const wrapper = mount(ShippingOrderExtractionCard, {
props: { state: buildState(), runNo: 'SNER-STABLE' },
global: { plugins: [i18n], provide: { [SHIPPING_WORKFLOW_KEY as symbol]: { processingWorkItems: workItems } } },
});
expect(wrapper.get('[data-testid="shipping-order-extraction-eml-aggregate"]').text()).toContain('stable.eml');
// 关键断言:右侧轮询暂时省略本 Intake 时,中间消息卡仍保留其自身的 EML 形态。
workItems.value = [];
await wrapper.vm.$nextTick();
expect(wrapper.get('[data-testid="shipping-order-extraction-eml-aggregate"]').text()).toContain('stable.eml');
});
it('expands an EML inside its status group and shows every child attachment state', async () => {
const child = {
workItemType: 'order_task', workItemNo: 'OT-CHILD-1', sourceType: 'eml', rootOrderTaskNo: 'OT-ROOT',
shippingNoticeNo: null, runNo: 'SNER-DETAIL', caseNo: null, conversationId: 'conv-1', submissionNo: 'SOS-1', intakeNo: 'SNI-DETAIL',
status: 'failed', stage: 'document_parsing', progressVersion: 1, lastActivityAt: '', currentGate: null, availableActions: [],
sourceSummary: { emailSubject: null, filename: 'failed.pdf', documentCount: 1, parsedDocumentCount: 0, candidateCount: 0, customerName: null, poNumber: null },
childOrderTasks: [], userStatus: 'failed', userStage: 'document_parsing', facts: { uploadState: 'not_created' },
blockingReason: { code: 'PARSE_FAILED' },
} as any;
const task = { user_task_no: 'INTAKE:SNI-DETAIL', title: 'mail.eml', file_count: 1, userGroup: 'failed', group: 'needs_action', aggregateChildren: [child], aggregateSummary: { intakeNo: 'SNI-DETAIL', total: 1, completed: 0, processing: 0, needsAction: 0, failed: 1, stages: ['document_parsing'], reasonCodes: ['PARSE_FAILED'] } } as any;
const wrapper = mount(ShippingOrderExtractionCard, {
props: { state: buildState(), runNo: 'SNER-DETAIL' },
global: {
plugins: [i18n],
provide: {
[SHIPPING_WORKFLOW_KEY as symbol]: {
processing: ref({ status_groups: { failed: [task], waiting_human: [], processing: [], completed: [], cancelled: [], archived: [] } }),
processingWorkItems: ref([]),
},
},
},
});
await wrapper.get('[data-testid="shipping-order-extraction-eml-failed-INTAKE:SNI-DETAIL"] button').trigger('click');
expect(wrapper.get('[data-testid="shipping-order-extraction-eml-children"]').text()).toContain('failed.pdf');
expect(wrapper.text()).toContain('异常 1');
expect(wrapper.text()).toContain('文件处理需要人工确认');
expect(wrapper.text()).not.toContain('PARSE_FAILED');
});
it('falls back to the matched work item children when the status task only has a summary', async () => {
const child = {
workItemType: 'order_task', workItemNo: 'OT-FALLBACK-1', sourceType: 'eml', rootOrderTaskNo: 'OT-FALLBACK',
shippingNoticeNo: null, runNo: 'SNER-FALLBACK', caseNo: null, conversationId: 'conv-1', submissionNo: 'SOS-1', intakeNo: 'SNI-FALLBACK',
status: 'processing', stage: 'document_parsing', progressVersion: 1, lastActivityAt: '', currentGate: null, availableActions: [],
sourceSummary: { emailSubject: null, filename: 'inside.eml.pdf', documentCount: 1, parsedDocumentCount: 1, candidateCount: 0, customerName: null, poNumber: null },
childOrderTasks: [], userStatus: 'running', userStage: 'document_parsing', facts: { uploadState: 'not_created' },
} as any;
const task = { user_task_no: 'INTAKE:SNI-FALLBACK', title: 'inside.eml', file_count: 1, userGroup: 'processing', group: 'processing', aggregateChildren: [], aggregateSummary: { intakeNo: 'SNI-FALLBACK', total: 1, completed: 0, processing: 1, needsAction: 0, failed: 0, stages: ['document_parsing'], reasonCodes: [] } } as any;
const wrapper = mount(ShippingOrderExtractionCard, {
props: { state: buildState(), runNo: 'SNER-FALLBACK' },
global: { plugins: [i18n], provide: { [SHIPPING_WORKFLOW_KEY as symbol]: {
processing: ref({ status_groups: { failed: [], waiting_human: [], processing: [task], completed: [], cancelled: [], archived: [] } }),
processingWorkItems: ref([{ workItemType: 'order_intake', workItemNo: 'INTAKE:SNI-FALLBACK', sourceType: 'eml', intakeNo: 'SNI-FALLBACK', aggregateChildren: [child] } as any]),
} } },
});
await wrapper.get('[data-testid="shipping-order-extraction-eml-processing-INTAKE:SNI-FALLBACK"] button').trigger('click');
expect(wrapper.get('[data-testid="shipping-order-extraction-eml-children"]').text()).toContain('inside.eml.pdf');
});
it('counts unique EML attachment children instead of task rows', async () => {
const childA = { workItemType: 'order_task', workItemNo: 'OT-A', sourceType: 'eml', intakeNo: 'SNI-COUNT', sourceSummary: { filename: 'a.pdf', documentId: 101, documentCount: 1 }, status: 'processing', stage: 'document_parsing', userStatus: 'running', facts: { uploadState: 'not_created' } } as any;
const childB = { ...childA, workItemNo: 'OT-B', sourceSummary: { filename: 'b.pdf', documentId: 102, documentCount: 1 } } as any;
const task = { user_task_no: 'INTAKE:SNI-COUNT', title: 'count.eml', file_count: 2, userGroup: 'processing', group: 'processing', aggregateChildren: [childA, childB], aggregateSummary: { intakeNo: 'SNI-COUNT', total: 2, completed: 0, processing: 2, needsAction: 0, failed: 0, stages: [], reasonCodes: [] } } as any;
const wrapper = mount(ShippingOrderExtractionCard, {
props: { state: buildState(), runNo: 'SNER-COUNT' },
global: { plugins: [i18n], provide: { [SHIPPING_WORKFLOW_KEY as symbol]: { processing: ref({ status_groups: { failed: [], waiting_human: [], processing: [task], completed: [], cancelled: [], archived: [] } }), processingWorkItems: ref([]) } } },
});
expect(wrapper.text()).toContain('2 个文件');
});
it('renders every projected file when the batch has two documents', () => {
const wrapper = mount(ShippingOrderExtractionCard, {
props: {
state: buildState({
summary: {
totalDocuments: 2,
pendingDocuments: 0,
processingDocuments: 0,
completedDocuments: 0,
reviewRequiredDocuments: 2,
failedDocuments: 0,
candidateCount: 0,
},
documents: [
{ unitId: 1, documentId: 11, fileName: '4518838154.pdf', status: 'review_required' },
{ unitId: 2, documentId: 12, fileName: '4518838152.pdf', status: 'review_required' },
],
availableActions: ['enter_manual_review'],
healthTips: [],
}),
runNo: 'SNER-2',
},
global: { plugins: [i18n] },
});
expect(wrapper.text()).toContain('4518838154.pdf');
expect(wrapper.text()).toContain('4518838152.pdf');
});
it('groups completed attachments under their EML intake instead of mixing unrelated files', async () => {
const wrapper = mount(ShippingOrderExtractionCard, {
props: {
state: buildState({
documents: [
{ unitId: 1, documentId: 11, intakeId: 7, documentType: 'email_body', fileName: 'Forwarder_A.eml', status: 'processing' },
{ unitId: 2, documentId: 12, intakeId: 7, documentType: 'attachment', fileName: 'Packing_List.pdf', status: 'candidate_ready' },
{ unitId: 3, documentId: 13, intakeId: 8, documentType: 'attachment', fileName: 'Customs_Form.pdf', status: 'processing' },
],
healthTips: [],
}),
},
global: { plugins: [i18n] },
});
await wrapper.find('button').trigger('click');
const text = wrapper.text();
expect(text.indexOf('Forwarder_A.eml')).toBeLessThan(text.indexOf('Packing_List.pdf'));
expect(text).toContain('Customs_Form.pdf');
expect(text.match(/Packing_List\.pdf/g)?.length).toBe(1);
});
it('groups by email_body document type and renders parse failure as failed', () => {
const wrapper = mount(ShippingOrderExtractionCard, {
props: {
state: buildState({
status: 'failed',
summary: {
totalDocuments: 2,
pendingDocuments: 0,
processingDocuments: 0,
completedDocuments: 0,
reviewRequiredDocuments: 0,
failedDocuments: 1,
candidateCount: 0,
},
documents: [
{ unitId: -7, documentId: 7, intakeId: 7, documentType: 'email_body', fileName: 'forwarder-message', status: 'failed', reasonCode: 'intake_parse_failed' },
{ unitId: 8, documentId: 8, intakeId: 7, documentType: 'attachment', fileName: 'po.pdf', status: 'failed', reasonCode: 'intake_parse_failed' },
],
healthTips: [],
currentActivity: null,
}),
},
global: { plugins: [i18n] },
});
const text = wrapper.text();
expect(text).toContain('forwarder-message');
expect(text).toContain('po.pdf');
expect(text).toContain('异常');
expect(wrapper.findAll('.animate-spin').length).toBe(0);
});
it('does not render completed files again as standalone cards', async () => {
const wrapper = mount(ShippingOrderExtractionCard, {
props: {
state: buildState({
summary: {
totalDocuments: 2,
pendingDocuments: 0,
processingDocuments: 0,
completedDocuments: 2,
reviewRequiredDocuments: 0,
failedDocuments: 0,
candidateCount: 2,
},
documents: [
{ unitId: 1, documentId: 11, fileName: '4518838152.pdf', status: 'candidate_ready' },
{ unitId: 2, documentId: 12, fileName: '4518838154.pdf', status: 'candidate_ready' },
],
healthTips: [],
}),
},
global: { plugins: [i18n] },
});
const accordion = wrapper.find('button');
await accordion.trigger('click');
expect(wrapper.text().match(/4518838152\.pdf/g)?.length).toBe(1);
});
it('aggregates a fully completed EML intake only inside the completed section', async () => {
const wrapper = mount(ShippingOrderExtractionCard, {
props: {
state: buildState({
summary: {
totalDocuments: 2,
pendingDocuments: 0,
processingDocuments: 0,
completedDocuments: 2,
reviewRequiredDocuments: 0,
failedDocuments: 0,
candidateCount: 2,
},
documents: [
{ unitId: -7, documentId: 7, intakeId: 7, documentType: 'email_body', fileName: 'forwarder.eml', status: 'processing' },
{ unitId: 8, documentId: 8, intakeId: 7, documentType: 'attachment', fileName: 'packing.pdf', status: 'candidate_ready' },
],
healthTips: [],
}),
},
global: { plugins: [i18n] },
});
expect(wrapper.text()).not.toContain('forwarder.eml');
expect(wrapper.text()).not.toContain('packing.pdf');
await wrapper.find('button').trigger('click');
expect(wrapper.text()).toContain('forwarder.eml');
expect(wrapper.text()).toContain('packing.pdf');
expect(wrapper.text().match(/forwarder\.eml/g)?.length).toBe(1);
expect(wrapper.text().match(/packing\.pdf/g)?.length).toBe(1);
expect(wrapper.text()).toContain('已提取');
});
it('keeps a partially completed EML intake outside the completed section', async () => {
const wrapper = mount(ShippingOrderExtractionCard, {
props: {
state: buildState({
documents: [
{ unitId: -7, documentId: 7, intakeId: 7, documentType: 'email_body', fileName: 'forwarder.eml', status: 'processing' },
{ unitId: 8, documentId: 8, intakeId: 7, documentType: 'attachment', fileName: 'packing.pdf', status: 'candidate_ready' },
{ unitId: 9, documentId: 9, intakeId: 7, documentType: 'attachment', fileName: 'invoice.pdf', status: 'processing' },
],
healthTips: [],
}),
},
global: { plugins: [i18n] },
});
await wrapper.find('button').trigger('click');
expect(wrapper.text()).toContain('forwarder.eml');
expect(wrapper.text()).toContain('invoice.pdf');
expect(wrapper.text().match(/packing\.pdf/g)?.length).toBe(1);
});
it('shows an EML as exception when a child failed even if the parent status is processing', () => {
const wrapper = mount(ShippingOrderExtractionCard, {
props: {
state: buildState({
documents: [
{ unitId: -7, documentId: 7, intakeId: 7, documentType: 'email_body', fileName: 'forwarder.eml', status: 'processing' },
{ unitId: 8, documentId: 8, intakeId: 7, documentType: 'attachment', fileName: 'packing.pdf', status: 'failed', reasonCode: 'intake_parse_failed' },
],
healthTips: [],
}),
},
global: { plugins: [i18n] },
});
expect(wrapper.text()).toContain('异常');
expect(wrapper.text()).not.toContain('解析附件中');
});
it('renders summary title, file count, system processing and no progress/refresh/cancel', () => {
const wrapper = mount(ShippingOrderExtractionCard, {
props: { state: buildState(), runNo: 'SNER-1' },