From 07d7f0c18abaab513673301b63e60a3d304a93d6 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 25 Apr 2024 18:00:33 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"feat(=E6=B5=8B=E8=AF=95=E8=B7=9F?= =?UTF-8?q?=E8=B8=AA):=20=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=97=B6=E5=A2=9E=E5=8A=A0=E7=89=88=E6=9C=AC=E7=BC=96?= =?UTF-8?q?=E8=BE=91"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit e1c724bf81802278b9ef186ef747517d06a5c3da. --- .../base/mapper/ext/ExtTestCaseMapper.java | 3 +- .../base/mapper/ext/ExtTestCaseMapper.xml | 8 -- .../metersphere/dto/TestCaseBatchEditDTO.java | 21 ---- .../metersphere/service/TestCaseService.java | 98 ------------------- .../utils/BatchProcessingUtil.java | 25 +---- .../business/case/components/BatchEdit.vue | 18 ++-- .../business/case/components/TestCaseList.vue | 16 +-- test-track/frontend/src/i18n/lang/en-US.js | 1 - test-track/frontend/src/i18n/lang/zh-CN.js | 1 - test-track/frontend/src/i18n/lang/zh-TW.js | 1 - 10 files changed, 11 insertions(+), 181 deletions(-) delete mode 100644 test-track/backend/src/main/java/io/metersphere/dto/TestCaseBatchEditDTO.java diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java index 66c2542772..065a278b9e 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java @@ -4,6 +4,7 @@ import io.metersphere.base.domain.TestCase; import io.metersphere.base.domain.TestCaseTest; import io.metersphere.base.domain.TestCaseWithBLOBs; import io.metersphere.dto.*; + import io.metersphere.request.BaseQueryRequest; import io.metersphere.request.testcase.DeleteTestCaseRequest; import io.metersphere.request.testcase.QueryTestCaseRequest; @@ -171,6 +172,4 @@ public interface ExtTestCaseMapper { List getTestCaseRelateList(@Param("testCaseId") String testCaseId); List getTestCaseForLastResultLog(@Param("ids") List ids); - - List selectByRefIdsAndVersionId(@Param("refIds") List refIds, @Param("versionId") String versionId); } diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml index 57bd7e87fc..0dc2b7f0d4 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml @@ -1536,12 +1536,4 @@ AND ui_scenario.STATUS != 'Trash' ) - diff --git a/test-track/backend/src/main/java/io/metersphere/dto/TestCaseBatchEditDTO.java b/test-track/backend/src/main/java/io/metersphere/dto/TestCaseBatchEditDTO.java deleted file mode 100644 index 5a5e02bae1..0000000000 --- a/test-track/backend/src/main/java/io/metersphere/dto/TestCaseBatchEditDTO.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.metersphere.dto; - -import io.metersphere.base.domain.ProjectVersion; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.apache.commons.collections.CollectionUtils; - -import java.util.List; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class TestCaseBatchEditDTO { - private List testCaseDTOList; - private ProjectVersion projectVersion; - - public boolean isNotEmpty() { - return projectVersion != null && CollectionUtils.isNotEmpty(testCaseDTOList); - } -} diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java index f643754ec0..ac9c4ec039 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java @@ -51,7 +51,6 @@ import io.metersphere.service.remote.project.TrackCustomFieldTemplateService; import io.metersphere.service.remote.project.TrackTestCaseTemplateService; import io.metersphere.service.remote.ui.RelevanceUiCaseService; import io.metersphere.service.wapper.TrackProjectService; -import io.metersphere.utils.BatchProcessingUtil; import io.metersphere.utils.DiscoveryUtil; import io.metersphere.xmind.XmindCaseParser; import io.metersphere.xmind.pojo.TestCaseXmindData; @@ -85,7 +84,6 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Function; import java.util.stream.Collectors; @Service @@ -2123,9 +2121,6 @@ public class TestCaseService { batchEditField(request); } else if (StringUtils.equals("tags", request.getType())) { batchEditTag(request); - } else if (StringUtils.equals("version", request.getType())) { - //批量修改版本 - this.preEditVersion(request); } else { // 批量移动 if (request.getCondition().isSelectAll()) { @@ -2141,99 +2136,6 @@ public class TestCaseService { } } - private void preEditVersion(TestCaseBatchRequest request) { - List testCaseDTOS = new ArrayList<>(); - ProjectVersion projectVersion = projectVersionMapper.selectByPrimaryKey(request.getVersionId()); - if (projectVersion == null) { - return; - } - - if (request.getCondition().isSelectAll()) { - // 全选则重新设置MoveIds - testCaseDTOS = listTestCase(request.getCondition(), true); - } else if (CollectionUtils.isNotEmpty(request.getIds())) { - testCaseDTOS = extTestCaseMapper.list(new QueryTestCaseRequest() {{ - this.setIds(request.getIds()); - }}); - } - - // 过滤掉当前版本的用例 - testCaseDTOS = testCaseDTOS.stream().filter(e -> !StringUtils.equals(request.getVersionId(), e.getVersionId())) - .collect(Collectors.toList()); - - BatchProcessingUtil.testCaseBatchProcess(testCaseDTOS, projectVersion, this::batchEditVersion); - } - - // 级联删除 - private void cascadeDeleteTestCase(List testCaseIds) { - //删除refTestCaseList - deleteTestPlanTestCaseBath(testCaseIds); - relationshipEdgeService.delete(testCaseIds); // 删除关系图 - customFieldTestCaseService.deleteByResourceIds(testCaseIds); // 删除自定义字段 - //删除执行信息 - functionCaseExecutionInfoService.deleteBySourceIdList(testCaseIds); - testCaseIds.forEach(testCaseId -> { // todo 优化下效率 - testCaseIssueService.delTestCaseIssues(testCaseId); - testCaseCommentService.deleteCaseComment(testCaseId); - TestCaseTestExample examples = new TestCaseTestExample(); - examples.createCriteria().andTestCaseIdEqualTo(testCaseId); - testCaseTestMapper.deleteByExample(examples); - relateDelete(testCaseId); - deleteFollows(testCaseId); - }); - - TestCaseExample example = new TestCaseExample(); - example.createCriteria().andIdIn(testCaseIds); - testCaseMapper.deleteByExample(example); - // 删除富文本框图片 - mdFileService.deleteBySourceIds(testCaseIds); - } - - /** - * 批量移动到指定版本: - * 1.指定版本不存在该用例时,直接移动(修改用例的version_id). - * 2.指定版本存在该用例时,先删除,再修改version. - * 2.1):删除时判断refId是否和Id相同。如果相同的话,把要修改用例的refId设置为它自己的ID. - * 2.2):判断latest是否为true。为true的话,要把新用例的latest设置为true. - */ - private void batchEditVersion(TestCaseBatchEditDTO batchEditDTO) { - if (batchEditDTO.isNotEmpty()) { - Map refTestCaseMap = batchEditDTO.getTestCaseDTOList().stream().collect(Collectors.toMap(TestCaseDTO::getRefId, Function.identity())); - List refTestCaseList = extTestCaseMapper.selectByRefIdsAndVersionId(new ArrayList<>(refTestCaseMap.keySet()), batchEditDTO.getProjectVersion().getId()); - //进行步骤2检查 - if (CollectionUtils.isNotEmpty(refTestCaseList)) { - for (TestCase refTestCase : refTestCaseList) { - TestCaseDTO oldDTO = refTestCaseMap.get(refTestCase.getRefId()); - if (oldDTO != null) { - if (StringUtils.equals(refTestCase.getId(), refTestCase.getRefId())) { - oldDTO.setRefId(oldDTO.getId()); - } - if (BooleanUtils.isTrue(refTestCase.getLatest())) { - oldDTO.setLatest(true); - } - } - } - - this.cascadeDeleteTestCase(refTestCaseList.stream().map(TestCase::getId).collect(Collectors.toList())); - } - - SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); - TestCaseMapper mapper = sqlSession.getMapper(TestCaseMapper.class); - for (TestCaseDTO testCaseDTO : refTestCaseMap.values()) { - TestCaseWithBLOBs updateCase = new TestCaseWithBLOBs(); - updateCase.setId(testCaseDTO.getId()); - updateCase.setVersionId(batchEditDTO.getProjectVersion().getId()); - updateCase.setLatest(testCaseDTO.getLatest()); - updateCase.setRefId(testCaseDTO.getRefId()); - mapper.updateByPrimaryKeySelective(updateCase); - } - sqlSession.flushStatements(); - if (sqlSession != null && sqlSessionFactory != null) { - SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); - } - } - } - private void batchEditTag(TestCaseBatchRequest request) { ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extTestCaseMapper.selectIds(query)); diff --git a/test-track/backend/src/main/java/io/metersphere/utils/BatchProcessingUtil.java b/test-track/backend/src/main/java/io/metersphere/utils/BatchProcessingUtil.java index f67de2b0a5..7ed9c5e651 100644 --- a/test-track/backend/src/main/java/io/metersphere/utils/BatchProcessingUtil.java +++ b/test-track/backend/src/main/java/io/metersphere/utils/BatchProcessingUtil.java @@ -1,10 +1,7 @@ package io.metersphere.utils; -import io.metersphere.base.domain.ProjectVersion; import io.metersphere.base.domain.TestCaseTest; import io.metersphere.base.domain.TestCaseTestExample; -import io.metersphere.dto.TestCaseBatchEditDTO; -import io.metersphere.dto.TestCaseDTO; import org.apache.commons.collections.CollectionUtils; import java.util.ArrayList; @@ -28,6 +25,7 @@ public class BatchProcessingUtil { List handleList = stringList.subList(0, BATCH_PROCESS_QUANTITY); consumer.accept(handleList); stringList.removeAll(handleList); + //记录循环次数,防止出现死循环 foreachIndex++; } @@ -108,25 +106,4 @@ public class BatchProcessingUtil { } return new ArrayList<>(); } - - public static void testCaseBatchProcess(List testCaseDTOS, ProjectVersion projectVersion, Consumer consumer) { - if (CollectionUtils.isNotEmpty(testCaseDTOS)) { - int foreachIndex = 0; - int foreachCount = testCaseDTOS.size() / BATCH_PROCESS_QUANTITY; - while (BATCH_PROCESS_QUANTITY < testCaseDTOS.size() || (foreachIndex > foreachCount)) { - List handleList = testCaseDTOS.subList(0, BATCH_PROCESS_QUANTITY); - TestCaseBatchEditDTO handleDTO = new TestCaseBatchEditDTO(handleList, projectVersion); - consumer.accept(handleDTO); - testCaseDTOS.removeAll(handleList); - - //记录循环次数,防止出现死循环 - foreachIndex++; - } - //处理剩余数据 - if (CollectionUtils.isNotEmpty(testCaseDTOS)) { - TestCaseBatchEditDTO handleDTO = new TestCaseBatchEditDTO(testCaseDTOS, projectVersion); - consumer.accept(handleDTO); - } - } - } } diff --git a/test-track/frontend/src/business/case/components/BatchEdit.vue b/test-track/frontend/src/business/case/components/BatchEdit.vue index f75776df0e..b0ed42dfd0 100644 --- a/test-track/frontend/src/business/case/components/BatchEdit.vue +++ b/test-track/frontend/src/business/case/components/BatchEdit.vue @@ -194,11 +194,6 @@ ref="commentEditInput" /> - - - {{ $t("case.batch_edit_version") }} -