From 8cf409628f6396dd03c25e44de17cb171f7c171b Mon Sep 17 00:00:00 2001 From: yinq Date: Mon, 19 May 2025 13:10:27 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=AF=BC=E5=85=A5=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=AF=8F=E5=AF=BC=E5=85=A510=E4=B8=AA=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E8=B0=83=E7=94=A8=E4=B8=80=E6=AC=A1=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/service/impl/KDocsServiceImpl.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java b/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java index 11ed7bb..e0a9bf9 100644 --- a/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java +++ b/tagApi-service/src/main/java/hw/tagApi/service/service/impl/KDocsServiceImpl.java @@ -59,6 +59,7 @@ public class KDocsServiceImpl implements IKDocsService { // 异步执行导入任务 executorService.execute(() -> { List resList = new ArrayList<>(); + int count = 0; for (ApiContent apiContent : contentList) { long startTime = System.currentTimeMillis(); ApiContent resContent = new ApiContent(); @@ -75,12 +76,23 @@ public class KDocsServiceImpl implements IKDocsService { resContent.setFields(errorFields); } resList.add(resContent); + count++; long endTime = System.currentTimeMillis(); log.info("数据库导入完成 - ID: {}, 耗时: {}ms", apiContent.getId(), (endTime - startTime)); + + // 每处理10个数据就发送一次回调 + if (count % 10 == 0) { + log.info("已处理{}条数据,发送回调", count); + httpClientUtils.sendResultToCallback(resList, ApiConstants.CALLBACK_URL, ApiConstants.DATA_IMPORT); + resList.clear(); // 清空列表,准备下一批数据 + } } - // 发送处理结果到回调接口 - httpClientUtils.sendResultToCallback(resList, ApiConstants.CALLBACK_URL, ApiConstants.DATA_IMPORT); + // 处理剩余的数据(不足10条的部分) + if (!resList.isEmpty()) { + log.info("处理剩余{}条数据,发送回调", resList.size()); + httpClientUtils.sendResultToCallback(resList, ApiConstants.CALLBACK_URL, ApiConstants.DATA_IMPORT); + } }); return resApiContentList;