feat(shipping): 实现订单批处理聊天聚合展示与优化后端逻辑

This commit is contained in:
hugo committed 2026-08-13 17:40:43 +08:00
1 parent 11cef575b4
commit 523b791c92
38 files changed
+2868 -414

No files matched your search

@@ -230,6 +230,29 @@ function normalizeFacts(raw: unknown): ShippingProcessingFacts | undefined {
return out;
}
function normalizeAggregateSummary(
raw: unknown,
): ShippingProcessingProjection['aggregateSummary'] {
if (!raw || typeof raw !== 'object') return null;
const item = raw as Record<string, unknown>;
const array = (value: unknown): string[] => Array.isArray(value)
? value.map((entry) => String(entry || '').trim()).filter(Boolean)
: [];
const count = (key: string): number => Number(item[key] || 0) || 0;
const intakeNo = String(item.intake_no ?? item.intakeNo ?? '').trim();
if (!intakeNo) return null;
return {
intakeNo,
total: count('total'),
completed: count('completed'),
processing: count('processing'),
needsAction: count('needs_action') || count('needsAction'),
failed: count('failed'),
stages: array(item.stages),
reasonCodes: array(item.reason_codes ?? item.reasonCodes),
};
}
/**
* 题4A:规范 inventory_preparation 结构化字段(snake_case → camelCase)。
* 注意:failed_sources 会进一步透传到 exhausted_sources 分开(二者互斥;仅 max_attempts 耗尽的源进 exhausted)。
@@ -324,6 +347,12 @@ export function normalizeShippingProcessingProjection(
const stageNodes = Array.isArray(stageNodesRaw)
? stageNodesRaw.map(normalizeStageNode).filter((row): row is ShippingProcessingStageNode => Boolean(row))
: undefined;
const aggregateChildrenRaw = item.aggregate_children ?? item.aggregateChildren;
const aggregateChildren = Array.isArray(aggregateChildrenRaw)
? aggregateChildrenRaw
.map(normalizeShippingProcessingProjection)
.filter((entry): entry is ShippingProcessingProjection => Boolean(entry))
: undefined;
return {
workItemType: (readString(item, 'work_item_type', 'workItemType') || 'order_task') as ShippingProcessingWorkItemType,
@@ -368,6 +397,9 @@ export function normalizeShippingProcessingProjection(
(item.retryable as boolean | undefined) == null ? false : Boolean(item.retryable),
primaryAction: normalizePrimaryAction(item.primary_action ?? item.primaryAction),
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: