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