feat(shipping-notice): 新增临时库存管理功能,支持创建会话、获取分析结果及字段映射建议
This commit is contained in:
1 parent
46eb63f5bb
commit
e9bdd81f1a
320 files changed
+28361
-10487
No files matched your search
@@ -1,18 +1,15 @@
|
||||
/**
|
||||
* features/chat/shipping/useChatShippingUploadHandler.ts
|
||||
* 用途:处理发货通知与库存文件上传、批量建单和附件建议提示。
|
||||
* 依赖:shipping.api、shippingUploadPrompt、shipping 常量、chat.types。
|
||||
* 逻辑:发货通知建批/库存上传/单票覆盖均经 startChatTurn + multipart SSE;待重试幂等键绑定 conversation_id。
|
||||
* 依赖:shipping.api、file-assets.api、shippingUploadPrompt、shipping 常量、chat.types。
|
||||
* 逻辑:发货通知建批和单票覆盖经 Chat Turn;对话上传库存文件先成为私有临时资产,再进入 Dify 受控分析分支。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import {
|
||||
createWorkspaceShippingTask,
|
||||
type ShippingTaskSummary,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import type { ShippingTaskSummary } from '@/features/chat/api/shipping.api';
|
||||
import { uploadFileAsset } from '@/shared/api/file-assets.api';
|
||||
import { extractExt } from '../constants/shipping';
|
||||
import { buildShippingCreateBatchTurn, buildShippingCreateBatchFromIntakesTurn, buildShippingReplaceNoticeTurn, buildShippingUploadInventoryTurn } from './shippingTurnActions';
|
||||
import { buildShippingCreateBatchTurn, buildShippingCreateBatchFromIntakesTurn, buildShippingReplaceNoticeTurn, buildShippingTurnRefs } from './shippingTurnActions';
|
||||
import { computeNoticeFilesContentFingerprint, computeNoticeIntakeNosFingerprint } from './shippingNoticeBatchIdempotency';
|
||||
import { classifyShippingUploadFile } from './shippingUploadPrompt';
|
||||
import type { StartChatTurnOptions } from '../types/chat-turn.types';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { PendingAttachment } from '../types/shipping.types';
|
||||
@@ -113,7 +110,6 @@ export interface ShippingUploadHandlerContext {
|
||||
shippingBatchTasks: Ref<ShippingTaskSummary[]>;
|
||||
shippingInventorySelectionActive: Ref<boolean>;
|
||||
shippingInventorySelectionTaskId: Ref<string>;
|
||||
shippingInventorySchemaPreviewCache: Ref<Record<string, unknown>>;
|
||||
getActiveShippingTaskId: () => string;
|
||||
startChatTurn: (options: StartChatTurnOptions) => Promise<boolean>;
|
||||
refreshShippingActions: () => Promise<void>;
|
||||
@@ -122,12 +118,13 @@ export interface ShippingUploadHandlerContext {
|
||||
getParsedIntakeNos?: () => string[];
|
||||
getSelectedCandidateNos?: () => string[];
|
||||
clearConsumedNoticeAttachments?: () => void;
|
||||
sendTemporaryInventoryMessage: (assetNo: string, fileName: string) => Promise<unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建发货通知上传处理器。
|
||||
*
|
||||
* 核心逻辑:识别附件属于发货通知还是库存文件,分别触发建单/建批或库存上传,并维护 task/batch 本地上下文。
|
||||
* 核心逻辑:通知附件触发建单/建批;临时库存文件只能由发送层在用户明确声明后调用,避免根据后缀误判业务类型。
|
||||
* @param ctx - 上传处理上下文
|
||||
* @returns 自动上传、文件选择器和建议提示相关处理函数
|
||||
*/
|
||||
@@ -138,28 +135,17 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
};
|
||||
|
||||
const runInventoryUploadChatTurn = async (taskId: string, file: File) => {
|
||||
const turn = buildShippingUploadInventoryTurn(taskId, file);
|
||||
const normalizedTaskId = String(taskId || '').trim().toUpperCase();
|
||||
const ok = await ctx.startChatTurn({
|
||||
agentId: ctx.currentAgentId.value,
|
||||
inputType: 'upload_followup',
|
||||
displayText: turn.displayText,
|
||||
actionType: turn.actionType,
|
||||
payload: turn.payload,
|
||||
files: turn.files,
|
||||
refs: turn.refs,
|
||||
displayText: `上传库存文件:${file.name}`,
|
||||
actionType: 'shipping.upload_inventory',
|
||||
payload: { task_no: normalizedTaskId },
|
||||
files: [file],
|
||||
refs: buildShippingTurnRefs(normalizedTaskId),
|
||||
hooks: {
|
||||
onAssistantMessageFinished: async (assistantMsg) => {
|
||||
const payload = assistantMsg.payload && typeof assistantMsg.payload === 'object'
|
||||
? assistantMsg.payload as { schema_preview?: unknown; task_no?: string }
|
||||
: {};
|
||||
const key = String(payload.task_no || taskId || '').trim().toUpperCase();
|
||||
const preview = payload.schema_preview;
|
||||
if (key && preview && typeof preview === 'object') {
|
||||
ctx.shippingInventorySchemaPreviewCache.value = {
|
||||
...ctx.shippingInventorySchemaPreviewCache.value,
|
||||
[key]: preview,
|
||||
};
|
||||
}
|
||||
syncBatchContextFromTurnMessage(assistantMsg);
|
||||
void ctx.refreshShippingActions();
|
||||
},
|
||||
@@ -271,25 +257,6 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
}
|
||||
};
|
||||
|
||||
const syncBatchContextFromNoticeResponse = (result: Record<string, unknown> | null | undefined) => {
|
||||
const batchNo = String(
|
||||
(result?.batch_no as string | undefined)
|
||||
|| ((result?.data as { batch?: { batch_no?: string } } | undefined)?.batch?.batch_no)
|
||||
|| '',
|
||||
).trim();
|
||||
const focusTaskNo = String(
|
||||
((result?.data as { focus_task?: { task_no?: string } } | undefined)?.focus_task?.task_no)
|
||||
|| (result?.task_id as string | undefined)
|
||||
|| '',
|
||||
).trim();
|
||||
const batchSummary = ((result?.data as { batch?: unknown } | undefined)?.batch) || null;
|
||||
if (batchNo) ctx.resolvedShippingBatchNo.value = batchNo;
|
||||
if (focusTaskNo) ctx.resolvedShippingTaskId.value = focusTaskNo;
|
||||
if (batchSummary && typeof batchSummary === 'object') {
|
||||
ctx.shippingBatchSummary.value = batchSummary;
|
||||
}
|
||||
};
|
||||
|
||||
const runReplaceNoticeChatTurn = async (taskId: string, file: File) => {
|
||||
const turn = buildShippingReplaceNoticeTurn(taskId, file);
|
||||
const ok = await ctx.startChatTurn({
|
||||
@@ -377,32 +344,9 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
};
|
||||
|
||||
const handleShippingAutoUploadFile = async (file: File) => {
|
||||
const kind = classifyShippingUploadFile(file, extractExt);
|
||||
if (kind === 'inventory') {
|
||||
let taskId = ctx.getActiveShippingTaskId();
|
||||
if (!taskId) {
|
||||
const created = await createWorkspaceShippingTask({
|
||||
source_type: 'manual',
|
||||
conversation_id: String(ctx.conversationId.value || '').trim() || undefined,
|
||||
});
|
||||
syncBatchContextFromNoticeResponse(created as unknown as Record<string, unknown>);
|
||||
taskId = String(created.task_id || '').trim();
|
||||
if (!taskId) {
|
||||
ctx.msg.warning('自动创建发货任务失败');
|
||||
return;
|
||||
}
|
||||
}
|
||||
await uploadInventoryForTask(taskId, file);
|
||||
return;
|
||||
}
|
||||
const pendingNoticeTaskId = String(ctx.pendingShippingNoticeTaskId.value || '').trim().toUpperCase();
|
||||
ctx.pendingShippingNoticeTaskId.value = '';
|
||||
const targetTaskId = pendingNoticeTaskId || String(ctx.getActiveShippingTaskId() || '').trim().toUpperCase();
|
||||
if (targetTaskId) {
|
||||
await handleReplaceNoticeForCurrentTask(targetTaskId, file);
|
||||
return;
|
||||
}
|
||||
await runNoticeBatchChatTurn([file]);
|
||||
// 调用方已验证用户明确声明库存;此处只创建隔离的临时资产,绝不建单或写正式库存。
|
||||
const asset = await uploadFileAsset(file);
|
||||
await ctx.sendTemporaryInventoryMessage(asset.asset_no, file.name);
|
||||
};
|
||||
|
||||
const handleShippingAutoUploadNoticeBatch = async (files: File[]) => {
|
||||
@@ -476,8 +420,9 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
| Extract<PendingAttachment, { kind: 'local' }>
|
||||
| undefined;
|
||||
if (!first) return '';
|
||||
const kind = classifyShippingUploadFile(first.file, extractExt);
|
||||
if (kind === 'inventory') return ctx.t('chat.shippingNoticePrompt.notice.autoInventoryAction');
|
||||
if (['xlsx', 'xls', 'csv'].includes(extractExt(first.file.name || '').toLowerCase())) {
|
||||
return ctx.t('chat.shippingNoticePrompt.notice.autoSpreadsheetAction');
|
||||
}
|
||||
return ctx.t('chat.shippingNoticePrompt.notice.autoNoticeAction');
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user