fix(测试跟踪): 修复测试计划关联场景时由于支持跨页选择项目环境而引起的无法全部添加场景用例的问题

--bug=1024678 --user=宋天阳
[测试跟踪]github#22858测试计划中添加场景用例,全选所有场景(不止一页数据),非当前页的某个场景含多个项目运行环境时,在测试计划中选择环境时无法选择多个项目环境,导致执行测试计划时一直running
https://www.tapd.cn/55049933/s/1354570
This commit is contained in:
song-tianyang 2023-03-22 18:26:02 +08:00 committed by 建国
parent 4f4fb8d8ad
commit 1b3da348c2
6 changed files with 60 additions and 20 deletions

View File

@ -0,0 +1,34 @@
package io.metersphere.api.dto.automation;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Data
public class ScenarioProjectDTO {
private List<String> projectIdList;
private Map<String, List<String>> scenarioProjectIdMap;
public ScenarioProjectDTO() {
this.projectIdList = new ArrayList<>();
this.scenarioProjectIdMap = new HashMap<>();
}
public void merge(ScenarioProjectDTO mergeDTO) {
if (CollectionUtils.isNotEmpty(mergeDTO.getProjectIdList())) {
for (String projectId : mergeDTO.getProjectIdList()) {
if (!this.projectIdList.contains(projectId)) {
projectIdList.add(projectId);
}
}
}
if (MapUtils.isNotEmpty(mergeDTO.getScenarioProjectIdMap())) {
this.scenarioProjectIdMap.putAll(mergeDTO.getScenarioProjectIdMap());
}
}
}

View File

@ -1,5 +1,6 @@
package io.metersphere.commons.utils;
import io.metersphere.api.dto.automation.ScenarioProjectDTO;
import io.metersphere.api.dto.definition.BatchDataCopyRequest;
import io.metersphere.base.domain.ApiScenarioReportResultWithBLOBs;
import org.apache.commons.collections.CollectionUtils;
@ -16,8 +17,8 @@ public class BatchProcessingUtil {
private static final int BATCH_PROCESS_QUANTITY = 1000;
public static List<String> getProjectIdsByScenarioIdList(List<String> scenarioIdList, Function<List<String>, List<String>> func) {
List<String> returnList = new ArrayList<>();
public static ScenarioProjectDTO getProjectIdsByScenarioIdList(List<String> scenarioIdList, Function<List<String>, ScenarioProjectDTO> func) {
ScenarioProjectDTO returnDTO = new ScenarioProjectDTO();
if (CollectionUtils.isNotEmpty(scenarioIdList)) {
int unProcessingCount = scenarioIdList.size();
while (scenarioIdList.size() > BATCH_PROCESS_QUANTITY) {
@ -26,9 +27,9 @@ public class BatchProcessingUtil {
processingList.add(scenarioIdList.get(i));
}
//函数处理
returnList.addAll(func.apply(processingList));
scenarioIdList.removeAll(processingList);
returnDTO.merge(func.apply(processingList));
scenarioIdList.removeAll(processingList);
//如果剩余数量没有发生变化则跳出循环防止出现死循环的情况
if (scenarioIdList.size() == unProcessingCount) {
break;
@ -38,10 +39,10 @@ public class BatchProcessingUtil {
}
if (CollectionUtils.isNotEmpty(scenarioIdList)) {
//剩余待处理数据进行处理
returnList.addAll(func.apply(scenarioIdList));
returnDTO.merge(func.apply(scenarioIdList));
}
}
return returnList;
return returnDTO;
}
public static List<ApiScenarioReportResultWithBLOBs> selectScenarioReportResultByScenarioReportId(List<String> scenarioReportId, Function<List<String>, List<ApiScenarioReportResultWithBLOBs>> func) {

View File

@ -79,7 +79,7 @@ public class TestPlanScenarioCaseController {
}
@PostMapping("/relevance/projectIds")
public List<String> relevanceProjectIds(@RequestBody ApiScenarioRequest request) {
public ScenarioProjectDTO relevanceProjectIds(@RequestBody ApiScenarioRequest request) {
return testPlanScenarioCaseService.relevanceProjectIds(request);
}

View File

@ -178,7 +178,7 @@ public class TestPlanScenarioCaseService {
return PageUtils.setPageInfo(page, apiAutomationService.list(request));
}
public List<String> relevanceProjectIds(ApiScenarioRequest request) {
public ScenarioProjectDTO relevanceProjectIds(ApiScenarioRequest request) {
request.setNotInTestPlan(true);
if (request.getAllowedRepeatCase()) {
request.setNotInTestPlan(false);

View File

@ -2309,19 +2309,17 @@ public class ApiScenarioService {
}
}
public List<String> projectIdInlist(ApiScenarioRequest request) {
public ScenarioProjectDTO projectIdInlist(ApiScenarioRequest request) {
request = this.initRequest(request, true, true);
List<String> scenarioIdList = extApiScenarioMapper.selectIdByScenarioRequest(request);
if (CollectionUtils.isNotEmpty(request.getUnSelectIds())) {
scenarioIdList.removeAll(request.getUnSelectIds());
}
List<String> projectIdList = BatchProcessingUtil.getProjectIdsByScenarioIdList(scenarioIdList, this::getProjectIdsByScenarioIdList);
return projectIdList;
return BatchProcessingUtil.getProjectIdsByScenarioIdList(scenarioIdList, this::getProjectIdsByScenarioIdList);
}
public List<String> getProjectIdsByScenarioIdList(List<String> scenarioIdList) {
List<String> projectIdList = new ArrayList<>();
public ScenarioProjectDTO getProjectIdsByScenarioIdList(List<String> scenarioIdList) {
ScenarioProjectDTO returnDTO = new ScenarioProjectDTO();
if (CollectionUtils.isNotEmpty(scenarioIdList)) {
ApiScenarioExample example = new ApiScenarioExample();
example.createCriteria().andIdIn(scenarioIdList);
@ -2330,14 +2328,15 @@ public class ApiScenarioService {
ScenarioEnv scenarioEnv = apiScenarioEnvService.getApiScenarioEnv(scenario.getScenarioDefinition());
if (CollectionUtils.isNotEmpty(scenarioEnv.getProjectIds())) {
scenarioEnv.getProjectIds().forEach(projectId -> {
if (!projectIdList.contains(projectId)) {
projectIdList.add(projectId);
if (!returnDTO.getProjectIdList().contains(projectId)) {
returnDTO.getProjectIdList().add(projectId);
}
});
}
returnDTO.getScenarioProjectIdMap().put(scenario.getId(), new ArrayList<>(scenarioEnv.getProjectIds()));
}
}
return projectIdList;
return returnDTO;
}

View File

@ -32,7 +32,6 @@
</ms-search>
<ms-table
ref="scenarioTable"
v-loading="result.loading"
:data="tableData"
:condition="condition"
:page-size="pageSize"
@ -355,8 +354,15 @@ export default {
scenarioRelevanceProjectIds(this.condition)
.then((rsp) => {
this.result.loading = false;
let projectIds = rsp.data;
if (rsp.data) {
let projectIds = rsp.data.projectIdList;
projectIds.forEach((d) => this.projectIds.add(d));
let scenarioProjectIdMap = rsp.data.scenarioProjectIdMap;
let scenarioIds = Object.keys(scenarioProjectIdMap);
scenarioIds.forEach((scenarioId) => {
this.map.set(scenarioId, scenarioProjectIdMap[scenarioId]);
});
}
})
.catch(() => {
this.result.loading = false;