diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/EnvironmentController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/EnvironmentController.java index cae71a145e..682641b658 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/EnvironmentController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/EnvironmentController.java @@ -130,4 +130,10 @@ public class EnvironmentController { environmentService.editPos(request); } + @GetMapping("/get-options/{projectId}") + @Operation(summary = "项目管理-环境-环境目录-列表") + @RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ) + public List list(@PathVariable String projectId) { + return environmentService.listOption(projectId); + } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/EnvironmentGroupController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/EnvironmentGroupController.java index d478d66615..477b9871f5 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/EnvironmentGroupController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/EnvironmentGroupController.java @@ -2,7 +2,7 @@ package io.metersphere.project.controller; 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.service.EnvironmentGroupLogService; import io.metersphere.project.service.EnvironmentGroupService; @@ -68,7 +68,7 @@ public class EnvironmentGroupController { @Operation(summary = "项目管理-环境组-详情") @RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ) @CheckOwner(resourceId = "#id", resourceType = "environment_group") - public List get(@PathVariable String id) { + public EnvironmentGroupDTO get(@PathVariable String id) { return environmentGroupService.get(id); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentGroupDTO.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentGroupDTO.java new file mode 100644 index 0000000000..4b80e67119 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentGroupDTO.java @@ -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; + +} \ No newline at end of file diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentGroupProjectDTO.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentGroupProjectDTO.java index 14bf98c23c..e6e090c128 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentGroupProjectDTO.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentGroupProjectDTO.java @@ -12,8 +12,6 @@ public class EnvironmentGroupProjectDTO implements Serializable { @Serial private static final long serialVersionUID = 1L; - @Schema(description = "环境组id") - private String environmentGroupId; @Schema(description = "环境id", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank private String environmentId; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentOptionsDTO.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentOptionsDTO.java new file mode 100644 index 0000000000..503bac9134 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentOptionsDTO.java @@ -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 domain; + @Schema(description = "是否是mock环境") + private Boolean mock; + @Schema(description = "描述") + private String description; + +} diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java index e0b3972e2b..45896b004c 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/http/HttpConfig.java @@ -23,7 +23,7 @@ public class HttpConfig implements Serializable { @Schema(description = "环境域名") private String url; /** - * 启用条件 + * 启用条件 * {@link HttpConfigMatchType} */ @Schema(description = "启用条件 NONE/MODULE/PATH") @@ -37,6 +37,8 @@ public class HttpConfig implements Serializable { private HttpConfigModuleMatchRule moduleMatchRule = new HttpConfigModuleMatchRule(); @Schema(description = "请求头") private List<@Valid KeyValueEnableParam> headers = new ArrayList<>(0); + @Schema(description = "描述") + private String description; public boolean isModuleMatchRule() { diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentGroupService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentGroupService.java index 0c4c0cbce9..bb499975c7 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentGroupService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentGroupService.java @@ -13,12 +13,12 @@ import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.mapper.EnvironmentGroupMapper; import io.metersphere.sdk.mapper.EnvironmentGroupRelationMapper; import io.metersphere.sdk.mapper.EnvironmentMapper; +import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.UserRoleRelationExample; import io.metersphere.system.dto.sdk.OptionDTO; import io.metersphere.system.dto.sdk.request.PosRequest; -import io.metersphere.system.mapper.OrganizationMapper; import io.metersphere.system.mapper.UserRoleRelationMapper; import io.metersphere.system.uid.IDGenerator; 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.SqlSessionFactory; import org.mybatis.spring.SqlSessionUtils; -import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -57,15 +56,13 @@ public class EnvironmentGroupService { @Resource private ExtProjectMapper extProjectMapper; @Resource - private OrganizationMapper organizationMapper; - @Resource private EnvironmentService environmentService; public static final Long ORDER_STEP = 5000L; public EnvironmentGroup add(EnvironmentGroupRequest request, String userId) { EnvironmentGroup environmentGroup = new EnvironmentGroup(); - BeanUtils.copyProperties(request, environmentGroup); + BeanUtils.copyBean(environmentGroup, request); environmentGroup.setId(IDGenerator.nextStr()); this.checkEnvironmentGroup(environmentGroup); @@ -173,8 +170,9 @@ public class EnvironmentGroupService { return extEnvironmentMapper.groupList(request.getKeyword(), request.getProjectId()); } - public List get(String groupId) { - checkEnvironmentGroup(groupId); + public EnvironmentGroupDTO get(String groupId) { + EnvironmentGroupDTO environmentGroupDTO = new EnvironmentGroupDTO(); + EnvironmentGroup environmentGroup = checkEnvironmentGroup(groupId); EnvironmentGroupRelationExample example = new EnvironmentGroupRelationExample(); example.createCriteria().andEnvironmentGroupIdEqualTo(groupId); List relations = environmentGroupRelationMapper.selectByExample(example); @@ -201,7 +199,9 @@ public class EnvironmentGroupService { } result.add(dto); }); - return result; + BeanUtils.copyBean(environmentGroupDTO, environmentGroup); + environmentGroupDTO.setEnvironmentGroupInfo(result); + return environmentGroupDTO; } public List getProject(String userId, String organizationId) { diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java index ba252852fd..c80d1b3603 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/EnvironmentService.java @@ -479,4 +479,29 @@ public class EnvironmentService { example.createCriteria().andIdIn(envIds); return environmentBlobMapper.selectByExampleWithBLOBs(example); } + + public List listOption(String projectId) { + List environmentOptions = new ArrayList<>(); + EnvironmentExample environmentExample = new EnvironmentExample(); + environmentExample.createCriteria().andProjectIdEqualTo(projectId); + List environments = environmentMapper.selectByExample(environmentExample); + List ids = environments.stream().map(Environment::getId).toList(); + EnvironmentBlobExample environmentBlobExample = new EnvironmentBlobExample(); + environmentBlobExample.createCriteria().andIdIn(ids); + List environmentBlobs = environmentBlobMapper.selectByExampleWithBLOBs(environmentBlobExample); + Map 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; + } } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java index 8121f52c79..b17a75c77d 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentControllerTests.java @@ -96,6 +96,7 @@ public class EnvironmentControllerTests extends BaseTest { private static final String validate = prefix + "/database/validate"; private static final String getOptions = prefix + "/database/driver-options/"; 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 ERROR_REQUEST_MATCHER = status().is5xxServerError(); private static String MOCKID; @@ -1200,4 +1201,12 @@ public class EnvironmentControllerTests extends BaseTest { request.setCreateUser(ADMIN.name()); return pluginService.add(request, mockMultipartFile); } + + @Test + @Order(17) + public void testGetOptions() throws Exception { + MvcResult mvcResult = responseGet(listOption + DEFAULT_PROJECT_ID); + List options = getResultDataArray(mvcResult, EnvironmentOptionsDTO.class); + Assertions.assertFalse(options.isEmpty()); + } } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentGroupControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentGroupControllerTests.java index 0055926fba..d231bb1e46 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentGroupControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/EnvironmentGroupControllerTests.java @@ -208,7 +208,7 @@ public class EnvironmentGroupControllerTests extends BaseTest { public void testGet() throws Exception { //环境不存在 MvcResult mvcResult = this.responseGet(get + getEnvironmentGroup()); - List response = parseObjectFromMvcResult(mvcResult, List.class); + EnvironmentGroupDTO response = parseObjectFromMvcResult(mvcResult, EnvironmentGroupDTO.class); Assertions.assertNotNull(response); }