refactor(shipping-notice): 重构货代发货通知状态管理,移除废弃的process_status字段

统一货代发货通知的业务阶段为四个标准阶段:接收解析、订单复核、发货准备、上传完成
设置 ui_state 为前端唯一状态数据源,不再依赖 process_status 驱动业务流程
删除 shipping_notices 表的废弃 process_status 列及对应复合索引,新增数据库迁移脚本
替换全栈代码中所有对 process_status 的引用为生命周期、上传状态等领域字段
更新相关文档、测试用例与前端展示逻辑适配新的状态管理规则
This commit is contained in:
hugo committed 2026-08-15 10:19:10 +08:00
1 parent 6684e7181a
commit 5ef8329bd8
178 files changed
+5091 -1734

No files matched your search

@@ -1,9 +1,8 @@
/**
* features/chat/shipping/shippingStepper.ts
* 用途:基于 shipping task 状态推导前端 Stepper 展示数据(七步 legacy / 四步履约)。
* 用途:基于后端 ui_state 投影渲染四阶段业务 Stepper。
* 依赖:ShippingProcessingProjection(可选叠加)、shippingProcessingFulfillment;ShippingWorkflowStepper.vue 消费输出。
* 逻辑:任务台优先 buildFulfillmentWorkflowSteps(四节点);无投影时不回退旧 ui_state;
* resolveShippingWorkflowSteps 仍供对话等未切流页面作 legacy 回退。
* 逻辑:只消费后端 ui_state.steps 四阶段投影;缺失投影时 fail-closed。
*/
import {
FULFILLMENT_PROGRESS_NODES,
@@ -11,12 +10,9 @@ import {
type FulfillmentProgressNodeKey,
} from './shippingProcessingFulfillment';
export interface ShippingTaskStepperSource {
process_status?: string | null;
review_status?: string | null;
pending_human_reason?: string | null;
match_status?: string | null;
export_file_name?: string | null;
current_step?: string | null;
ui_state?: {
steps?: ShippingWorkflowStepSource[] | null;
} | null;
}
export interface ShippingWorkflowStepItem {
@@ -33,32 +29,12 @@ type ShippingWorkflowStepSource = {
};
export const SHIPPING_WORKFLOW_STEP_LABELS = [
'chat.shippingNoticeUi.stepper.noticeSubmit',
'chat.shippingNoticeUi.stepper.parseConfirm',
'chat.shippingNoticeUi.stepper.inventoryPrepare',
'chat.shippingNoticeUi.stepper.alignConfirm',
'chat.shippingNoticeUi.stepper.matchInventory',
'chat.shippingNoticeUi.stepper.generateFile',
'chat.shippingNoticeUi.stepper.uploadFreight',
'chat.shippingNoticeUi.stage.intakeParse',
'chat.shippingNoticeUi.stage.orderReview',
'chat.shippingNoticeUi.stage.fulfillmentPrep',
'chat.shippingNoticeUi.stage.uploadComplete',
] as const;
const CURRENT_STEP_INDEX_MAP: Record<string, number> = {
step1_notice_submit: 0,
step2_parse_confirm: 1,
step3_inventory_prepare: 2,
step2_inventory_prepare: 2,
step4_align_confirm: 3,
step5_match_inventory: 4,
step3_inventory_match: 4,
step4_shortage_review: 4,
step6_generate_file: 5,
step5_export_excel: 5,
step7_upload_freight: 6,
step6_upload_freight: 6,
step7_finish: 6,
};
const TERMINAL_PROCESS_STATUSES = new Set(['uploaded', 'closed']);
const WORKFLOW_STEP_STATUSES = new Set<ShippingWorkflowStepItem['status']>([
'completed',
'current',
@@ -80,7 +56,7 @@ export function normalizeShippingWorkflowSteps(
return null;
}
return {
id: String(step?.id || step?.code || `shipping-step-${index + 1}`),
id: String(step?.id || step?.code || `shipping-stage-${index + 1}`),
label: String(step?.label || SHIPPING_WORKFLOW_STEP_LABELS[index] || ''),
status: status as ShippingWorkflowStepItem['status'],
};
@@ -89,76 +65,32 @@ export function normalizeShippingWorkflowSteps(
}
/**
* 优先消费后端状态机 UI State steps;没有时按 task 状态本地推导。
* 只消费后端状态机 UI State steps;没有投影时返回空数组,禁止本地猜测阶段。
*/
export function resolveShippingWorkflowSteps(
task: (ShippingTaskStepperSource & { ui_state?: { steps?: ShippingWorkflowStepSource[] | null } | null }) | null | undefined,
task: ShippingTaskStepperSource | null | undefined,
): ShippingWorkflowStepItem[] {
const uiStateSteps = normalizeShippingWorkflowSteps(task?.ui_state?.steps);
return uiStateSteps.length ? uiStateSteps : buildShippingWorkflowSteps(task);
}
function deriveCurrentIndex(task: ShippingTaskStepperSource | null | undefined): number {
const currentStep = String(task?.current_step || '').trim();
const processStatus = String(task?.process_status || '').trim();
const reviewStatus = String(task?.review_status || '').trim();
const pendingReason = String(task?.pending_human_reason || '').trim();
const matchStatus = String(task?.match_status || '').trim();
const hasExport = !!String(task?.export_file_name || '').trim();
if (currentStep) {
const currentStepIndex = CURRENT_STEP_INDEX_MAP[currentStep];
if (currentStepIndex !== undefined) {
return currentStepIndex;
}
}
if (TERMINAL_PROCESS_STATUSES.has(processStatus)) return 6;
if (processStatus === 'waiting_upload' || processStatus === 'upload_failed' || hasExport) return 5;
if (processStatus === 'matched') return 4;
if (reviewStatus === 'shortage_review' || pendingReason === 'shortage_review' || pendingReason === 'shortage') return 4;
if (processStatus === 'inventory_ready' || matchStatus) return 4;
if (
processStatus === 'waiting_inventory'
|| pendingReason === 'rpa_pending'
|| pendingReason === 'inv_unavail'
|| pendingReason === 'rpa_exhausted'
) {
return 2;
}
if (
processStatus === 'parsed'
|| processStatus === 'pending_review'
|| reviewStatus === 'pending_confirm'
|| reviewStatus === 'parse_review'
|| reviewStatus === 'rsv_required'
|| pendingReason === 'low_confidence'
|| pendingReason === 'rsv_required'
|| pendingReason === 'inventory_source_unresolved'
) {
return 1;
}
return 0;
return uiStateSteps;
}
/** 统一 ShippingProcessingStage → 粗粒度 Stepper 下标(过渡期;阶段 2 换 UnifiedProgressTrack)。 */
const PROCESSING_STAGE_INDEX_MAP: Record<string, number> = {
upload_received: 0,
email_parsing: 1,
document_parsing: 1,
email_parsing: 0,
document_parsing: 0,
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_source_resolving: 2,
inventory_fetching: 2,
inventory_matching: 4,
excel_generating: 5,
freight_uploading: 6,
completed: 6,
inventory_matching: 2,
excel_generating: 2,
freight_uploading: 3,
completed: 3,
};
/**
@@ -167,7 +99,7 @@ const PROCESSING_STAGE_INDEX_MAP: Record<string, number> = {
* 核心逻辑:有投影时按 stage 重算 completed/current/pending;blocked/failed 标当前步 blocked;
* 无投影或无法映射时原样返回 baseSteps。
*
* @param baseSteps - ui_state / process_status 推导的步骤
* @param baseSteps - ui_state 推导的步骤
* @param projection - 统一 order_task 投影
*/
export function applyShippingProcessingStageToSteps(
@@ -200,47 +132,12 @@ export function applyShippingProcessingStageToSteps(
}
/**
* 将 task 状态映射为七步 Stepper 项(id / label / done / active)。
* 缺少后端投影时 fail-closed,不根据 review/match/upload 等领域事实猜测阶段。
*/
export function buildShippingWorkflowSteps(
task: ShippingTaskStepperSource | null | undefined,
_task: ShippingTaskStepperSource | null | undefined,
): ShippingWorkflowStepItem[] {
const currentIndex = deriveCurrentIndex(task);
const reviewStatus = String(task?.review_status || '').trim();
const pendingReason = String(task?.pending_human_reason || '').trim();
const processStatus = String(task?.process_status || '').trim();
return SHIPPING_WORKFLOW_STEP_LABELS.map((label, index) => {
let status: ShippingWorkflowStepItem['status'] = 'pending';
// [STEP 1] uploaded/closed 是整票已完成的终态,不能再被 current_step 渲染成“第 7 步进行中”。
if (TERMINAL_PROCESS_STATUSES.has(processStatus)) {
status = 'completed';
} else if (index < currentIndex) {
status = 'completed';
} else if (index === currentIndex) {
status = 'current';
}
if (
(index === 1 && (
reviewStatus === 'parse_review'
|| pendingReason === 'low_confidence'
|| pendingReason === 'rsv_required'
|| pendingReason === 'inventory_source_unresolved'
))
|| (index === 2 && (pendingReason === 'inv_unavail' || pendingReason === 'rpa_exhausted'))
|| (index === 4 && (reviewStatus === 'shortage_review' || pendingReason === 'shortage_review' || pendingReason === 'shortage'))
|| (index === 6 && processStatus === 'upload_failed')
) {
status = 'blocked';
}
return {
id: `shipping-step-${index + 1}`,
label,
status,
};
});
return [];
}
/**