refactor(项目管理): 环境组可以保存为空的数据

This commit is contained in:
wxg0103 2024-03-05 19:25:56 +08:00 committed by Craftsman
parent 1301433836
commit ce6c994386
6 changed files with 14 additions and 10 deletions

View File

@ -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<EnvironmentGroupProjectDTO> envGroupProject;
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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();

View File

@ -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");

View File

@ -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);
//校验权限