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

@@ -7,6 +7,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { nextTick, ref } from 'vue';
import {
resolveProcessingPollIntervalMs,
resolveProcessingPollBackoffMs,
shouldContinueProcessingPolling,
useShippingNoticeWorkflow,
@@ -31,6 +32,12 @@ vi.mock('../api/shipping.api', () => ({
* 构造历史会话右侧任务投影。
*/
function buildProcessing(conversationId = 'conv-1'): ConversationProcessingProjection {
const needsAction = {
user_task_no: `OT-${conversationId}`,
group: 'needs_action' as const,
can_append: false,
file_count: 2,
};
return {
conversation_id: conversationId,
summary: {
@@ -42,14 +49,12 @@ function buildProcessing(conversationId = 'conv-1'): ConversationProcessingProje
history: 0,
},
processing: [],
needs_action: [{
user_task_no: `OT-${conversationId}`,
group: 'needs_action',
can_append: false,
file_count: 2,
}],
needs_action: [needsAction],
completed: [],
history: [],
status_groups: {
failed: [], waiting_human: [needsAction], processing: [], completed: [], cancelled: [], archived: [],
},
};
}
@@ -111,11 +116,19 @@ function deferred<T>() {
}
describe('useShippingNoticeWorkflow helpers', () => {
it('caps failure backoff at 8s', () => {
expect(resolveProcessingPollBackoffMs(1)).toBe(2000);
expect(resolveProcessingPollBackoffMs(2)).toBe(4000);
expect(resolveProcessingPollBackoffMs(3)).toBe(8000);
expect(resolveProcessingPollBackoffMs(10)).toBe(8000);
it('uses the specified 10s, 20s, 30s failure backoff', () => {
expect(resolveProcessingPollBackoffMs(1)).toBe(10000);
expect(resolveProcessingPollBackoffMs(2)).toBe(20000);
expect(resolveProcessingPollBackoffMs(3)).toBe(30000);
expect(resolveProcessingPollBackoffMs(10)).toBe(30000);
});
it('tiers active polling by elapsed time and page visibility', () => {
expect(resolveProcessingPollIntervalMs({ elapsedMs: 0, visibility: 'visible', hasProcessing: true, failureCount: 0 })).toBe(2000);
expect(resolveProcessingPollIntervalMs({ elapsedMs: 15000, visibility: 'visible', hasProcessing: true, failureCount: 0 })).toBe(5000);
expect(resolveProcessingPollIntervalMs({ elapsedMs: 60000, visibility: 'visible', hasProcessing: true, failureCount: 0 })).toBe(10000);
expect(resolveProcessingPollIntervalMs({ elapsedMs: 0, visibility: 'hidden', hasProcessing: true, failureCount: 0 })).toBe(30000);
expect(resolveProcessingPollIntervalMs({ elapsedMs: 0, visibility: 'visible', hasProcessing: false, failureCount: 0 })).toBeNull();
});
it('stops when processing idle', () => {
@@ -269,7 +282,7 @@ describe('useShippingNoticeWorkflow', () => {
work_items: [{
workItemType: 'order_intake',
workItemNo: 'SNI-1',
sourceType: 'email',
sourceType: 'eml',
conversationId: 'conv-1',
intakeNo: 'SNI-1',
status: 'processing',
@@ -418,7 +431,7 @@ describe('useShippingNoticeWorkflow', () => {
await nextTick();
expect(ctl.error.value).toBe('network_recoverable');
await vi.advanceTimersByTimeAsync(2000);
await vi.advanceTimersByTimeAsync(10000);
await nextTick();
await Promise.resolve();
@@ -450,4 +463,62 @@ describe('useShippingNoticeWorkflow', () => {
expect(ctl.processing.value?.conversation_id).toBe('conv-new');
ctl.stop();
});
it('immediately restores a cached conversation projection while it revalidates', async () => {
const revalidate = deferred<ReturnType<typeof buildUnifiedProcessing>>();
api.getShippingProcessing
.mockResolvedValueOnce(buildUnifiedProcessing('conv-a'))
.mockResolvedValueOnce(buildUnifiedProcessing('conv-b'))
.mockImplementationOnce(() => revalidate.promise);
const conversationId = ref('conv-a');
const ctl = useShippingNoticeWorkflow({ conversationId });
await vi.advanceTimersByTimeAsync(0);
await Promise.resolve();
conversationId.value = 'conv-b';
await nextTick();
await vi.advanceTimersByTimeAsync(0);
await Promise.resolve();
conversationId.value = 'conv-a';
await nextTick();
// 已访问会话首帧使用本会话最后成功 Projection,不会退回骨架或 B 的数据。
expect(ctl.processing.value?.conversation_id).toBe('conv-a');
expect(ctl.initialLoading.value).toBe(false);
expect(ctl.isRefreshing.value).toBe(true);
revalidate.resolve(buildUnifiedProcessing('conv-a'));
ctl.stop();
});
it('drops a response whose server conversation id differs from the request target', async () => {
api.getShippingProcessing.mockResolvedValue(buildUnifiedProcessing('wrong-conversation'));
const ctl = useShippingNoticeWorkflow({ conversationId: ref('conv-a') });
await vi.advanceTimersByTimeAsync(0);
await Promise.resolve();
expect(ctl.processing.value).toBeNull();
ctl.stop();
});
it('marks the restored conversation as initial loading after aborting an old poll', async () => {
const oldPoll = deferred<ReturnType<typeof buildUnifiedProcessing>>();
const newInitial = deferred<ReturnType<typeof buildUnifiedProcessing>>();
api.getShippingProcessing
.mockImplementationOnce(() => oldPoll.promise)
.mockImplementationOnce(() => newInitial.promise);
const conversationId = ref('conv-old');
const ctl = useShippingNoticeWorkflow({ conversationId });
await vi.advanceTimersByTimeAsync(0);
conversationId.value = 'conv-new';
await nextTick();
await vi.advanceTimersByTimeAsync(0);
expect(ctl.initialLoading.value).toBe(true);
expect(ctl.manualRefreshing.value).toBe(false);
expect(ctl.polling.value).toBe(false);
newInitial.resolve(buildUnifiedProcessing('conv-new'));
await Promise.resolve();
ctl.stop();
});
});