From 2650f482f6369c92877c077df955a24ee6ad3355 Mon Sep 17 00:00:00 2001 From: Jianguo-Genius Date: Mon, 22 Apr 2024 15:51:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=8E=A5=E5=8F=A3=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E6=89=B9=E5=A4=84=E7=90=86=E6=96=B9=E6=B3=95=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=89=B9=E5=A4=84=E7=90=86=E6=9D=A1=E6=95=B0=E9=98=B2?= =?UTF-8?q?=E6=AD=A2=E5=86=85=E5=AD=98=E6=BA=A2=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/scenario/ApiScenarioService.java | 27 ++++++++----------- .../utils/ApiScenarioBatchOperationUtils.java | 4 +-- .../dto/excel/UserExcelValidateHelper.java | 6 ++++- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index 28dfdfbf96..b6823808b9 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -2569,37 +2569,32 @@ public class ApiScenarioService extends MoveNodeService { } SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); ApiScenarioMapper mapper = sqlSession.getMapper(ApiScenarioMapper.class); - SubListUtils.dealForSubList(insertApiScenarioList, 100, subList -> { - subList.forEach(mapper::insertSelective); - }); - response.setSuccess(insertApiScenarioList.size()); + + insertApiScenarioList.forEach(mapper::insertSelective); + if (CollectionUtils.isNotEmpty(insertApiScenarioBlobList)) { ApiScenarioBlobMapper blobMapper = sqlSession.getMapper(ApiScenarioBlobMapper.class); - SubListUtils.dealForSubList(insertApiScenarioBlobList, 100, subList -> { - subList.forEach(blobMapper::insertSelective); - }); + insertApiScenarioBlobList.forEach(blobMapper::insertSelective); } if (CollectionUtils.isNotEmpty(insertApiScenarioStepList)) { ApiScenarioStepMapper stepMapper = sqlSession.getMapper(ApiScenarioStepMapper.class); - SubListUtils.dealForSubList(insertApiScenarioStepList, 100, subList -> { - subList.forEach(stepMapper::insertSelective); - }); + insertApiScenarioStepList.forEach(stepMapper::insertSelective); } if (CollectionUtils.isNotEmpty(insertApiScenarioStepBlobList)) { ApiScenarioStepBlobMapper stepBlobMapper = sqlSession.getMapper(ApiScenarioStepBlobMapper.class); - SubListUtils.dealForSubList(insertApiScenarioStepBlobList, 100, subList -> { - subList.forEach(stepBlobMapper::insertSelective); - }); + insertApiScenarioStepBlobList.forEach(stepBlobMapper::insertSelective); + } if (CollectionUtils.isNotEmpty(insertApiFileResourceList)) { - SubListUtils.dealForSubList(insertApiFileResourceList, 100, subList -> { - apiFileResourceService.batchInsert(subList); - }); + apiFileResourceService.batchInsert(insertApiFileResourceList); } + sqlSession.flushStatements(); if (sqlSessionFactory != null) { SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); } + + response.setSuccess(insertApiScenarioList.size()); return response; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/utils/ApiScenarioBatchOperationUtils.java b/backend/services/api-test/src/main/java/io/metersphere/api/utils/ApiScenarioBatchOperationUtils.java index 2f2442a7a6..8c5ceab53d 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/utils/ApiScenarioBatchOperationUtils.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/utils/ApiScenarioBatchOperationUtils.java @@ -8,12 +8,12 @@ import java.util.function.Function; //场景批量操作工具类 public class ApiScenarioBatchOperationUtils { - private static int MAX_OPERATION_SIZE = 100; + private static int MAX_OPERATION_SIZE = 20; public static ApiScenarioBatchOperationResponse executeWithBatchOperationResponse(List totalList, Function, ApiScenarioBatchOperationResponse> subFunc) { ApiScenarioBatchOperationResponse response = new ApiScenarioBatchOperationResponse(); List operationList = new ArrayList<>(totalList); - while (operationList.size() > 100) { + while (operationList.size() > MAX_OPERATION_SIZE) { List subList = operationList.subList(0, MAX_OPERATION_SIZE); response.merge( subFunc.apply(subList)); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/excel/UserExcelValidateHelper.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/excel/UserExcelValidateHelper.java index c479fe630b..f06a7624d5 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/excel/UserExcelValidateHelper.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/excel/UserExcelValidateHelper.java @@ -8,6 +8,7 @@ import jakarta.validation.groups.Default; import org.springframework.stereotype.Component; import java.util.Set; +import java.util.TreeSet; @Component public class UserExcelValidateHelper { @@ -21,9 +22,12 @@ public class UserExcelValidateHelper { StringBuilder result = new StringBuilder(); Set> set = excelValidateHelper.validator.validate(obj, Default.class); if (set != null && !set.isEmpty()) { + //报错信息进行有序、去重处理 + Set errorMsgSet = new TreeSet<>(); for (ConstraintViolation cv : set) { - result.append(cv.getMessage()).append("; "); + errorMsgSet.add(cv.getMessage()); } + errorMsgSet.forEach(item -> result.append(item).append("; ")); } return result.toString(); }