feat(shipping): 新增货代发货批量自动处理与任务重试功能

本次提交完整实现货代发货通知的自动化批量处理能力:
1.  新增发货单票后台任务类型与专用worker队列,实现任务持久化调度
2.  实现发货批次后台编排器,支持上传后自动逐票推进解析、匹配、导出全流程
3.  新增单票重试、批次待处理重试的API与前端操作界面
4.  补充全量多语言翻译,新增重试、任务列表、状态展示相关文案
5.  优化上传交互逻辑,改为后台自动处理任务,无需手动触发解析指令
6.  修复文件检核工具无数据预检逻辑,避免创建空检核批次
7.  调整发货工作流细节,优化Excel生成幂等性与任务状态同步
8.  更新环境配置与API文档,修正货代工具接口地址端口
This commit is contained in:
hugo committed 2026-06-23 11:22:09 +08:00
1 parent 70e8f700ff
commit 08360a4142
40 files changed
+2515 -371

No files matched your search

@@ -45,6 +45,8 @@ const CURRENT_STEP_INDEX_MAP: Record<string, number> = {
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();
@@ -60,7 +62,7 @@ function deriveCurrentIndex(task: ShippingTaskStepperSource | null | undefined):
}
}
if (processStatus === 'uploaded' || processStatus === 'closed') return 6;
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;
@@ -102,7 +104,10 @@ export function buildShippingWorkflowSteps(
return SHIPPING_WORKFLOW_STEP_LABELS.map((label, index) => {
let status: ShippingWorkflowStepItem['status'] = 'pending';
if (index < currentIndex) {
// [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';
@@ -47,6 +47,11 @@ export function buildShippingNoticeUploadPrompt(
|| ((result?.data as { tasks?: Array<{ task_id?: string }> } | undefined)?.tasks?.[0]?.task_id)
|| '',
).trim();
const taskIds = Array.isArray((result?.data as { tasks?: unknown[] } | undefined)?.tasks)
? ((result?.data as { tasks?: Array<{ task_id?: string }> }).tasks || [])
.map((task) => String(task?.task_id || '').trim())
.filter(Boolean)
: [];
const fileCount = Number(options?.fileCount || 0);
const fileLabel = options?.fileName
? `《${options.fileName}》`
@@ -54,7 +59,11 @@ export function buildShippingNoticeUploadPrompt(
const parts = [`我已上传${fileLabel}`];
if (batchNo) parts.push(`批次 ${batchNo}`);
if (taskId) parts.push(`当前任务 ${taskId}`);
return `${parts.join(',')}。请读取任务 raw_text,用 LLM 抽取结构化字段后调用 parse_notice(structured=...) 落库;若抽取失败可仅传 raw_text 走后端规则兜底,并展示解析结果供我确认。`;
if (fileCount > 1 || taskIds.length > 1) {
const taskListText = taskIds.length ? `任务列表:${taskIds.join('、')}。` : '';
return `${parts.join(',')}。${taskListText}请立即开始整批处理,不要只处理当前任务。先调用 get_batch_status 查看整批状态,再按批次顺序逐票处理:必要时调用 switch_focus_task 切到对应任务,然后读取该任务 raw_text,用 LLM 抽取结构化字段并调用 parse_notice(structured=...) 落库;若抽取失败可仅传 task_id 让后端用 raw_text 兜底。每处理完一票,都继续切到下一票,直到本批每一票都进入各自下一阶段(待确认、待上传库存、自动推进中的任一状态)。禁止再次询问我“是否开始解析”或只停在第一票。`;
}
return `${parts.join(',')}。请立即读取任务 raw_text,用 LLM 抽取结构化字段后直接调用 parse_notice(structured=...) 落库;若抽取失败可仅传 raw_text 走后端规则兜底。禁止再次询问我“是否开始解析”或“是否现在开始解析”。解析完成后,请直接展示解析结果供我确认。`;
}
/**
@@ -107,12 +107,11 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
};
const assistantMsg: ChatMessage = {
role: 'assistant',
type: 'shipping-match-result',
type: 'text',
content: [
String(result.message || '').trim(),
`任务编号:${taskId}`,
].filter(Boolean).join('\n'),
payload: buildMatchResultPayload(taskId, result),
local_id: ctx.newLocalMessageId('shipping-assistant'),
local_only: true,
};
@@ -158,11 +157,9 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
};
const assistantMsg: ChatMessage = {
role: 'assistant',
type: 'text',
content: [
String(result.message || '').trim(),
`任务编号:${taskId}`,
].filter(Boolean).join('\n'),
type: 'shipping-match-result',
content: String(result.message || '').trim(),
payload: buildMatchResultPayload(taskId, result),
local_id: ctx.newLocalMessageId('shipping-assistant'),
local_only: true,
};
@@ -12,7 +12,7 @@ import {
type ShippingTaskSummary,
} from '@/features/chat/api/shipping.api';
import { extractExt } from '../constants/shipping';
import { buildShippingInventoryUploadPrompt, buildShippingNoticeUploadPrompt, classifyShippingUploadFile } from './shippingUploadPrompt';
import { buildShippingInventoryUploadPrompt, classifyShippingUploadFile } from './shippingUploadPrompt';
import type { PendingAttachment } from '../types/shipping.types';
import type { Ref } from 'vue';
@@ -184,18 +184,19 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
).trim();
const hint = String(result.message || '').trim();
const status = String((result as { status?: string }).status || '').trim();
const orchestratorStarted = Boolean(
(result.data as { orchestrator_started?: boolean } | undefined)?.orchestrator_started,
);
const tail = status === 'needs_human' ? '请根据提示进行确认/驳回。' : '';
await ctx.pushShippingLocalAssistantMessage(
[
hint || `已处理发货通知附件:${file.name}`,
batchNo ? `批次编号:${batchNo}` : '',
taskId ? `任务编号:${taskId}` : '',
orchestratorStarted ? '后台已开始按票处理,请稍后查看进度自动刷新。' : '',
tail,
].filter(Boolean).join('\n'),
);
await ctx.sendShippingMenuMessage(
buildShippingNoticeUploadPrompt(result as unknown as Record<string, unknown>, { fileName: file.name }),
);
void ctx.refreshShippingActions();
};
@@ -231,6 +232,9 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
const fileCount = Number(batch?.file_count || noticeFiles.length || 0);
const hint = String(result.message || '').trim();
const status = String((result as { status?: string }).status || '').trim();
const orchestratorStarted = Boolean(
(result.data as { orchestrator_started?: boolean } | undefined)?.orchestrator_started,
);
const tail = status === 'needs_human' ? '请根据提示进行确认/驳回。' : '';
await ctx.pushShippingLocalAssistantMessage(
[
@@ -238,12 +242,10 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
batchNo ? `批次编号:${batchNo}` : '',
taskId ? `当前任务:${taskId}` : '',
focusProgress,
orchestratorStarted ? `后台已开始按票拆分处理,本批 ${fileCount} 票会逐步更新状态。` : '',
tail,
].filter(Boolean).join('\n'),
);
await ctx.sendShippingMenuMessage(
buildShippingNoticeUploadPrompt(result as unknown as Record<string, unknown>, { fileCount }),
);
void ctx.refreshShippingActions();
};