feat(shipping_notice): 添加重新上传发货通知功能
- 新增接口支持覆盖当前任务的发货通知 - 重新解析时重置任务状态,避免重复任务 - 增加库存 RPA 等待时间的复查逻辑 - 更新状态机以处理文本抽取失败的情况 - 增强测试用例以覆盖新功能
This commit is contained in:
1 parent
f434402530
commit
7f1d5dfbcd
20 files changed
+691
-26
No files matched your search
@@ -7,6 +7,7 @@ export const SHIPPING_ACTION_IDS = [
|
||||
'confirm',
|
||||
'reject',
|
||||
'reparse',
|
||||
'replace_notice_file',
|
||||
'confirm_inventory_mapping',
|
||||
'correct_inventory_mapping',
|
||||
'reparse_inventory',
|
||||
|
||||
@@ -167,6 +167,28 @@ export async function createWorkspaceShippingTaskFromNotice(file: File, conversa
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新上传发货通知并覆盖当前任务。
|
||||
* @param taskNo - 需要覆盖的发货任务编号
|
||||
* @param file - 新的发货通知文件
|
||||
* @returns 覆盖后的任务状态与后台编排结果
|
||||
*/
|
||||
export async function replaceWorkspaceShippingTaskNotice(taskNo: string, file: File) {
|
||||
const form = new FormData();
|
||||
form.append('file', file);
|
||||
const headers = getAuthHeaders();
|
||||
delete (headers as Record<string, string>)['Content-Type'];
|
||||
const res = await fetch(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/replace-notice`,
|
||||
{ method: 'POST', headers, body: form },
|
||||
);
|
||||
const body = (await res.json().catch(() => ({}))) as ShippingNoticeUploadResponse & { error?: string };
|
||||
if (!res.ok || body.status === 'failed') {
|
||||
throw new Error(body.error || body.message || res.statusText);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量上传多份发货通知并创建批次。
|
||||
* @param files - 发货通知附件列表
|
||||
|
||||
@@ -44,6 +44,7 @@ const props = defineProps<{
|
||||
shippingFocusReason?: string;
|
||||
/** 用对象包裹 Ref,避免 template 自动解包 */
|
||||
shippingPickerRefHolder: { pickerRef: Ref<HTMLInputElement | null> };
|
||||
shippingNoticePickerRefHolder: { pickerRef: Ref<HTMLInputElement | null> };
|
||||
getKbLabel: (kb: string) => string;
|
||||
}>();
|
||||
|
||||
@@ -121,6 +122,15 @@ const bindShippingPickerRef = (el: unknown) => {
|
||||
props.shippingPickerRefHolder.pickerRef.value = (el as HTMLInputElement | null) ?? null;
|
||||
};
|
||||
|
||||
const bindShippingNoticePickerRef = (el: unknown) => {
|
||||
props.shippingNoticePickerRefHolder.pickerRef.value = (el as HTMLInputElement | null) ?? null;
|
||||
};
|
||||
|
||||
const bindAttachmentPickerRef = (el: unknown) => {
|
||||
filePickerRef.value = (el as HTMLInputElement | null) ?? null;
|
||||
bindShippingNoticePickerRef(el);
|
||||
};
|
||||
|
||||
const handleDocumentPointerDown = (event: MouseEvent | TouchEvent) => {
|
||||
const target = event.target as Node | null;
|
||||
if (!target) return;
|
||||
@@ -185,7 +195,7 @@ onBeforeUnmount(() => {
|
||||
/>
|
||||
|
||||
<input
|
||||
ref="filePickerRef"
|
||||
:ref="bindAttachmentPickerRef"
|
||||
type="file"
|
||||
multiple
|
||||
class="hidden"
|
||||
|
||||
@@ -145,6 +145,7 @@ const page = useChatPageContext();
|
||||
:shipping-focus-task-no="page.focusedShippingTaskNo"
|
||||
:shipping-focus-reason="page.shippingFocusReason"
|
||||
:shipping-picker-ref-holder="page.shippingPickerRefHolder"
|
||||
:shipping-notice-picker-ref-holder="page.shippingNoticePickerRefHolder"
|
||||
:get-kb-label="page.getKbLabel"
|
||||
@send="page.handleSend()"
|
||||
@voice-click="page.handleVoiceFeatureClick"
|
||||
|
||||
@@ -306,6 +306,7 @@ export function useChatPage() {
|
||||
const leaveMessageHandlers = createLeaveMessageHandlers(leave);
|
||||
const shippingMappingHandlers = createShippingMappingHandlers(shipping);
|
||||
const shippingPickerRefHolder = markRaw(createShippingPickerRefHolder(shipping.shippingInventoryPickerRef));
|
||||
const shippingNoticePickerRefHolder = markRaw(createShippingPickerRefHolder(shipping.shippingNoticePickerRef));
|
||||
|
||||
const showChatRating = ref(false);
|
||||
|
||||
@@ -399,6 +400,7 @@ export function useChatPage() {
|
||||
leaveMessageHandlers,
|
||||
shippingMappingHandlers,
|
||||
shippingPickerRefHolder,
|
||||
shippingNoticePickerRefHolder,
|
||||
shouldShowThinkingBubble: markdown.shouldShowThinkingBubble,
|
||||
messageBubbleHandlers: markdown.messageBubbleHandlers,
|
||||
shouldRenderMessage: markdown.shouldRenderMessage,
|
||||
|
||||
@@ -135,6 +135,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
);
|
||||
const shippingAutoFlowRequested = ref(false);
|
||||
const shippingInventoryPickerRef = ref<HTMLInputElement | null>(null);
|
||||
const shippingNoticePickerRef = ref<HTMLInputElement | null>(null);
|
||||
const pendingShippingUploadTaskId = ref('');
|
||||
const pendingShippingInventoryFile = ref<File | null>(null);
|
||||
const shippingInventorySelectionActive = ref(false);
|
||||
@@ -609,6 +610,10 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
sendShippingMenuMessage,
|
||||
openShippingInventoryMappingFormForTask,
|
||||
openShippingInventoryPicker,
|
||||
openShippingNoticePicker: () => {
|
||||
shippingNoticePickerRef.value?.click();
|
||||
return true;
|
||||
},
|
||||
executeShippingDecision,
|
||||
executeShippingManualUpload,
|
||||
refreshShippingActions,
|
||||
@@ -855,6 +860,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
prepareMarkdownDisplayText,
|
||||
shippingAutoFlowRequested,
|
||||
shippingInventoryPickerRef,
|
||||
shippingNoticePickerRef,
|
||||
pendingShippingUploadTaskId,
|
||||
shippingInventorySelectionActive,
|
||||
shippingInventorySelectionTaskId,
|
||||
|
||||
@@ -26,6 +26,7 @@ export interface ShippingMenuHandlerContext {
|
||||
sendShippingMenuMessage: (message: string) => Promise<void>;
|
||||
openShippingInventoryMappingFormForTask: (taskId: string) => Promise<boolean>;
|
||||
openShippingInventoryPicker: () => boolean;
|
||||
openShippingNoticePicker: () => boolean;
|
||||
executeShippingDecision: (decision: string, displayText?: string) => Promise<boolean>;
|
||||
executeShippingManualUpload: (taskId: string, displayText?: string) => Promise<boolean>;
|
||||
refreshShippingActions: () => Promise<void>;
|
||||
@@ -175,6 +176,10 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
ctx.openShippingInventoryPicker();
|
||||
return;
|
||||
}
|
||||
if (action.id === 'replace_notice_file') {
|
||||
ctx.openShippingNoticePicker();
|
||||
return;
|
||||
}
|
||||
if (action.id === 'match_inventory') {
|
||||
if (chatMsg?.shipping_actions_used) return;
|
||||
if (chatMsg) chatMsg.shipping_actions_used = true;
|
||||
|
||||
@@ -8,6 +8,7 @@ import { computed } from 'vue';
|
||||
import {
|
||||
createWorkspaceShippingBatchFromNotices,
|
||||
createWorkspaceShippingTask,
|
||||
replaceWorkspaceShippingTaskNotice,
|
||||
uploadWorkspaceShippingInventory,
|
||||
type ShippingTaskSummary,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
@@ -133,6 +134,26 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
}
|
||||
};
|
||||
|
||||
const handleReplaceNoticeForCurrentTask = async (taskId: string, file: File) => {
|
||||
const result = await replaceWorkspaceShippingTaskNotice(taskId, file);
|
||||
syncBatchContextFromNoticeResponse(result as unknown as Record<string, unknown>);
|
||||
ctx.resolvedShippingTaskId.value = taskId;
|
||||
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,
|
||||
);
|
||||
await ctx.pushShippingLocalAssistantMessage(
|
||||
[
|
||||
hint || `已重新上传发货通知并覆盖当前任务 ${taskId}`,
|
||||
`任务编号:${taskId}`,
|
||||
orchestratorStarted ? '后台已开始重新解析当前任务,请稍后查看进度自动刷新。' : '',
|
||||
status === 'needs_human' ? '请根据提示重新上传清晰文件,或粘贴通知正文。' : '',
|
||||
].filter(Boolean).join('\n'),
|
||||
);
|
||||
void ctx.refreshShippingActions();
|
||||
};
|
||||
|
||||
const handleShippingAutoUploadFile = async (file: File) => {
|
||||
const kind = classifyShippingUploadFile(file, extractExt);
|
||||
if (kind === 'inventory') {
|
||||
@@ -152,6 +173,11 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
await uploadInventoryForTask(taskId, file);
|
||||
return;
|
||||
}
|
||||
const activeTaskId = String(ctx.getActiveShippingTaskId() || '').trim().toUpperCase();
|
||||
if (activeTaskId) {
|
||||
await handleReplaceNoticeForCurrentTask(activeTaskId, file);
|
||||
return;
|
||||
}
|
||||
const result = await createWorkspaceShippingBatchFromNotices(
|
||||
[file],
|
||||
String(ctx.conversationId.value || '').trim() || undefined,
|
||||
@@ -188,6 +214,12 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
const handleShippingAutoUploadNoticeBatch = async (files: File[]) => {
|
||||
const noticeFiles = files.filter(Boolean);
|
||||
if (!noticeFiles.length) return;
|
||||
const activeTaskId = String(ctx.getActiveShippingTaskId() || '').trim().toUpperCase();
|
||||
const singleNoticeFile = noticeFiles[0];
|
||||
if (noticeFiles.length === 1 && activeTaskId && singleNoticeFile) {
|
||||
await handleReplaceNoticeForCurrentTask(activeTaskId, singleNoticeFile);
|
||||
return;
|
||||
}
|
||||
const result = await createWorkspaceShippingBatchFromNotices(
|
||||
noticeFiles,
|
||||
String(ctx.conversationId.value || '').trim() || undefined,
|
||||
|
||||
Reference in new issue
Block a user