feat(shipping-freight-auto-upload): 新增货代发货Excel连接级自动上传全链路功能

为提升货代上传的自动化程度,减少人工操作,本提交实现完整的连接级自动上传功能,包含以下变更:
- 新增数据库迁移与ShippingRpaProfile模型字段,存储连接级上传配置
- 完善RPA自动上传触发、回调与状态管理逻辑,支持三态结果与人工兜底
- 优化聊天界面任务卡片加载与按钮渲染,修复无文案幽灵按钮问题
This commit is contained in:
hugo committed 2026-08-27 12:44:12 +08:00
1 parent 06c18b3c7c
commit 434c04ed2d
30 files changed
+1574 -185

No files matched your search

@@ -594,6 +594,7 @@ async function mountView(query: Record<string, string> = {}) {
waiting_to_start: '等待系统启动',
order_creating: '等待系统启动',
inventory_matching: '库存匹配',
excel_generating: 'Excel 生成',
},
},
currentTask: {
@@ -680,7 +681,14 @@ async function mountView(query: Record<string, string> = {}) {
},
progress: {
step: { profile_matching: '正在匹配订单模板' },
lifecycleReason: { processing_slow: '当前步骤耗时较长,系统仍在继续。' },
lifecycleReason: {
processing_slow: '当前步骤耗时较长,系统仍在继续。',
review_required: '当前结果需要人工复核。',
failed: '当前步骤处理失败,请查看详情后重试。',
cancelled: '本次处理已取消。',
},
systemProcessingNeed: '系统正在自动处理,请稍候或刷新进度',
lifecycleWaitingNeed: '当前步骤需要人工处理',
},
},
shippingSessionWorkItem: {
@@ -873,6 +881,54 @@ describe('ShippingOrderReviewView layout phase 1', () => {
expect(wrapper.get('[data-testid="review-run-lifecycle-progress"]').text()).toContain('正在匹配订单模板');
});
it('does not claim automatic processing when the run is waiting at a human gate', async () => {
// 关键断言:门禁待机(waiting)时不得声称「系统正在自动处理」,也不得渲染呼吸点;
// 后端此时通常没有 current_step_i18n_key,旧逻辑会落入自动处理兜底文案。
activeCase.value = null as any;
reviewRun.value = { run_no: 'RUN-WAITING-GATE', items: [] };
extractionLifecycleProgress.value = {
lifecycle_stage: 'order_review', lifecycle_status: 'waiting',
current_step_i18n_key: null,
blocking_reason_i18n_key: 'chat.shippingProcessing.progress.lifecycleReason.review_required',
completed_step_codes: [], health_status: 'normal',
};
const wrapper = await mountView();
const banner = wrapper.get('[data-testid="review-run-lifecycle-current-step"]');
expect(banner.text()).not.toContain('系统正在自动处理');
expect(banner.text()).toContain('当前结果需要人工复核');
expect(banner.html()).not.toContain('animate-pulse');
});
it('shows a waiting fallback without the auto-processing claim when no reason is provided', async () => {
// 关键断言:waiting 且后端未给原因/步骤时,只展示「需要人工处理」,禁止回到自动处理文案。
activeCase.value = null as any;
reviewRun.value = { run_no: 'RUN-WAITING-FALLBACK', items: [] };
extractionLifecycleProgress.value = {
lifecycle_stage: 'order_review', lifecycle_status: 'waiting',
current_step_i18n_key: null,
blocking_reason_i18n_key: null,
completed_step_codes: [], health_status: 'normal',
};
const wrapper = await mountView();
const banner = wrapper.get('[data-testid="review-run-lifecycle-current-step"]');
expect(banner.text()).not.toContain('系统正在自动处理');
expect(banner.text()).toContain('当前步骤需要人工处理');
});
it('does not render the run progress banner for a completed run', async () => {
// 关键断言:Run 已完成时无待办,横幅直接隐藏,避免「已完成仍显示处理中」的矛盾。
activeCase.value = null as any;
reviewRun.value = { run_no: 'RUN-COMPLETED', items: [] };
extractionLifecycleProgress.value = {
lifecycle_stage: 'order_review', lifecycle_status: 'completed',
current_step_i18n_key: null,
blocking_reason_i18n_key: null,
completed_step_codes: ['review_ready'], health_status: 'normal',
};
const wrapper = await mountView();
expect(wrapper.find('[data-testid="review-run-lifecycle-current-step"]').exists()).toBe(false);
});
it('loads a cross-Run file once through the route watcher', async () => {
const originalQueue = reviewQueue.value;
try {
@@ -1211,6 +1267,30 @@ describe('ShippingOrderReviewView layout phase 1', () => {
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
});
it('keeps the known Case stage while the authoritative projection is still loading', async () => {
// Case 先到、Projection 后到的过渡窗口:阶段与投影同源(project_stage_for_task),
// 必须直接展示「Excel 生成」,禁止退回自动建单阶段或“正在更新状态”占位。
activeCase.value = {
...activeCase.value,
status: 'confirmed',
has_formal_ot: true,
task_missing: false,
confirmed_task_id: 91,
confirmed_task_no: 'SN-STAGE-PENDING',
current_stage: { code: 'excel_generating', label_key: 'excel_generating', inconsistent: false },
automation: { status: 'running', retryable: false, can_auto_create: false, can_build: true },
};
shippingProcessingProjection.value = null;
shippingProcessingLoading.value = true;
const wrapper = await mountView();
await flushPromises();
expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).toContain('Excel 生成');
// 状态列:loading 只抑制动作,不掩盖后端 automation 运行态真值(系统处理中)。
expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toContain('系统处理中');
});
it('does not render legacy reparse failure stage as a separate progress source', async () => {
reviewProgressContext.value = {
item_no: 'WFI-1',
@@ -2047,6 +2127,120 @@ describe('ShippingOrderReviewView layout phase 1', () => {
expect(startWorkflowProgressPollingMock).toHaveBeenCalledTimes(2);
});
it('advances to freight upload after an accepted shortage release', async () => {
const taskApi = await import('@/features/chat/api/shipping.api');
let releaseAccepted = false;
activeCase.value = {
...activeCase.value,
status: 'confirmed', confirmed_task_id: 903, confirmed_task_no: 'SN-FROZEN', has_formal_ot: true,
line_fulfillment: {
lines: [{
line_key: 'line-frozen',
inventory_source: { code: 'DBS', label: 'DBS', status: 'resolved' },
line_allowed_actions: ['release_inventory_shortage'],
release_template_fields: [
{ field_id: '101', display_name: 'ODM ID', value: 'ODM-001', value_source: 'inventory_snapshot', requires_manual: false },
{ field_id: '102', display_name: '库位', value: null, value_source: 'manual_required', requires_manual: true },
],
release_required_fields: [{ field_id: '102', display_name: '库位' }],
}],
},
};
vi.mocked(taskApi.decideWorkspaceShippingOrderReviewLineFulfillment).mockImplementation(async () => {
releaseAccepted = true;
return { status: 'ok' } as any;
});
vi.mocked(taskApi.getWorkspaceShippingTask).mockImplementation(async () => ({
task_no: 'SN-FROZEN', status: 'waiting_human', lines: [], events: [],
ui_state: {
process_gate: {
execution_no: 'EXEC-FROZEN-LINE',
current_blocking_gate: { gate_code: 'manual_upload_handoff', status: 'blocked_manual' },
},
actions: { primary: null, secondary: [] },
lifecycle_stage: releaseAccepted ? 'freight_upload' : 'fulfillment_prep',
lifecycle_entries: releaseAccepted
? [
{ code: 'fulfillment_prep', state: 'available' },
{ code: 'freight_upload', state: 'current' },
]
: [{ code: 'fulfillment_prep', state: 'current' }],
stage_context: { upload: {} },
},
} as any));
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
await flushPromises();
await wrapper.get('[data-testid="review-fulfillment-line-release-line-frozen"]').trigger('click');
const dialog = wrapper.get('[data-testid="review-release-inventory-dialog"]');
await dialog.find('textarea').setValue('客户确认分批发货');
await dialog.find('input').setValue('A-01');
await dialog.get('button.bg-amber-600').trigger('click');
await new Promise<void>((resolve) => setTimeout(resolve, 0));
await nextTick();
// 放行后的首个权威刷新抵达目标阶段时,页面必须同步深链。
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
.toBe('freight_upload');
});
it('keeps notification preparation when the user navigates there while a shortage release is advancing', async () => {
const taskApi = await import('@/features/chat/api/shipping.api');
let releaseAccepted = false;
let resolvePostReleaseTask: ((detail: any) => void) | null = null;
activeCase.value = {
...activeCase.value,
status: 'confirmed', confirmed_task_id: 904, confirmed_task_no: 'SN-MANUAL', has_formal_ot: true,
line_fulfillment: {
lines: [{
line_key: 'line-manual',
inventory_source: { code: 'DBS', label: 'DBS', status: 'resolved' },
line_allowed_actions: ['release_inventory_shortage'],
release_template_fields: [
{ field_id: '101', display_name: 'ODM ID', value: 'ODM-001', value_source: 'inventory_snapshot', requires_manual: false },
{ field_id: '102', display_name: '库位', value: null, value_source: 'manual_required', requires_manual: true },
],
release_required_fields: [{ field_id: '102', display_name: '库位' }],
}],
},
};
const taskDetail = () => ({
task_no: 'SN-MANUAL', status: 'waiting_human', lines: [], events: [],
ui_state: {
process_gate: { execution_no: 'EXEC-MANUAL-LINE', current_blocking_gate: { gate_code: 'manual_upload_handoff', status: 'blocked_manual' } },
actions: { primary: null, secondary: [] },
lifecycle_stage: releaseAccepted ? 'freight_upload' : 'fulfillment_prep',
lifecycle_entries: releaseAccepted
? [{ code: 'fulfillment_prep', state: 'available' }, { code: 'freight_upload', state: 'current' }]
: [{ code: 'fulfillment_prep', state: 'current' }],
stage_context: { upload: {} },
},
});
vi.mocked(taskApi.decideWorkspaceShippingOrderReviewLineFulfillment).mockImplementation(async () => {
releaseAccepted = true;
return { status: 'ok' } as any;
});
vi.mocked(taskApi.getWorkspaceShippingTask).mockImplementation(async () => {
if (!releaseAccepted) return taskDetail() as any;
return new Promise((resolve) => { resolvePostReleaseTask = resolve; });
});
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
await wrapper.get('[data-testid="review-fulfillment-line-release-line-manual"]').trigger('click');
const dialog = wrapper.get('[data-testid="review-release-inventory-dialog"]');
await dialog.find('textarea').setValue('客户确认分批发货');
await dialog.find('input').setValue('A-01');
await dialog.get('button.bg-amber-600').trigger('click');
await wrapper.get('[data-testid="review-lifecycle-stage-fulfillment_prep"]').findAll('button')[1].trigger('click');
resolvePostReleaseTask?.(taskDetail());
await new Promise<void>((resolve) => setTimeout(resolve, 0));
await nextTick();
// 用户显式回看通知准备会消费本次自动推进许可,后端异步投影不得抢回焦点。
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
.toBe('fulfillment_prep');
});
it('keeps the manual notice-generation entry in the main workspace for an editable formal task', async () => {
const taskApi = await import('@/features/chat/api/shipping.api');
reviewEditable.value = false;