diff --git a/src/App.tsx b/src/App.tsx index 8bde89b..921b405 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2712,6 +2712,50 @@ export default function App() { } } } + + if (!isBackward && mode === 'generate' && showUI && currentExpectedDate && !isNaN(currentExpectedDate.getTime()) && results.length > 0) { + const findLastCompletionDate = (): Date | null => { + for (let i = results.length - 1; i >= 0; i--) { + const endStr = results[i]?.estimatedEnd; + if (typeof endStr !== 'string' || endStr.trim() === '' || endStr.includes('未找到') || endStr.includes('时效值为0')) continue; + const d = parseDate(endStr); + if (d && !isNaN(d.getTime())) return d; + } + return null; + }; + + const lastCompletionDate = findLastCompletionDate(); + if (lastCompletionDate) { + const deliveryDate = new Date(lastCompletionDate); + deliveryDate.setDate(deliveryDate.getDate() + Math.max(0, Math.ceil(baseBufferDays))); + const increaseDays = differenceInCalendarDays(currentExpectedDate, deliveryDate); + + if (increaseDays > 0) { + const shouldApply = await new Promise((resolve) => { + Modal.confirm({ + title: '是否增加缓冲期使其一致?', + content: `请业务确认:OMS 获取小ERP的预计交付日期。\n当前预计交付日期:${formatDate(deliveryDate, 'CHINESE_DATE')}\n客户期望日期:${formatDate(currentExpectedDate, 'CHINESE_DATE')}\n是否增加缓冲期 +${increaseDays} 天使其一致?`, + okText: '确认增加', + cancelText: '不调整', + onOk: () => resolve(true), + onCancel: () => resolve(false), + }); + }); + + if (shouldApply) { + setBaseBufferDays((prev) => Math.max(0, Math.ceil(prev) + increaseDays)); + setHasAppliedSuggestedBuffer(true); + setLastSuggestedApplied(increaseDays); + if (bitable.ui.showToast) { + await bitable.ui.showToast({ + toastType: ToastType.success, + message: `已自动增加缓冲期 +${increaseDays} 天,使预计交付日期对齐客户期望日期`, + }); + } + } + } + } + } setTimelineResults(results); if (showUI && !delayShowTimelineModal) {