feat(shipping-notice): 增强发货通知候选管理功能,支持候选选择、重复检测与业务摘要修订
This commit is contained in:
1 parent
70f684b94a
commit
b595e157e9
83 files changed
+5857
-200
No files matched your search
@@ -540,10 +540,41 @@ export const refreshShippingNoticeDuplicate = (intakeNo: string) =>
|
||||
{ method: 'POST' },
|
||||
);
|
||||
|
||||
export const updateShippingNoticeCandidate = (
|
||||
candidateNo: string,
|
||||
patch: { selected?: boolean; business_summary?: Record<string, unknown> },
|
||||
) => requestJson<import('../types/shipping.api.types').ShippingNoticeCandidateResponse>(
|
||||
`/api/workspace/shipping-notice/candidates/${encodeURIComponent(candidateNo)}`,
|
||||
{
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(patch),
|
||||
},
|
||||
);
|
||||
|
||||
export const resolveShippingNoticeCandidateDuplicate = (
|
||||
candidateNo: string,
|
||||
action: string,
|
||||
targetTaskNo?: string | null,
|
||||
reason?: string | null,
|
||||
) => requestJson<import('../types/shipping.api.types').ShippingNoticeCandidateResponse>(
|
||||
`/api/workspace/shipping-notice/candidates/${encodeURIComponent(candidateNo)}/duplicate-resolution`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
action,
|
||||
target_task_no: targetTaskNo || undefined,
|
||||
reason: reason || undefined,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
export const createWorkspaceShippingBatchFromIntakes = (
|
||||
intakeNos: string[],
|
||||
conversationId?: string | null,
|
||||
idempotencyKey?: string,
|
||||
candidateNos?: string[],
|
||||
) =>
|
||||
requestJson<ShippingCreateBatchFromIntakesResponse>('/api/workspace/shipping-batches/create-from-intakes', {
|
||||
method: 'POST',
|
||||
@@ -555,6 +586,7 @@ export const createWorkspaceShippingBatchFromIntakes = (
|
||||
intake_nos: intakeNos,
|
||||
conversation_id: conversationId || undefined,
|
||||
idempotency_key: idempotencyKey,
|
||||
candidate_nos: candidateNos,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
X,
|
||||
} from 'lucide-vue-next';
|
||||
import type { PendingAttachment, ShippingNoticePendingAttachment } from '../types/shipping.types';
|
||||
import ShippingNoticeCandidateReview from './ShippingNoticeCandidateReview.vue';
|
||||
import {
|
||||
isBlockingWarning,
|
||||
isShippingNoticeAttachmentParseIncomplete,
|
||||
@@ -49,6 +50,7 @@ const props = defineProps<{
|
||||
isShippingNoticeAgent: boolean;
|
||||
isMaintenanceAgent?: boolean;
|
||||
canManageMaintenance?: boolean;
|
||||
canForceCreateShippingDuplicate?: boolean;
|
||||
shippingSuggestedPrompt: string;
|
||||
shippingFocusTaskNo?: string;
|
||||
shippingFocusReason?: string;
|
||||
@@ -65,6 +67,9 @@ const emit = defineEmits<{
|
||||
'remove-attachment': [id: string];
|
||||
'retry-shipping-notice-attachment': [id: string];
|
||||
'resolve-shipping-notice-duplicate': [id: string];
|
||||
'select-shipping-candidate': [candidateNo: string, selected: boolean];
|
||||
'update-shipping-candidate': [candidateNo: string, businessSummary: Record<string, unknown>, done: (success: boolean) => void];
|
||||
'resolve-shipping-candidate-duplicate': [candidateNo: string, action: import('../types/shipping.types').ShippingDuplicateAction, targetTaskNo: string | undefined, reason: string | undefined, done: (success: boolean) => void];
|
||||
'local-files-selected': [event: Event];
|
||||
'add-remote-url': [url: string];
|
||||
'shipping-inventory-selected': [event: Event];
|
||||
@@ -276,6 +281,18 @@ watch(
|
||||
<X class="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="isShippingNoticeAgent" class="space-y-2 px-3 pb-1">
|
||||
<ShippingNoticeCandidateReview
|
||||
v-for="a in attachments.filter((item): item is ShippingNoticePendingAttachment => item.kind === 'shipping_notice' && !!item.candidates?.length)"
|
||||
:key="`candidate-${a.id}`"
|
||||
:attachment="a"
|
||||
:can-force-create="!!canForceCreateShippingDuplicate"
|
||||
@select="(candidateNo, selected) => emit('select-shipping-candidate', candidateNo, selected)"
|
||||
@update="(candidateNo, summary, done) => emit('update-shipping-candidate', candidateNo, summary, done)"
|
||||
@resolve-duplicate="(candidateNo, action, targetTaskNo, reason, done) => emit('resolve-shipping-candidate-duplicate', candidateNo, action, targetTaskNo, reason, done)"
|
||||
/>
|
||||
</div>
|
||||
<textarea
|
||||
ref="textareaRef"
|
||||
v-model="inputValue"
|
||||
@@ -319,11 +336,11 @@ watch(
|
||||
<span v-if="a.uploadStatus === 'uploading'" class="text-muted"> · {{ t('chat.shippingNoticeUploading') }}</span>
|
||||
<span v-else-if="a.parseStatus === 'queued' || a.parseStatus === 'parsing'" class="text-muted"> · {{ t('chat.shippingNoticeParsing') }}</span>
|
||||
<span
|
||||
v-else-if="a.parseStatus === 'parsed' && a.duplicate?.status === 'possible_duplicate' && !a.duplicateResolution?.action"
|
||||
v-else-if="a.parseStatus === 'parsed' && !a.candidates?.length && a.duplicate?.status === 'possible_duplicate' && !a.duplicateResolution?.action"
|
||||
class="font-medium text-amber-700"
|
||||
> · {{ t('chat.shippingNoticeDuplicatePossibleBadge') }}</span>
|
||||
<span
|
||||
v-else-if="a.parseStatus === 'parsed' && a.duplicate?.blocking && !a.duplicateResolution?.action"
|
||||
v-else-if="a.parseStatus === 'parsed' && !a.candidates?.length && a.duplicate?.blocking && !a.duplicateResolution?.action"
|
||||
class="font-medium text-amber-700"
|
||||
> · {{ t('chat.shippingNoticeDuplicateBlockingBadge') }}</span>
|
||||
<span
|
||||
@@ -355,7 +372,7 @@ watch(
|
||||
</template>
|
||||
</span>
|
||||
<button
|
||||
v-if="a.kind === 'shipping_notice' && a.duplicate?.blocking && !a.duplicateResolution?.action"
|
||||
v-if="a.kind === 'shipping_notice' && !a.candidates?.length && a.duplicate?.blocking && !a.duplicateResolution?.action"
|
||||
type="button"
|
||||
class="text-amber-700 hover:text-amber-800"
|
||||
:title="t('chat.shippingNoticeDuplicateHandle')"
|
||||
|
||||
@@ -276,6 +276,7 @@ watch(() => page.currentAgentId, () => {
|
||||
:is-shipping-notice-agent="page.isShippingNoticeAgent"
|
||||
:is-maintenance-agent="isMaintenanceAgentPage"
|
||||
:can-manage-maintenance="canManageMaintenance"
|
||||
:can-force-create-shipping-duplicate="page.canForceCreateShippingDuplicate"
|
||||
:shipping-suggested-prompt="page.shippingSuggestedPrompt"
|
||||
:shipping-focus-task-no="page.focusedShippingTaskNo"
|
||||
:shipping-focus-reason="page.shippingFocusReason"
|
||||
@@ -288,6 +289,9 @@ watch(() => page.currentAgentId, () => {
|
||||
@remove-attachment="page.removeAttachment"
|
||||
@retry-shipping-notice-attachment="page.retryShippingNoticeAttachment"
|
||||
@resolve-shipping-notice-duplicate="page.openShippingDuplicateDialog"
|
||||
@select-shipping-candidate="page.setShippingCandidateSelected"
|
||||
@update-shipping-candidate="page.updateShippingCandidateSummary"
|
||||
@resolve-shipping-candidate-duplicate="page.resolveShippingCandidateDuplicate"
|
||||
@local-files-selected="page.handleLocalFilesSelected"
|
||||
@add-remote-url="page.addRemoteUrlAttachment"
|
||||
@shipping-inventory-selected="page.handleShippingInventorySelected"
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
<!--
|
||||
features/chat/components/ShippingNoticeCandidateReview.vue
|
||||
用途:展示一封 EML 下的订单候选,并提供选择、结构化修订与重复决策入口。
|
||||
依赖:shipping.types、Vue I18n。
|
||||
逻辑:组件维护 PO 与订单行编辑草稿,持久化操作通过事件交给 useShippingNoticeIntakes。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { ShippingDuplicateAction, ShippingNoticePendingAttachment } from '../types/shipping.types';
|
||||
|
||||
interface EditableCandidateLine {
|
||||
source: Record<string, unknown>;
|
||||
sku: string;
|
||||
qty: string;
|
||||
reservation_id: string;
|
||||
hub_code: string;
|
||||
uom: string;
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
attachment: ShippingNoticePendingAttachment;
|
||||
canForceCreate: boolean;
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
select: [candidateNo: string, selected: boolean];
|
||||
update: [candidateNo: string, businessSummary: Record<string, unknown>, done: (success: boolean) => void];
|
||||
resolveDuplicate: [candidateNo: string, action: ShippingDuplicateAction, targetTaskNo: string | undefined, reason: string | undefined, done: (success: boolean) => void];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const editingCandidateNo = ref('');
|
||||
const editError = ref('');
|
||||
const editPoNumber = ref('');
|
||||
const editLines = reactive<EditableCandidateLine[]>([]);
|
||||
const forceReasonCandidateNo = ref('');
|
||||
const forceReason = ref('');
|
||||
const submittingCandidateNo = ref('');
|
||||
const candidates = computed(() => props.attachment.candidates || []);
|
||||
|
||||
watch(() => props.attachment.candidates, () => {
|
||||
if (editingCandidateNo.value && !candidates.value.some((item) => item.candidateNo === editingCandidateNo.value)) {
|
||||
editingCandidateNo.value = '';
|
||||
}
|
||||
});
|
||||
|
||||
/** 将 Candidate 摘要投影为业务用户可编辑的 PO、SKU、Qty、Reservation 与 Hub 字段。 */
|
||||
function startEdit(candidateNo: string): void {
|
||||
const candidate = candidates.value.find((item) => item.candidateNo === candidateNo);
|
||||
if (!candidate) return;
|
||||
const sourceLines = Array.isArray(candidate.businessSummary.lines)
|
||||
? candidate.businessSummary.lines.filter((item): item is Record<string, unknown> => !!item && typeof item === 'object')
|
||||
: [];
|
||||
editingCandidateNo.value = candidateNo;
|
||||
editPoNumber.value = String(candidate.businessSummary.po_number || candidate.poNumber || '');
|
||||
editLines.splice(0, editLines.length, ...sourceLines.map((line) => ({
|
||||
source: { ...line },
|
||||
sku: String(line.sku || ''),
|
||||
qty: String(line.qty ?? ''),
|
||||
reservation_id: String(line.reservation_id || ''),
|
||||
hub_code: String(line.hub_code || ''),
|
||||
uom: String(line.uom || 'EA'),
|
||||
})));
|
||||
if (!editLines.length) addLine();
|
||||
editError.value = '';
|
||||
}
|
||||
|
||||
/** 新增一条待修订订单行。 */
|
||||
function addLine(): void {
|
||||
editLines.push({ source: {}, sku: '', qty: '', reservation_id: '', hub_code: '', uom: 'EA' });
|
||||
}
|
||||
|
||||
/** 校验所有订单行后提交,不允许空 SKU、非正数数量或空行静默通过。 */
|
||||
function saveEdit(): void {
|
||||
const candidate = candidates.value.find((item) => item.candidateNo === editingCandidateNo.value);
|
||||
if (!candidate || !editLines.length) return;
|
||||
const normalizedLines = editLines.map((line) => ({
|
||||
...line.source,
|
||||
sku: line.sku.trim(),
|
||||
qty: Number(line.qty),
|
||||
reservation_id: line.reservation_id.trim() || undefined,
|
||||
hub_code: line.hub_code.trim() || undefined,
|
||||
uom: line.uom.trim() || 'EA',
|
||||
}));
|
||||
if (normalizedLines.some((line) => !line.sku || !Number.isFinite(line.qty) || line.qty <= 0)) {
|
||||
editError.value = t('chat.shippingCandidateInvalidLine');
|
||||
return;
|
||||
}
|
||||
submittingCandidateNo.value = candidate.candidateNo;
|
||||
emit('update', candidate.candidateNo, {
|
||||
...candidate.businessSummary,
|
||||
po_number: editPoNumber.value.trim() || null,
|
||||
lines: normalizedLines,
|
||||
}, (success) => {
|
||||
submittingCandidateNo.value = '';
|
||||
if (success) {
|
||||
editingCandidateNo.value = '';
|
||||
editError.value = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 对当前首个重复目标应用决策;强制新建时要求填写原因。 */
|
||||
function resolveDuplicate(candidateNo: string, action: ShippingDuplicateAction): void {
|
||||
const candidate = candidates.value.find((item) => item.candidateNo === candidateNo);
|
||||
const target = candidate?.duplicate?.matches?.[0]?.taskNo;
|
||||
if (action === 'force_create') {
|
||||
forceReasonCandidateNo.value = candidateNo;
|
||||
forceReason.value = '';
|
||||
return;
|
||||
}
|
||||
submittingCandidateNo.value = candidateNo;
|
||||
emit('resolveDuplicate', candidateNo, action, target, undefined, () => {
|
||||
submittingCandidateNo.value = '';
|
||||
});
|
||||
}
|
||||
|
||||
/** 提交内联强制新建原因,避免浏览器 prompt 丢失上下文或不可访问。 */
|
||||
function submitForceCreate(candidateNo: string): void {
|
||||
const candidate = candidates.value.find((item) => item.candidateNo === candidateNo);
|
||||
const reason = forceReason.value.trim();
|
||||
if (!candidate || !reason) return;
|
||||
submittingCandidateNo.value = candidateNo;
|
||||
emit(
|
||||
'resolveDuplicate',
|
||||
candidateNo,
|
||||
'force_create',
|
||||
candidate.duplicate?.matches?.[0]?.taskNo,
|
||||
reason,
|
||||
(success) => {
|
||||
submittingCandidateNo.value = '';
|
||||
if (success) forceReasonCandidateNo.value = '';
|
||||
},
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="candidates.length" class="w-full space-y-2 rounded-xl border border-default bg-surface px-3 py-2">
|
||||
<div class="flex items-center justify-between text-xs">
|
||||
<span class="font-semibold text-primary">{{ t('chat.shippingCandidateTitle') }}</span>
|
||||
<span class="text-muted">{{ t('chat.shippingCandidateCount', { count: candidates.length }) }}</span>
|
||||
</div>
|
||||
<div v-for="candidate in candidates" :key="candidate.candidateNo" class="rounded-lg border border-default bg-surface-soft p-2 text-xs">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="candidate.selected"
|
||||
:disabled="!!candidate.consumedTaskId"
|
||||
@change="emit('select', candidate.candidateNo, ($event.target as HTMLInputElement).checked)"
|
||||
/>
|
||||
<span class="font-mono text-primary">{{ candidate.candidateNo }}</span>
|
||||
<span class="font-medium text-secondary">PO {{ candidate.poNumber || '-' }}</span>
|
||||
<span v-if="candidate.documentFilename" class="max-w-40 truncate text-muted">{{ candidate.documentFilename }}</span>
|
||||
<span :class="candidate.validationStatus === 'ready' ? 'text-emerald-700' : 'text-amber-700'">
|
||||
{{ candidate.validationStatus === 'ready' ? t('chat.shippingCandidateReady') : t('chat.shippingCandidateNeedsReview') }}
|
||||
</span>
|
||||
<button type="button" class="ml-auto text-brand-700 hover:underline" @click="startEdit(candidate.candidateNo)">
|
||||
{{ t('chat.shippingCandidateEdit') }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="candidate.conflicts.length" class="mt-1 text-amber-700">
|
||||
{{ t('chat.shippingCandidateConflictCount', { count: candidate.conflicts.length }) }}
|
||||
</div>
|
||||
<div v-if="candidate.duplicate?.blocking && !candidate.duplicateResolution" class="mt-2 flex flex-wrap items-center gap-2 text-amber-700">
|
||||
<span>{{ t('chat.shippingCandidateDuplicate', { task: candidate.duplicate.matches[0]?.taskNo || '-' }) }}</span>
|
||||
<button
|
||||
v-if="candidate.duplicate.allowedActions.includes('open_existing')"
|
||||
type="button"
|
||||
class="rounded border border-default bg-surface px-2 py-0.5"
|
||||
@click="resolveDuplicate(candidate.candidateNo, 'open_existing')"
|
||||
>{{ t('chat.shippingNoticeDuplicateOpenExisting') }}</button>
|
||||
<button
|
||||
v-if="candidate.duplicate.allowedActions.includes('create_revision')"
|
||||
type="button"
|
||||
class="rounded border border-default bg-surface px-2 py-0.5"
|
||||
@click="resolveDuplicate(candidate.candidateNo, 'create_revision')"
|
||||
>{{ t('chat.shippingNoticeDuplicateCreateRevision') }}</button>
|
||||
<button
|
||||
v-if="canForceCreate && candidate.duplicate.allowedActions.includes('force_create')"
|
||||
type="button"
|
||||
class="rounded border border-amber-300 bg-surface px-2 py-0.5"
|
||||
@click="resolveDuplicate(candidate.candidateNo, 'force_create')"
|
||||
>{{ t('chat.shippingNoticeDuplicateForceCreate') }}</button>
|
||||
</div>
|
||||
<div v-if="forceReasonCandidateNo === candidate.candidateNo" class="mt-2 flex gap-2">
|
||||
<input v-model="forceReason" :placeholder="t('chat.shippingCandidateForceReasonPrompt')" class="min-w-0 flex-1 rounded border border-default bg-surface px-2 py-1" />
|
||||
<button type="button" class="rounded bg-amber-600 px-2 py-1 text-white disabled:opacity-50" :disabled="!forceReason.trim() || submittingCandidateNo === candidate.candidateNo" @click="submitForceCreate(candidate.candidateNo)">{{ t('chat.shippingNoticeDuplicateConfirm') }}</button>
|
||||
<button type="button" class="text-muted" @click="forceReasonCandidateNo = ''">{{ t('common.cancel') }}</button>
|
||||
</div>
|
||||
<div v-else-if="candidate.duplicateResolution" class="mt-1 text-muted">
|
||||
{{ t('chat.shippingCandidateDuplicateResolved', { action: candidate.duplicateResolution.action }) }}
|
||||
</div>
|
||||
<div v-if="editingCandidateNo === candidate.candidateNo" class="mt-2 space-y-2">
|
||||
<label class="block">
|
||||
<span class="text-muted">{{ t('chat.shippingCandidatePoNumber') }}</span>
|
||||
<input v-model="editPoNumber" class="mt-1 w-full rounded border border-default bg-surface px-2 py-1 text-primary" />
|
||||
</label>
|
||||
<div v-for="(line, index) in editLines" :key="index" class="grid grid-cols-2 gap-2 rounded border border-default bg-surface p-2 md:grid-cols-5">
|
||||
<input v-model="line.sku" :placeholder="t('chat.shippingCandidateSku')" class="rounded border border-default px-2 py-1" />
|
||||
<input v-model="line.qty" type="number" min="0.0001" step="any" :placeholder="t('chat.shippingCandidateQty')" class="rounded border border-default px-2 py-1" />
|
||||
<input v-model="line.reservation_id" :placeholder="t('chat.shippingCandidateReservation')" class="rounded border border-default px-2 py-1" />
|
||||
<input v-model="line.hub_code" :placeholder="t('chat.shippingCandidateHubCode')" class="rounded border border-default px-2 py-1" />
|
||||
<div class="flex gap-1">
|
||||
<input v-model="line.uom" :placeholder="t('chat.shippingCandidateUom')" class="min-w-0 flex-1 rounded border border-default px-2 py-1" />
|
||||
<button v-if="editLines.length > 1" type="button" class="text-red-600" @click="editLines.splice(index, 1)">×</button>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="text-brand-700 hover:underline" @click="addLine">{{ t('chat.shippingCandidateAddLine') }}</button>
|
||||
<div v-if="editError" class="text-red-600">{{ editError }}</div>
|
||||
<div class="flex justify-end gap-2">
|
||||
<button type="button" class="rounded px-2 py-1 text-secondary" @click="editingCandidateNo = ''">{{ t('common.cancel') }}</button>
|
||||
<button type="button" class="rounded bg-brand-600 px-2 py-1 text-white disabled:opacity-50" :disabled="submittingCandidateNo === candidate.candidateNo" @click="saveEdit">{{ t('chat.shippingCandidateSave') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -433,7 +433,7 @@ export function useChat() {
|
||||
| { type: 'image' | 'document' | 'audio' | 'video' | 'custom'; transfer_method: 'local_file'; upload_file_id: string }
|
||||
| { type: 'image' | 'document' | 'audio' | 'video' | 'custom'; transfer_method: 'remote_url'; url: string }
|
||||
>,
|
||||
context?: { task_id?: string; batch_no?: string; display_query?: string },
|
||||
context?: { task_id?: string; batch_no?: string; shipping_intake_nos?: string[]; display_query?: string },
|
||||
hooks?: SendMessageLifecycleHooks,
|
||||
) => {
|
||||
const displayQuery = String(context?.display_query || query || '').trim();
|
||||
@@ -495,6 +495,7 @@ export function useChat() {
|
||||
files: files && files.length > 0 ? files : undefined,
|
||||
task_id: context?.task_id || undefined,
|
||||
batch_no: context?.batch_no || undefined,
|
||||
shipping_intake_nos: context?.shipping_intake_nos?.length ? context.shipping_intake_nos : undefined,
|
||||
display_query: context?.display_query || undefined,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -551,6 +551,9 @@ export function useChatPage() {
|
||||
attachmentApi.removeAttachment(id);
|
||||
},
|
||||
retryShippingNoticeAttachment: shipping.retryShippingNoticeAttachment,
|
||||
setShippingCandidateSelected: shipping.setShippingCandidateSelected,
|
||||
updateShippingCandidateSummary: shipping.updateShippingCandidateSummary,
|
||||
resolveShippingCandidateDuplicate: shipping.resolveShippingCandidateDuplicate,
|
||||
showShippingDuplicateDialog: shipping.showShippingDuplicateDialog,
|
||||
shippingDuplicateAttachment: shipping.shippingDuplicateAttachment,
|
||||
canForceCreateShippingDuplicate: shipping.canForceCreateShippingDuplicate,
|
||||
|
||||
@@ -93,7 +93,7 @@ export interface UseChatShippingOptions {
|
||||
agentId: number,
|
||||
kb: string,
|
||||
files: ChatUploadFileSpec[],
|
||||
context?: { task_id?: string; batch_no?: string; display_query?: string },
|
||||
context?: { task_id?: string; batch_no?: string; shipping_intake_nos?: string[]; display_query?: string },
|
||||
hooks?: { onAssistantMessageFinished?: (message: ChatMessage, runMessages: ChatMessage[]) => void | Promise<void> },
|
||||
) => Promise<void>;
|
||||
startChatTurn: (options: import('../types/chat-turn.types').StartChatTurnOptions) => Promise<boolean>;
|
||||
@@ -429,6 +429,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const getCurrentShippingChatContext = () => ({
|
||||
task_id: getActiveBatchTaskId() || getActiveShippingTaskId(),
|
||||
batch_no: getActiveShippingBatchNo(),
|
||||
shipping_intake_nos: shippingIntakes.getParsedIntakeNos(),
|
||||
});
|
||||
|
||||
const getCurrentShippingChatContextWithDisplay = (displayQuery: string) => ({
|
||||
@@ -561,6 +562,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
*/
|
||||
const finalizeShippingAssistantMessage = async () => {
|
||||
if (!isShippingNoticeAgent.value) return;
|
||||
await shippingIntakes.refreshStatuses();
|
||||
shippingIntakes.clearConsumedAttachments();
|
||||
await refreshShippingActions();
|
||||
};
|
||||
|
||||
@@ -730,6 +733,49 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
shippingDuplicateAttachmentId.value = null;
|
||||
};
|
||||
|
||||
/** 更新 Candidate 选择状态,并将 API 失败统一反馈给用户。 */
|
||||
const setShippingCandidateSelected = async (candidateNo: string, selected: boolean) => {
|
||||
try {
|
||||
await shippingIntakes.setCandidateSelected(candidateNo, selected);
|
||||
} catch (error: unknown) {
|
||||
msg.warning(error instanceof Error ? error.message : t('chat.shippingCandidateUpdateFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
/** 保存 Candidate 结构化修订,并保留服务端校验错误。 */
|
||||
const updateShippingCandidateSummary = async (
|
||||
candidateNo: string,
|
||||
businessSummary: Record<string, unknown>,
|
||||
done?: (success: boolean) => void,
|
||||
) => {
|
||||
try {
|
||||
await shippingIntakes.updateCandidateSummary(candidateNo, businessSummary);
|
||||
msg.success(t('chat.shippingCandidateUpdateDone'));
|
||||
done?.(true);
|
||||
} catch (error: unknown) {
|
||||
msg.warning(error instanceof Error ? error.message : t('chat.shippingCandidateUpdateFailed'));
|
||||
done?.(false);
|
||||
}
|
||||
};
|
||||
|
||||
/** 保存 Candidate 重复决策,并统一展示权限或目标漂移错误。 */
|
||||
const resolveShippingCandidateDuplicate = async (
|
||||
candidateNo: string,
|
||||
action: import('../types/shipping.types').ShippingDuplicateAction,
|
||||
targetTaskNo?: string,
|
||||
reason?: string,
|
||||
done?: (success: boolean) => void,
|
||||
) => {
|
||||
try {
|
||||
await shippingIntakes.resolveCandidateDuplicate(candidateNo, action, targetTaskNo, reason);
|
||||
msg.success(t('chat.shippingNoticeDuplicateResolved'));
|
||||
done?.(true);
|
||||
} catch (error: unknown) {
|
||||
msg.warning(error instanceof Error ? error.message : t('chat.shippingNoticeDuplicateResolveFailed'));
|
||||
done?.(false);
|
||||
}
|
||||
};
|
||||
|
||||
const {
|
||||
handleShippingAutoUploadFile,
|
||||
handleShippingAutoUploadNoticeBatch,
|
||||
@@ -763,6 +809,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
startChatTurn,
|
||||
refreshShippingActions,
|
||||
getParsedIntakeNos: shippingIntakes.getParsedIntakeNos,
|
||||
getSelectedCandidateNos: shippingIntakes.getSelectedCandidateNos,
|
||||
clearConsumedNoticeAttachments: shippingIntakes.clearConsumedAttachments,
|
||||
msg,
|
||||
t,
|
||||
@@ -819,8 +866,12 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
hasBlockingNoticeIntake: () => shippingIntakes.hasBlockingUploadOrParse.value,
|
||||
hasNoticeIntakeFailures: () => shippingIntakes.hasParseFailures.value,
|
||||
hasBlockingNoticeDuplicates: () => shippingIntakes.hasBlockingDuplicates.value,
|
||||
hasCandidateReviewIssues: () => shippingIntakes.hasCandidateReviewIssues.value,
|
||||
hasSelectedNoticeCandidates: () => shippingIntakes.getSelectedCandidateNos().length > 0,
|
||||
openShippingDuplicateDialog,
|
||||
getParsedIntakeNos: shippingIntakes.getParsedIntakeNos,
|
||||
refreshNoticeIntakeStatuses: shippingIntakes.refreshStatuses,
|
||||
clearConsumedNoticeAttachments: shippingIntakes.clearConsumedAttachments,
|
||||
refreshShippingActions,
|
||||
shippingSuggestedPrompt,
|
||||
isShippingShortageQueryIntent,
|
||||
@@ -1132,6 +1183,10 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
handleShippingLocalFilesSelected,
|
||||
removeShippingNoticeAttachment: shippingIntakes.removeNoticeAttachment,
|
||||
retryShippingNoticeAttachment: shippingIntakes.retryNoticeAttachment,
|
||||
shippingNoticeAllReadyForConfirmation: shippingIntakes.allReadyForConfirmation,
|
||||
setShippingCandidateSelected,
|
||||
updateShippingCandidateSummary,
|
||||
resolveShippingCandidateDuplicate,
|
||||
showShippingDuplicateDialog,
|
||||
shippingDuplicateAttachment,
|
||||
canForceCreateShippingDuplicate,
|
||||
|
||||
@@ -48,7 +48,7 @@ export interface ChatPageSendContext {
|
||||
agentId: number,
|
||||
kb: string,
|
||||
files: ChatUploadFileSpec[],
|
||||
context?: { task_id?: string; batch_no?: string; display_query?: string },
|
||||
context?: { task_id?: string; batch_no?: string; shipping_intake_nos?: string[]; display_query?: string },
|
||||
hooks?: { onAssistantMessageFinished?: (message: ChatMessage, runMessages: ChatMessage[]) => void | Promise<void> },
|
||||
) => Promise<void>;
|
||||
refreshHistoryAfterSend: () => Promise<void>;
|
||||
@@ -69,7 +69,7 @@ export interface ChatPageSendContext {
|
||||
msg: { warning: (text: string) => void; info: (text: string) => void };
|
||||
t: (key: string) => string;
|
||||
copiedIndex: Ref<number | null>;
|
||||
getChatContext?: () => { task_id?: string; batch_no?: string; display_query?: string };
|
||||
getChatContext?: () => { task_id?: string; batch_no?: string; shipping_intake_nos?: string[]; display_query?: string };
|
||||
onAssistantMessageFinished?: (message: ChatMessage, runMessages: ChatMessage[]) => void | Promise<void>;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 用途:验证建批 Chat Turn payload 包含幂等键与会话映射。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildShippingCreateBatchTurn } from './shippingTurnActions';
|
||||
import { buildShippingCreateBatchFromIntakesTurn, buildShippingCreateBatchTurn } from './shippingTurnActions';
|
||||
|
||||
describe('shippingTurnActions', () => {
|
||||
it('buildShippingCreateBatchTurn includes idempotency_key in payload', () => {
|
||||
@@ -19,4 +19,17 @@ describe('shippingTurnActions', () => {
|
||||
expect(turn.payload.idempotency_key).toBe('idem-key-001');
|
||||
expect(turn.files).toEqual(files);
|
||||
});
|
||||
|
||||
it('buildShippingCreateBatchFromIntakesTurn includes selected candidate_nos', () => {
|
||||
const turn = buildShippingCreateBatchFromIntakesTurn(
|
||||
['SNI-001'],
|
||||
'conv-001',
|
||||
'idem-candidate-001',
|
||||
['SNC-001', 'SNC-003'],
|
||||
);
|
||||
|
||||
expect(turn.actionType).toBe('shipping.create_batch_from_intakes');
|
||||
expect(turn.payload.intake_nos).toEqual(['SNI-001']);
|
||||
expect(turn.payload.candidate_nos).toEqual(['SNC-001', 'SNC-003']);
|
||||
});
|
||||
});
|
||||
@@ -103,6 +103,7 @@ export function buildShippingCreateBatchFromIntakesTurn(
|
||||
intakeNos: string[],
|
||||
conversationId?: string | null,
|
||||
idempotencyKey?: string,
|
||||
candidateNos?: string[],
|
||||
): { actionType: string; displayText: string; payload: Record<string, unknown> } {
|
||||
const count = intakeNos.length;
|
||||
const displayText = count === 1
|
||||
@@ -115,6 +116,7 @@ export function buildShippingCreateBatchFromIntakesTurn(
|
||||
intake_nos: intakeNos,
|
||||
conversation_id: conversationId || undefined,
|
||||
idempotency_key: idempotencyKey,
|
||||
candidate_nos: candidateNos,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* features/chat/shipping/useChatShippingSendHandler.spec.ts
|
||||
* 用途:验证建批提交中发送拦截不会回退到普通聊天发送。
|
||||
* 用途:验证上传预处理与点击发送完整抽取链路,以及建批提交中的并发拦截。
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
@@ -71,4 +71,80 @@ describe('useChatShippingSendHandler', () => {
|
||||
expect(ctx.handleShippingAutoUploadNoticeBatch).not.toHaveBeenCalled();
|
||||
expect(ctx.msg.info).toHaveBeenCalledWith('chat.shippingNoticeBatchSubmitting');
|
||||
});
|
||||
|
||||
it('sends parsed intakes to the existing Chatflow without requiring upload-time candidates', async () => {
|
||||
const attachment = {
|
||||
id: 'notice-1',
|
||||
kind: 'shipping_notice' as const,
|
||||
type: 'document' as const,
|
||||
uploadStatus: 'uploaded' as const,
|
||||
parseStatus: 'parsed' as const,
|
||||
uploadProgress: 100,
|
||||
originalFilename: 'orders.eml',
|
||||
fileSize: 100,
|
||||
intakeNo: 'SNI-1',
|
||||
};
|
||||
const ctx = createContext({
|
||||
attachments: ref([attachment]),
|
||||
hasCandidateReviewIssues: () => true,
|
||||
hasSelectedNoticeCandidates: () => true,
|
||||
getParsedIntakeNos: () => ['SNI-1'],
|
||||
refreshNoticeIntakeStatuses: vi.fn(async () => undefined),
|
||||
clearConsumedNoticeAttachments: vi.fn(),
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
const consumed = await tryHandleShippingAttachmentAutoFlow(undefined, '', '');
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(ctx.handleShippingAutoUploadNoticeBatch).not.toHaveBeenCalled();
|
||||
expect(ctx.sendMessage).toHaveBeenCalledWith(
|
||||
'chat.shippingOrderExtractionDefaultPrompt',
|
||||
1,
|
||||
'',
|
||||
[],
|
||||
{
|
||||
shipping_intake_nos: ['SNI-1'],
|
||||
display_query: 'chat.shippingOrderExtractionDefaultPrompt',
|
||||
},
|
||||
expect.objectContaining({ onAssistantMessageFinished: expect.any(Function) }),
|
||||
);
|
||||
});
|
||||
|
||||
it('uses the user query for full extraction even when no candidate exists before send', async () => {
|
||||
const attachment = {
|
||||
id: 'notice-1',
|
||||
kind: 'shipping_notice' as const,
|
||||
type: 'document' as const,
|
||||
uploadStatus: 'uploaded' as const,
|
||||
parseStatus: 'parsed' as const,
|
||||
uploadProgress: 100,
|
||||
originalFilename: 'orders.eml',
|
||||
fileSize: 100,
|
||||
intakeNo: 'SNI-1',
|
||||
};
|
||||
const ctx = createContext({
|
||||
attachments: ref([attachment]),
|
||||
hasCandidateReviewIssues: () => false,
|
||||
hasSelectedNoticeCandidates: () => false,
|
||||
getParsedIntakeNos: () => ['SNI-1'],
|
||||
});
|
||||
const { tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers(ctx);
|
||||
|
||||
const consumed = await tryHandleShippingAttachmentAutoFlow(undefined, '请解析这些附件', '请解析这些附件');
|
||||
|
||||
expect(consumed).toBe(true);
|
||||
expect(ctx.handleShippingAutoUploadNoticeBatch).not.toHaveBeenCalled();
|
||||
expect(ctx.sendMessage).toHaveBeenCalledWith(
|
||||
'请解析这些附件',
|
||||
1,
|
||||
'',
|
||||
[],
|
||||
{
|
||||
shipping_intake_nos: ['SNI-1'],
|
||||
display_query: '请解析这些附件',
|
||||
},
|
||||
expect.objectContaining({ onAssistantMessageFinished: expect.any(Function) }),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* features/chat/shipping/useChatShippingSendHandler.ts
|
||||
* 用途:在聊天发送前拦截发货通知专属意图,如切票、决策文本、列映射和附件自动流程。
|
||||
* 用途:在聊天发送前拦截发货通知专属意图,如订单抽取、切票、决策文本、列映射和附件自动流程。
|
||||
* 依赖:shipping.api、shippingIntents、shippingMenu、shippingMapping、shippingDownload、chat.types。
|
||||
* 逻辑:业务动作经 Chat Turn / handleShippingMenuAction;纯 UI(下载/选文件/映射卡片)保留本地或客户端行为。
|
||||
* 逻辑:已预处理 Intake 通过普通聊天接口进入现有 Dify Chatflow;其他业务动作经 Chat Turn / handleShippingMenuAction。
|
||||
*/
|
||||
import {
|
||||
getWorkspaceShippingBatch,
|
||||
@@ -50,6 +50,8 @@ export interface ShippingSendHandlerContext {
|
||||
agentId: number,
|
||||
kb: string,
|
||||
files: ChatUploadFileSpec[],
|
||||
context?: { task_id?: string; batch_no?: string; shipping_intake_nos?: string[]; display_query?: string },
|
||||
hooks?: { onAssistantMessageFinished?: (message: ChatMessage, runMessages: ChatMessage[]) => void | Promise<void> },
|
||||
) => Promise<void>;
|
||||
buildFileSpecsForSend: () => Promise<ChatUploadFileSpec[]>;
|
||||
loadHistory: () => Promise<void>;
|
||||
@@ -65,8 +67,12 @@ export interface ShippingSendHandlerContext {
|
||||
hasBlockingNoticeIntake?: () => boolean;
|
||||
hasNoticeIntakeFailures?: () => boolean;
|
||||
hasBlockingNoticeDuplicates?: () => boolean;
|
||||
hasCandidateReviewIssues?: () => boolean;
|
||||
hasSelectedNoticeCandidates?: () => boolean;
|
||||
openShippingDuplicateDialog?: (attachmentId?: string) => void;
|
||||
getParsedIntakeNos?: () => string[];
|
||||
refreshNoticeIntakeStatuses?: () => Promise<void>;
|
||||
clearConsumedNoticeAttachments?: () => void;
|
||||
refreshShippingActions: () => Promise<void>;
|
||||
shippingSuggestedPrompt: ComputedRef<string>;
|
||||
isShippingShortageQueryIntent: (text: string) => boolean;
|
||||
@@ -78,7 +84,7 @@ export interface ShippingSendHandlerContext {
|
||||
/**
|
||||
* 创建发货通知发送拦截器。
|
||||
*
|
||||
* 核心逻辑:识别切换任务、数字菜单、决策文本、映射文本、上传/导出意图,并在命中时直接走本地前后端流程。
|
||||
* 核心逻辑:已预处理邮件固定 Intake 上下文后调用普通聊天;其余识别切换任务、数字菜单、决策文本、映射文本、上传/导出意图。
|
||||
* @param ctx - 发送拦截上下文
|
||||
* @returns 发送前文本与附件自动流程处理函数;返回 true 表示已消费本次发送
|
||||
*/
|
||||
@@ -203,17 +209,30 @@ export function createShippingSendHandlers(ctx: ShippingSendHandlerContext) {
|
||||
ctx.msg.warning(ctx.t('chat.shippingNoticeParseFailedHint'));
|
||||
return true;
|
||||
}
|
||||
if (ctx.hasBlockingNoticeDuplicates?.()) {
|
||||
ctx.openShippingDuplicateDialog?.();
|
||||
ctx.msg.warning(ctx.t('chat.shippingNoticeDuplicateNeedsResolution'));
|
||||
return true;
|
||||
}
|
||||
const intakeNos = ctx.getParsedIntakeNos?.() || [];
|
||||
if (intakeNos.length && (!trimmed || ctx.shippingAutoFlowRequested.value)) {
|
||||
if (intakeNos.length) {
|
||||
const query = trimmed || ctx.t('chat.shippingOrderExtractionDefaultPrompt');
|
||||
ctx.shippingAutoFlowRequested.value = false;
|
||||
if (typeof textOrEvent !== 'string') ctx.input.value = '';
|
||||
try {
|
||||
await ctx.handleShippingAutoUploadNoticeBatch([]);
|
||||
await ctx.sendMessage(
|
||||
query,
|
||||
ctx.currentAgentId.value,
|
||||
ctx.selectedKb.value,
|
||||
[],
|
||||
{
|
||||
shipping_intake_nos: intakeNos,
|
||||
display_query: query,
|
||||
},
|
||||
{
|
||||
onAssistantMessageFinished: async () => {
|
||||
await ctx.refreshNoticeIntakeStatuses?.();
|
||||
ctx.clearConsumedNoticeAttachments?.();
|
||||
await ctx.refreshShippingActions();
|
||||
},
|
||||
},
|
||||
);
|
||||
await ctx.loadHistory();
|
||||
} catch (e: unknown) {
|
||||
const errorMessage = e instanceof Error ? e.message : '文件处理失败';
|
||||
ctx.msg.warning(errorMessage);
|
||||
|
||||
@@ -120,6 +120,7 @@ export interface ShippingUploadHandlerContext {
|
||||
msg: { warning: (text: string) => void };
|
||||
t: (key: string, params?: Record<string, unknown>) => string;
|
||||
getParsedIntakeNos?: () => string[];
|
||||
getSelectedCandidateNos?: () => string[];
|
||||
clearConsumedNoticeAttachments?: () => void;
|
||||
}
|
||||
|
||||
@@ -310,14 +311,14 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
return ok;
|
||||
};
|
||||
|
||||
const runNoticeBatchFromIntakes = async (intakeNos: string[]) => {
|
||||
const runNoticeBatchFromIntakes = async (intakeNos: string[], candidateNos: string[]) => {
|
||||
if (noticeBatchSubmitting) {
|
||||
return true;
|
||||
}
|
||||
noticeBatchSubmitting = true;
|
||||
try {
|
||||
const conversationKey = normalizeConversationId(ctx.conversationId.value);
|
||||
const intakeFingerprint = computeNoticeIntakeNosFingerprint(intakeNos);
|
||||
const intakeFingerprint = computeNoticeIntakeNosFingerprint([...intakeNos, ...candidateNos]);
|
||||
if (pendingNoticeBatchRetry) {
|
||||
reconcilePendingNoticeBatchConversation(pendingNoticeBatchRetry, conversationKey);
|
||||
}
|
||||
@@ -337,7 +338,12 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
pendingNoticeBatchRetry.fileFingerprint = intakeFingerprint;
|
||||
}
|
||||
const idempotencyKey = pendingNoticeBatchRetry.idempotencyKey;
|
||||
const turn = buildShippingCreateBatchFromIntakesTurn(intakeNos, ctx.conversationId.value, idempotencyKey);
|
||||
const turn = buildShippingCreateBatchFromIntakesTurn(
|
||||
intakeNos,
|
||||
ctx.conversationId.value,
|
||||
idempotencyKey,
|
||||
candidateNos,
|
||||
);
|
||||
const ok = await ctx.startChatTurn({
|
||||
agentId: ctx.currentAgentId.value,
|
||||
inputType: 'upload_followup',
|
||||
@@ -402,8 +408,9 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
const handleShippingAutoUploadNoticeBatch = async (files: File[]) => {
|
||||
const noticeFiles = files.filter(Boolean);
|
||||
const intakeNos = ctx.getParsedIntakeNos?.() || [];
|
||||
const candidateNos = ctx.getSelectedCandidateNos?.() || [];
|
||||
if (!noticeFiles.length && intakeNos.length) {
|
||||
await runNoticeBatchFromIntakes(intakeNos);
|
||||
await runNoticeBatchFromIntakes(intakeNos, candidateNos);
|
||||
return;
|
||||
}
|
||||
if (!noticeFiles.length) return;
|
||||
|
||||
@@ -13,15 +13,18 @@ import type {
|
||||
ShippingDuplicateResult,
|
||||
ShippingNoticeParseSummary,
|
||||
ShippingNoticePendingAttachment,
|
||||
ShippingNoticeCandidate,
|
||||
} from '../types/shipping.types';
|
||||
import type { ShippingNoticeIntakeResponse } from '../types/shipping.api.types';
|
||||
import type { ShippingNoticeCandidateResponse, ShippingNoticeIntakeResponse } from '../types/shipping.api.types';
|
||||
import {
|
||||
cancelShippingNoticeIntake,
|
||||
createShippingNoticeIntake,
|
||||
getShippingNoticeIntakeStatuses,
|
||||
listActiveShippingNoticeIntakes,
|
||||
resolveShippingNoticeDuplicate,
|
||||
resolveShippingNoticeCandidateDuplicate,
|
||||
retryShippingNoticeIntake,
|
||||
updateShippingNoticeCandidate,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import { isShippingNoticeAttachmentParseIncomplete } from './shippingNoticeAttachmentIntegrity';
|
||||
|
||||
@@ -82,6 +85,44 @@ function listSafe(value: unknown): string[] {
|
||||
return Array.isArray(value) ? value.map((item) => String(item)) : [];
|
||||
}
|
||||
|
||||
/** 将 Candidate API 契约映射为输入区可审核状态。 */
|
||||
function mapServerCandidate(remote: ShippingNoticeCandidateResponse): ShippingNoticeCandidate {
|
||||
const duplicate = remote.duplicate
|
||||
? {
|
||||
status: remote.duplicate.status,
|
||||
blocking: Boolean(remote.duplicate.blocking),
|
||||
fingerprintStrength: remote.duplicate.fingerprint_strength,
|
||||
matches: (remote.duplicate.matches || []).map((item) => ({
|
||||
taskNo: item.task_no,
|
||||
processStatus: item.process_status,
|
||||
documentVersion: Number(item.document_version || 1),
|
||||
matchType: item.match_type,
|
||||
matchedFields: listSafe(item.matched_fields),
|
||||
createdAt: item.created_at,
|
||||
})),
|
||||
allowedActions: (remote.duplicate.allowed_actions || []) as ShippingDuplicateAction[],
|
||||
}
|
||||
: undefined;
|
||||
return {
|
||||
candidateNo: remote.candidate_no,
|
||||
poNumber: remote.po_number || undefined,
|
||||
documentFilename: remote.primary_document_filename || undefined,
|
||||
validationStatus: remote.validation_status,
|
||||
selected: Boolean(remote.selected),
|
||||
conflicts: remote.conflicts || [],
|
||||
businessSummary: remote.business_summary || {},
|
||||
duplicate,
|
||||
duplicateResolution: remote.duplicate_resolution
|
||||
? {
|
||||
action: remote.duplicate_resolution.action,
|
||||
targetTaskNo: remote.duplicate_resolution.target_task_no || undefined,
|
||||
reason: remote.duplicate_resolution.reason || undefined,
|
||||
}
|
||||
: undefined,
|
||||
consumedTaskId: remote.consumed_task_id || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function createPendingAttachment(file: File): ShippingNoticePendingAttachment {
|
||||
return {
|
||||
id: `${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
||||
@@ -142,12 +183,28 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
|
||||
const hasBlockingDuplicates = computed(() =>
|
||||
noticeAttachments.value.some(
|
||||
(item) => item.duplicate?.blocking && !item.duplicateResolution?.action,
|
||||
(item) => (item.candidates?.length
|
||||
? item.candidates.some((candidate) =>
|
||||
candidate.selected && candidate.duplicate?.blocking && !candidate.duplicateResolution?.action,
|
||||
)
|
||||
: item.duplicate?.blocking && !item.duplicateResolution?.action),
|
||||
),
|
||||
);
|
||||
|
||||
const hasCandidateReviewIssues = computed(() =>
|
||||
noticeAttachments.value.some((item) =>
|
||||
(item.candidates || []).some((candidate) =>
|
||||
candidate.selected && candidate.validationStatus !== 'ready',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const allReadyForConfirmation = computed(() =>
|
||||
allParsedReady.value && !hasBlockingDuplicates.value && !hasParseFailures.value,
|
||||
allParsedReady.value
|
||||
&& !hasBlockingDuplicates.value
|
||||
&& !hasCandidateReviewIssues.value
|
||||
&& !hasParseFailures.value
|
||||
&& noticeAttachments.value.some((item) => (item.candidates || []).some((candidate) => candidate.selected)),
|
||||
);
|
||||
|
||||
const stopPolling = () => {
|
||||
@@ -198,12 +255,15 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
if (!local) continue;
|
||||
patchAttachment(local.id, {
|
||||
parseStatus: mapServerParseStatus(remote.parse_status),
|
||||
orderExtractionStatus: remote.order_extraction_status || undefined,
|
||||
orderExtractionVersion: remote.order_extraction_version || undefined,
|
||||
parseSummary: (remote.parse_summary || undefined) as ShippingNoticeParseSummary | undefined,
|
||||
errorCode: remote.error_code || undefined,
|
||||
errorMessage: remote.error_message || undefined,
|
||||
errorCode: remote.order_extraction_error_code || remote.error_code || undefined,
|
||||
errorMessage: remote.order_extraction_error_message || remote.error_message || undefined,
|
||||
expiresAt: remote.expires_at || undefined,
|
||||
assetNo: remote.asset_no || local.assetNo,
|
||||
...mapServerDuplicate(remote),
|
||||
candidates: (remote.candidates || []).map(mapServerCandidate),
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -226,10 +286,14 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
patchAttachment(attachment.id, {
|
||||
intakeNo: intake.intake_no,
|
||||
parseStatus: mapServerParseStatus(intake.parse_status),
|
||||
orderExtractionStatus: intake.order_extraction_status || undefined,
|
||||
orderExtractionVersion: intake.order_extraction_version || undefined,
|
||||
parseSummary: (intake.parse_summary || undefined) as ShippingNoticeParseSummary | undefined,
|
||||
errorCode: intake.error_code || undefined,
|
||||
errorMessage: intake.error_message || undefined,
|
||||
errorCode: intake.order_extraction_error_code || intake.error_code || undefined,
|
||||
errorMessage: intake.order_extraction_error_message || intake.error_message || undefined,
|
||||
expiresAt: intake.expires_at || undefined,
|
||||
...mapServerDuplicate(intake),
|
||||
candidates: (intake.candidates || []).map(mapServerCandidate),
|
||||
});
|
||||
schedulePoll();
|
||||
} catch (error) {
|
||||
@@ -294,8 +358,10 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
.map((item) => String(item.intakeNo));
|
||||
|
||||
const clearConsumedAttachments = () => {
|
||||
options.attachments.value = options.attachments.value.filter((item) => item.kind !== 'shipping_notice');
|
||||
stopPolling();
|
||||
options.attachments.value = options.attachments.value.filter(
|
||||
(item) => item.kind !== 'shipping_notice' || item.parseStatus !== 'consumed',
|
||||
);
|
||||
if (!noticeAttachments.value.length) stopPolling();
|
||||
};
|
||||
|
||||
const restoreForConversation = async (conversationId?: string | null) => {
|
||||
@@ -311,14 +377,17 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
intakeNo: item.intake_no,
|
||||
uploadStatus: 'uploaded' as const,
|
||||
parseStatus: mapServerParseStatus(item.parse_status),
|
||||
orderExtractionStatus: item.order_extraction_status || undefined,
|
||||
orderExtractionVersion: item.order_extraction_version || undefined,
|
||||
uploadProgress: 100,
|
||||
originalFilename: item.original_filename || item.intake_no,
|
||||
fileSize: Number(item.file_size || 0),
|
||||
parseSummary: (item.parse_summary || undefined) as ShippingNoticeParseSummary | undefined,
|
||||
errorCode: item.error_code || undefined,
|
||||
errorMessage: item.error_message || undefined,
|
||||
errorCode: item.order_extraction_error_code || item.error_code || undefined,
|
||||
errorMessage: item.order_extraction_error_message || item.error_message || undefined,
|
||||
expiresAt: item.expires_at || undefined,
|
||||
...mapServerDuplicate(item),
|
||||
...mapServerDuplicate(item),
|
||||
candidates: (item.candidates || []).map(mapServerCandidate),
|
||||
}));
|
||||
const nonNotice = options.attachments.value.filter((item) => item.kind !== 'shipping_notice');
|
||||
options.attachments.value = [...nonNotice, ...restored];
|
||||
@@ -347,6 +416,56 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
});
|
||||
};
|
||||
|
||||
/** 切换 Candidate 是否参与本次建批。 */
|
||||
const setCandidateSelected = async (candidateNo: string, selected: boolean) => {
|
||||
const remote = await updateShippingNoticeCandidate(candidateNo, { selected });
|
||||
for (const attachment of noticeAttachments.value) {
|
||||
if (!(attachment.candidates || []).some((item) => item.candidateNo === candidateNo)) continue;
|
||||
patchAttachment(attachment.id, {
|
||||
candidates: (attachment.candidates || []).map((item) =>
|
||||
item.candidateNo === candidateNo ? mapServerCandidate(remote) : item,
|
||||
),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/** 保存 Candidate 人工修订后的订单摘要。 */
|
||||
const updateCandidateSummary = async (candidateNo: string, businessSummary: Record<string, unknown>) => {
|
||||
const remote = await updateShippingNoticeCandidate(candidateNo, { business_summary: businessSummary });
|
||||
for (const attachment of noticeAttachments.value) {
|
||||
if (!(attachment.candidates || []).some((item) => item.candidateNo === candidateNo)) continue;
|
||||
patchAttachment(attachment.id, {
|
||||
candidates: (attachment.candidates || []).map((item) =>
|
||||
item.candidateNo === candidateNo ? mapServerCandidate(remote) : item,
|
||||
),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/** 保存单个 Candidate 的重复处理决策。 */
|
||||
const resolveCandidateDuplicate = async (
|
||||
candidateNo: string,
|
||||
action: ShippingDuplicateAction,
|
||||
targetTaskNo?: string,
|
||||
reason?: string,
|
||||
) => {
|
||||
const remote = await resolveShippingNoticeCandidateDuplicate(candidateNo, action, targetTaskNo, reason);
|
||||
for (const attachment of noticeAttachments.value) {
|
||||
if (!(attachment.candidates || []).some((item) => item.candidateNo === candidateNo)) continue;
|
||||
patchAttachment(attachment.id, {
|
||||
candidates: (attachment.candidates || []).map((item) =>
|
||||
item.candidateNo === candidateNo ? mapServerCandidate(remote) : item,
|
||||
),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const getSelectedCandidateNos = () => noticeAttachments.value.flatMap((item) =>
|
||||
(item.candidates || [])
|
||||
.filter((candidate) => candidate.selected)
|
||||
.map((candidate) => candidate.candidateNo),
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
stopPolling();
|
||||
});
|
||||
@@ -357,12 +476,18 @@ export function useShippingNoticeIntakes(options: UseShippingNoticeIntakesOption
|
||||
hasParseFailures,
|
||||
allParsedReady,
|
||||
hasBlockingDuplicates,
|
||||
hasCandidateReviewIssues,
|
||||
allReadyForConfirmation,
|
||||
enqueueNoticeFiles,
|
||||
removeNoticeAttachment,
|
||||
retryNoticeAttachment,
|
||||
resolveDuplicateAttachment,
|
||||
resolveCandidateDuplicate,
|
||||
setCandidateSelected,
|
||||
updateCandidateSummary,
|
||||
getParsedIntakeNos,
|
||||
getSelectedCandidateNos,
|
||||
refreshStatuses,
|
||||
clearConsumedAttachments,
|
||||
restoreForConversation,
|
||||
stopPolling,
|
||||
|
||||
@@ -81,6 +81,7 @@ export interface ShippingTaskSummary {
|
||||
line_results?: ShippingMatchLineResult[];
|
||||
step_payload?: Record<string, unknown> & {
|
||||
current_step_progress?: ShippingCurrentStepProgress;
|
||||
parse_validation?: ShippingParseValidation;
|
||||
};
|
||||
rpa_runtime?: ShippingRpaRuntime | null;
|
||||
rpa_inventory_source?: Record<string, unknown> | null;
|
||||
@@ -138,6 +139,25 @@ export interface ShippingCurrentStepProgress {
|
||||
extra?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface ShippingParseIssue {
|
||||
line_index?: number;
|
||||
sku?: string | null;
|
||||
field: string;
|
||||
reason: 'missing' | 'invalid_format' | 'source_conflict' | 'value_corrected' | string;
|
||||
severity: 'blocking' | 'info' | string;
|
||||
raw_value?: string | null;
|
||||
resolved_value?: string | null;
|
||||
resolution_basis?: string | null;
|
||||
evidence_values?: string[];
|
||||
}
|
||||
|
||||
export interface ShippingParseValidation {
|
||||
status: 'ready' | 'needs_review' | string;
|
||||
issues: ShippingParseIssue[];
|
||||
contract_version?: string;
|
||||
resolution_source?: string;
|
||||
}
|
||||
|
||||
export interface ShippingNoticeHeader {
|
||||
customer_name?: string | null;
|
||||
customer_code?: string | null;
|
||||
@@ -320,6 +340,10 @@ export interface ShippingNoticeIntakeResponse {
|
||||
conversation_id?: string | null;
|
||||
parse_status: string;
|
||||
parser_version?: string;
|
||||
order_extraction_status?: string | null;
|
||||
order_extraction_version?: string | null;
|
||||
order_extraction_error_code?: string | null;
|
||||
order_extraction_error_message?: string | null;
|
||||
parse_summary?: Record<string, unknown> | null;
|
||||
business_summary?: Record<string, unknown> | null;
|
||||
business_fingerprint?: string | null;
|
||||
@@ -343,6 +367,37 @@ export interface ShippingNoticeIntakeResponse {
|
||||
original_filename?: string;
|
||||
file_size?: number;
|
||||
content_hash?: string;
|
||||
documents?: ShippingNoticeDocumentResponse[];
|
||||
candidates?: ShippingNoticeCandidateResponse[];
|
||||
document_count?: number;
|
||||
candidate_count?: number;
|
||||
}
|
||||
|
||||
export interface ShippingNoticeDocumentResponse {
|
||||
id: number;
|
||||
document_type: string;
|
||||
filename?: string | null;
|
||||
classification: string;
|
||||
parse_status: string;
|
||||
warnings?: string[];
|
||||
}
|
||||
|
||||
export interface ShippingNoticeCandidateResponse {
|
||||
candidate_no: string;
|
||||
primary_document_id?: number;
|
||||
primary_document_filename?: string | null;
|
||||
po_number?: string | null;
|
||||
validation_status: string;
|
||||
selected: boolean;
|
||||
conflicts?: Array<Record<string, unknown>>;
|
||||
business_summary?: Record<string, unknown> | null;
|
||||
duplicate?: ShippingDuplicateResult | null;
|
||||
duplicate_resolution?: {
|
||||
action: ShippingDuplicateAction;
|
||||
target_task_no?: string | null;
|
||||
reason?: string | null;
|
||||
} | null;
|
||||
consumed_task_id?: number | null;
|
||||
}
|
||||
|
||||
export type ShippingDuplicateStatus =
|
||||
@@ -351,7 +406,10 @@ export type ShippingDuplicateStatus =
|
||||
| 'exact_file'
|
||||
| 'same_active_task'
|
||||
| 'same_completed_task'
|
||||
| 'possible_duplicate';
|
||||
| 'possible_duplicate'
|
||||
| 'same_business_content'
|
||||
| 'possible_revision'
|
||||
| 'partial_duplicate';
|
||||
|
||||
export type ShippingDuplicateAction = 'open_existing' | 'create_revision' | 'force_create';
|
||||
|
||||
|
||||
@@ -32,7 +32,10 @@ export type ShippingDuplicateStatus =
|
||||
| 'exact_file'
|
||||
| 'same_active_task'
|
||||
| 'same_completed_task'
|
||||
| 'possible_duplicate';
|
||||
| 'possible_duplicate'
|
||||
| 'same_business_content'
|
||||
| 'possible_revision'
|
||||
| 'partial_duplicate';
|
||||
|
||||
export interface ShippingDuplicateMatch {
|
||||
taskNo: string;
|
||||
@@ -57,6 +60,19 @@ export interface ShippingDuplicateResolution {
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
export interface ShippingNoticeCandidate {
|
||||
candidateNo: string;
|
||||
poNumber?: string;
|
||||
documentFilename?: string;
|
||||
validationStatus: string;
|
||||
selected: boolean;
|
||||
conflicts: Array<Record<string, unknown>>;
|
||||
businessSummary: Record<string, unknown>;
|
||||
duplicate?: ShippingDuplicateResult;
|
||||
duplicateResolution?: ShippingDuplicateResolution;
|
||||
consumedTaskId?: number;
|
||||
}
|
||||
|
||||
export interface ShippingNoticeParseAttachmentSummary {
|
||||
attachment_key?: string;
|
||||
filename?: string;
|
||||
@@ -113,11 +129,14 @@ export type ShippingNoticePendingAttachment = {
|
||||
originalFilename: string;
|
||||
fileSize: number;
|
||||
parseSummary?: ShippingNoticeParseSummary;
|
||||
orderExtractionStatus?: string;
|
||||
orderExtractionVersion?: string;
|
||||
errorCode?: string;
|
||||
errorMessage?: string;
|
||||
expiresAt?: string;
|
||||
duplicate?: ShippingDuplicateResult;
|
||||
duplicateResolution?: ShippingDuplicateResolution;
|
||||
candidates?: ShippingNoticeCandidate[];
|
||||
};
|
||||
|
||||
/** 待发送附件(本地文件、远程 URL 或货代通知预解析) */
|
||||
|
||||
@@ -130,6 +130,13 @@ const detailStepDetail = computed(() =>
|
||||
const detailErrorMessage = computed(() =>
|
||||
sanitizeShippingRuntimeStatusText(String(detail.value?.error_message || '').trim()),
|
||||
);
|
||||
const detailIssues = computed(() => (
|
||||
Array.isArray(detail.value?.ui_state?.summary?.issues)
|
||||
? detail.value.ui_state.summary.issues
|
||||
.map((item) => sanitizeShippingRuntimeStatusText(String(item || '').trim()))
|
||||
.filter(Boolean)
|
||||
: []
|
||||
));
|
||||
|
||||
const inventorySnapshotLabel = (triggerType?: string | null) => {
|
||||
const key = String(triggerType || 'on_demand');
|
||||
@@ -489,6 +496,10 @@ onMounted(async () => {
|
||||
{{ detailErrorMessage }}
|
||||
</div>
|
||||
|
||||
<div v-if="detailIssues.length" class="rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-800">
|
||||
<div v-for="issue in detailIssues" :key="issue" class="py-0.5">{{ issue }}</div>
|
||||
</div>
|
||||
|
||||
<ShippingMatchResultCard
|
||||
v-if="hasMatchCard"
|
||||
:task-id="detail.task_no"
|
||||
|
||||
Reference in new issue
Block a user