fix(接口测试): 修复接口列表环境为空报错的缺陷

This commit is contained in:
wxg0103 2022-03-15 18:26:34 +08:00 committed by fit2-zhao
parent 9bfadd32fd
commit f5c30c5af2
1 changed files with 7 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import io.metersphere.base.domain.ApiTestEnvironmentExample;
import io.metersphere.base.mapper.ApiDefinitionEnvMapper;
import io.metersphere.base.mapper.ApiTestEnvironmentMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -42,12 +43,14 @@ public class ApiDefinitionEnvService {
if (CollectionUtils.isNotEmpty(list)) {
ApiTestEnvironmentExample environmentExample = new ApiTestEnvironmentExample();
if (StringUtils.isNotEmpty(list.get(0).getEnvId())) {
environmentExample.createCriteria().andProjectIdEqualTo(projectId).andIdEqualTo(list.get(0).getEnvId());
long count = apiTestEnvironmentMapper.countByExample(environmentExample);
if (count > 0) {
return list.get(0);
}
}
}
return null;
}