feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a9fbac2fc
commit
d2b3d74def
571 files changed
+78064
-24681
No files matched your search
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* features/chat/shipping/normalizeShippingProcessing.ts
|
||||
* 用途:将后端 snake_case ShippingProcessingProjection 规范为前端 camelCase DTO。
|
||||
* 依赖:shipping.api.types ShippingProcessingProjection / ProcessGateSummary。
|
||||
* 逻辑:API 边界一次性转换;透传 Gate attemptNo 与 Intake 失败恢复摘要字段。
|
||||
*/
|
||||
|
||||
import type {
|
||||
OrderIntakeSourceType,
|
||||
ProcessGateSummary,
|
||||
ShippingOrderTaskSummary,
|
||||
ShippingProcessingProjection,
|
||||
ShippingProcessingStage,
|
||||
ShippingProcessingStatus,
|
||||
ShippingProcessingWorkItemType,
|
||||
} from '../types/shipping.api.types';
|
||||
|
||||
/**
|
||||
* 读取原始对象上的字符串字段(兼容 snake / camel)。
|
||||
*/
|
||||
function readString(raw: Record<string, unknown>, snake: string, camel: string): string {
|
||||
const value = raw[snake] ?? raw[camel];
|
||||
return value == null ? '' : String(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取可空字符串。
|
||||
*/
|
||||
function readNullableString(
|
||||
raw: Record<string, unknown>,
|
||||
snake: string,
|
||||
camel: string,
|
||||
): string | null {
|
||||
const value = raw[snake] ?? raw[camel];
|
||||
if (value == null || value === '') return null;
|
||||
return String(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范单个 OT 摘要。
|
||||
*/
|
||||
function normalizeChildTask(raw: unknown): ShippingOrderTaskSummary | null {
|
||||
if (!raw || typeof raw !== 'object') return null;
|
||||
const item = raw as Record<string, unknown>;
|
||||
const orderTaskNo = readString(item, 'order_task_no', 'orderTaskNo');
|
||||
if (!orderTaskNo) return null;
|
||||
return {
|
||||
orderTaskNo,
|
||||
status: readString(item, 'status', 'status') as ShippingProcessingStatus,
|
||||
stage: readString(item, 'stage', 'stage') as ShippingProcessingStage,
|
||||
customerName: readNullableString(item, 'customer_name', 'customerName'),
|
||||
poNumber: readNullableString(item, 'po_number', 'poNumber'),
|
||||
lastActivityAt: readNullableString(item, 'last_activity_at', 'lastActivityAt'),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范 Gate 摘要。
|
||||
*/
|
||||
function normalizeGate(raw: unknown): ProcessGateSummary | null {
|
||||
if (!raw || typeof raw !== 'object') return null;
|
||||
const item = raw as Record<string, unknown>;
|
||||
const gateCode = readString(item, 'gate_code', 'gateCode');
|
||||
if (!gateCode) return null;
|
||||
return {
|
||||
gateCode,
|
||||
status: readString(item, 'status', 'status') || 'unknown',
|
||||
nextActionCode: readNullableString(item, 'next_action_code', 'nextActionCode'),
|
||||
blockingReasonCode: readNullableString(item, 'blocking_reason_code', 'blockingReasonCode'),
|
||||
attemptNo: (() => {
|
||||
const rawAttempt = item.attempt_no ?? item.attemptNo;
|
||||
if (rawAttempt == null || rawAttempt === '') return null;
|
||||
const n = Number(rawAttempt);
|
||||
return Number.isFinite(n) ? n : null;
|
||||
})(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 将后端 / 混合字段投影规范为 ShippingProcessingProjection。
|
||||
* 核心逻辑:缺字段给安全默认值,保证四页面可渲染;非法输入返回 null。
|
||||
*
|
||||
* @param raw - API 原始对象
|
||||
* @returns 规范化投影;无法识别时 null
|
||||
*/
|
||||
export function normalizeShippingProcessingProjection(
|
||||
raw: unknown,
|
||||
): ShippingProcessingProjection | null {
|
||||
if (!raw || typeof raw !== 'object') return null;
|
||||
const item = raw as Record<string, unknown>;
|
||||
const workItemNo = readString(item, 'work_item_no', 'workItemNo');
|
||||
if (!workItemNo) return null;
|
||||
|
||||
const summaryRaw = (item.source_summary ?? item.sourceSummary ?? {}) as Record<string, unknown>;
|
||||
const childrenRaw = item.child_order_tasks ?? item.childOrderTasks;
|
||||
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)
|
||||
: [];
|
||||
|
||||
return {
|
||||
workItemType: (readString(item, 'work_item_type', 'workItemType') || 'order_task') as ShippingProcessingWorkItemType,
|
||||
workItemNo,
|
||||
sourceType: (readNullableString(item, 'source_type', 'sourceType') || 'eml') as OrderIntakeSourceType,
|
||||
rootOrderTaskNo: readNullableString(item, 'root_order_task_no', 'rootOrderTaskNo'),
|
||||
shippingNoticeNo: readNullableString(item, 'shipping_notice_no', 'shippingNoticeNo'),
|
||||
conversationId: readNullableString(item, 'conversation_id', 'conversationId'),
|
||||
submissionNo: readString(item, 'submission_no', 'submissionNo'),
|
||||
intakeNo: readString(item, 'intake_no', 'intakeNo'),
|
||||
status: (readString(item, 'status', 'status') || 'processing') as ShippingProcessingStatus,
|
||||
stage: (readString(item, 'stage', 'stage') || 'upload_received') as ShippingProcessingStage,
|
||||
progressVersion: Number(item.progress_version ?? item.progressVersion ?? 0) || 0,
|
||||
lastActivityAt: readString(item, 'last_activity_at', 'lastActivityAt'),
|
||||
currentGate: normalizeGate(item.current_gate ?? item.currentGate),
|
||||
availableActions,
|
||||
sourceSummary: {
|
||||
emailSubject: readNullableString(summaryRaw, 'email_subject', 'emailSubject'),
|
||||
filename: readNullableString(summaryRaw, 'filename', 'filename'),
|
||||
documentCount: Number(summaryRaw.document_count ?? summaryRaw.documentCount ?? 0) || 0,
|
||||
parsedDocumentCount: Number(summaryRaw.parsed_document_count ?? summaryRaw.parsedDocumentCount ?? 0) || 0,
|
||||
candidateCount: Number(summaryRaw.candidate_count ?? summaryRaw.candidateCount ?? 0) || 0,
|
||||
customerName: readNullableString(summaryRaw, 'customer_name', 'customerName'),
|
||||
poNumber: readNullableString(summaryRaw, 'po_number', 'poNumber'),
|
||||
failureReasonCode: readNullableString(summaryRaw, 'failure_reason_code', 'failureReasonCode'),
|
||||
parseAttemptCount: Number(summaryRaw.parse_attempt_count ?? summaryRaw.parseAttemptCount ?? 0) || 0,
|
||||
assetStatus: readNullableString(summaryRaw, 'asset_status', 'assetStatus'),
|
||||
},
|
||||
childOrderTasks: children,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 将会话级统一投影响应中的 work_items 规范为数组。
|
||||
*/
|
||||
export function normalizeShippingProcessingWorkItems(raw: unknown): ShippingProcessingProjection[] {
|
||||
if (!Array.isArray(raw)) return [];
|
||||
return raw
|
||||
.map(normalizeShippingProcessingProjection)
|
||||
.filter((item): item is ShippingProcessingProjection => Boolean(item));
|
||||
}
|
||||
Reference in new issue
Block a user