feat(shipping-notice): 增强发货通知候选管理功能,支持候选选择、重复检测与业务摘要修订
This commit is contained in:
1 parent
70f684b94a
commit
b595e157e9
83 files changed
+5857
-200
No files matched your search
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user