diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalTestCaseController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalTestCaseController.java index 17658e142f..aa4534dd5f 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalTestCaseController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalTestCaseController.java @@ -7,12 +7,15 @@ import io.metersphere.functional.dto.FunctionalCaseTestDTO; import io.metersphere.functional.request.AssociateCaseModuleRequest; import io.metersphere.functional.request.DisassociateOtherCaseRequest; import io.metersphere.functional.request.FunctionalCaseTestRequest; +import io.metersphere.functional.service.FunctionalCaseLogService; import io.metersphere.functional.service.FunctionalTestCaseService; import io.metersphere.request.AssociateCaseModuleProviderRequest; import io.metersphere.request.AssociateOtherCaseRequest; import io.metersphere.request.TestCasePageProviderRequest; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.dto.sdk.BaseTreeNode; +import io.metersphere.system.log.annotation.Log; +import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.security.CheckOwner; import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.Pager; @@ -76,6 +79,7 @@ public class FunctionalTestCaseController { @PostMapping("/disassociate/case") @Operation(summary = "用例管理-功能用例-关联其他用例-取消关联用例") + @Log(type = OperationLogType.DISASSOCIATE, expression = "#msClass.disassociateCaseLog(#request)", msClass = FunctionalCaseLogService.class) @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ) @CheckOwner(resourceId = "#request.projectId", resourceType = "project") public void disassociateCase(@Validated @RequestBody DisassociateOtherCaseRequest request) { @@ -88,8 +92,7 @@ public class FunctionalTestCaseController { @RequiresPermissions(value = {PermissionConstants.FUNCTIONAL_CASE_READ_ADD, PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE, PermissionConstants.FUNCTIONAL_CASE_READ_DELETE}, logical = Logical.OR) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") public Pager> getAssociateOtherCaseList(@Validated @RequestBody FunctionalCaseTestRequest request) { - Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc"); + Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize()); return PageUtils.setPageInfo(page, functionalTestCaseService.hasAssociatePage(request)); } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java index 13ac287238..1674265ecb 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java @@ -1,5 +1,6 @@ package io.metersphere.functional.service; +import io.metersphere.api.mapper.ApiTestCaseMapper; import io.metersphere.functional.domain.*; import io.metersphere.functional.dto.BaseFunctionalCaseBatchDTO; import io.metersphere.functional.dto.FunctionalCaseHistoryLogDTO; @@ -46,6 +47,9 @@ public class FunctionalCaseLogService { @Resource private FileAssociationMapper fileAssociationMapper; + @Resource + private ApiTestCaseMapper apiTestCaseMapper; + //TODO 日志(需要修改) @@ -282,6 +286,32 @@ public class FunctionalCaseLogService { return null; } + /** + * 取消关联 + * + * @param request request + * @return 日志详情 + */ + public LogDTO disassociateCaseLog(DisassociateOtherCaseRequest request) { + FunctionalCase functionalCase = functionalCaseMapper.selectByPrimaryKey(request.getCaseId()); + if (functionalCase != null) { + LogDTO dto = new LogDTO( + functionalCase.getProjectId(), + null, + functionalCase.getId(), + functionalCase.getCreateUser(), + OperationLogType.DISASSOCIATE.name(), + OperationLogModule.FUNCTIONAL_CASE, + functionalCase.getName()); + + dto.setPath("/functional/case/test/disassociate/case"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(functionalCase)); + return dto; + } + return null; + } + public List batchEditFunctionalCaseLog(FunctionalCaseBatchEditRequest request) { List ids = functionalCaseService.doSelectIds(request, request.getProjectId()); diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalTestCaseControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalTestCaseControllerTests.java index f4c7bbe4ca..a2c28d70bf 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalTestCaseControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalTestCaseControllerTests.java @@ -5,8 +5,11 @@ import io.metersphere.api.domain.ApiTestCase; import io.metersphere.api.mapper.ApiDefinitionModuleMapper; import io.metersphere.dto.TestCaseProviderDTO; import io.metersphere.functional.constants.AssociateCaseType; +import io.metersphere.functional.constants.FunctionalCaseReviewStatus; +import io.metersphere.functional.domain.FunctionalCase; import io.metersphere.functional.domain.FunctionalCaseTest; import io.metersphere.functional.dto.FunctionalCaseTestDTO; +import io.metersphere.functional.mapper.FunctionalCaseMapper; import io.metersphere.functional.mapper.FunctionalCaseTestMapper; import io.metersphere.functional.request.AssociateCaseModuleRequest; import io.metersphere.functional.request.DisassociateOtherCaseRequest; @@ -15,6 +18,7 @@ import io.metersphere.provider.BaseAssociateApiProvider; import io.metersphere.request.AssociateCaseModuleProviderRequest; import io.metersphere.request.AssociateOtherCaseRequest; import io.metersphere.request.TestCasePageProviderRequest; +import io.metersphere.sdk.constants.FunctionalCaseExecuteResult; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; @@ -59,6 +63,9 @@ public class FunctionalTestCaseControllerTests extends BaseTest { @Resource private FunctionalCaseTestMapper functionalCaseTestMapper; + @Resource + private FunctionalCaseMapper functionalCaseMapper; + @Resource private ApiDefinitionModuleMapper apiDefinitionModuleMapper; @@ -166,6 +173,7 @@ public class FunctionalTestCaseControllerTests extends BaseTest { @Test @Order(5) public void disassociateCaseSuccess() throws Exception { + addFunctionalCase(); addFunctionalCaseTest(); DisassociateOtherCaseRequest request = new DisassociateOtherCaseRequest(); request.setSourceType(AssociateCaseType.API); @@ -261,4 +269,28 @@ public class FunctionalTestCaseControllerTests extends BaseTest { functionalCaseTestMapper.insert(functionalCaseTest); } + private void addFunctionalCase() { + FunctionalCase functionalCase = new FunctionalCase(); + functionalCase.setName("测试关联"); + functionalCase.setNum(100001l); + functionalCase.setModuleId("module"); + functionalCase.setProjectId("gyq-organization-associate-case-test"); + functionalCase.setDeleted(false); + functionalCase.setTemplateId("default_template"); + functionalCase.setId("gyq_associate_functional_case_id_1"); + functionalCase.setReviewStatus(FunctionalCaseReviewStatus.UN_REVIEWED.name()); + functionalCase.setCaseEditType("Text"); + functionalCase.setPos(500L); + functionalCase.setVersionId("12335"); + functionalCase.setRefId(functionalCase.getId()); + functionalCase.setLastExecuteResult(FunctionalCaseExecuteResult.UN_EXECUTED.name()); + functionalCase.setPublicCase(false); + functionalCase.setLatest(true); + functionalCase.setCreateUser("gyq"); + functionalCase.setCreateTime(System.currentTimeMillis()); + functionalCase.setUpdateUser("gyq"); + functionalCase.setUpdateTime(System.currentTimeMillis()); + functionalCaseMapper.insertSelective(functionalCase); + } + }