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(); }