feat(测试跟踪): 功能用例回收站关联版本的改动

This commit is contained in:
zhangdahai112 2022-01-18 20:16:45 +08:00 committed by song-tianyang
parent 50734bf030
commit a7521a10ea
10 changed files with 82 additions and 25 deletions

View File

@ -1,7 +1,5 @@
package io.metersphere.api.dto.automation; package io.metersphere.api.dto.automation;
import org.junit.internal.runners.statements.Fail;
public enum ScenarioStatus { public enum ScenarioStatus {
Saved, Success, Error, Timeout, Fail, Trash, Underway Saved, Success, Error, Timeout, Fail, Trash, Underway
} }

View File

@ -134,4 +134,6 @@ public interface ExtTestCaseMapper {
String getLastExecStatusById(String id); String getLastExecStatusById(String id);
int countByWorkSpaceId(String workSpaceId); int countByWorkSpaceId(String workSpaceId);
long trashCount(@Param("projectId") String projectId);
} }

View File

@ -865,7 +865,7 @@
status = original_status, status = original_status,
delete_user_id = null, delete_user_id = null,
delete_time = null delete_time = null
where id in where ref_id in
<foreach collection="ids" item="v" separator="," open="(" close=")"> <foreach collection="ids" item="v" separator="," open="(" close=")">
#{v} #{v}
</foreach> </foreach>
@ -898,4 +898,14 @@
and status != 'Trash' and status != 'Trash'
</select> </select>
<select id="trashCount" resultType="java.lang.Long">
SELECT
count(DISTINCT ref_id)
FROM
test_case
WHERE
project_id = #{projectId}
AND STATUS = 'Trash'
</select>
</mapper> </mapper>

View File

@ -244,7 +244,7 @@ public class TestCaseController {
@MsAuditLog(module = "track_test_case", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#testCaseId)", msClass = TestCaseService.class) @MsAuditLog(module = "track_test_case", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#testCaseId)", msClass = TestCaseService.class)
public int deleteTestCase(@PathVariable String testCaseId) { public int deleteTestCase(@PathVariable String testCaseId) {
checkPermissionService.checkTestCaseOwner(testCaseId); checkPermissionService.checkTestCaseOwner(testCaseId);
return testCaseService.deleteTestCase(testCaseId); return testCaseService.deleteTestCaseBySameVersion(testCaseId);
} }
@PostMapping("/deleteToGc/{testCaseId}") @PostMapping("/deleteToGc/{testCaseId}")

View File

@ -774,9 +774,7 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
} }
public long trashCount(String projectId) { public long trashCount(String projectId) {
TestCaseExample testCaseExample = new TestCaseExample(); return extTestCaseMapper.trashCount(projectId);
testCaseExample.createCriteria().andProjectIdEqualTo(projectId).andStatusEqualTo("Trash");
return testCaseMapper.countByExample(testCaseExample);
} }
public void minderEdit(TestCaseMinderEditRequest request) { public void minderEdit(TestCaseMinderEditRequest request) {

View File

@ -9,6 +9,7 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.ApiScenarioRequest; import io.metersphere.api.dto.automation.ApiScenarioRequest;
import io.metersphere.api.dto.automation.ScenarioStatus;
import io.metersphere.api.dto.definition.ApiTestCaseDTO; import io.metersphere.api.dto.definition.ApiTestCaseDTO;
import io.metersphere.api.dto.definition.ApiTestCaseRequest; import io.metersphere.api.dto.definition.ApiTestCaseRequest;
import io.metersphere.api.service.ApiAutomationService; import io.metersphere.api.service.ApiAutomationService;
@ -491,6 +492,24 @@ public class TestCaseService {
return testCaseMapper.deleteByPrimaryKey(testCaseId); return testCaseMapper.deleteByPrimaryKey(testCaseId);
} }
public int deleteTestCaseBySameVersion(String testCaseId) {
TestCase testCase = testCaseMapper.selectByPrimaryKey(testCaseId);
if (testCase == null) {
return 0;
}
if (StringUtils.isNotBlank(testCase.getRefId())) {
TestCaseExample testCaseExample = new TestCaseExample();
testCaseExample.createCriteria().andRefIdEqualTo(testCase.getRefId());
// 因为删除
List<String> sameVersionIds = testCaseMapper.selectByExample(testCaseExample).stream().map(TestCase::getId).collect(Collectors.toList());
AtomicInteger integer = new AtomicInteger(0);
sameVersionIds.forEach(id -> integer.getAndAdd(deleteTestCase(id)));
return integer.get();
} else {
return deleteTestCase(testCaseId);
}
}
private void deleteFollows(String testCaseId) { private void deleteFollows(String testCaseId) {
TestCaseFollowExample example = new TestCaseFollowExample(); TestCaseFollowExample example = new TestCaseFollowExample();
example.createCriteria().andCaseIdEqualTo(testCaseId); example.createCriteria().andCaseIdEqualTo(testCaseId);
@ -2082,8 +2101,14 @@ public class TestCaseService {
//检查原来模块是否还在 //检查原来模块是否还在
example = new TestCaseExample(); example = new TestCaseExample();
// 关联版本之后必须查询每一个数据的所有版本依次还原
example.createCriteria().andIdIn(request.getIds()); example.createCriteria().andIdIn(request.getIds());
List<TestCase> reductionCaseList = testCaseMapper.selectByExample(example); List<TestCase> reductionCaseList = testCaseMapper.selectByExample(example);
List<String> refIds = reductionCaseList.stream().map(TestCase::getRefId).collect(Collectors.toList());
example.clear();
example.createCriteria().andRefIdIn(refIds);
reductionCaseList = testCaseMapper.selectByExample(example);
request.setIds(reductionCaseList.stream().map(TestCase::getId).collect(Collectors.toList()));
Map<String, List<TestCase>> nodeMap = reductionCaseList.stream().collect(Collectors.groupingBy(TestCase::getNodeId)); Map<String, List<TestCase>> nodeMap = reductionCaseList.stream().collect(Collectors.groupingBy(TestCase::getNodeId));
for (Map.Entry<String, List<TestCase>> entry : nodeMap.entrySet()) { for (Map.Entry<String, List<TestCase>> entry : nodeMap.entrySet()) {
String nodeId = entry.getKey(); String nodeId = entry.getKey();
@ -2383,6 +2408,13 @@ public class TestCaseService {
} }
QueryTestCaseRequest request = new QueryTestCaseRequest(); QueryTestCaseRequest request = new QueryTestCaseRequest();
request.setRefId(testCase.getRefId()); request.setRefId(testCase.getRefId());
if (ScenarioStatus.Trash.name().equalsIgnoreCase(testCase.getStatus())) {
request.setFilters(new HashMap<String, List<String>>() {{
put("status", new ArrayList() {{
add(ScenarioStatus.Trash.name());
}});
}});
}
return this.listTestCase(request); return this.listTestCase(request);
} }

@ -1 +1 @@
Subproject commit 284ed8efddbec514b00d8116d21ed4918a871dc8 Subproject commit ee5cf6abb8595938c253274659443a12ac84b227

View File

@ -24,22 +24,29 @@
<ms-main-container> <ms-main-container>
<el-tabs v-model="activeName" @tab-click="addTab" @tab-remove="closeConfirm"> <el-tabs v-model="activeName" @tab-click="addTab" @tab-remove="closeConfirm">
<el-tab-pane name="trash" v-if="trashEnable" :label="$t('commons.trash')"> <el-tab-pane name="trash" v-if="trashEnable" :label="$t('commons.trash')">
<test-case-list <ms-tab-button
:checkRedirectID="checkRedirectID" :isShowChangeButton="false">
:isRedirectEdit="isRedirectEdit" <template v-slot:version>
:tree-nodes="treeNodes" <version-select v-xpack :project-id="projectId" @changeVersion="changeTrashVersion" margin-left="-10"/>
:trash-enable="true" </template>
@refreshTable="refresh" <test-case-list
@testCaseEdit="editTestCase" :checkRedirectID="checkRedirectID"
@testCaseCopy="copyTestCase" :isRedirectEdit="isRedirectEdit"
@testCaseDetail="showTestCaseDetail" :tree-nodes="treeNodes"
@getTrashList="getTrashList" :trash-enable="true"
@getPublicList="getPublicList" :current-version="currentTrashVersion"
@refresh="refresh" @refreshTable="refresh"
@refreshAll="refreshAll" @testCaseEdit="editTestCase"
@setCondition="setCondition" @testCaseCopy="copyTestCase"
ref="testCaseTrashList"> @testCaseDetail="showTestCaseDetail"
</test-case-list> @getTrashList="getTrashList"
@getPublicList="getPublicList"
@refresh="refresh"
@refreshAll="refreshAll"
@setCondition="setCondition"
ref="testCaseTrashList">
</test-case-list>
</ms-tab-button>
</el-tab-pane> </el-tab-pane>
<el-tab-pane name="public" v-if="publicEnable" :label="$t('project.case_public')"> <el-tab-pane name="public" v-if="publicEnable" :label="$t('project.case_public')">
<test-case-list <test-case-list
@ -230,6 +237,7 @@ export default {
publicTotal: 0, publicTotal: 0,
tmpPath: null, tmpPath: null,
currentVersion: null, currentVersion: null,
currentTrashVersion: null,
}; };
}, },
mounted() { mounted() {
@ -635,6 +643,9 @@ export default {
changeVersion(currentVersion) { changeVersion(currentVersion) {
this.currentVersion = currentVersion || null; this.currentVersion = currentVersion || null;
}, },
changeTrashVersion(currentVersion) {
this.currentTrashVersion = currentVersion || null;
},
checkout(testCase, item) { checkout(testCase, item) {
Object.assign(item.testCaseInfo, testCase) Object.assign(item.testCaseInfo, testCase)
// copy // copy

View File

@ -540,6 +540,7 @@ export default {
this.$emit('testCaseEdit', testCase); this.$emit('testCaseEdit', testCase);
}); });
} }
this.getVersionOptions();
}, },
activated() { activated() {
this.getTemplateField(); this.getTemplateField();
@ -728,7 +729,12 @@ export default {
this.condition.filters.priority = this.condition.filters['用例等级']; this.condition.filters.priority = this.condition.filters['用例等级'];
this.condition.filters.status = this.condition.filters['用例状态']; this.condition.filters.status = this.condition.filters['用例状态'];
if (this.trashEnable) { if (this.trashEnable) {
//
let versionIds = this.condition.filters.version_id;
this.condition.filters = {status: ["Trash"]}; this.condition.filters = {status: ["Trash"]};
if (versionIds) {
this.condition.filters.version_id = versionIds;
}
} }
if (this.projectId) { if (this.projectId) {
this.condition.projectId = this.projectId; this.condition.projectId = this.projectId;

@ -1 +1 @@
Subproject commit 6e2a9167d1dcfb7f359ccc8114b5fa5188f23950 Subproject commit 964acf775191a3243b1da5225352da8c1d998235