diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentGroupRequest.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentGroupRequest.java index c2a04d13fa..e1974051af 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentGroupRequest.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/EnvironmentGroupRequest.java @@ -3,7 +3,6 @@ package io.metersphere.project.dto.environment; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotEmpty; import lombok.Data; import java.util.List; @@ -22,6 +21,5 @@ public class EnvironmentGroupRequest { @Schema(description = "环境组描述") private String description; @Schema(description = "环境组id") - @NotEmpty private List envGroupProject; } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/host/Host.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/host/Host.java index 01d7ffbc49..d9e5585168 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/host/Host.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/environment/host/Host.java @@ -14,8 +14,6 @@ public class Host implements Serializable { private String domain; @Schema(description = "描述") private String description; - @Schema(description = "id") - private String uuid; @Serial private static final long serialVersionUID = 1L; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateEnvironmentResourceService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateEnvironmentResourceService.java index 241f3c93e5..a118e5da91 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateEnvironmentResourceService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateEnvironmentResourceService.java @@ -62,7 +62,7 @@ public class CreateEnvironmentResourceService implements CreateProjectResourceSe if (StringUtils.isNotEmpty(baseUrl)) { if (CollectionUtils.isEmpty(httpConfigs)) { HttpConfig httpConfig = new HttpConfig(); - httpConfig.setHostname(StringUtils.join(baseUrl, MOCK_EVN_SOCKET, "100001")); + httpConfig.setHostname(StringUtils.join(baseUrl, MOCK_EVN_SOCKET, project.getNum())); httpConfigs.add(httpConfig); } } 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 a883c55d18..d59d085d8c 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 @@ -80,7 +80,9 @@ public class EnvironmentGroupService { environmentGroup.setPos(getNextOrder(request.getProjectId())); environmentGroupMapper.insertSelective(environmentGroup); request.setId(environmentGroup.getId()); - this.insertGroupProject(request); + if (CollectionUtils.isNotEmpty(request.getEnvGroupProject())) { + this.insertGroupProject(request); + } return environmentGroup; } @@ -157,8 +159,13 @@ public class EnvironmentGroupService { environmentGroup.setUpdateUser(userId); environmentGroup.setDescription(request.getDescription()); environmentGroupMapper.updateByPrimaryKeySelective(environmentGroup); - - this.insertGroupProject(request); + if (CollectionUtils.isNotEmpty(request.getEnvGroupProject())) { + this.insertGroupProject(request); + } else { + EnvironmentGroupRelationExample example = new EnvironmentGroupRelationExample(); + example.createCriteria().andEnvironmentGroupIdEqualTo(request.getId()); + environmentGroupRelationMapper.deleteByExample(example); + } return environmentGroup; } @@ -203,7 +210,7 @@ public class EnvironmentGroupService { EnvironmentConfig environmentConfig = JSON.parseObject(new String(environmentBlob.getConfig()), EnvironmentConfig.class); dto.setDomain(ObjectUtils.isNotEmpty(environmentConfig) ? environmentConfig.getHttpConfig() : new ArrayList<>()); } - if (environment !=null && BooleanUtils.isTrue(environment.getMock())) { + if (environment != null && BooleanUtils.isTrue(environment.getMock())) { SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class); if (systemParameterService != null) { BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); 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 9e48f1d32d..bd4ed6d4ef 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 @@ -272,7 +272,6 @@ public class EnvironmentControllerTests extends BaseTest { HostConfig hostConfig = new HostConfig(); hostConfig.setEnable(true); Host host = new Host(); - host.setUuid("uuid"); host.setDomain("domain"); host.setDescription("description"); host.setIp("ip"); 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 4a73b5d731..61abe9f268 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 @@ -249,6 +249,8 @@ public class EnvironmentGroupControllerTests extends BaseTest { Assertions.assertEquals(groupResponse.getId(), environmentGroup.getId()); Assertions.assertEquals(groupResponse.getName(), environmentGroup.getName()); checkLog(environmentGroup.getId(), OperationLogType.ADD); + groupRequest.setEnvGroupProject(new ArrayList<>()); + requestPost(update, groupRequest); groupRequest.setEnvGroupProject(List.of(environmentGroupProjectDTO, environmentGroupProjectDTO)); requestPost(update, groupRequest, ERROR_REQUEST_MATCHER); //校验权限