From 8406e8596305f18b21a6577b51c2162758c0db0b Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Thu, 6 Jun 2024 10:16:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=94=A8=E4=BE=8B=E6=89=B9=E9=87=8F=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E5=85=B3=E8=81=94=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TestPlanApiCaseController.java | 20 +++++++++++++++---- .../TestPlanFunctionalCaseController.java | 4 ++-- .../request/TestPlanApiCaseBatchRequest.java | 17 ++++++++++++++++ .../request/TestPlanApiCaseUpdateRequest.java | 9 ++------- .../plan/mapper/ExtTestPlanApiCaseMapper.java | 4 ++-- .../plan/mapper/ExtTestPlanApiCaseMapper.xml | 4 ++-- .../service/TestPlanApiCaseLogService.java | 2 +- .../plan/service/TestPlanApiCaseService.java | 16 +++++++-------- .../TestPlanApiCaseControllerTests.java | 17 ++++++++++++++++ 9 files changed, 66 insertions(+), 27 deletions(-) create mode 100644 backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanApiCaseBatchRequest.java diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java index 90ee77269f..cebae7cab6 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanApiCaseController.java @@ -2,7 +2,7 @@ package io.metersphere.plan.controller; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; -import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest; +import io.metersphere.plan.dto.request.TestPlanApiCaseBatchRequest; import io.metersphere.plan.dto.request.TestPlanApiCaseRequest; import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest; import io.metersphere.plan.dto.request.TestPlanDisassociationRequest; @@ -75,19 +75,31 @@ public class TestPlanApiCaseController { @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION) @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") public TestPlanAssociationResponse disassociate(@Validated @RequestBody TestPlanDisassociationRequest request) { - BasePlanCaseBatchRequest batchRequest = new BasePlanCaseBatchRequest(); + TestPlanApiCaseBatchRequest batchRequest = new TestPlanApiCaseBatchRequest(); batchRequest.setTestPlanId(request.getTestPlanId()); batchRequest.setSelectIds(List.of(request.getId())); - TestPlanAssociationResponse response = testPlanApiCaseService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/association", HttpMethodConstants.POST.name())); + TestPlanAssociationResponse response = testPlanApiCaseService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/disassociate", HttpMethodConstants.POST.name())); testPlanService.refreshTestPlanStatus(request.getTestPlanId()); return response; } + + @PostMapping("/batch/disassociate") + @Operation(summary = "测试计划-计划详情-列表-批量取消关联用例") + @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION) + @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") + public TestPlanAssociationResponse batchDisassociate(@Validated @RequestBody TestPlanApiCaseBatchRequest request) { + TestPlanAssociationResponse response = testPlanApiCaseService.disassociate(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/api/case/batch/disassociate", HttpMethodConstants.POST.name())); + testPlanService.refreshTestPlanStatus(request.getTestPlanId()); + return response; + } + + @PostMapping("/batch/update/executor") @Operation(summary = "测试计划-计划详情-功能用例-批量更新执行人") @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_UPDATE) @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") - @Log(type = OperationLogType.DISASSOCIATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanApiCaseLogService.class) + @Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateExecutor(#request)", msClass = TestPlanApiCaseLogService.class) public void batchUpdateExecutor(@Validated @RequestBody TestPlanApiCaseUpdateRequest request) { testPlanApiCaseService.batchUpdateExecutor(request); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java index 36e4d25099..c9ac84bde3 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseController.java @@ -91,7 +91,7 @@ public class TestPlanFunctionalCaseController { BasePlanCaseBatchRequest batchRequest = new BasePlanCaseBatchRequest(); batchRequest.setTestPlanId(request.getTestPlanId()); batchRequest.setSelectIds(List.of(request.getId())); - TestPlanAssociationResponse response = testPlanFunctionalCaseService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/association", HttpMethodConstants.POST.name())); + TestPlanAssociationResponse response = testPlanFunctionalCaseService.disassociate(batchRequest, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/disassociate", HttpMethodConstants.POST.name())); testPlanService.refreshTestPlanStatus(request.getTestPlanId()); return response; } @@ -102,7 +102,7 @@ public class TestPlanFunctionalCaseController { @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") public TestPlanAssociationResponse batchDisassociate(@Validated @RequestBody BasePlanCaseBatchRequest request) { testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_FUNCTIONAL_CASE)); - TestPlanAssociationResponse response = testPlanFunctionalCaseService.disassociate(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/association", HttpMethodConstants.POST.name())); + TestPlanAssociationResponse response = testPlanFunctionalCaseService.disassociate(request, new LogInsertModule(SessionUtils.getUserId(), "/test-plan/functional/case/batch/disassociate", HttpMethodConstants.POST.name())); testPlanService.refreshTestPlanStatus(request.getTestPlanId()); return response; } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanApiCaseBatchRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanApiCaseBatchRequest.java new file mode 100644 index 0000000000..671a385d8e --- /dev/null +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanApiCaseBatchRequest.java @@ -0,0 +1,17 @@ +package io.metersphere.plan.dto.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; +import lombok.Data; + +import java.util.List; + +/** + * @author wx + */ +@Data +public class TestPlanApiCaseBatchRequest extends BasePlanCaseBatchRequest { + @Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "{api_definition.protocol.not_blank}") + private List protocols; +} diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanApiCaseUpdateRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanApiCaseUpdateRequest.java index 08daca3ae3..50485cd3d7 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanApiCaseUpdateRequest.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanApiCaseUpdateRequest.java @@ -2,23 +2,18 @@ package io.metersphere.plan.dto.request; 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; - /** * @author wx */ @Data -public class TestPlanApiCaseUpdateRequest extends BasePlanCaseBatchRequest { +public class TestPlanApiCaseUpdateRequest extends TestPlanApiCaseBatchRequest { @Schema(description = "执行人id", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "{test_plan.user_id.not_blank}") private String userId; - @Schema(description = "接口协议", requiredMode = Schema.RequiredMode.REQUIRED) - @NotEmpty(message = "{api_definition.protocol.not_blank}") - private List protocols; + } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.java index 8785e7b59e..6c47ac73b3 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.java @@ -7,7 +7,7 @@ import io.metersphere.plan.domain.TestPlanApiCase; import io.metersphere.plan.dto.ApiCaseModuleDTO; import io.metersphere.plan.dto.ResourceSelectParam; import io.metersphere.plan.dto.TestPlanCaseRunResultCount; -import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest; +import io.metersphere.plan.dto.request.TestPlanApiCaseBatchRequest; import io.metersphere.plan.dto.request.TestPlanApiCaseRequest; import io.metersphere.plan.dto.request.TestPlanApiRequest; import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse; @@ -49,7 +49,7 @@ public interface ExtTestPlanApiCaseMapper { List selectBaseByProjectIdAndTestPlanId(@Param("testPlanId") String testPlanId); - List getIds(@Param("request") BasePlanCaseBatchRequest request, @Param("deleted") boolean deleted, @Param("protocols") List protocols); + List getIds(@Param("request") TestPlanApiCaseBatchRequest request, @Param("deleted") boolean deleted); void batchUpdateExecutor(@Param("ids") List ids, @Param("userId") String userId); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml index 7d072f7ca6..fb3443241a 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml @@ -599,9 +599,9 @@ - + and a.protocol in - + #{protocol} diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseLogService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseLogService.java index d345eb4c4c..4ff8eb29ee 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseLogService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseLogService.java @@ -34,7 +34,7 @@ public class TestPlanApiCaseLogService { private ApiTestCaseMapper apiTestCaseMapper; public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) { - List ids = testPlanApiCaseService.doSelectIds(request, request.getProtocols()); + List ids = testPlanApiCaseService.doSelectIds(request); if (CollectionUtils.isNotEmpty(ids)) { TestPlanApiCaseExample example = new TestPlanApiCaseExample(); example.createCriteria().andIdIn(ids); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java index 13e521a4fa..c79edc11ef 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java @@ -12,10 +12,7 @@ import io.metersphere.plan.domain.TestPlanApiCaseExample; import io.metersphere.plan.dto.ApiCaseModuleDTO; import io.metersphere.plan.dto.TestPlanCaseRunResultCount; import io.metersphere.plan.dto.TestPlanResourceAssociationParam; -import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest; -import io.metersphere.plan.dto.request.TestPlanApiCaseRequest; -import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest; -import io.metersphere.plan.dto.request.TestPlanApiRequest; +import io.metersphere.plan.dto.request.*; import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse; import io.metersphere.plan.dto.response.TestPlanAssociationResponse; import io.metersphere.plan.mapper.ExtTestPlanApiCaseMapper; @@ -324,12 +321,13 @@ public class TestPlanApiCaseService extends TestPlanResourceService { * @param logInsertModule * @return */ - public TestPlanAssociationResponse disassociate(BasePlanCaseBatchRequest request, LogInsertModule logInsertModule) { + public TestPlanAssociationResponse disassociate(TestPlanApiCaseBatchRequest request, LogInsertModule logInsertModule) { + List selectIds = doSelectIds(request); return super.disassociate( TestPlanResourceConstants.RESOURCE_API_CASE, request, logInsertModule, - request.getSelectIds(), + selectIds, this::deleteTestPlanResource); } @@ -341,9 +339,9 @@ public class TestPlanApiCaseService extends TestPlanResourceService { } - public List doSelectIds(BasePlanCaseBatchRequest request, List protocols) { + public List doSelectIds(TestPlanApiCaseBatchRequest request) { if (request.isSelectAll()) { - List ids = extTestPlanApiCaseMapper.getIds(request, false, protocols); + List ids = extTestPlanApiCaseMapper.getIds(request, false); if (CollectionUtils.isNotEmpty(request.getExcludeIds())) { ids.removeAll(request.getExcludeIds()); } @@ -360,7 +358,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService { * @param request */ public void batchUpdateExecutor(TestPlanApiCaseUpdateRequest request) { - List ids = doSelectIds(request, request.getProtocols()); + List ids = doSelectIds(request); if (CollectionUtils.isNotEmpty(ids)) { extTestPlanApiCaseMapper.batchUpdateExecutor(ids, request.getUserId()); } diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java index 4fdc7981d1..91e546153a 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanApiCaseControllerTests.java @@ -1,5 +1,6 @@ package io.metersphere.plan.controller; +import io.metersphere.plan.dto.request.TestPlanApiCaseBatchRequest; import io.metersphere.plan.dto.request.TestPlanApiCaseRequest; import io.metersphere.plan.dto.request.TestPlanApiCaseUpdateRequest; import io.metersphere.plan.dto.request.TestPlanDisassociationRequest; @@ -26,6 +27,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest { public static final String API_CASE_TREE_COUNT = "/test-plan/api/case/module/count"; public static final String API_CASE_TREE_MODULE_TREE = "/test-plan/api/case/tree/"; public static final String API_CASE_DISASSOCIATE = "/test-plan/api/case/disassociate"; + public static final String API_CASE_BATCH_DISASSOCIATE = "/test-plan/api/case/batch/disassociate"; public static final String API_CASE_BATCH_UPDATE_EXECUTOR_URL = "/test-plan/api/case/batch/update/executor"; @Test @@ -104,4 +106,19 @@ public class TestPlanApiCaseControllerTests extends BaseTest { request.setSelectIds(List.of("wxxx_1")); this.requestPostWithOk(API_CASE_BATCH_UPDATE_EXECUTOR_URL, request); } + + + @Test + @Order(6) + public void testApiCaseBatchDisassociate() throws Exception { + TestPlanApiCaseBatchRequest request = new TestPlanApiCaseBatchRequest(); + request.setTestPlanId("wxxx_2"); + request.setProtocols(List.of("HTTP")); + request.setSelectAll(true); + MvcResult mvcResult = this.requestPostWithOkAndReturn(API_CASE_BATCH_DISASSOCIATE, request); + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + Assertions.assertNotNull(resultHolder); + + } }