feat(shipping-notice): 支持发货通知解析延后至 Dify 画布,优化任务创建流程
This commit is contained in:
1 parent
d46d61bfa1
commit
70e8f700ff
38 files changed
+3215
-714
No files matched your search
@@ -29,13 +29,37 @@ export const SHIPPING_WORKFLOW_STEP_LABELS = [
|
||||
'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,
|
||||
};
|
||||
|
||||
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 (processStatus === 'uploaded' || processStatus === 'closed') return 6;
|
||||
if (processStatus === 'waiting_upload' || processStatus === 'upload_failed' || hasExport) return 5;
|
||||
if (processStatus === 'matched') return 4;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* features/chat/shipping/shippingUploadPrompt.ts
|
||||
* 用途:库存上传后发给 Dify 的提示语构建与附件类型分类。
|
||||
* 用途:库存/通知上传后发给 Dify 的提示语构建与附件类型分类。
|
||||
* 依赖:无;useChatShippingUploadHandler 在上传成功后调用。
|
||||
* 逻辑:按 checkpoint 生成不同 follow-up 提示;classifyShippingUploadFile 区分库存/通知附件。
|
||||
* 逻辑:按 checkpoint 生成不同 follow-up 提示;通知建批后触发 Dify LLM 解析续办。
|
||||
*/
|
||||
/**
|
||||
* 根据上传 API 响应 checkpoint 生成发给 Agent 的 follow-up 提示语。
|
||||
@@ -29,6 +29,34 @@ export function buildShippingInventoryUploadPrompt(
|
||||
return `${prefix}。请继续处理库存导入,并告诉我下一步。`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据通知建批 API 响应生成发给 Dify 的 follow-up 提示语(触发画布 LLM 抽取 + parse_notice)。
|
||||
*/
|
||||
export function buildShippingNoticeUploadPrompt(
|
||||
result: Record<string, unknown> | null | undefined,
|
||||
options?: { fileCount?: number; fileName?: string },
|
||||
): string {
|
||||
const batchNo = String(
|
||||
(result?.batch_no as string | undefined)
|
||||
|| ((result?.data as { batch?: { batch_no?: string } } | undefined)?.batch?.batch_no)
|
||||
|| '',
|
||||
).trim();
|
||||
const taskId = String(
|
||||
((result?.data as { focus_task?: { task_no?: string } } | undefined)?.focus_task?.task_no)
|
||||
|| (result?.task_id as string | undefined)
|
||||
|| ((result?.data as { tasks?: Array<{ task_id?: string }> } | undefined)?.tasks?.[0]?.task_id)
|
||||
|| '',
|
||||
).trim();
|
||||
const fileCount = Number(options?.fileCount || 0);
|
||||
const fileLabel = options?.fileName
|
||||
? `《${options.fileName}》`
|
||||
: (fileCount > 1 ? `${fileCount} 份发货通知` : '发货通知');
|
||||
const parts = [`我已上传${fileLabel}`];
|
||||
if (batchNo) parts.push(`批次 ${batchNo}`);
|
||||
if (taskId) parts.push(`当前任务 ${taskId}`);
|
||||
return `${parts.join(',')}。请读取任务 raw_text,用 LLM 抽取结构化字段后调用 parse_notice(structured=...) 落库;若抽取失败可仅传 raw_text 走后端规则兜底,并展示解析结果供我确认。`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按扩展名判断附件是库存 Excel 还是发货通知文件。
|
||||
*/
|
||||
|
||||
@@ -60,10 +60,14 @@ export function createShippingParseReviewHandlers(ctx: ShippingParseReviewContex
|
||||
const removeParseReviewMessageForTask = (taskId: string) => {
|
||||
const normalized = String(taskId || '').trim().toUpperCase();
|
||||
if (!normalized) return;
|
||||
ctx.messages.value = ctx.messages.value.filter((msg) => {
|
||||
for (let i = ctx.messages.value.length - 1; i >= 0; i -= 1) {
|
||||
const msg = ctx.messages.value[i];
|
||||
if (!msg) continue;
|
||||
const payload = getShippingParseReviewPayload(msg);
|
||||
return payload?.taskId?.trim().toUpperCase() !== normalized;
|
||||
});
|
||||
if (payload?.taskId?.trim().toUpperCase() === normalized) {
|
||||
ctx.messages.value.splice(i, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const upsertParseReviewMessage = async (payload: ShippingParseReviewPayload) => {
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
type ShippingTaskSummary,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import { extractExt } from '../constants/shipping';
|
||||
import { buildShippingInventoryUploadPrompt, classifyShippingUploadFile } from './shippingUploadPrompt';
|
||||
import { buildShippingInventoryUploadPrompt, buildShippingNoticeUploadPrompt, classifyShippingUploadFile } from './shippingUploadPrompt';
|
||||
import type { PendingAttachment } from '../types/shipping.types';
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
@@ -193,6 +193,9 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
tail,
|
||||
].filter(Boolean).join('\n'),
|
||||
);
|
||||
await ctx.sendShippingMenuMessage(
|
||||
buildShippingNoticeUploadPrompt(result as unknown as Record<string, unknown>, { fileName: file.name }),
|
||||
);
|
||||
void ctx.refreshShippingActions();
|
||||
};
|
||||
|
||||
@@ -238,6 +241,9 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
tail,
|
||||
].filter(Boolean).join('\n'),
|
||||
);
|
||||
await ctx.sendShippingMenuMessage(
|
||||
buildShippingNoticeUploadPrompt(result as unknown as Record<string, unknown>, { fileCount }),
|
||||
);
|
||||
void ctx.refreshShippingActions();
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user