From 3cab981a9ab3f6dd0f92b823f8a1f25339ef5b13 Mon Sep 17 00:00:00 2001 From: wyb <1977763549@qq.com> Date: Fri, 17 Mar 2023 09:25:10 +0800 Subject: [PATCH] =?UTF-8?q?subList=20=E4=BD=BF=E7=94=A8=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../report/service/impl/ReportServiceImpl.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/docus/server/report/service/impl/ReportServiceImpl.java b/src/main/java/com/docus/server/report/service/impl/ReportServiceImpl.java index d06b8a0..355ab99 100644 --- a/src/main/java/com/docus/server/report/service/impl/ReportServiceImpl.java +++ b/src/main/java/com/docus/server/report/service/impl/ReportServiceImpl.java @@ -90,17 +90,17 @@ public class ReportServiceImpl implements ReportService { @Override public void makeupReportByTaskIds(List taskIds) throws Exception { - int taskIdLength = taskIds.size(); // 定义一批200查询,分批次 final int oneBatchCount = 200; - int startIndex; - int toIndex = 0; + int startIndex = 0; + int toIndex = oneBatchCount; + boolean loop = true; do { - startIndex = toIndex; - toIndex = startIndex + oneBatchCount; - // 如果大于原来集合长度,最大截取就是集合长度 - if (toIndex >= taskIdLength) { - toIndex = taskIdLength; + // 获取截取下标 + if (taskIds.size() <= oneBatchCount) { + toIndex = taskIds.size(); + // 最后一批截取 + loop = false; } // 截取每一批 List makeupTaskIds = taskIds.subList(startIndex, toIndex); @@ -114,6 +114,6 @@ public class ReportServiceImpl implements ReportService { } } // 当截取长度小于集合长度,可以进行下次循环截取 - } while (toIndex < taskIdLength); + } while (loop); } }