chore(shipping-notice): 统一货代发货生命周期阶段命名并优化全链路业务逻辑

This commit is contained in:
hugo committed 2026-08-17 19:56:51 +08:00
1 parent 5ef8329bd8
commit 4ec4e57005
183 files changed
+14653 -3936

No files matched your search

@@ -6,6 +6,7 @@
*/
import type {
ConversationProcessingUiState,
OrderIntakeSourceType,
ProcessGateSummary,
ShippingInventoryPerSourceAttempt,
@@ -23,6 +24,9 @@ import type {
ShippingProcessGateUserSummary,
} from '../types/shipping.api.types';
/** 后端可裁决并透传到订单生命周期工作台的阶段;前端不根据本地状态补造入口。 */
const lifecycleStages = ['intake_parse', 'order_review', 'fulfillment_prep', 'upload_complete'] as const;
/**
* 读取原始对象上的字符串字段(兼容 snake / camel)。
*/
@@ -137,9 +141,40 @@ function normalizePrimaryAction(raw: unknown): ShippingProcessingPrimaryAction |
typeof item.parameters === 'object' && item.parameters != null
? (item.parameters as Record<string, unknown>)
: {},
executionMode: item.execution_mode === 'navigate' || item.executionMode === 'navigate'
? 'navigate'
: item.execution_mode === 'execute' || item.executionMode === 'execute'
? 'execute'
: undefined,
targetSurface: item.target_surface === 'order_lifecycle_workbench' || item.targetSurface === 'order_lifecycle_workbench'
? 'order_lifecycle_workbench'
: null,
targetLifecycleStage: lifecycleStages.includes(
String(item.target_lifecycle_stage ?? item.targetLifecycleStage ?? '') as typeof lifecycleStages[number],
)
? String(item.target_lifecycle_stage ?? item.targetLifecycleStage) as ShippingProcessingPrimaryAction['targetLifecycleStage']
: null,
};
}
/** 规范后端生命周期入口,前端不得由候选数或当前阶段补造入口。 */
function normalizeLifecycleEntries(raw: unknown): NonNullable<ConversationProcessingUiState['lifecycleEntries']> {
if (!Array.isArray(raw)) return [];
return raw
.filter((item): item is Record<string, unknown> => Boolean(item && typeof item === 'object'))
.map((item) => ({
code: String(item.code ?? '') as NonNullable<ConversationProcessingUiState['lifecycleEntries']>[number]['code'],
state: String(item.state ?? '') as NonNullable<ConversationProcessingUiState['lifecycleEntries']>[number]['state'],
targetSurface: String(item.target_surface ?? item.targetSurface ?? '') as NonNullable<ConversationProcessingUiState['lifecycleEntries']>[number]['targetSurface'],
disabledReasonKey: item.disabled_reason_key != null
? String(item.disabled_reason_key)
: item.disabledReasonKey != null ? String(item.disabledReasonKey) : null,
}))
.filter((item) => lifecycleStages.includes(item.code as typeof lifecycleStages[number])
&& ['available', 'current', 'unavailable'].includes(item.state)
&& item.targetSurface === 'order_lifecycle_workbench');
}
/**
* [T9 用户态 Projection] 规范 facts(后端 snake_case 子状态字典;camelCase key)。
*/
@@ -430,15 +465,17 @@ function normalizeProcessingUiState(raw: unknown): ShippingProcessingProjection[
const secondaryActions = Array.isArray(secondaryRaw)
? secondaryRaw
.filter((item): item is Record<string, unknown> => Boolean(item && typeof item === 'object'))
.map((item) => ({
code: readString(item, 'code', 'code'),
enabled: item.enabled !== false,
}))
.filter((item) => Boolean(item.code))
.map((item) => {
const normalized = normalizePrimaryAction(item);
return normalized ? { ...normalized, enabled: item.enabled !== false } : null;
})
.filter((item): item is NonNullable<typeof item> => item !== null)
: [];
return {
status: (readString(state, 'status', 'status') || 'running') as NonNullable<ShippingProcessingProjection['userStatus']>,
stage: readString(state, 'stage', 'stage'),
lifecycleStage: readString(state, 'lifecycle_stage', 'lifecycleStage') as ConversationProcessingUiState['lifecycleStage'],
lifecycleEntries: normalizeLifecycleEntries(state.lifecycle_entries ?? state.lifecycleEntries),
blocking_reason: normalizeBlockingReason(state.blocking_reason ?? state.blockingReason),
primary_action: normalizePrimaryAction(state.primary_action ?? state.primaryAction),
secondary_actions: secondaryActions,