feat(shipping-notice): 新增发货通知重复检测与处理接口,支持重复决策保存与重新执行检测

This commit is contained in:
hugo committed 2026-07-14 21:12:36 +08:00
1 parent 729546a7b7
commit ceb49461e8
72 files changed
+14270 -460

No files matched your search

@@ -20,7 +20,11 @@ import {
Square,
X,
} from 'lucide-vue-next';
import type { PendingAttachment } from '../types/shipping.types';
import type { PendingAttachment, ShippingNoticePendingAttachment } from '../types/shipping.types';
import {
isBlockingWarning,
isShippingNoticeAttachmentParseIncomplete,
} from '../shipping/shippingNoticeAttachmentIntegrity';
export interface ChatInputAttachmentPolicy {
anyEnabled: boolean;
@@ -60,6 +64,7 @@ const emit = defineEmits<{
'voice-click': [];
'remove-attachment': [id: string];
'retry-shipping-notice-attachment': [id: string];
'resolve-shipping-notice-duplicate': [id: string];
'local-files-selected': [event: Event];
'add-remote-url': [url: string];
'shipping-inventory-selected': [event: Event];
@@ -79,6 +84,73 @@ const showAttachmentMenu = ref(false);
const showAttachmentUrlPanel = ref(false);
const showKbDropdown = ref(false);
const attachmentUrlInput = ref('');
/**
* 汇总 EML 附件解析进度,供输入栏徽标展示。
* 核心逻辑:failed/empty/skipped/超限/文本预算耗尽计为问题;duplicate 单独提示,不记为失败。
*/
function shippingNoticeAttachmentHint(attachment: ShippingNoticePendingAttachment): string {
const summary = attachment.parseSummary;
const total = Number(summary?.attachment_count || 0);
const rows = summary?.attachments || [];
const warnings = summary?.warnings || [];
const hasBlockingWarning = warnings.some((w) => isBlockingWarning(String(w || '')));
if (!total && !hasBlockingWarning && !rows.length) return '';
const effectiveTotal = total || rows.length;
const ok = rows.filter((item) => item.parse_status === 'parsed').length;
const problematic = rows.filter((item) =>
['failed', 'empty', 'skipped'].includes(String(item.parse_status || '')),
).length;
const duplicates = rows.filter((item) => item.parse_status === 'duplicate').length;
const overflow = Math.max(0, effectiveTotal - rows.length);
const issues = problematic + overflow + (hasBlockingWarning && problematic === 0 && overflow === 0 ? 1 : 0);
if (issues > 0) {
return t('chat.shippingNoticeAttachmentHintPartial', {
ok,
total: effectiveTotal || Math.max(ok + issues, 1),
failed: issues,
});
}
if (duplicates > 0) {
return t('chat.shippingNoticeAttachmentHintWithDup', { ok, total: effectiveTotal, duplicates });
}
if (!effectiveTotal) return '';
return t('chat.shippingNoticeAttachmentHint', { ok, total: effectiveTotal });
}
/**
* 是否展示「重试解析」:顶层失败,或已 parsed 但附件不完整。
*/
function canRetryShippingNoticeParse(attachment: ShippingNoticePendingAttachment): boolean {
if (attachment.kind !== 'shipping_notice') return false;
if (attachment.parseStatus === 'failed') return true;
return (
attachment.parseStatus === 'parsed'
&& isShippingNoticeAttachmentParseIncomplete(attachment.parseSummary)
);
}
/**
* 生成附件明细 title(文件名 + 状态 + 关键警告),便于悬停查看完整性。
*/
function shippingNoticeAttachmentTitle(attachment: ShippingNoticePendingAttachment): string {
const rows = attachment.parseSummary?.attachments || [];
const warnings = attachment.parseSummary?.warnings || [];
const lines: string[] = [];
for (const item of rows) {
const name = item.filename || item.attachment_key || 'attachment';
const status = item.parse_status || 'unknown';
lines.push(`${name}: ${status}`);
}
for (const warning of warnings) {
const text = String(warning || '').trim();
if (text) lines.push(`warning: ${text}`);
}
return lines.join('\n');
}
const closeAttachmentMenu = () => {
showAttachmentMenu.value = false;
showAttachmentUrlPanel.value = false;
@@ -246,7 +318,36 @@ watch(
{{ a.originalFilename }}
<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'" class="text-muted"> · {{ t('chat.shippingNoticeParsed') }}</span>
<span
v-else-if="a.parseStatus === 'parsed' && 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"
class="font-medium text-amber-700"
> · {{ t('chat.shippingNoticeDuplicateBlockingBadge') }}</span>
<span
v-else-if="a.parseStatus === 'parsed' && a.duplicateResolution?.action === 'create_revision'"
class="text-brand-700"
> · {{ t('chat.shippingNoticeDuplicateRevisionChosen') }}</span>
<span
v-else-if="a.parseStatus === 'parsed' && a.duplicateResolution?.action === 'force_create'"
class="text-amber-700"
> · {{ t('chat.shippingNoticeDuplicateForceChosen') }}</span>
<span
v-else-if="a.parseStatus === 'parsed' && a.duplicateResolution?.action === 'open_existing'"
class="text-muted"
> · {{ t('chat.shippingNoticeDuplicateOpenChosen') }}</span>
<span
v-else-if="a.parseStatus === 'parsed'"
class="text-muted"
:title="shippingNoticeAttachmentTitle(a)"
>
· {{ t('chat.shippingNoticeParsed') }}
<template v-if="shippingNoticeAttachmentHint(a)">
· {{ shippingNoticeAttachmentHint(a) }}
</template>
</span>
<span v-else-if="a.parseStatus === 'failed'" class="text-muted"> · {{ t('chat.shippingNoticeParseFailed') }}</span>
</template>
<template v-else>
@@ -254,7 +355,16 @@ watch(
</template>
</span>
<button
v-if="a.kind === 'shipping_notice' && a.parseStatus === 'failed'"
v-if="a.kind === 'shipping_notice' && a.duplicate?.blocking && !a.duplicateResolution?.action"
type="button"
class="text-amber-700 hover:text-amber-800"
:title="t('chat.shippingNoticeDuplicateHandle')"
@click="emit('resolve-shipping-notice-duplicate', a.id)"
>
{{ t('chat.shippingNoticeDuplicateHandle') }}
</button>
<button
v-if="a.kind === 'shipping_notice' && canRetryShippingNoticeParse(a)"
type="button"
class="text-muted hover:text-primary"
:title="t('chat.shippingNoticeRetryParse')"