From 7e72fb4594ce4cf3ec6dd7b382d074f5db2942ec Mon Sep 17 00:00:00 2001 From: lishuai Date: Fri, 28 Feb 2025 11:38:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=85=A5=E5=BA=93=202025?= =?UTF-8?q?=E5=B9=B42=E6=9C=8828=E6=97=A511:38:17?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CalcLogServiceImpl.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/calculation/src/main/java/com/thing/calculation/service/impl/CalcLogServiceImpl.java b/modules/calculation/src/main/java/com/thing/calculation/service/impl/CalcLogServiceImpl.java index 13d24f3..cc0cd62 100644 --- a/modules/calculation/src/main/java/com/thing/calculation/service/impl/CalcLogServiceImpl.java +++ b/modules/calculation/src/main/java/com/thing/calculation/service/impl/CalcLogServiceImpl.java @@ -107,7 +107,20 @@ public class CalcLogServiceImpl extends BaseServiceImpl logs) { - mapper.batchSaveOrUpdate(logs); + if (CollectionUtils.isEmpty(logs)) { + return; + } + // 将 logs 分割成多个子集合,每个子集合包含 BATCH_SIZE 条数据 + List logList = new ArrayList<>(logs); + int totalSize = logList.size(); + for (int i = 0; i < totalSize; i += 1000) { + // 计算每一批的结束索引,确保不越界 + int end = Math.min(i + 1000, totalSize); + // 获取当前批次的数据 + List batch = logList.subList(i, end); + // 执行批量保存或更新 + mapper.batchSaveOrUpdate(batch); + } } /** 清理已过期的计算记录(状态为已计算,且为两天前的计算日志) */