refactor(项目管理): 删除环境及联删除环境组的关系

This commit is contained in:
wxg0103 2024-03-07 17:18:33 +08:00 committed by Craftsman
parent ac0e994a41
commit 858f9bd16d
4 changed files with 15 additions and 8 deletions

View File

@ -106,7 +106,7 @@ public class EnvironmentController {
@PostMapping(value = "/import", consumes = {"multipart/form-data"}) @PostMapping(value = "/import", consumes = {"multipart/form-data"})
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_IMPORT) @RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_IMPORT)
@Operation(summary = "项目管理-环境-环境目录-导入") @Operation(summary = "项目管理-环境-环境目录-导入")
public void create(@RequestPart(value = "request") EnvironmentImportRequest request, @RequestPart(value = "file") MultipartFile file) { public void create(@RequestPart(value = "request") EnvironmentImportRequest request, @RequestPart(value = "file", required = false) MultipartFile file) {
environmentService.create(request, file, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId()); environmentService.create(request, file, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId());
} }

View File

@ -62,7 +62,7 @@ public class GlobalParamsController {
@PostMapping(value = "/import", consumes = {"multipart/form-data"}) @PostMapping(value = "/import", consumes = {"multipart/form-data"})
@RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_IMPORT) @RequiresPermissions(PermissionConstants.PROJECT_ENVIRONMENT_READ_IMPORT)
@Operation(summary = "项目管理-环境-全局参数-导入") @Operation(summary = "项目管理-环境-全局参数-导入")
public void create(@RequestPart(value = "file") MultipartFile file) { public void create(@RequestPart(value = "file", required = false) MultipartFile file) {
globalParamsService.importData(file, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId()); globalParamsService.importData(file, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId());
} }

View File

@ -10,14 +10,12 @@ import io.metersphere.project.mapper.ExtEnvironmentMapper;
import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.constants.DefaultRepositoryDir;
import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.HttpMethodConstants;
import io.metersphere.sdk.domain.Environment; import io.metersphere.sdk.domain.*;
import io.metersphere.sdk.domain.EnvironmentBlob;
import io.metersphere.sdk.domain.EnvironmentBlobExample;
import io.metersphere.sdk.domain.EnvironmentExample;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.file.FileRequest; import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.file.MinioRepository; import io.metersphere.sdk.file.MinioRepository;
import io.metersphere.sdk.mapper.EnvironmentBlobMapper; import io.metersphere.sdk.mapper.EnvironmentBlobMapper;
import io.metersphere.sdk.mapper.EnvironmentGroupRelationMapper;
import io.metersphere.sdk.mapper.EnvironmentMapper; import io.metersphere.sdk.mapper.EnvironmentMapper;
import io.metersphere.sdk.util.*; import io.metersphere.sdk.util.*;
import io.metersphere.system.domain.PluginScript; import io.metersphere.system.domain.PluginScript;
@ -80,6 +78,8 @@ public class EnvironmentService {
private PluginScriptService pluginScriptService; private PluginScriptService pluginScriptService;
@Resource @Resource
private SystemParameterService systemParameterService; private SystemParameterService systemParameterService;
@Resource
private EnvironmentGroupRelationMapper environmentGroupRelationMapper;
public static final Long ORDER_STEP = 5000L; public static final Long ORDER_STEP = 5000L;
private static final String USERNAME = "user"; private static final String USERNAME = "user";
@ -124,6 +124,10 @@ public class EnvironmentService {
} }
environmentMapper.deleteByPrimaryKey(id); environmentMapper.deleteByPrimaryKey(id);
environmentBlobMapper.deleteByPrimaryKey(id); environmentBlobMapper.deleteByPrimaryKey(id);
//删除环境组及联关系
EnvironmentGroupRelationExample environmentGroupRelationExample = new EnvironmentGroupRelationExample();
environmentGroupRelationExample.createCriteria().andEnvironmentIdEqualTo(id);
environmentGroupRelationMapper.deleteByExample(environmentGroupRelationExample);
} }

View File

@ -470,9 +470,12 @@ public class GlobalParamsControllerTests extends BaseTest {
paramMap.add("file", List.of(file)); paramMap.add("file", List.of(file));
requestMultipartWithOk(importUrl, paramMap); requestMultipartWithOk(importUrl, paramMap);
paramMap.clear(); paramMap.clear();
paramMap.add("file", List.of(new File( inputStream = new FileInputStream(new File(
this.getClass().getClassLoader().getResource("file/huanj.json") this.getClass().getClassLoader().getResource("file/huanj.json")
.getPath()))); .getPath()));
file = new MockMultipartFile("file", "huanj.json", MediaType.APPLICATION_OCTET_STREAM_VALUE, inputStream);
paramMap.add("file", List.of(file));
this.requestMultipart(importUrl, paramMap, status().is5xxServerError()); this.requestMultipart(importUrl, paramMap, status().is5xxServerError());