refactor(接口测试): 批量执行场景支持跨项目选环境

--bug=1028821 --user=赵勇 【接口测试】场景详情含跨项目复制和引用场景、case、api-未选择当前项目和更多项目环境-场景列表批量执行-只显示当前项目 https://www.tapd.cn/55049933/s/1404474

Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2023-08-16 14:06:28 +08:00 committed by fit2-zhao
parent 4a71b5d3c4
commit 040a3d264f
1 changed files with 9 additions and 4 deletions

View File

@ -2350,9 +2350,8 @@ public class ApiScenarioService {
public Map<String, List<String>> getProjectEnvMap(RunScenarioRequest request) {
ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiScenarioMapper.selectIdsByQuery(query));
List<String> ids = request.getIds();
ApiScenarioExample example = new ApiScenarioExample();
example.createCriteria().andIdIn(ids);
example.createCriteria().andIdIn(request.getIds());
List<ApiScenarioWithBLOBs> apiScenarios = apiScenarioMapper.selectByExampleWithBLOBs(example);
Map<String, List<String>> projectEnvMap = new HashMap<>();
apiScenarios.forEach(item -> {
@ -2360,8 +2359,7 @@ public class ApiScenarioService {
JSONObject jsonObject = JSONUtil.parseObject(item.getEnvironmentJson());
Map<String, Object> projectIdEnvMap = jsonObject.toMap();
if (MapUtils.isNotEmpty(projectIdEnvMap)) {
Set<String> projectIds = projectIdEnvMap.keySet();
projectIds.forEach(t -> {
projectIdEnvMap.keySet().forEach(t -> {
List<String> envIds = projectEnvMap.get(t);
if (CollectionUtils.isNotEmpty(envIds)) {
if (!envIds.contains(projectIdEnvMap.get(t).toString())) {
@ -2376,6 +2374,13 @@ public class ApiScenarioService {
});
}
}
// 未选择环境的项目
List<String> scenarioProjectIds = ElementUtil.getProjectIds(item.getScenarioDefinition());
scenarioProjectIds.forEach(id -> {
if (!projectEnvMap.containsKey(id)) {
projectEnvMap.put(id, new ArrayList<>());
}
});
});
return projectEnvMap;
}