feat(shipping-notice): 完善发货通知自动推进与多库存源复核闭环

This commit is contained in:
hugo committed 2026-08-09 11:43:53 +08:00
1 parent cfa19a0b7b
commit 8e0bbf7a81
180 files changed
+31210 -1864

No files matched your search

@@ -32,6 +32,7 @@ import type {
} from '../types/shipping.api.types';
import {
buildProcessingSemanticKey,
createIntakeOtStabilizer,
resolveConversationProcessingFromUnified,
} from './conversationProcessingProjection';
@@ -147,6 +148,27 @@ export function useShippingNoticeWorkflow(
let failureCount = 0;
let pollingStopped = false;
let lastSemanticKey = '';
const intakeOtStabilizer = createIntakeOtStabilizer();
/**
* 在 Intake→OT 过渡窗里,若 projection 被稳定器保留为上一轮 OT 视图,
* 则 work_items 也必须同步保留上一轮 order_task;否则卡片正文与侧边进度条
* 会来自两轮不同响应,导致右侧布局在“带进度条/只剩按钮”之间来回切换。
*/
function resolveStableWorkItems(
nextWorkItems: ShippingProcessingProjection[],
previousProjection: ConversationProcessingProjection | null,
nextProjection: ConversationProcessingProjection | null,
): ShippingProcessingProjection[] {
const hasNextOrderTask = nextWorkItems.some((item) => item.workItemType === 'order_task');
if (hasNextOrderTask) return nextWorkItems;
if (!previousProjection || nextProjection !== previousProjection) return nextWorkItems;
const currentWorkItems = Array.isArray(processingWorkItems.value)
? processingWorkItems.value
: [];
const hasCurrentOrderTask = currentWorkItems.some((item) => item.workItemType === 'order_task');
return hasCurrentOrderTask ? currentWorkItems : nextWorkItems;
}
const normalizedConversationId = computed(() =>
String(readOption(options.conversationId) || '').trim(),
@@ -212,10 +234,20 @@ export function useShippingNoticeWorkflow(
workItems,
embedded,
prevProjection,
{
conversationId,
hasSeenOrderTaskBefore: (cId) => intakeOtStabilizer.hasSeenOrderTaskBefore(cId),
markSeen: (cId) => intakeOtStabilizer.markSeen(cId),
reset: (cId) => intakeOtStabilizer.reset(cId),
},
);
const nextSemanticKey = buildProcessingSemanticKey(nextProjection);
processingWorkItems.value = workItems;
processingWorkItems.value = resolveStableWorkItems(
workItems,
prevProjection,
nextProjection,
);
if (nextSemanticKey !== lastSemanticKey) {
processing.value = nextProjection;
lastSemanticKey = nextSemanticKey;
@@ -255,6 +287,7 @@ export function useShippingNoticeWorkflow(
lastSemanticKey = '';
return Promise.resolve();
}
intakeOtStabilizer.reset(conversationId);
if (inFlightRefresh?.conversationId === conversationId) {
return inFlightRefresh.promise;
}
@@ -278,12 +311,16 @@ export function useShippingNoticeWorkflow(
}): void {
const workItems = Array.isArray(response.work_items) ? response.work_items : [];
if (workItems.length > 0) {
processingWorkItems.value = workItems as typeof processingWorkItems.value;
const nextProjection = resolveConversationProcessingFromUnified(
workItems as typeof processingWorkItems.value,
response.processing ?? null,
processing.value,
);
processingWorkItems.value = resolveStableWorkItems(
workItems as typeof processingWorkItems.value,
processing.value,
nextProjection,
);
const nextKey = buildProcessingSemanticKey(nextProjection);
if (nextKey !== lastSemanticKey) {
processing.value = nextProjection;