feat(shipping-notice): 新增通用解析能力,优化性能并清理遗留废弃代码
This commit is contained in:
1 parent
935bf26fa6
commit
7cfd5d167e
230 files changed
+9337
-10989
No files matched your search
@@ -25,25 +25,23 @@ import type {
|
||||
} from '../types/shipping.api.types';
|
||||
|
||||
/** 后端可裁决并透传到订单生命周期工作台的阶段;前端不根据本地状态补造入口。 */
|
||||
const lifecycleStages = ['intake_parse', 'order_review', 'fulfillment_prep', 'upload_complete'] as const;
|
||||
const lifecycleStages = ['intake_parse', 'order_review', 'fulfillment_prep', 'freight_upload', 'upload_complete'] as const;
|
||||
|
||||
/**
|
||||
* 读取原始对象上的字符串字段(兼容 snake / camel)。
|
||||
*/
|
||||
function readString(raw: Record<string, unknown>, snake: string, camel: string): string {
|
||||
const value = raw[snake] ?? raw[camel];
|
||||
/** 读取后端正式 snake_case DTO 的字符串字段。 */
|
||||
function readString(raw: Record<string, unknown>, snake: string, _removedLegacyCamel?: string): string {
|
||||
const value = raw[snake];
|
||||
return value == null ? '' : String(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取可空字符串。
|
||||
* 读取后端正式 snake_case DTO 的可空字符串。
|
||||
*/
|
||||
function readNullableString(
|
||||
raw: Record<string, unknown>,
|
||||
snake: string,
|
||||
camel: string,
|
||||
_removedLegacyCamel?: string,
|
||||
): string | null {
|
||||
const value = raw[snake] ?? raw[camel];
|
||||
const value = raw[snake];
|
||||
if (value == null || value === '') return null;
|
||||
return String(value);
|
||||
}
|
||||
@@ -118,7 +116,7 @@ function normalizeBlockingReason(raw: unknown): ShippingProcessingBlockingReason
|
||||
if (!code) return null;
|
||||
return {
|
||||
code,
|
||||
i18nKey: item.i18n_key != null ? String(item.i18n_key) : (item.i18nKey != null ? String(item.i18nKey) : null),
|
||||
i18nKey: item.i18n_key != null ? String(item.i18n_key) : null,
|
||||
details:
|
||||
typeof item.details === 'object' && item.details != null
|
||||
? (item.details as Record<string, unknown>)
|
||||
@@ -136,23 +134,23 @@ function normalizePrimaryAction(raw: unknown): ShippingProcessingPrimaryAction |
|
||||
if (!code) return null;
|
||||
return {
|
||||
code,
|
||||
i18nKey: item.i18n_key != null ? String(item.i18n_key) : (item.i18nKey != null ? String(item.i18nKey) : null),
|
||||
i18nKey: item.i18n_key != null ? String(item.i18n_key) : null,
|
||||
parameters:
|
||||
typeof item.parameters === 'object' && item.parameters != null
|
||||
? (item.parameters as Record<string, unknown>)
|
||||
: {},
|
||||
executionMode: item.execution_mode === 'navigate' || item.executionMode === 'navigate'
|
||||
executionMode: item.execution_mode === 'navigate'
|
||||
? 'navigate'
|
||||
: item.execution_mode === 'execute' || item.executionMode === 'execute'
|
||||
: item.execution_mode === 'execute'
|
||||
? 'execute'
|
||||
: undefined,
|
||||
targetSurface: item.target_surface === 'order_lifecycle_workbench' || item.targetSurface === 'order_lifecycle_workbench'
|
||||
targetSurface: item.target_surface === '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 ?? '') as typeof lifecycleStages[number],
|
||||
)
|
||||
? String(item.target_lifecycle_stage ?? item.targetLifecycleStage) as ShippingProcessingPrimaryAction['targetLifecycleStage']
|
||||
? String(item.target_lifecycle_stage) as ShippingProcessingPrimaryAction['targetLifecycleStage']
|
||||
: null,
|
||||
};
|
||||
}
|
||||
@@ -165,10 +163,10 @@ function normalizeLifecycleEntries(raw: unknown): NonNullable<ConversationProces
|
||||
.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'],
|
||||
targetSurface: String(item.target_surface ?? '') as NonNullable<ConversationProcessingUiState['lifecycleEntries']>[number]['targetSurface'],
|
||||
disabledReasonKey: item.disabled_reason_key != null
|
||||
? String(item.disabled_reason_key)
|
||||
: item.disabledReasonKey != null ? String(item.disabledReasonKey) : null,
|
||||
: null,
|
||||
}))
|
||||
.filter((item) => lifecycleStages.includes(item.code as typeof lifecycleStages[number])
|
||||
&& ['available', 'current', 'unavailable'].includes(item.state)
|
||||
@@ -373,9 +371,13 @@ export function normalizeShippingProcessingProjection(
|
||||
const children = Array.isArray(childrenRaw)
|
||||
? childrenRaw.map(normalizeChildTask).filter((row): row is ShippingOrderTaskSummary => Boolean(row))
|
||||
: [];
|
||||
const actionsRaw = item.available_actions ?? item.availableActions;
|
||||
const availableActions = Array.isArray(actionsRaw)
|
||||
? actionsRaw.map((action) => String(action || '').trim()).filter(Boolean)
|
||||
// ui_state 是处理进度唯一的用户态/动作合同。旧顶层动作字段已下线,
|
||||
// 客户端只能由该合同派生本地展示索引,不能读取或补造历史 available_actions。
|
||||
const uiState = normalizeProcessingUiState(item.ui_state);
|
||||
const availableActions = uiState
|
||||
? [uiState.primary_action, ...uiState.secondary_actions]
|
||||
.map((action) => String(action?.code || '').trim())
|
||||
.filter(Boolean)
|
||||
: [];
|
||||
const stageNodesRaw = item.stage_nodes ?? item.stageNodes;
|
||||
const stageNodes = Array.isArray(stageNodesRaw)
|
||||
@@ -428,14 +430,12 @@ export function normalizeShippingProcessingProjection(
|
||||
userStage: readNullableString(item, 'user_stage', 'userStage') as ShippingProcessingProjection['userStage'],
|
||||
userCurrentGateCode: readNullableString(item, 'user_current_gate_code', 'userCurrentGateCode'),
|
||||
blockingReason: normalizeBlockingReason(item.blocking_reason ?? item.blockingReason),
|
||||
primaryAction: normalizePrimaryAction(item.primary_action ?? item.primaryAction),
|
||||
uiState: normalizeProcessingUiState(item.ui_state ?? item.uiState),
|
||||
primaryAction: uiState?.primary_action ?? null,
|
||||
uiState,
|
||||
facts: normalizeFacts(item.facts),
|
||||
userGroup: readNullableString(item, 'user_group', 'userGroup') as ShippingProcessingProjection['userGroup'],
|
||||
aggregateSummary: normalizeAggregateSummary(item.aggregate_summary ?? item.aggregateSummary),
|
||||
aggregateChildren: aggregateChildren?.length ? aggregateChildren : undefined,
|
||||
legacyStatus: readNullableString(item, 'legacy_status', 'legacyStatus'),
|
||||
legacyStage: readNullableString(item, 'legacy_stage', 'legacyStage'),
|
||||
hasFormalOt:
|
||||
(item.has_formal_ot as boolean | undefined) == null ? false : Boolean(item.has_formal_ot),
|
||||
inventoryPreparation: normalizeInventoryPreparation(
|
||||
@@ -453,11 +453,11 @@ function normalizeProcessGateSummary(raw: unknown): ShippingProcessGateUserSumma
|
||||
: null;
|
||||
}
|
||||
|
||||
/** 规范化单项后端 UI 裁决;缺失时返回 undefined 以保留旧响应兼容。 */
|
||||
/** 规范化单项后端 UI 裁决;缺失时不展示动作,禁止从旧顶层字段回退。 */
|
||||
function normalizeProcessingUiState(raw: unknown): ShippingProcessingProjection['uiState'] {
|
||||
if (!raw || typeof raw !== 'object') return undefined;
|
||||
const state = raw as Record<string, unknown>;
|
||||
const secondaryRaw = state.secondary_actions ?? state.secondaryActions;
|
||||
const secondaryRaw = state.secondary_actions;
|
||||
const secondaryActions = Array.isArray(secondaryRaw)
|
||||
? secondaryRaw
|
||||
.filter((item): item is Record<string, unknown> => Boolean(item && typeof item === 'object'))
|
||||
@@ -470,10 +470,10 @@ function normalizeProcessingUiState(raw: unknown): ShippingProcessingProjection[
|
||||
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),
|
||||
lifecycleStage: readString(state, 'lifecycle_stage') as ConversationProcessingUiState['lifecycleStage'],
|
||||
lifecycleEntries: normalizeLifecycleEntries(state.lifecycle_entries),
|
||||
blocking_reason: normalizeBlockingReason(state.blocking_reason),
|
||||
primary_action: normalizePrimaryAction(state.primary_action),
|
||||
secondary_actions: secondaryActions,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user