feat(shipping-notice): 完成货代发货通知全门禁恢复MVP收口
完成全门禁恢复MVP版本交付:调整自动上传与重试配置,重构正式执行链路;修复多处代码bug,新增测试与审计工具;更新全流程文档与契约规范。
This commit is contained in:
1 parent
8e0bbf7a81
commit
c94d173f92
181 files changed
+12947
-1724
No files matched your search
@@ -94,6 +94,12 @@ describe('normalizeShippingProcessingProjection', () => {
|
||||
i18n_key: 'workspace.shippingNotice.processGate.reasons.inventory_candidates_missing',
|
||||
},
|
||||
facts: {
|
||||
inventory_milestones: {
|
||||
candidates_calculated: 'completed',
|
||||
candidates_frozen: 'completed',
|
||||
snapshots_ready: 'pending',
|
||||
matched: 'pending',
|
||||
},
|
||||
candidate_set_id: 12,
|
||||
candidate_set_version: 3,
|
||||
candidate_set_status: 'frozen',
|
||||
@@ -117,6 +123,12 @@ describe('normalizeShippingProcessingProjection', () => {
|
||||
expect(projection?.facts?.sourceAttempts).toEqual({
|
||||
DBS_DUB: { status: 'consumed', attempt_no: 1 },
|
||||
});
|
||||
expect(projection?.facts?.inventoryMilestones).toEqual({
|
||||
candidatesCalculated: 'completed',
|
||||
candidatesFrozen: 'completed',
|
||||
snapshotsReady: 'pending',
|
||||
matched: 'pending',
|
||||
});
|
||||
expect(projection?.blockingReason?.code).toBe('inventory_candidates_missing');
|
||||
});
|
||||
|
||||
|
||||
@@ -162,6 +162,19 @@ function normalizeFacts(raw: unknown): ShippingProcessingFacts | undefined {
|
||||
? String(item.inventorySourceStatus)
|
||||
: null;
|
||||
}
|
||||
if ('inventory_milestones' in item || 'inventoryMilestones' in item) {
|
||||
const rawMilestones = item.inventory_milestones ?? item.inventoryMilestones;
|
||||
if (rawMilestones && typeof rawMilestones === 'object') {
|
||||
const milestones = rawMilestones as Record<string, unknown>;
|
||||
const state = (value: unknown): 'pending' | 'completed' => value === 'completed' ? 'completed' : 'pending';
|
||||
out.inventoryMilestones = {
|
||||
candidatesCalculated: state(milestones.candidates_calculated ?? milestones.candidatesCalculated),
|
||||
candidatesFrozen: state(milestones.candidates_frozen ?? milestones.candidatesFrozen),
|
||||
snapshotsReady: state(milestones.snapshots_ready ?? milestones.snapshotsReady),
|
||||
matched: state(milestones.matched),
|
||||
};
|
||||
}
|
||||
}
|
||||
if ('candidate_set_id' in item || 'candidateSetId' in item) {
|
||||
const v = item.candidate_set_id ?? item.candidateSetId;
|
||||
out.candidateSetId = v == null || v === '' ? null : Number(v);
|
||||
|
||||
@@ -23,7 +23,6 @@ export type FulfillmentProgressNodeKey = typeof FULFILLMENT_PROGRESS_NODES[numbe
|
||||
export const MANUAL_UPLOAD_GATE_ACTIONS = new Set([
|
||||
'wait_manual_upload',
|
||||
'mark_manual_uploaded',
|
||||
'regenerate_manual_upload_todo',
|
||||
]);
|
||||
|
||||
/** 统一 ShippingProcessing 终态 status(停止轮询)。 */
|
||||
|
||||
@@ -81,7 +81,7 @@ describe('useChatShippingMenuHandler', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('uses explicit taskId for generate_excel via Chat Turn', async () => {
|
||||
it('does not dispatch legacy generate_excel Chat Turn', async () => {
|
||||
const ctx = createContext();
|
||||
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
|
||||
|
||||
@@ -91,14 +91,22 @@ describe('useChatShippingMenuHandler', () => {
|
||||
{ taskId: 'sn-target-777' },
|
||||
);
|
||||
|
||||
expect(ctx.startChatTurn).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
inputType: 'action',
|
||||
actionType: 'shipping.generate_excel',
|
||||
payload: { task_no: 'SN-TARGET-777' },
|
||||
refs: expect.objectContaining({ task_no: 'SN-TARGET-777' }),
|
||||
}),
|
||||
expect(ctx.startChatTurn).not.toHaveBeenCalled();
|
||||
expect(ctx.refreshShippingActions).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('does not dispatch legacy match_inventory Chat Turn', async () => {
|
||||
const ctx = createContext();
|
||||
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
|
||||
|
||||
await handleShippingMenuAction(
|
||||
{ id: 'match_inventory', label: '匹配库存', message: '请匹配库存' },
|
||||
undefined,
|
||||
{ taskId: 'sn-target-778' },
|
||||
);
|
||||
|
||||
expect(ctx.startChatTurn).not.toHaveBeenCalled();
|
||||
expect(ctx.refreshShippingActions).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('reads the displayed order version before freezing through Chat Turn', async () => {
|
||||
|
||||
@@ -152,6 +152,14 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 旧匹配/Excel 动作仅保留历史文案兼容;业务执行必须由 Projection
|
||||
// 下发的正式 Gate Action 驱动,Chat 不得再创建 legacy Turn。
|
||||
if (action.id === 'match_inventory' || action.id === 'generate_excel') {
|
||||
await ctx.refreshShippingActions();
|
||||
ctx.msg.info(ctx.t('chat.shippingNoticeRefreshDone'));
|
||||
return;
|
||||
}
|
||||
|
||||
const chatTurnActionIds = new Set([
|
||||
'freeze_order',
|
||||
'generate_excel',
|
||||
|
||||
@@ -212,6 +212,24 @@ describe('useShippingNoticeWorkflow', () => {
|
||||
ctl.stop();
|
||||
});
|
||||
|
||||
it('ignores external refresh triggers once only manual Gate tasks remain', async () => {
|
||||
const refreshTrigger = ref(0);
|
||||
api.getShippingProcessing.mockResolvedValue(buildUnifiedProcessing());
|
||||
const ctl = useShippingNoticeWorkflow({ conversationId: ref('conv-1'), refreshTrigger });
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
await nextTick();
|
||||
await Promise.resolve();
|
||||
|
||||
expect(api.getShippingProcessing).toHaveBeenCalledTimes(1);
|
||||
refreshTrigger.value += 1;
|
||||
await nextTick();
|
||||
await vi.advanceTimersByTimeAsync(0);
|
||||
|
||||
// 仅待人工处理时,Run 轮询的旁路 refreshTrigger 不得重复唤醒右侧 GET。
|
||||
expect(api.getShippingProcessing).toHaveBeenCalledTimes(1);
|
||||
ctl.stop();
|
||||
});
|
||||
|
||||
it('uses unified work_items as the sole processing read source', async () => {
|
||||
api.getShippingProcessing.mockResolvedValue({
|
||||
conversation_id: 'conv-1',
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* 逻辑:由 ChatViewContent / ShippingWorkflowTimeline 消费;仅读 shipping-processing;
|
||||
* focus/viewed 写路径优先应用响应中的 work_items;
|
||||
* 前台 2s / 后台 8s;请求 10s AbortController 超时;失败指数退避至 8s;
|
||||
* 分层轮询:系统处理中 2s 轮询,待复核 30s 轮询;
|
||||
* 分层轮询:仅系统处理中 2s 轮询;外部 Run 轮询不会在待人工处理时反复唤醒本读接口;
|
||||
* 区分 initialLoading / manualRefreshing / polling 三种 loading 态;
|
||||
* 语义签名比较:业务状态未变化时不替换投影对象,防止按钮闪烁与 DOM 重建。
|
||||
*/
|
||||
@@ -450,6 +450,9 @@ export function useShippingNoticeWorkflow(
|
||||
() => readOption(options.refreshTrigger ?? 0),
|
||||
() => {
|
||||
if (!normalizedConversationId.value) return;
|
||||
// [STEP] Run 轮询也会递增 refreshTrigger。右侧已进入人工 Gate 时状态不会
|
||||
// 自动变化,禁止每次 Run 轮询都重拉同一会话投影;首次尚无投影时仍允许恢复。
|
||||
if (processing.value && !shouldContinueProcessingPolling(processing.value)) return;
|
||||
pollingStopped = false;
|
||||
schedulePoll(pollGeneration, 0);
|
||||
},
|
||||
|
||||
@@ -60,6 +60,7 @@ export function useShippingProcessingWorkItem(
|
||||
let timer: ReturnType<typeof window.setTimeout> | null = null;
|
||||
let generation = 0;
|
||||
let stopped = false;
|
||||
let refreshInFlight: { no: string; promise: Promise<void> } | null = null;
|
||||
const pollMs = options.pollMs ?? DEFAULT_POLL_MS;
|
||||
const monotonic = Boolean(options.monotonicProgressVersion);
|
||||
|
||||
@@ -87,6 +88,10 @@ export function useShippingProcessingWorkItem(
|
||||
*/
|
||||
async function refresh(): Promise<void> {
|
||||
const no = String(toValue(workItemNo) || '').trim();
|
||||
if (refreshInFlight?.no === no) {
|
||||
await refreshInFlight.promise;
|
||||
return;
|
||||
}
|
||||
const enabled = options.enabled == null ? true : Boolean(toValue(options.enabled));
|
||||
if (!enabled || !no) {
|
||||
projection.value = null;
|
||||
@@ -96,7 +101,8 @@ export function useShippingProcessingWorkItem(
|
||||
}
|
||||
const gen = generation;
|
||||
loading.value = true;
|
||||
try {
|
||||
const request = (async () => {
|
||||
try {
|
||||
const raw = await getWorkspaceShippingProcessingWorkItem(workItemType, no);
|
||||
if (stopped || gen !== generation) return;
|
||||
const normalized = normalizeShippingProcessingProjection(raw);
|
||||
@@ -112,7 +118,7 @@ export function useShippingProcessingWorkItem(
|
||||
void refresh();
|
||||
}, pollMs);
|
||||
}
|
||||
} catch (err) {
|
||||
} catch (err) {
|
||||
if (stopped || gen !== generation) return;
|
||||
// 404 / 业务不存在:清空投影但不抛到页面主流程。
|
||||
if (err instanceof BusinessError && (err.status === 404 || err.code?.includes('NOT_FOUND'))) {
|
||||
@@ -128,8 +134,15 @@ export function useShippingProcessingWorkItem(
|
||||
void refresh();
|
||||
}, pollMs);
|
||||
}
|
||||
} finally {
|
||||
} finally {
|
||||
if (gen === generation) loading.value = false;
|
||||
}
|
||||
})();
|
||||
refreshInFlight = { no, promise: request };
|
||||
try {
|
||||
await request;
|
||||
} finally {
|
||||
if (refreshInFlight?.promise === request) refreshInFlight = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,6 +160,9 @@ export function useShippingProcessingWorkItem(
|
||||
error.value = null;
|
||||
return;
|
||||
}
|
||||
// OT/PDF 切换时先清空旧投影,避免新请求完成前继续展示第一份 PDF 的状态。
|
||||
projection.value = null;
|
||||
error.value = null;
|
||||
void refresh();
|
||||
},
|
||||
{ immediate: true },
|
||||
|
||||
Reference in new issue
Block a user