fix(测试跟踪): 场景自定义ID开启时功能用例关联显示有误

--bug=1028007 --user=宋昌昌 [接口测试]github#25700接口测试场景用例都自定义了ID,但在测试跟踪-功能用例下去关联场景用例时,显示的ID还是默认的 https://www.tapd.cn/55049933/s/1396370
This commit is contained in:
song-cc-rock 2023-07-24 10:59:35 +08:00 committed by fit2-zhao
parent 3ef7b12f39
commit d43cb36b3c
4 changed files with 50 additions and 6 deletions

View File

@ -941,7 +941,8 @@
atc.step_total, atc.step_total,
atc. STATUS, atc. STATUS,
atc.tags, atc.tags,
atc.version_id atc.version_id,
atc.custom_num
FROM FROM
api_scenario atc api_scenario atc
LEFT JOIN test_case_test tct ON atc.id = tct.test_id LEFT JOIN test_case_test tct ON atc.id = tct.test_id

View File

@ -59,6 +59,16 @@ public class BaseProjectApplicationService {
return projectApplications.get(0); return projectApplications.get(0);
} }
public List<ProjectApplication> getProjectApplicationByIds(List<String> projectIds, String type) {
ProjectApplicationExample projectApplicationExample = new ProjectApplicationExample();
projectApplicationExample.createCriteria().andProjectIdIn(projectIds).andTypeEqualTo(type);
List<ProjectApplication> projectApplications = projectApplicationMapper.selectByExample(projectApplicationExample);
if (CollectionUtils.isEmpty(projectApplications)) {
return new ArrayList<>();
}
return projectApplications;
}
public HashMap<String, String> getProjectConfigMap(String projectId) { public HashMap<String, String> getProjectConfigMap(String projectId) {
ProjectApplicationExample example = new ProjectApplicationExample(); ProjectApplicationExample example = new ProjectApplicationExample();
example.createCriteria().andProjectIdEqualTo(projectId); example.createCriteria().andProjectIdEqualTo(projectId);
@ -153,6 +163,17 @@ public class BaseProjectApplicationService {
return config; return config;
} }
/**
* 返回多个项目下某配置的值
*
* @param projectIds 项目ID集合
* @param type ProjectApplicationType中某项目配置
* @return ProjectConfigGroupDTOs 项目ID和配置集合
*/
public List<ProjectApplication> getProjectApplicationTypeVals(List<String> projectIds, String type) {
return this.getProjectApplicationByIds(projectIds, type);
}
private Object valueOf(Class<?> type, String value) { private Object valueOf(Class<?> type, String value) {
//todo 其他类型 //todo 其他类型
if (type == Boolean.class) { if (type == Boolean.class) {

View File

@ -2804,6 +2804,7 @@ public class TestCaseService {
Set<String> serviceIdSet = DiscoveryUtil.getServiceIdSet(); Set<String> serviceIdSet = DiscoveryUtil.getServiceIdSet();
List<String> scenarioProjectIds = new ArrayList<>();
List<String> projectIds = new ArrayList<>(); List<String> projectIds = new ArrayList<>();
List<String> versionIds = new ArrayList<>(); List<String> versionIds = new ArrayList<>();
List<ApiTestCase> apiCases = new ArrayList<>(); List<ApiTestCase> apiCases = new ArrayList<>();
@ -2817,7 +2818,8 @@ public class TestCaseService {
apiScenarios = relevanceApiCaseService.getScenarioCaseByIds( apiScenarios = relevanceApiCaseService.getScenarioCaseByIds(
getTestIds(testCaseTests, TestCaseTestType.automation.name())); getTestIds(testCaseTests, TestCaseTestType.automation.name()));
projectIds.addAll(apiCases.stream().map(s -> s.getProjectId()).collect(Collectors.toList())); projectIds.addAll(apiCases.stream().map(s -> s.getProjectId()).collect(Collectors.toList()));
projectIds.addAll(apiScenarios.stream().map(s -> s.getProjectId()).collect(Collectors.toList())); scenarioProjectIds = apiScenarios.stream().map(s -> s.getProjectId()).distinct().collect(Collectors.toList());
projectIds.addAll(scenarioProjectIds);
versionIds.addAll(apiCases.stream().map(s -> s.getVersionId()).collect(Collectors.toList())); versionIds.addAll(apiCases.stream().map(s -> s.getVersionId()).collect(Collectors.toList()));
versionIds.addAll(apiScenarios.stream().map(s -> s.getVersionId()).collect(Collectors.toList())); versionIds.addAll(apiScenarios.stream().map(s -> s.getVersionId()).collect(Collectors.toList()));
} }
@ -2858,13 +2860,22 @@ public class TestCaseService {
Map<String, String> versionNameMap = projectVersions.stream().collect(Collectors.toMap(ProjectVersion::getId, ProjectVersion::getName)); Map<String, String> versionNameMap = projectVersions.stream().collect(Collectors.toMap(ProjectVersion::getId, ProjectVersion::getName));
// 获取项目下自定义场景ID配置
List<ProjectApplication> projectApplicationTypeVals = new ArrayList<>();
if (CollectionUtils.isNotEmpty(scenarioProjectIds)) {
projectApplicationTypeVals = baseProjectApplicationService.getProjectApplicationTypeVals(scenarioProjectIds, ProjectApplicationType.SCENARIO_CUSTOM_NUM.name());
}
Map<String, String> customTypeMap = projectApplicationTypeVals.stream().collect(Collectors.toMap(ProjectApplication::getProjectId, ProjectApplication::getTypeValue));
List<TestCaseTestDao> testCaseTestList = new ArrayList<>(); List<TestCaseTestDao> testCaseTestList = new ArrayList<>();
apiCases.forEach(item -> { apiCases.forEach(item -> {
getTestCaseTestDaoList(TestCaseTestType.testcase.name(), item.getNum(), item.getName(), item.getId(), projectNameMap.get(item.getProjectId()), versionNameMap.get(item.getVersionId()), getTestCaseTestDaoList(TestCaseTestType.testcase.name(), item.getNum(), item.getName(), item.getId(), projectNameMap.get(item.getProjectId()), versionNameMap.get(item.getVersionId()),
testCaseTestList, testCaseTestsMap); testCaseTestList, testCaseTestsMap);
}); });
apiScenarios.forEach(item -> { apiScenarios.forEach(item -> {
getTestCaseTestDaoList(TestCaseTestType.automation.name(), item.getNum(), item.getName(), item.getId(), projectNameMap.get(item.getProjectId()), versionNameMap.get(item.getVersionId()), // 所属项目是否开启自定义场景ID
String customType = customTypeMap.get(item.getProjectId());
getTestCaseTestDaoList(TestCaseTestType.automation.name(), StringUtils.equals(customType, "true") ? item.getCustomNum() : item.getNum(), item.getName(), item.getId(), projectNameMap.get(item.getProjectId()), versionNameMap.get(item.getVersionId()),
testCaseTestList, testCaseTestsMap); testCaseTestList, testCaseTestsMap);
}); });
apiLoadTests.forEach(item -> { apiLoadTests.forEach(item -> {

View File

@ -38,8 +38,8 @@
@refresh="initTable" @refresh="initTable"
ref="table" ref="table"
> >
<ms-table-column prop="num" label="ID" width="100px" sortable="true">
</ms-table-column> <ms-table-column :prop="scenarioCustomNumEnable ? 'customNum' : 'num'" label="ID" width="100px" sortable="true" />
<ms-table-column <ms-table-column
prop="name" prop="name"
@ -131,6 +131,7 @@ import MxVersionSelect from "metersphere-frontend/src/components/version/MxVersi
import { getTestCaseRelevanceScenarioList } from "@/api/testCase"; import { getTestCaseRelevanceScenarioList } from "@/api/testCase";
import {getTagToolTips, parseColumnTag} from "@/business/case/test-case"; import {getTagToolTips, parseColumnTag} from "@/business/case/test-case";
import {getCurrentProjectID} from "metersphere-frontend/src/utils/token"; import {getCurrentProjectID} from "metersphere-frontend/src/utils/token";
import {getProjectConfig} from "@/api/project";
export default { export default {
name: "CaseRelateScenarioList", name: "CaseRelateScenarioList",
@ -166,7 +167,8 @@ export default {
pageSize: 10, pageSize: 10,
total: 0, total: 0,
versionFilters: [], versionFilters: [],
refreshBySearch: false refreshBySearch: false,
scenarioCustomNumEnable: false,
}; };
}, },
props: { props: {
@ -183,6 +185,7 @@ export default {
this.$emit('setCondition', this.condition); this.$emit('setCondition', this.condition);
this.getVersionOptions(); this.getVersionOptions();
this.initTable(); this.initTable();
this.getCustomNumEnable();
}, },
watch: { watch: {
selectNodeIds() { selectNodeIds() {
@ -192,6 +195,7 @@ export default {
this.condition.versionId = null; this.condition.versionId = null;
this.getVersionOptions(); this.getVersionOptions();
this.initTable(this.projectId); this.initTable(this.projectId);
this.getCustomNumEnable();
}, },
}, },
computed: { computed: {
@ -204,6 +208,13 @@ export default {
}, },
}, },
methods: { methods: {
getCustomNumEnable() {
getProjectConfig(this.projectId, '/SCENARIO_CUSTOM_NUM').then((result) => {
if (result.data) {
this.scenarioCustomNumEnable = result.data['scenarioCustomNum'];
}
});
},
selectCountChange(data) { selectCountChange(data) {
this.$emit("selectCountChange", data); this.$emit("selectCountChange", data);
}, },