feat(shipping-notice): 新增发货批次和任务管理功能,支持批次创建与任务处理
This commit is contained in:
1 parent
457f0f4e5e
commit
634dee4b81
81 files changed
+9088
-3625
No files matched your search
@@ -1,10 +1,13 @@
|
||||
/**
|
||||
* 出货聊天:库存/发货通知文件上传、隐藏 file input、附件建议提示。
|
||||
/**
|
||||
* features/chat/shipping/useChatShippingUploadHandler.ts
|
||||
* 用途:处理发货通知与库存文件上传、批量建单和附件建议提示。
|
||||
* 依赖:shipping.api、shippingUploadPrompt、shipping 常量、chat.types。
|
||||
* 逻辑:由 useChatShipping 调用本文件;本文件识别附件类型后决定是创建任务/批次还是上传库存,并把结果同步到聊天上下文。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import {
|
||||
createWorkspaceShippingBatchFromNotices,
|
||||
createWorkspaceShippingTask,
|
||||
createWorkspaceShippingTaskFromNotice,
|
||||
uploadWorkspaceShippingInventory,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import { extractExt } from '../constants/shipping';
|
||||
@@ -20,6 +23,8 @@ export interface ShippingUploadHandlerContext {
|
||||
shippingInventoryPickerRef: Ref<HTMLInputElement | null>;
|
||||
pendingShippingUploadTaskId: Ref<string>;
|
||||
resolvedShippingTaskId: Ref<string>;
|
||||
resolvedShippingBatchNo: Ref<string>;
|
||||
shippingBatchSummary: Ref<unknown | null>;
|
||||
shippingInventorySchemaPreviewCache: Ref<Record<string, unknown>>;
|
||||
getActiveShippingTaskId: () => string;
|
||||
sendShippingMenuMessage: (message: string) => Promise<void>;
|
||||
@@ -29,6 +34,13 @@ export interface ShippingUploadHandlerContext {
|
||||
t: (key: string) => string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建发货通知上传处理器。
|
||||
*
|
||||
* 核心逻辑:识别附件属于发货通知还是库存文件,分别触发建单/建批或库存上传,并维护 task/batch 本地上下文。
|
||||
* @param ctx - 上传处理上下文
|
||||
* @returns 自动上传、文件选择器和建议提示相关处理函数
|
||||
*/
|
||||
export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext) {
|
||||
const continueShippingInventoryUploadWithDify = async (
|
||||
taskId: string,
|
||||
@@ -47,6 +59,25 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
await ctx.sendShippingMenuMessage(buildShippingInventoryUploadPrompt(result, fileName));
|
||||
};
|
||||
|
||||
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 handleShippingAutoUploadFile = async (file: File) => {
|
||||
const kind = classifyShippingUploadFile(file, extractExt);
|
||||
if (kind === 'inventory') {
|
||||
@@ -67,18 +98,28 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
await continueShippingInventoryUploadWithDify(taskId, result as unknown as Record<string, unknown>, file.name);
|
||||
return;
|
||||
}
|
||||
const result = await createWorkspaceShippingTaskFromNotice(
|
||||
file,
|
||||
const result = await createWorkspaceShippingBatchFromNotices(
|
||||
[file],
|
||||
String(ctx.conversationId.value || '').trim() || undefined,
|
||||
);
|
||||
const taskId = String(result.task_id || '').trim();
|
||||
if (taskId) ctx.resolvedShippingTaskId.value = taskId;
|
||||
syncBatchContextFromNoticeResponse(result as unknown as Record<string, unknown>);
|
||||
const taskId = String(
|
||||
((result.data as { focus_task?: { task_no?: string } } | undefined)?.focus_task?.task_no)
|
||||
|| result.task_id
|
||||
|| '',
|
||||
).trim();
|
||||
const batchNo = String(
|
||||
result.batch_no
|
||||
|| ((result.data as { batch?: { batch_no?: string } } | undefined)?.batch?.batch_no)
|
||||
|| '',
|
||||
).trim();
|
||||
const hint = String(result.message || '').trim();
|
||||
const status = String((result as { status?: string }).status || '').trim();
|
||||
const tail = status === 'needs_human' ? '请根据提示进行确认/驳回。' : '';
|
||||
await ctx.pushShippingLocalAssistantMessage(
|
||||
[
|
||||
hint || `已处理发货通知附件:${file.name}`,
|
||||
batchNo ? `批次编号:${batchNo}` : '',
|
||||
taskId ? `任务编号:${taskId}` : '',
|
||||
tail,
|
||||
].filter(Boolean).join('\n'),
|
||||
@@ -86,6 +127,51 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
void ctx.refreshShippingActions();
|
||||
};
|
||||
|
||||
const handleShippingAutoUploadNoticeBatch = async (files: File[]) => {
|
||||
const noticeFiles = files.filter(Boolean);
|
||||
if (!noticeFiles.length) return;
|
||||
const result = await createWorkspaceShippingBatchFromNotices(
|
||||
noticeFiles,
|
||||
String(ctx.conversationId.value || '').trim() || undefined,
|
||||
);
|
||||
syncBatchContextFromNoticeResponse(result as unknown as Record<string, unknown>);
|
||||
const taskId = String(
|
||||
((result.data as { focus_task?: { task_no?: string } } | undefined)?.focus_task?.task_no)
|
||||
|| result.task_id
|
||||
|| '',
|
||||
).trim();
|
||||
const batchNo = String(
|
||||
result.batch_no
|
||||
|| ((result.data as { batch?: { batch_no?: string } } | undefined)?.batch?.batch_no)
|
||||
|| '',
|
||||
).trim();
|
||||
const batch = (result.data as {
|
||||
batch?: { file_count?: number };
|
||||
tasks?: Array<{ batch_index?: number; batch_total?: number }>;
|
||||
} | undefined)?.batch;
|
||||
const tasks = Array.isArray((result.data as { tasks?: unknown[] } | undefined)?.tasks)
|
||||
? (result.data as { tasks: Array<{ batch_index?: number; batch_total?: number }> }).tasks
|
||||
: [];
|
||||
const focusTask = tasks[0];
|
||||
const focusProgress = focusTask?.batch_index && focusTask?.batch_total
|
||||
? `当前第 ${focusTask.batch_index}/${focusTask.batch_total} 票`
|
||||
: '';
|
||||
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 tail = status === 'needs_human' ? '请根据提示进行确认/驳回。' : '';
|
||||
await ctx.pushShippingLocalAssistantMessage(
|
||||
[
|
||||
hint || `已处理 ${fileCount} 份发货通知附件`,
|
||||
batchNo ? `批次编号:${batchNo}` : '',
|
||||
taskId ? `当前任务:${taskId}` : '',
|
||||
focusProgress,
|
||||
tail,
|
||||
].filter(Boolean).join('\n'),
|
||||
);
|
||||
void ctx.refreshShippingActions();
|
||||
};
|
||||
|
||||
const openShippingInventoryPicker = (): boolean => {
|
||||
const taskId = ctx.getActiveShippingTaskId();
|
||||
if (!taskId) {
|
||||
@@ -132,6 +218,7 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
|
||||
return {
|
||||
handleShippingAutoUploadFile,
|
||||
handleShippingAutoUploadNoticeBatch,
|
||||
openShippingInventoryPicker,
|
||||
handleShippingInventorySelected,
|
||||
shippingSuggestedPrompt,
|
||||
|
||||
Reference in new issue
Block a user