refactor(shipping-notice): 重构货代发货通知状态管理,移除废弃的process_status字段
统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成 设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程 删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本 替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段 更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
This commit is contained in:
1 parent
6684e7181a
commit
5ef8329bd8
178 files changed
+5091
-1734
No files matched your search
@@ -53,7 +53,7 @@ const buildBatchUiStateEvent = (
|
||||
task_no: taskNo,
|
||||
batch_no: batchNo,
|
||||
checkpoint,
|
||||
process_status: 'matched',
|
||||
match_status: 'matched',
|
||||
review_status: null,
|
||||
pending_human_reason: null,
|
||||
match_status: 'fulfillable',
|
||||
@@ -92,7 +92,7 @@ describe('useChat shipping_ui_state SSE', () => {
|
||||
|
||||
expect(message.shipping_ui_state?.task_no).toBe('SN-UNIT-001');
|
||||
expect(message.shipping_actions).toBeUndefined();
|
||||
expect((message.payload as { action_buttons?: unknown[] }).action_buttons).toEqual([]);
|
||||
expect((message.payload as { action_buttons?: unknown[] }).action_buttons).toBeUndefined();
|
||||
expect((message.payload as { shipping_batch_ui_state?: { batch_no?: string } }).shipping_batch_ui_state?.batch_no).toBe('SB-UNIT-001');
|
||||
});
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ export const applyShippingUiStateToMessage = (msg: ChatMessage, data: Record<str
|
||||
msg.shipping_ui_state = uiState;
|
||||
msg.shipping_actions = undefined;
|
||||
if (msg.type === 'shipping-match-result' && msg.payload && typeof msg.payload === 'object') {
|
||||
(msg.payload as { action_buttons?: ChatMessage['shipping_actions'] }).action_buttons = [];
|
||||
delete (msg.payload as { action_buttons?: ChatMessage['shipping_actions'] }).action_buttons;
|
||||
}
|
||||
msg.payload = {
|
||||
...(msg.payload && typeof msg.payload === 'object' ? msg.payload as Record<string, unknown> : {}),
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* features/chat/composables/useChatRouteSync.spec.ts
|
||||
* 用途:验证聊天路由初始化的关键首屏请求调度。
|
||||
* 依赖:vitest、useChatRouteSync。
|
||||
* 逻辑:历史会话列表属于后台辅助数据,不能阻塞指定 conversation 的消息与进度加载。
|
||||
*/
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
vi.mock('vue', () => ({
|
||||
onBeforeUnmount: vi.fn(),
|
||||
onMounted: vi.fn(),
|
||||
watch: vi.fn(),
|
||||
}));
|
||||
|
||||
import { useChatRouteSync } from './useChatRouteSync';
|
||||
|
||||
describe('useChatRouteSync', () => {
|
||||
it('starts the requested conversation before the history list resolves', async () => {
|
||||
let resolveHistory!: () => void;
|
||||
const loadHistory = vi.fn(() => new Promise<void>((resolve) => {
|
||||
resolveHistory = resolve;
|
||||
}));
|
||||
const loadConversation = vi.fn(async () => undefined);
|
||||
const routeSync = useChatRouteSync({
|
||||
deps: {
|
||||
route: {
|
||||
params: { agentId: '24' },
|
||||
query: { conversation_id: 'conversation-b' },
|
||||
},
|
||||
router: { push: vi.fn() },
|
||||
} as never,
|
||||
currentAgentId: { value: 24 } as never,
|
||||
presetQuestion: { value: '' } as never,
|
||||
shippingTaskIdFromQuery: { value: null } as never,
|
||||
isShippingNoticeAgent: { value: true } as never,
|
||||
resetChatStateForAgentChange: vi.fn(),
|
||||
cancelVoiceInput: vi.fn(),
|
||||
syncCurrentUserProfile: vi.fn(async () => undefined),
|
||||
loadAgent: vi.fn(async () => undefined),
|
||||
loadUserAgents: vi.fn(async () => undefined),
|
||||
loadHistory,
|
||||
loadConversation,
|
||||
resumeShippingTaskFromQuery: vi.fn(async () => undefined),
|
||||
handleSend: vi.fn(async () => undefined),
|
||||
createNewChatView: vi.fn(),
|
||||
onAuthLogout: vi.fn(),
|
||||
onViewportResize: vi.fn(),
|
||||
disposePeripherals: vi.fn(),
|
||||
scheduleScrollToBottom: vi.fn(),
|
||||
input: { value: '' } as never,
|
||||
});
|
||||
|
||||
const pending = routeSync.syncChatStateForRoute();
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(loadHistory).toHaveBeenCalledTimes(1);
|
||||
expect(loadConversation).toHaveBeenCalledWith('conversation-b', { force: true });
|
||||
});
|
||||
|
||||
resolveHistory();
|
||||
await pending;
|
||||
});
|
||||
});
|
||||
@@ -94,16 +94,23 @@ export function useChatRouteSync(options: UseChatRouteSyncOptions) {
|
||||
await loadUserAgents();
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
|
||||
await loadHistory();
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
|
||||
const convId = route.query.conversation_id as string;
|
||||
// 历史列表是辅助内容;直达会话时不能阻塞消息/货代 Projection 的首屏读取。
|
||||
const historyPromise = loadHistory();
|
||||
if (convId) {
|
||||
await loadConversation(convId, { force: true });
|
||||
await Promise.all([
|
||||
historyPromise,
|
||||
loadConversation(convId, { force: true }),
|
||||
]);
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
} else if (shippingTaskIdFromQuery.value || shippingBatchNoFromQuery?.value) {
|
||||
await historyPromise;
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
await resumeShippingTaskFromQuery();
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
} else {
|
||||
await historyPromise;
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
}
|
||||
|
||||
if (presetQuestion.value) {
|
||||
|
||||
@@ -103,7 +103,7 @@ describe('useChatShipping persisted batch snapshot', () => {
|
||||
shipping_batch_ui_state: {
|
||||
batch_no: 'SB-EXISTING',
|
||||
current_focus_task_no: 'SN-EXISTING',
|
||||
tasks: [{ task_no: 'SN-EXISTING', source_type: 'email', process_status: 'pending_review' }],
|
||||
tasks: [{ task_no: 'SN-EXISTING', source_type: 'email', review_status: 'parse_review' }],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -133,7 +133,7 @@ describe('useChatShipping message recovery payload', () => {
|
||||
shipping_ui_state: {
|
||||
task_no: 'SN-OPEN-EXISTING',
|
||||
batch_no: 'SB-OPEN-EXISTING',
|
||||
process_status: 'waiting_inventory',
|
||||
inventory_lines_json: [{ reservation_id: 'R-1' }],
|
||||
steps: [],
|
||||
summary: {},
|
||||
action_buttons: [],
|
||||
|
||||
@@ -554,7 +554,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
|
||||
const hasRunningShippingBatchTasks = () =>
|
||||
shippingBatchTasks.value.some(
|
||||
(task) => !['uploaded', 'completed', 'closed', 'rejected'].includes(String(task.process_status || '').trim()),
|
||||
(task) => String(task.ui_state?.stage?.code || '').trim() !== 'upload_complete',
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -591,10 +591,10 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const normalizedTaskId = String(taskId || getActiveShippingTaskId() || '').trim().toUpperCase();
|
||||
if (!conversationKey || !normalizedTaskId || !isShippingNoticeAgent.value || isShippingActionBusy.value) return;
|
||||
const detail = activeShippingTaskDetail.value;
|
||||
// 任务详情接口当前不返回顶层 checkpoint,parse_review 需从详情状态字段回推。
|
||||
// 复核同步只消费后端统一 ui_state.checkpoint,不读取 review_status 等领域事实推导。
|
||||
const checkpoint = String(
|
||||
(detail?.step_payload as Record<string, unknown> | undefined)?.checkpoint
|
||||
|| detail?.review_status
|
||||
detail?.ui_state?.checkpoint?.code
|
||||
|| detail?.ui_state?.checkpoint_code
|
||||
|| '',
|
||||
).trim();
|
||||
if (checkpoint !== 'parse_review') return;
|
||||
|
||||
Reference in new issue
Block a user