diff --git a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java index 9801009c1b..0217e7861c 100644 --- a/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java +++ b/backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java @@ -5,6 +5,7 @@ import io.metersphere.api.service.*; import io.metersphere.base.domain.ApiDefinitionExecResult; import io.metersphere.base.domain.ApiScenarioReport; import io.metersphere.base.domain.ApiTestReport; +import io.metersphere.base.domain.TestPlanReport; import io.metersphere.commons.constants.*; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.LogUtil; @@ -14,6 +15,7 @@ import io.metersphere.notice.sender.NoticeModel; import io.metersphere.notice.service.NoticeSendService; import io.metersphere.service.SystemParameterService; import io.metersphere.track.service.TestPlanReportService; +import io.metersphere.track.service.TestPlanService; import io.metersphere.track.service.TestPlanTestCaseService; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 70be9377cb..c984f0880e 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -403,17 +403,24 @@ public class ApiDefinitionService { private void importMsCase(ApiDefinitionImport apiImport, SqlSession sqlSession, ApiTestCaseMapper apiTestCaseMapper) { List cases = apiImport.getCases(); + List caseNames = apiTestCaseService.listPorjectAllCaseName(SessionUtils.getCurrentProjectId()); + Set existCaseName = new HashSet<>(); + caseNames.forEach(item -> { + existCaseName.add(item); + }); if (CollectionUtils.isNotEmpty(cases)) { int batchCount = 0; cases.forEach(item -> { - item.setId(UUID.randomUUID().toString()); - item.setCreateTime(System.currentTimeMillis()); - item.setUpdateTime(System.currentTimeMillis()); - item.setCreateUserId(SessionUtils.getUserId()); - item.setUpdateUserId(SessionUtils.getUserId()); - item.setProjectId(SessionUtils.getCurrentProjectId()); - item.setNum(getNextNum(item.getApiDefinitionId())); - apiTestCaseMapper.insert(item); + if(!existCaseName.contains(item.getName())) { + item.setId(UUID.randomUUID().toString()); + item.setCreateTime(System.currentTimeMillis()); + item.setUpdateTime(System.currentTimeMillis()); + item.setCreateUserId(SessionUtils.getUserId()); + item.setUpdateUserId(SessionUtils.getUserId()); + item.setProjectId(SessionUtils.getCurrentProjectId()); + item.setNum(getNextNum(item.getApiDefinitionId())); + apiTestCaseMapper.insert(item); + } }); if (batchCount % 300 == 0) { sqlSession.flushStatements(); @@ -628,12 +635,7 @@ public class ApiDefinitionService { } if (!CollectionUtils.isEmpty(apiImport.getCases())) { - for (int i = 0; i < apiImport.getCases().size(); i++) { - importMsCase(apiImport, sqlSession, apiTestCaseMapper); - if (i % 300 == 0) { - sqlSession.flushStatements(); - } - } + importMsCase(apiImport, sqlSession, apiTestCaseMapper); } sqlSession.flushStatements(); } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index c7282b0b65..a93b406924 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -80,6 +80,10 @@ public class ApiTestCaseService { private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; + public List listPorjectAllCaseName(String projectId) { + return extApiTestCaseMapper.listPorjectAllCaseName(projectId); + } + public List list(ApiTestCaseRequest request) { request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); List returnList = extApiTestCaseMapper.list(request); diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java index 4e1ad1b010..d8275a2cb3 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java @@ -12,6 +12,8 @@ import java.util.List; public interface ExtApiTestCaseMapper { + List listPorjectAllCaseName(@Param("projectId") String projectId); + List list(@Param("request") ApiTestCaseRequest request); List listSimple(@Param("request") ApiTestCaseRequest request); diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml index 0cea320af6..812eec744f 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml @@ -391,6 +391,8 @@ - + \ No newline at end of file diff --git a/frontend/src/business/components/track/plan/components/TestPlanList.vue b/frontend/src/business/components/track/plan/components/TestPlanList.vue index e7b880c2e0..15e45fb445 100644 --- a/frontend/src/business/components/track/plan/components/TestPlanList.vue +++ b/frontend/src/business/components/track/plan/components/TestPlanList.vue @@ -86,7 +86,7 @@ show-overflow-tooltip :key="index">