feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-06 10:18:37 +08:00
1 parent 3a9fbac2fc
commit d2b3d74def
571 files changed
+78064 -24681

No files matched your search

@@ -1,9 +1,15 @@
/**
* features/chat/shipping/shippingStepper.ts
* 用途:基于 shipping task 状态推导前端七步 Stepper 展示数据。
* 依赖:无外部模块;ShippingWorkflowStepper.vue 消费本模块输出。
* 逻辑:buildShippingWorkflowSteps 将 process_status / checkpoint 等映射为步骤 id 与 done/active 状态。
* 用途:基于 shipping task 状态推导前端 Stepper 展示数据(七步 legacy / 四步履约)。
* 依赖:ShippingProcessingProjection(可选叠加)、shippingProcessingFulfillment;ShippingWorkflowStepper.vue 消费输出。
* 逻辑:任务台优先 buildFulfillmentWorkflowSteps(四节点);无投影时不回退旧 ui_state;
* resolveShippingWorkflowSteps 仍供对话等未切流页面作 legacy 回退。
*/
import {
FULFILLMENT_PROGRESS_NODES,
fulfillmentNodeIndexFromStage,
type FulfillmentProgressNodeKey,
} from './shippingProcessingFulfillment';
export interface ShippingTaskStepperSource {
process_status?: string | null;
review_status?: string | null;
@@ -135,6 +141,64 @@ function deriveCurrentIndex(task: ShippingTaskStepperSource | null | undefined):
return 0;
}
/** 统一 ShippingProcessingStage → 粗粒度 Stepper 下标(过渡期;阶段 2 换 UnifiedProgressTrack)。 */
const PROCESSING_STAGE_INDEX_MAP: Record<string, number> = {
upload_received: 0,
email_parsing: 1,
document_parsing: 1,
email_adjudicating: 1,
candidate_creating: 1,
customer_resolving: 1,
duplicate_checking: 1,
// 业务 15 阶中库存源在复核前;七步 legacy 仍映射到「库存准备」步。
inventory_source_resolving: 2,
waiting_review: 1,
order_creating: 1,
inventory_fetching: 2,
inventory_matching: 4,
excel_generating: 5,
freight_uploading: 6,
completed: 6,
};
/**
* 用统一投影 stage/status 覆盖 Stepper 当前步(切流主源)。
*
* 核心逻辑:有投影时按 stage 重算 completed/current/pending;blocked/failed 标当前步 blocked;
* 无投影或无法映射时原样返回 baseSteps。
*
* @param baseSteps - ui_state / process_status 推导的步骤
* @param projection - 统一 order_task 投影
*/
export function applyShippingProcessingStageToSteps(
baseSteps: ShippingWorkflowStepItem[],
projection: { status?: string | null; stage?: string | null; currentGate?: { status?: string | null } | null } | null | undefined,
): ShippingWorkflowStepItem[] {
if (!projection || !baseSteps.length) return baseSteps;
const stage = String(projection.stage || '').trim();
const status = String(projection.status || '').trim().toLowerCase();
const stageIndex = PROCESSING_STAGE_INDEX_MAP[stage];
if (stageIndex === undefined && status !== 'completed' && status !== 'failed' && status !== 'blocked') {
return baseSteps;
}
const currentIndex = status === 'completed' ? baseSteps.length - 1 : (stageIndex ?? 0);
const gateBlocked = String(projection.currentGate?.status || '').trim().toLowerCase() === 'blocked'
|| status === 'blocked'
|| status === 'failed'
|| status === 'waiting_review';
return baseSteps.map((step, index) => {
let nextStatus: ShippingWorkflowStepItem['status'] = 'pending';
if (status === 'completed' || status === 'cancelled') {
nextStatus = 'completed';
} else if (index < currentIndex) {
nextStatus = 'completed';
} else if (index === currentIndex) {
nextStatus = gateBlocked ? 'blocked' : 'current';
}
return { ...step, status: nextStatus };
});
}
/**
* 将 task 状态映射为七步 Stepper 项(id / label / done / active)。
*/
@@ -178,3 +242,45 @@ export function buildShippingWorkflowSteps(
};
});
}
/**
* 从统一 ShippingProcessing 投影构建履约四节点 Stepper(任务台主源)。
*
* 核心逻辑:仅在有投影时返回步骤;节点标签由调用方传入 i18n 文案。
*
* @param projection - 统一 order_task 投影
* @param nodeLabels - 四节点展示文案(building_order … freight_uploading)
* @returns 四步 Stepper 项;无投影时返回 null
*/
export function buildFulfillmentWorkflowSteps(
projection: {
stage?: string | null;
status?: string | null;
currentGate?: { status?: string | null } | null;
} | null | undefined,
nodeLabels: Record<FulfillmentProgressNodeKey, string>,
): ShippingWorkflowStepItem[] | null {
if (!projection) return null;
const activeIndex = fulfillmentNodeIndexFromStage(projection.stage, projection.status);
const status = String(projection.status || '').trim().toLowerCase();
const gateBlocked = String(projection.currentGate?.status || '').trim().toLowerCase() === 'blocked'
|| status === 'blocked'
|| status === 'failed'
|| status === 'waiting_review';
return FULFILLMENT_PROGRESS_NODES.map((key, index) => {
let stepStatus: ShippingWorkflowStepItem['status'] = 'pending';
if (status === 'completed' || status === 'cancelled') {
stepStatus = 'completed';
} else if (activeIndex >= 0 && index < activeIndex) {
stepStatus = 'completed';
} else if (activeIndex >= 0 && index === activeIndex) {
stepStatus = gateBlocked ? 'blocked' : 'current';
}
return {
id: `fulfillment-${key}`,
label: nodeLabels[key as FulfillmentProgressNodeKey],
status: stepStatus,
};
});
}