From c14b6399ec9aaa5c813a0d64cf88c22fefb123f4 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Wed, 5 Jun 2024 12:06:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E5=8F=96=E6=B6=88=E5=85=B3=E8=81=94=E6=8E=A5=E5=8F=A3=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/i18n/plan_en_US.properties | 2 + .../main/resources/i18n/plan_zh_CN.properties | 2 + .../main/resources/i18n/plan_zh_TW.properties | 2 + .../controller/TestPlanApiCaseController.java | 23 ++++++++++ .../plan/mapper/ExtTestPlanApiCaseMapper.java | 3 ++ .../plan/mapper/ExtTestPlanApiCaseMapper.xml | 45 +++++++++++++++++++ .../plan/service/TestPlanApiCaseService.java | 45 +++++++++++++++++++ .../service/TestPlanBaseUtilsService.java | 2 +- .../service/TestPlanResourceLogService.java | 34 ++++++++++++++ .../plan/service/TestPlanResourceService.java | 2 +- .../TestPlanApiCaseControllerTests.java | 16 +++++++ 11 files changed, 174 insertions(+), 2 deletions(-) diff --git a/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties index 8f6943d090..b04ed80361 100644 --- a/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/plan_en_US.properties @@ -92,6 +92,8 @@ log.delete.test_plan_group=Test plan group deleted log.test_plan.add=Association resources log.test_plan.remove=Remove resource log.test_plan.move=Move resources +log.test_plan.disassociate=Disassociate resources +log.test_plan.associate=Associate resources log.test_plan.move.test_plan=Move test plan log.test_plan.update=Update resources log.test_plan.functional_case=Functional case diff --git a/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties index cf2ebdb0d1..480e6b7121 100644 --- a/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/plan_zh_CN.properties @@ -92,6 +92,8 @@ log.delete.test_plan_group=删除测试计划组 log.test_plan.add=关联了资源 log.test_plan.remove=移除了资源 log.test_plan.move=移动了资源 +log.test_plan.disassociate=取消关联了资源 +log.test_plan.associate=关联了资源 log.test_plan.move.test_plan=移动了测试计划 log.test_plan.update=修改了资源 log.test_plan.functional_case=功能用例 diff --git a/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties index 41ced1eeba..4424db4222 100644 --- a/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/plan_zh_TW.properties @@ -91,6 +91,8 @@ log.delete.test_plan_group=刪除測試計劃組 log.test_plan.add=關聯了資源 log.test_plan.remove=移除了資源 log.test_plan.move=移動了資源 +log.test_plan.disassociate=取消關聯了資源 +log.test_plan.associate=關聯了賳源 log.test_plan.move.test_plan=移動了測試計劃 log.test_plan.update=修改了資源 log.test_plan.functional_case=功能用例 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 5640a34ad6..1f387150f1 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,14 +2,21 @@ 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.TestPlanApiCaseRequest; +import io.metersphere.plan.dto.request.TestPlanDisassociationRequest; import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse; +import io.metersphere.plan.dto.response.TestPlanAssociationResponse; import io.metersphere.plan.service.TestPlanApiCaseService; +import io.metersphere.plan.service.TestPlanService; +import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.system.dto.LogInsertModule; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.security.CheckOwner; import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.Pager; +import io.metersphere.system.utils.SessionUtils; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; @@ -28,6 +35,8 @@ public class TestPlanApiCaseController { @Resource private TestPlanApiCaseService testPlanApiCaseService; + @Resource + private TestPlanService testPlanService; @PostMapping("/page") @@ -57,5 +66,19 @@ public class TestPlanApiCaseController { return testPlanApiCaseService.getTree(testPlanId); } + @PostMapping("/disassociate") + @Operation(summary = "测试计划-计划详情-接口用例列表-取消关联用例") + @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_ASSOCIATION) + @CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan") + public TestPlanAssociationResponse disassociate(@Validated @RequestBody TestPlanDisassociationRequest request) { + BasePlanCaseBatchRequest batchRequest = new BasePlanCaseBatchRequest(); + 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())); + testPlanService.refreshTestPlanStatus(request.getTestPlanId()); + return response; + } + + //TODO 计划集 type } 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 b1325e33d1..cfe85e9c6e 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,6 +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.TestPlanApiCaseRequest; import io.metersphere.plan.dto.request.TestPlanApiRequest; import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse; @@ -47,4 +48,6 @@ public interface ExtTestPlanApiCaseMapper { List selectRootIdByTestPlanId(@Param("testPlanId") String testPlanId); List selectBaseByProjectIdAndTestPlanId(@Param("testPlanId") String testPlanId); + + List getIds(@Param("request") BasePlanCaseBatchRequest request, @Param("deleted") boolean deleted); } 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 c6ee435af3..6c76e728a6 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 @@ -584,4 +584,49 @@ ORDER BY pos + + + + + and a.protocol = #{request.protocol} + + + and atc.api_definition_id = #{request.apiDefinitionId} + + + and ( + atc.name like concat('%', #{request.condition.keyword},'%') + or atc.num like concat('%', #{request.condition.keyword},'%') + or a.path like concat('%', #{request.condition.keyword},'%') + or atc.tags like concat('%', #{request.condition.keyword},'%') + ) + + + and a.module_id in + + #{nodeId} + + + + and t.test_plan_collection_id in + + #{collectionId} + + + + + + + \ No newline at end of file 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 0b6935a54f..bcec19bff2 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 @@ -11,9 +11,12 @@ import io.metersphere.plan.domain.TestPlanApiCase; 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.TestPlanApiRequest; import io.metersphere.plan.dto.response.TestPlanApiCasePageResponse; +import io.metersphere.plan.dto.response.TestPlanAssociationResponse; import io.metersphere.plan.mapper.ExtTestPlanApiCaseMapper; import io.metersphere.plan.mapper.TestPlanApiCaseMapper; import io.metersphere.project.domain.Project; @@ -21,11 +24,13 @@ import io.metersphere.project.domain.ProjectExample; import io.metersphere.project.dto.ModuleCountDTO; import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.ModuleConstants; +import io.metersphere.sdk.constants.TestPlanResourceConstants; import io.metersphere.sdk.domain.Environment; import io.metersphere.sdk.domain.EnvironmentExample; import io.metersphere.sdk.mapper.EnvironmentMapper; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.Translator; +import io.metersphere.system.dto.LogInsertModule; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.service.UserLoginService; import io.metersphere.system.uid.IDGenerator; @@ -39,6 +44,7 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.validation.annotation.Validated; import java.util.ArrayList; import java.util.HashMap; @@ -68,6 +74,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService { private static final String CASE_MODULE_COUNT_ALL = "all"; @Resource private SqlSessionFactory sqlSessionFactory; + @Override public void deleteBatchByTestPlanId(List testPlanIdList) { TestPlanApiCaseExample example = new TestPlanApiCaseExample(); @@ -307,4 +314,42 @@ public class TestPlanApiCaseService extends TestPlanResourceService { }); return returnList; } + + + /** + * 取消关联 + * + * @param request + * @param logInsertModule + * @return + */ + public TestPlanAssociationResponse disassociate(BasePlanCaseBatchRequest request, LogInsertModule logInsertModule) { + List selectIds = doSelectIds(request); + return super.disassociate( + TestPlanResourceConstants.RESOURCE_API_CASE, + request, + logInsertModule, + selectIds, + this::deleteTestPlanResource); + } + + + public void deleteTestPlanResource(@Validated TestPlanResourceAssociationParam associationParam) { + TestPlanApiCaseExample testPlanApiCaseExample = new TestPlanApiCaseExample(); + testPlanApiCaseExample.createCriteria().andIdIn(associationParam.getResourceIdList()); + testPlanApiCaseMapper.deleteByExample(testPlanApiCaseExample); + } + + + public List doSelectIds(BasePlanCaseBatchRequest request) { + if (request.isSelectAll()) { + List ids = extTestPlanApiCaseMapper.getIds(request, false); + if (CollectionUtils.isNotEmpty(request.getExcludeIds())) { + ids.removeAll(request.getExcludeIds()); + } + return ids; + } else { + return request.getSelectIds(); + } + } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBaseUtilsService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBaseUtilsService.java index 1f59e7cba5..882b6df0d2 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBaseUtilsService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanBaseUtilsService.java @@ -104,7 +104,7 @@ public class TestPlanBaseUtilsService { if (CollectionUtils.isNotEmpty(functionalSelectIds)) { TestPlanResourceAssociationParam associationParam = new TestPlanResourceAssociationParam(functionalSelectIds, testPlan.getProjectId(), testPlan.getId(), testPlan.getNum(), testPlan.getCreateUser()); testPlanCaseService.saveTestPlanResource(associationParam); - testPlanResourceLogService.saveAddLog(testPlan, new ResourceLogInsertModule(TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE, new LogInsertModule(operator, "/test-plan/association", HttpMethodConstants.POST.name()))); + testPlanResourceLogService.saveAssociateLog(testPlan, new ResourceLogInsertModule(TestPlanResourceConstants.RESOURCE_FUNCTIONAL_CASE, new LogInsertModule(operator, "/test-plan/association", HttpMethodConstants.POST.name()))); } } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceLogService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceLogService.java index db2006ff86..a7527b12ae 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceLogService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceLogService.java @@ -86,4 +86,38 @@ public class TestPlanResourceLogService { .build().getLogDTO(); operationLogService.add(dto); } + + + public void saveDisassociateLog(TestPlan module, @Validated ResourceLogInsertModule logInsertModule) { + Project project = projectMapper.selectByPrimaryKey(module.getProjectId()); + LogDTO dto = LogDTOBuilder.builder() + .projectId(module.getProjectId()) + .organizationId(project.getOrganizationId()) + .type(OperationLogType.DISASSOCIATE.name()) + .module(logModule) + .method(logInsertModule.getRequestMethod()) + .path(logInsertModule.getRequestUrl()) + .sourceId(module.getId()) + .content(generateContent(module.getName(), logInsertModule.getResourceType(), "disassociate")) + .createUser(logInsertModule.getOperator()) + .build().getLogDTO(); + operationLogService.add(dto); + } + + + public void saveAssociateLog(TestPlan module, @Validated ResourceLogInsertModule logInsertModule) { + Project project = projectMapper.selectByPrimaryKey(module.getProjectId()); + LogDTO dto = LogDTOBuilder.builder() + .projectId(module.getProjectId()) + .organizationId(project.getOrganizationId()) + .type(OperationLogType.ASSOCIATE.name()) + .module(logModule) + .method(logInsertModule.getRequestMethod()) + .path(logInsertModule.getRequestUrl()) + .sourceId(module.getId()) + .content(generateContent(module.getName(), logInsertModule.getResourceType(), "associate")) + .createUser(logInsertModule.getOperator()) + .build().getLogDTO(); + operationLogService.add(dto); + } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java index ef5468f1cd..3cb08f4387 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java @@ -47,7 +47,7 @@ public abstract class TestPlanResourceService extends TestPlanSortService { TestPlanResourceAssociationParam associationParam = new TestPlanResourceAssociationParam(associationIdList, testPlan.getProjectId(), testPlan.getId(), testPlan.getNum(), logInsertModule.getOperator()); disassociate.accept(associationParam); response.setAssociationCount(associationIdList.size()); - testPlanResourceLogService.saveDeleteLog(testPlan, new ResourceLogInsertModule(resourceType, logInsertModule)); + testPlanResourceLogService.saveDisassociateLog(testPlan, new ResourceLogInsertModule(resourceType, logInsertModule)); } return response; } 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 e528e36bcb..2a9dc77f32 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,6 +1,7 @@ package io.metersphere.plan.controller; import io.metersphere.plan.dto.request.TestPlanApiCaseRequest; +import io.metersphere.plan.dto.request.TestPlanDisassociationRequest; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; @@ -22,6 +23,7 @@ public class TestPlanApiCaseControllerTests extends BaseTest { public static final String API_CASE_PAGE = "/test-plan/api/case/page"; 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"; @Test @Order(1) @@ -70,4 +72,18 @@ public class TestPlanApiCaseControllerTests extends BaseTest { this.requestGetWithOkAndReturn(API_CASE_TREE_MODULE_TREE + "wxxx_2"); } + + @Test + @Order(4) + public void testApiCaseDisassociate() throws Exception { + TestPlanDisassociationRequest request = new TestPlanDisassociationRequest(); + request.setTestPlanId("wxxx_2"); + request.setId("wxxx_3"); + + MvcResult mvcResult = this.requestPostWithOkAndReturn(API_CASE_DISASSOCIATE, request); + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + Assertions.assertNotNull(resultHolder); + + } }