本次提交完整实现货代发货通知的自动化批量处理能力: 1. 新增发货单票后台任务类型与专用worker队列,实现任务持久化调度 2. 实现发货批次后台编排器,支持上传后自动逐票推进解析、匹配、导出全流程 3. 新增单票重试、批次待处理重试的API与前端操作界面 4. 补充全量多语言翻译,新增重试、任务列表、状态展示相关文案 5. 优化上传交互逻辑,改为后台自动处理任务,无需手动触发解析指令 6. 修复文件检核工具无数据预检逻辑,避免创建空检核批次 7. 调整发货工作流细节,优化Excel生成幂等性与任务状态同步 8. 更新环境配置与API文档,修正货代工具接口地址端口
132 lines
4.7 KiB
TypeScript
132 lines
4.7 KiB
TypeScript
/**
|
|
* features/chat/shipping/shippingStepper.ts
|
|
* 用途:基于 shipping task 状态推导前端七步 Stepper 展示数据。
|
|
* 依赖:无外部模块;ShippingWorkflowStepper.vue 消费本模块输出。
|
|
* 逻辑:buildShippingWorkflowSteps 将 process_status / checkpoint 等映射为步骤 id 与 done/active 状态。
|
|
*/
|
|
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;
|
|
}
|
|
|
|
export interface ShippingWorkflowStepItem {
|
|
id: string;
|
|
label: string;
|
|
status: 'completed' | 'current' | 'pending' | 'blocked';
|
|
}
|
|
|
|
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',
|
|
] 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']);
|
|
|
|
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 (reviewStatus === 'align_review' || pendingReason === 'align_review') return 3;
|
|
if (processStatus === 'inventory_ready' || matchStatus) return 4;
|
|
if (
|
|
processStatus === 'waiting_inventory'
|
|
|| pendingReason === 'map_infer'
|
|
|| 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'
|
|
) {
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* 将 task 状态映射为七步 Stepper 项(id / label / done / active)。
|
|
*/
|
|
export function buildShippingWorkflowSteps(
|
|
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'))
|
|
|| (index === 3 && (reviewStatus === 'align_review' || pendingReason === 'align_review'))
|
|
|| (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,
|
|
};
|
|
});
|
|
}
|