fix(接口测试): 优化批量查询环境的地方
--bug=1020204 --user=宋天阳 [测试跟踪] github#20073升级到2.3.1测试跟踪--测试计划-报告打开报错误 https://www.tapd.cn/55049933/s/1304179
This commit is contained in:
parent
23779785c9
commit
58a08b9ebe
|
@ -2969,6 +2969,41 @@ public class ApiDefinitionService {
|
||||||
return returnMap;
|
return returnMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, List<String>> getProjectEnvNameByEnvConfig(Map<String, List<String>> projectEnvConfigMap) {
|
||||||
|
Map<String, List<String>> returnMap = new HashMap<>();
|
||||||
|
if (MapUtils.isNotEmpty(projectEnvConfigMap)) {
|
||||||
|
for (Map.Entry<String, List<String>> entry : projectEnvConfigMap.entrySet()) {
|
||||||
|
String projectId = entry.getKey();
|
||||||
|
List<String> configList = entry.getValue();
|
||||||
|
Project project = baseProjectService.getProjectById(projectId);
|
||||||
|
List<String> envIdList = new ArrayList<>();
|
||||||
|
configList.forEach(envConfig -> {
|
||||||
|
RunModeConfigDTO runModeConfigDTO = null;
|
||||||
|
try {
|
||||||
|
runModeConfigDTO = JSON.parseObject(envConfig, RunModeConfigDTO.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogUtil.error("解析" + envConfig + "为RunModeConfigDTO时失败!", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(projectId) && runModeConfigDTO != null && MapUtils.isNotEmpty(runModeConfigDTO.getEnvMap())) {
|
||||||
|
String envId = runModeConfigDTO.getEnvMap().get(projectId);
|
||||||
|
if (!envIdList.contains(envId)) {
|
||||||
|
envIdList.add(envId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
String projectName = project == null ? null : project.getName();
|
||||||
|
if (StringUtils.isNotEmpty(projectName) && CollectionUtils.isNotEmpty(envIdList)) {
|
||||||
|
List<String> envNameList = apiTestEnvironmentService.selectNameByIdList(envIdList);
|
||||||
|
returnMap.put(projectName, envNameList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return returnMap;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ApiDefinition> selectApiDefinitionBydIds(List<String> ids) {
|
public List<ApiDefinition> selectApiDefinitionBydIds(List<String> ids) {
|
||||||
if (CollectionUtils.isEmpty(ids)) {
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
|
|
@ -508,12 +508,19 @@ public class TestPlanApiCaseService {
|
||||||
Map<String, List<String>> result = new LinkedHashMap<>();
|
Map<String, List<String>> result = new LinkedHashMap<>();
|
||||||
if (!CollectionUtils.isEmpty(resourceIds)) {
|
if (!CollectionUtils.isEmpty(resourceIds)) {
|
||||||
List<ApiDefinitionExecResultWithBLOBs> execResults = apiDefinitionExecResultService.selectByResourceIdsAndMaxCreateTime(resourceIds);
|
List<ApiDefinitionExecResultWithBLOBs> execResults = apiDefinitionExecResultService.selectByResourceIdsAndMaxCreateTime(resourceIds);
|
||||||
|
Map<String, List<String>> projectConfigMap = new HashMap<>();
|
||||||
execResults.forEach(item -> {
|
execResults.forEach(item -> {
|
||||||
String envConf = item.getEnvConfig();
|
String envConf = item.getEnvConfig();
|
||||||
String projectId = item.getProjectId();
|
String projectId = item.getProjectId();
|
||||||
Map<String, List<String>> projectEnvMap = apiDefinitionService.getProjectEnvNameByEnvConfig(projectId, envConf);
|
if (projectConfigMap.containsKey(projectId)) {
|
||||||
this.setProjectEnvMap(result, projectEnvMap);
|
projectConfigMap.get(projectId).add(envConf);
|
||||||
|
} else {
|
||||||
|
projectConfigMap.put(projectId, new ArrayList<>() {{
|
||||||
|
this.add(envConf);
|
||||||
|
}});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
Map<String, List<String>> projectEnvMap = apiDefinitionService.getProjectEnvNameByEnvConfig(projectConfigMap);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,4 +13,5 @@ public interface BaseApiTestEnvironmentMapper {
|
||||||
|
|
||||||
List<ApiModuleDTO> getNodeTreeByProjectId(@Param("projectId") String projectId, @Param("protocol") String protocol);
|
List<ApiModuleDTO> getNodeTreeByProjectId(@Param("projectId") String projectId, @Param("protocol") String protocol);
|
||||||
|
|
||||||
|
List<String> selectNameByIdList(@Param("ids") List<String> envIdList);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,16 @@
|
||||||
FROM api_test_environment
|
FROM api_test_environment
|
||||||
WHERE id = #{0}
|
WHERE id = #{0}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectNameByIdList" resultType="java.lang.String">
|
||||||
|
SELECT name
|
||||||
|
FROM api_test_environment
|
||||||
|
WHERE id IN
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="getNodeTreeByProjectId" resultType="io.metersphere.environment.dto.ApiModuleDTO">
|
<select id="getNodeTreeByProjectId" resultType="io.metersphere.environment.dto.ApiModuleDTO">
|
||||||
select * from api_module
|
select * from api_module
|
||||||
where api_module.project_id = #{projectId}
|
where api_module.project_id = #{projectId}
|
||||||
|
|
|
@ -828,4 +828,12 @@ public class BaseEnvironmentService extends NodeTreeService<ApiModuleDTO> {
|
||||||
}
|
}
|
||||||
return returnMap;
|
return returnMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> selectNameByIdList(List<String> envIdList) {
|
||||||
|
if (CollectionUtils.isNotEmpty(envIdList)) {
|
||||||
|
return baseApiTestEnvironmentMapper.selectNameByIdList(envIdList);
|
||||||
|
} else {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue