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

@@ -0,0 +1,54 @@
/**
* features/chat/shipping/shippingNoticeAttachmentIntegrity.ts
* 用途:发货通知附件完整性门禁契约(阻断 warning 前缀与 incomplete 判定)。
* 依赖:shipping.types(ParseSummary 形状)。
* 逻辑:与后端 attachment_integrity.BLOCKING_WARNING_PREFIXES /
* is_attachment_parse_incomplete 保持一致;契约测试校验两端前缀集合。
*/
import type { ShippingNoticeParseSummary } from '../types/shipping.types';
/** 阻断 warning 前缀;须与 backend BLOCKING_WARNING_PREFIXES 完全一致(顺序可不同)。 */
export const BLOCKING_WARNING_PREFIXES = [
'eml_nesting_depth_exceeded:',
'eml_attachment_limit_exceeded:',
'eml_total_attachment_size_exceeded:',
'eml_nested_message_unreadable',
'eml_attachment_text_budget_exhausted:',
'eml_attachment_text_truncated:',
'notice_text_truncated:',
] as const;
const INCOMPLETE_ATTACHMENT_STATUSES = new Set(['failed', 'empty', 'skipped']);
/**
* 判定单条 warning 是否为完整性阻断项。
*/
export function isBlockingWarning(text: string): boolean {
const normalized = String(text || '');
return BLOCKING_WARNING_PREFIXES.some((prefix) => normalized.startsWith(prefix));
}
/**
* 判定 EML 等 intake 是否存在未完整解析的附件(含超深/超限/截断警告)。
* 核心逻辑:阻断警告、登记数少于发现数、或 failed/empty/skipped 均视为不完整;
* duplicate 仅为去重,不阻断建单。
*/
export function isShippingNoticeAttachmentParseIncomplete(
summary?: ShippingNoticeParseSummary | null,
): boolean {
if (!summary) return false;
const warnings = summary.warnings || [];
if (warnings.some((item) => isBlockingWarning(String(item || '')))) {
return true;
}
const rows = summary.attachments || [];
const total = Number(summary.attachment_count || 0);
if (total > rows.length) return true;
return rows.some((item) => {
if (INCOMPLETE_ATTACHMENT_STATUSES.has(String(item.parse_status || ''))) {
return true;
}
return (item.warnings || []).some((w) => isBlockingWarning(String(w || '')));
});
}