Revert "feat(测试跟踪): 功能用例编辑时增加版本编辑"

This reverts commit e1c724bf81.
This commit is contained in:
fit2-zhao 2024-04-25 18:00:33 +08:00
parent e1c724bf81
commit 07d7f0c18a
10 changed files with 11 additions and 181 deletions

View File

@ -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<TestCaseTest> getTestCaseRelateList(@Param("testCaseId") String testCaseId);
List<TestCase> getTestCaseForLastResultLog(@Param("ids") List<String> ids);
List<TestCase> selectByRefIdsAndVersionId(@Param("refIds") List<String> refIds, @Param("versionId") String versionId);
}

View File

@ -1536,12 +1536,4 @@
AND ui_scenario.STATUS != 'Trash'
)
</select>
<select id="selectByRefIdsAndVersionId" resultType="io.metersphere.base.domain.TestCase">
select * from test_case
where ref_id in
<foreach collection="refIds" item="refId" separator="," open="(" close=")">
#{refId}
</foreach>
and version_id = #{versionId}
</select>
</mapper>

View File

@ -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<TestCaseDTO> testCaseDTOList;
private ProjectVersion projectVersion;
public boolean isNotEmpty() {
return projectVersion != null && CollectionUtils.isNotEmpty(testCaseDTOList);
}
}

View File

@ -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<TestCaseDTO> 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<String> 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<String, TestCaseDTO> refTestCaseMap = batchEditDTO.getTestCaseDTOList().stream().collect(Collectors.toMap(TestCaseDTO::getRefId, Function.identity()));
List<TestCase> 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));

View File

@ -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<String> 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<TestCaseDTO> testCaseDTOS, ProjectVersion projectVersion, Consumer<TestCaseBatchEditDTO> consumer) {
if (CollectionUtils.isNotEmpty(testCaseDTOS)) {
int foreachIndex = 0;
int foreachCount = testCaseDTOS.size() / BATCH_PROCESS_QUANTITY;
while (BATCH_PROCESS_QUANTITY < testCaseDTOS.size() || (foreachIndex > foreachCount)) {
List<TestCaseDTO> 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);
}
}
}
}

View File

@ -194,11 +194,6 @@
ref="commentEditInput"
/>
</el-form-item>
<span v-if="form.type === 'version'"
style="font-size:12px">
{{ $t("case.batch_edit_version") }}
</span>
</el-form>
<template v-slot:footer>
<el-button @click="dialogVisible = false" size="small">{{
@ -221,7 +216,10 @@
<script>
import MsDialogFooter from "metersphere-frontend/src/components/MsDialogFooter";
import {listenGoBack, removeGoBackListener,} from "metersphere-frontend/src/utils";
import {
listenGoBack,
removeGoBackListener,
} from "metersphere-frontend/src/utils";
import EnvPopover from "@/business/plan/env/EnvPopover";
import MsTag from "metersphere-frontend/src/components/MsTag";
import { ENV_TYPE } from "metersphere-frontend/src/utils/constants";

View File

@ -12,8 +12,7 @@
<ms-new-ui-search :condition.sync="condition" @search="search" style="float: left" />
<!-- 版本切换组件 -->
<version-select ref="versionSelect" v-xpack :default-version="defaultVersion" :project-id="projectId"
@changeVersion="changeVersion"/>
<version-select v-xpack :project-id="projectId" :default-version="defaultVersion" @changeVersion="changeVersion" />
<!-- 高级搜索框 -->
<ms-table-adv-search :condition.sync="condition" @search="search" ref="advanceSearch"/>
@ -659,16 +658,6 @@ export default {
id: "tags",
name: this.$t('commons.tag')
})
if (this.enableVersionColumn) {
this.typeArr.push({
id: "version",
name: this.$t('commons.version')
})
let versionOptions = this.$refs.versionSelect.versionOptions;
// console.info("version-options", versionOptions);
this.valueArr['version'] = versionOptions;
}
getCustomFieldBatchEditOption(template.customFields, this.typeArr, this.valueArr, this.members);
this.$nextTick(() => {
if (this.$refs.table) {
@ -1122,9 +1111,6 @@ export default {
param.type = form.type;
param.appendTag = form.appendTag;
param.tagList = form.tags;
} else if (form.type === 'version') {
param.type = form.type;
param.versionId = form.value;
}
testCaseBatchEdit(param)
.then(() => {

View File

@ -171,7 +171,6 @@ const message = {
batch_remove_confirm: "Confirm remove {0} item use case?",
},
enter_issues_content: "Please enter the defect content...",
batch_edit_version: "The specified update version exists data will be forced to cover, please operate with caution!",
},
attachment: {
preview: "Preview",

View File

@ -170,7 +170,6 @@ const message = {
batch_remove_confirm: "确定移除{0}项用例?",
},
enter_issues_content: "请输入缺陷内容...",
batch_edit_version: "指定的更新版本存在数据会被强制覆盖,请谨慎操作!",
},
attachment: {
preview: "预览",

View File

@ -170,7 +170,6 @@ const message = {
batch_remove_confirm: "確定移除{0}項用例?",
},
enter_issues_content: "輸入缺陷內容...",
batch_edit_version: "指定的更新版本存在數據會被強制覆蓋,請謹慎操作!",
},
attachment: {
preview: "預覽",