refactor(项目管理): 优化获取环境列表接口
This commit is contained in:
parent
ef622cfc57
commit
ec3ef79081
|
@ -130,4 +130,10 @@ public class EnvironmentController {
|
||||||
environmentService.editPos(request);
|
environmentService.editPos(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get-options/{projectId}")
|
||||||
|
@Operation(summary = "项目管理-环境-环境目录-列表")
|
||||||
|
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ)
|
||||||
|
public List<EnvironmentOptionsDTO> list(@PathVariable String projectId) {
|
||||||
|
return environmentService.listOption(projectId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package io.metersphere.project.controller;
|
||||||
|
|
||||||
|
|
||||||
import io.metersphere.project.dto.environment.EnvironmentFilterRequest;
|
import io.metersphere.project.dto.environment.EnvironmentFilterRequest;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentGroupInfo;
|
import io.metersphere.project.dto.environment.EnvironmentGroupDTO;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentGroupRequest;
|
import io.metersphere.project.dto.environment.EnvironmentGroupRequest;
|
||||||
import io.metersphere.project.service.EnvironmentGroupLogService;
|
import io.metersphere.project.service.EnvironmentGroupLogService;
|
||||||
import io.metersphere.project.service.EnvironmentGroupService;
|
import io.metersphere.project.service.EnvironmentGroupService;
|
||||||
|
@ -68,7 +68,7 @@ public class EnvironmentGroupController {
|
||||||
@Operation(summary = "项目管理-环境组-详情")
|
@Operation(summary = "项目管理-环境组-详情")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ)
|
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ)
|
||||||
@CheckOwner(resourceId = "#id", resourceType = "environment_group")
|
@CheckOwner(resourceId = "#id", resourceType = "environment_group")
|
||||||
public List<EnvironmentGroupInfo> get(@PathVariable String id) {
|
public EnvironmentGroupDTO get(@PathVariable String id) {
|
||||||
return environmentGroupService.get(id);
|
return environmentGroupService.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package io.metersphere.project.dto.environment;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EnvironmentGroupDTO implements Serializable {
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Schema(description = "环境组名")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "所属项目id")
|
||||||
|
private String projectId;
|
||||||
|
|
||||||
|
@Schema(description = "环境组描述")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Schema(description = "创建人")
|
||||||
|
private String createUser;
|
||||||
|
|
||||||
|
@Schema(description = "修改人")
|
||||||
|
private String updateUser;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
private Long createTime;
|
||||||
|
|
||||||
|
@Schema(description = "更新时间")
|
||||||
|
private Long updateTime;
|
||||||
|
|
||||||
|
@Schema(description = "自定义排序")
|
||||||
|
private Long pos;
|
||||||
|
|
||||||
|
@Schema(description = "环境组详情")
|
||||||
|
private List<EnvironmentGroupInfo> environmentGroupInfo;
|
||||||
|
|
||||||
|
}
|
|
@ -12,8 +12,6 @@ public class EnvironmentGroupProjectDTO implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@Schema(description = "环境组id")
|
|
||||||
private String environmentGroupId;
|
|
||||||
@Schema(description = "环境id", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "环境id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String environmentId;
|
private String environmentId;
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package io.metersphere.project.dto.environment;
|
||||||
|
|
||||||
|
import io.metersphere.project.dto.environment.http.HttpConfig;
|
||||||
|
import io.metersphere.sdk.domain.Environment;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EnvironmentOptionsDTO extends Environment implements Serializable {
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Schema(description = "ID")
|
||||||
|
private String id;
|
||||||
|
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
private String projectId;
|
||||||
|
@Schema(description = "环境名称")
|
||||||
|
private String name;
|
||||||
|
@Schema(description = "域名")
|
||||||
|
private List<HttpConfig> domain;
|
||||||
|
@Schema(description = "是否是mock环境")
|
||||||
|
private Boolean mock;
|
||||||
|
@Schema(description = "描述")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
}
|
|
@ -23,7 +23,7 @@ public class HttpConfig implements Serializable {
|
||||||
@Schema(description = "环境域名")
|
@Schema(description = "环境域名")
|
||||||
private String url;
|
private String url;
|
||||||
/**
|
/**
|
||||||
* 启用条件
|
* 启用条件
|
||||||
* {@link HttpConfigMatchType}
|
* {@link HttpConfigMatchType}
|
||||||
*/
|
*/
|
||||||
@Schema(description = "启用条件 NONE/MODULE/PATH")
|
@Schema(description = "启用条件 NONE/MODULE/PATH")
|
||||||
|
@ -37,6 +37,8 @@ public class HttpConfig implements Serializable {
|
||||||
private HttpConfigModuleMatchRule moduleMatchRule = new HttpConfigModuleMatchRule();
|
private HttpConfigModuleMatchRule moduleMatchRule = new HttpConfigModuleMatchRule();
|
||||||
@Schema(description = "请求头")
|
@Schema(description = "请求头")
|
||||||
private List<@Valid KeyValueEnableParam> headers = new ArrayList<>(0);
|
private List<@Valid KeyValueEnableParam> headers = new ArrayList<>(0);
|
||||||
|
@Schema(description = "描述")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
|
||||||
public boolean isModuleMatchRule() {
|
public boolean isModuleMatchRule() {
|
||||||
|
|
|
@ -13,12 +13,12 @@ import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.sdk.mapper.EnvironmentGroupMapper;
|
import io.metersphere.sdk.mapper.EnvironmentGroupMapper;
|
||||||
import io.metersphere.sdk.mapper.EnvironmentGroupRelationMapper;
|
import io.metersphere.sdk.mapper.EnvironmentGroupRelationMapper;
|
||||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||||
|
import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.domain.UserRoleRelationExample;
|
import io.metersphere.system.domain.UserRoleRelationExample;
|
||||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||||
import io.metersphere.system.mapper.OrganizationMapper;
|
|
||||||
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
import io.metersphere.system.mapper.UserRoleRelationMapper;
|
||||||
import io.metersphere.system.uid.IDGenerator;
|
import io.metersphere.system.uid.IDGenerator;
|
||||||
import io.metersphere.system.utils.ServiceUtils;
|
import io.metersphere.system.utils.ServiceUtils;
|
||||||
|
@ -29,7 +29,6 @@ import org.apache.ibatis.session.ExecutorType;
|
||||||
import org.apache.ibatis.session.SqlSession;
|
import org.apache.ibatis.session.SqlSession;
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.mybatis.spring.SqlSessionUtils;
|
import org.mybatis.spring.SqlSessionUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@ -57,15 +56,13 @@ public class EnvironmentGroupService {
|
||||||
@Resource
|
@Resource
|
||||||
private ExtProjectMapper extProjectMapper;
|
private ExtProjectMapper extProjectMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private OrganizationMapper organizationMapper;
|
|
||||||
@Resource
|
|
||||||
private EnvironmentService environmentService;
|
private EnvironmentService environmentService;
|
||||||
|
|
||||||
public static final Long ORDER_STEP = 5000L;
|
public static final Long ORDER_STEP = 5000L;
|
||||||
|
|
||||||
public EnvironmentGroup add(EnvironmentGroupRequest request, String userId) {
|
public EnvironmentGroup add(EnvironmentGroupRequest request, String userId) {
|
||||||
EnvironmentGroup environmentGroup = new EnvironmentGroup();
|
EnvironmentGroup environmentGroup = new EnvironmentGroup();
|
||||||
BeanUtils.copyProperties(request, environmentGroup);
|
BeanUtils.copyBean(environmentGroup, request);
|
||||||
environmentGroup.setId(IDGenerator.nextStr());
|
environmentGroup.setId(IDGenerator.nextStr());
|
||||||
this.checkEnvironmentGroup(environmentGroup);
|
this.checkEnvironmentGroup(environmentGroup);
|
||||||
|
|
||||||
|
@ -173,8 +170,9 @@ public class EnvironmentGroupService {
|
||||||
return extEnvironmentMapper.groupList(request.getKeyword(), request.getProjectId());
|
return extEnvironmentMapper.groupList(request.getKeyword(), request.getProjectId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EnvironmentGroupInfo> get(String groupId) {
|
public EnvironmentGroupDTO get(String groupId) {
|
||||||
checkEnvironmentGroup(groupId);
|
EnvironmentGroupDTO environmentGroupDTO = new EnvironmentGroupDTO();
|
||||||
|
EnvironmentGroup environmentGroup = checkEnvironmentGroup(groupId);
|
||||||
EnvironmentGroupRelationExample example = new EnvironmentGroupRelationExample();
|
EnvironmentGroupRelationExample example = new EnvironmentGroupRelationExample();
|
||||||
example.createCriteria().andEnvironmentGroupIdEqualTo(groupId);
|
example.createCriteria().andEnvironmentGroupIdEqualTo(groupId);
|
||||||
List<EnvironmentGroupRelation> relations = environmentGroupRelationMapper.selectByExample(example);
|
List<EnvironmentGroupRelation> relations = environmentGroupRelationMapper.selectByExample(example);
|
||||||
|
@ -201,7 +199,9 @@ public class EnvironmentGroupService {
|
||||||
}
|
}
|
||||||
result.add(dto);
|
result.add(dto);
|
||||||
});
|
});
|
||||||
return result;
|
BeanUtils.copyBean(environmentGroupDTO, environmentGroup);
|
||||||
|
environmentGroupDTO.setEnvironmentGroupInfo(result);
|
||||||
|
return environmentGroupDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OptionDTO> getProject(String userId, String organizationId) {
|
public List<OptionDTO> getProject(String userId, String organizationId) {
|
||||||
|
|
|
@ -479,4 +479,29 @@ public class EnvironmentService {
|
||||||
example.createCriteria().andIdIn(envIds);
|
example.createCriteria().andIdIn(envIds);
|
||||||
return environmentBlobMapper.selectByExampleWithBLOBs(example);
|
return environmentBlobMapper.selectByExampleWithBLOBs(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<EnvironmentOptionsDTO> listOption(String projectId) {
|
||||||
|
List<EnvironmentOptionsDTO> environmentOptions = new ArrayList<>();
|
||||||
|
EnvironmentExample environmentExample = new EnvironmentExample();
|
||||||
|
environmentExample.createCriteria().andProjectIdEqualTo(projectId);
|
||||||
|
List<Environment> environments = environmentMapper.selectByExample(environmentExample);
|
||||||
|
List<String> ids = environments.stream().map(Environment::getId).toList();
|
||||||
|
EnvironmentBlobExample environmentBlobExample = new EnvironmentBlobExample();
|
||||||
|
environmentBlobExample.createCriteria().andIdIn(ids);
|
||||||
|
List<EnvironmentBlob> environmentBlobs = environmentBlobMapper.selectByExampleWithBLOBs(environmentBlobExample);
|
||||||
|
Map<String, EnvironmentBlob> environmentBlobMap = environmentBlobs.stream().collect(Collectors.toMap(EnvironmentBlob::getId, Function.identity()));
|
||||||
|
environments.forEach(environment -> {
|
||||||
|
EnvironmentOptionsDTO environmentOptionsDTO = new EnvironmentOptionsDTO();
|
||||||
|
BeanUtils.copyBean(environmentOptionsDTO, environment);
|
||||||
|
EnvironmentBlob environmentBlob = environmentBlobMap.get(environment.getId());
|
||||||
|
if (environmentBlob != null) {
|
||||||
|
EnvironmentConfig environmentConfig = JSON.parseObject(new String(environmentBlob.getConfig()), EnvironmentConfig.class);
|
||||||
|
if (environmentConfig != null && CollectionUtils.isNotEmpty(environmentConfig.getHttpConfig())) {
|
||||||
|
environmentOptionsDTO.setDomain(environmentConfig.getHttpConfig());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
environmentOptions.add(environmentOptionsDTO);
|
||||||
|
});
|
||||||
|
return environmentOptions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
private static final String validate = prefix + "/database/validate";
|
private static final String validate = prefix + "/database/validate";
|
||||||
private static final String getOptions = prefix + "/database/driver-options/";
|
private static final String getOptions = prefix + "/database/driver-options/";
|
||||||
private static final String SCRIPTS = prefix + "/scripts/{0}";
|
private static final String SCRIPTS = prefix + "/scripts/{0}";
|
||||||
|
private static final String listOption = prefix + "/get-options/";
|
||||||
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
private static final ResultMatcher BAD_REQUEST_MATCHER = status().isBadRequest();
|
||||||
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
|
||||||
private static String MOCKID;
|
private static String MOCKID;
|
||||||
|
@ -1200,4 +1201,12 @@ public class EnvironmentControllerTests extends BaseTest {
|
||||||
request.setCreateUser(ADMIN.name());
|
request.setCreateUser(ADMIN.name());
|
||||||
return pluginService.add(request, mockMultipartFile);
|
return pluginService.add(request, mockMultipartFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Order(17)
|
||||||
|
public void testGetOptions() throws Exception {
|
||||||
|
MvcResult mvcResult = responseGet(listOption + DEFAULT_PROJECT_ID);
|
||||||
|
List<EnvironmentOptionsDTO> options = getResultDataArray(mvcResult, EnvironmentOptionsDTO.class);
|
||||||
|
Assertions.assertFalse(options.isEmpty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,7 +208,7 @@ public class EnvironmentGroupControllerTests extends BaseTest {
|
||||||
public void testGet() throws Exception {
|
public void testGet() throws Exception {
|
||||||
//环境不存在
|
//环境不存在
|
||||||
MvcResult mvcResult = this.responseGet(get + getEnvironmentGroup());
|
MvcResult mvcResult = this.responseGet(get + getEnvironmentGroup());
|
||||||
List<EnvironmentGroupInfo> response = parseObjectFromMvcResult(mvcResult, List.class);
|
EnvironmentGroupDTO response = parseObjectFromMvcResult(mvcResult, EnvironmentGroupDTO.class);
|
||||||
Assertions.assertNotNull(response);
|
Assertions.assertNotNull(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue