From 0c6f7a47750d2c7f09e86d9ba6df70b46dc38729 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Wed, 1 Jul 2026 13:53:53 +0800 Subject: [PATCH] =?UTF-8?q?SQL=20Server=20=E5=8D=95=E6=9D=A1=E8=AF=AD?= =?UTF-8?q?=E5=8F=A5=E5=8F=82=E6=95=B0=E4=B8=8A=E9=99=90=EF=BC=88=E5=AE=98?= =?UTF-8?q?=E6=96=B9=E9=99=90=E5=88=B6=202100=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CoDelExcelServiceImpl.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java index daf65a1b..e7d3d511 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java +++ b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java @@ -69,6 +69,20 @@ import java.util.stream.Stream; @Service @Slf4j public class CoDelExcelServiceImpl implements CoDelExcelService { + /** + * batchSaveEcssCoDelNotifyDetail 每行参数个数(与 CoDelMapper.xml 中 values 字段保持一致) + */ + private static final int NOTIFY_DETAIL_PARAM_COUNT_PER_ROW = 39; + /** + * 明细分批插入条数,避免单次请求参数超限 + */ + private static final int SQL_SERVER_PARAM_SAFE_LIMIT = 2000; + /** + * 使用安全阈值(2000)而不是理论上限(2100),给 SQL 预留余量 + */ + private static final int NOTIFY_DETAIL_BATCH_SIZE = + Math.max(1, SQL_SERVER_PARAM_SAFE_LIMIT / NOTIFY_DETAIL_PARAM_COUNT_PER_ROW); + @Autowired private QcMapper qcMapper; @Autowired @@ -305,7 +319,7 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { list.get(i).setDelNo(transNo); list.get(i).setItemNo(i + 1); } - coDelMapper.batchSaveEcssCoDelNotifyDetail(list); + batchSaveNotifyDetailSafely(list); // 加入成功列表 successList.add("发票号:" + cmcInvoice + " 导入成功"); @@ -321,6 +335,20 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { return resultMap; } + /** + * 分批保存明细,规避 SQL Server 单次请求 2100 参数上限 + */ + private void batchSaveNotifyDetailSafely(List detailList) { + if (detailList == null || detailList.isEmpty()) { + return; + } + for (int start = 0; start < detailList.size(); start += NOTIFY_DETAIL_BATCH_SIZE) { + int end = Math.min(start + NOTIFY_DETAIL_BATCH_SIZE, detailList.size()); + List subList = new ArrayList<>(detailList.subList(start, end)); + coDelMapper.batchSaveEcssCoDelNotifyDetail(subList); + } + } + /** * 安全获取字符串列值(支持可选列) @@ -1212,7 +1240,7 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { boolean hasPnOrQtyModified = excelList.stream() .anyMatch(item -> item.getModifyQtyFlag() != null && item.getModifyQtyFlag()); - coDelMapper.batchSaveEcssCoDelNotifyDetail(excelList); + batchSaveNotifyDetailSafely(excelList); headerData.setModifyFlag(true); // 更新头表字段,包括ReadyDate、ShippingMode、Destination coDelMapper.updateEcssDelHeader(headerData);