From 1cc659f0e9a8ae17d65b1143b1a939668a18427c Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 5 Feb 2024 19:42:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=8E=A5=E5=8F=A3=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../definition/ApiDefinitionController.java | 11 ++++++++- .../definition/ApiTestCaseController.java | 6 ++--- .../scenario/ApiScenarioController.java | 12 ++++++++-- .../api/mapper/ExtApiDefinitionMapper.java | 4 ++++ .../api/mapper/ExtApiDefinitionMapper.xml | 17 ++++++++++++++ .../api/mapper/ExtApiScenarioMapper.java | 5 ++++ .../api/mapper/ExtApiScenarioMapper.xml | 17 ++++++++++++++ .../api/mapper/ExtApiTestCaseMapper.xml | 3 ++- .../definition/ApiDefinitionService.java | 10 ++++++++ .../service/scenario/ApiScenarioService.java | 10 ++++++++ .../ApiDefinitionControllerTests.java | 23 ++++++++++++++++--- .../ApiScenarioControllerTests.java | 17 ++++++++++++-- .../project/mapper/ExtEnvironmentMapper.xml | 4 ++-- 13 files changed, 125 insertions(+), 14 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java index 53a21fc184..6865b59717 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionController.java @@ -12,6 +12,7 @@ import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.system.dto.OperationHistoryDTO; import io.metersphere.system.dto.request.OperationHistoryRequest; import io.metersphere.system.dto.request.OperationHistoryVersionRequest; +import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.notice.annotation.SendNotice; @@ -139,7 +140,7 @@ public class ApiDefinitionController { @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") public Pager> getPage(@Validated @RequestBody ApiDefinitionPageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc"); + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc"); return PageUtils.setPageInfo(page, apiDefinitionService.getApiDefinitionPage(request, SessionUtils.getUserId())); } @@ -235,4 +236,12 @@ public class ApiDefinitionController { apiDefinitionService.saveOperationHistory(request); } + @PostMapping("/edit/pos") + @Operation(summary = "接口测试-接口管理-接口-拖拽排序") + @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_UPDATE) + public void editPos(@Validated @RequestBody PosRequest request) { + apiDefinitionService.editPos(request); + } + + } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java index 88323412d8..5716aa701b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiTestCaseController.java @@ -141,7 +141,7 @@ public class ApiTestCaseController { @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ) public Pager> page(@Validated @RequestBody ApiTestCasePageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc"); + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc"); return PageUtils.setPageInfo(page, apiTestCaseService.page(request, false)); } @@ -184,11 +184,11 @@ public class ApiTestCaseController { @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ) public Pager> pageTrash(@Validated @RequestBody ApiTestCasePageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc"); + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc"); return PageUtils.setPageInfo(page, apiTestCaseService.page(request, true)); } - @PostMapping("edit/pos") + @PostMapping("/edit/pos") @Operation(summary = "接口测试-接口管理-接口用例-拖拽排序") @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_UPDATE) public void editPos(@Validated @RequestBody PosRequest request) { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java index 5352b568b6..8d86cfcc6b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioController.java @@ -10,6 +10,7 @@ import io.metersphere.api.service.scenario.ApiScenarioLogService; import io.metersphere.api.service.scenario.ApiScenarioNoticeService; import io.metersphere.api.service.scenario.ApiScenarioService; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.notice.annotation.SendNotice; @@ -45,7 +46,7 @@ public class ApiScenarioController { @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") public Pager> getPage(@Validated @RequestBody ApiScenarioPageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc"); + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc"); return PageUtils.setPageInfo(page, apiScenarioService.getScenarioPage(request)); } @@ -55,7 +56,7 @@ public class ApiScenarioController { @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") public Pager> getTrashPage(@Validated @RequestBody ApiScenarioPageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), - StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc"); + StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc"); request.setDeleted(true); return PageUtils.setPageInfo(page, apiScenarioService.getScenarioPage(request)); } @@ -200,5 +201,12 @@ public class ApiScenarioController { return apiScenarioService.getSystemRequest(request); } + @PostMapping("/edit/pos") + @Operation(summary = "接口测试-接口场景管理-场景-拖拽排序") + @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_UPDATE) + public void editPos(@Validated @RequestBody PosRequest request) { + apiScenarioService.editPos(request); + } + } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java index 2262808836..0066d1f2a5 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.java @@ -57,4 +57,8 @@ public interface ExtApiDefinitionMapper { List getCustomFieldByCaseIds(@Param("ids") List ids); List getIdsByModules(@Param("request") ScenarioSystemRequest request); + + Long getPrePos(@Param("projectId") String projectId, @Param("basePos") Long basePos); + + Long getLastPos(@Param("projectId") String projectId, @Param("basePos") Long basePos); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml index 11044ba680..4c92a313ae 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml @@ -524,4 +524,21 @@ + + + + + diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java index eb8b325cba..9561287c76 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.java @@ -39,4 +39,9 @@ public interface ExtApiScenarioMapper { List getIdsByModules(@Param("request") ScenarioSystemRequest scenarioRequest); List selectByProjectId(String projectId); + + Long getPrePos(@Param("projectId") String projectId, @Param("basePos") Long basePos); + + Long getLastPosEdit(@Param("projectId") String projectId, @Param("basePos") Long basePos); + } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml index 6d7c19752b..50a08d2170 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml @@ -479,4 +479,21 @@ + + + + + diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml index 157ad558d6..433a204e5a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml @@ -51,7 +51,8 @@ t1.last_report_id, t1.environment_id, t1.tags, - a.module_id + a.module_id, + t1.pos FROM api_test_case t1 LEFT JOIN api_report t3 ON t1.last_report_id = t3.id diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java index 6dfbbe4b30..c10e5fcc71 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionService.java @@ -28,6 +28,7 @@ import io.metersphere.system.dto.OperationHistoryDTO; import io.metersphere.system.dto.request.OperationHistoryRequest; import io.metersphere.system.dto.request.OperationHistoryVersionRequest; import io.metersphere.system.dto.sdk.SessionUser; +import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.service.OperationHistoryService; @@ -999,4 +1000,13 @@ public class ApiDefinitionService { apiDefinitionBlobExample.createCriteria().andIdIn(apiIds); return apiDefinitionBlobMapper.selectByExampleWithBLOBs(apiDefinitionBlobExample); } + + public void editPos(PosRequest request) { + ServiceUtils.updatePosField(request, + ApiDefinition.class, + apiDefinitionMapper::selectByPrimaryKey, + extApiDefinitionMapper::getPrePos, + extApiTestCaseMapper::getLastPos, + apiDefinitionMapper::updateByPrimaryKeySelective); + } } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java index 176df85e57..3924c3484f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioService.java @@ -46,6 +46,7 @@ import io.metersphere.system.domain.Schedule; import io.metersphere.system.domain.ScheduleExample; import io.metersphere.system.dto.LogInsertModule; import io.metersphere.system.dto.request.ScheduleConfig; +import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.mapper.ScheduleMapper; @@ -1951,4 +1952,13 @@ public class ApiScenarioService { } return steps; } + + public void editPos(PosRequest request) { + ServiceUtils.updatePosField(request, + ApiScenario.class, + apiScenarioMapper::selectByPrimaryKey, + extApiScenarioMapper::getPrePos, + extApiScenarioMapper::getLastPosEdit, + apiScenarioMapper::updateByPrimaryKeySelective); + } } \ No newline at end of file diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java index 169951be21..515a58819e 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDefinitionControllerTests.java @@ -24,8 +24,6 @@ import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.file.FileCenter; import io.metersphere.sdk.file.FileRequest; -import io.metersphere.sdk.mapper.OperationLogBlobMapper; -import io.metersphere.sdk.mapper.OperationLogMapper; import io.metersphere.sdk.util.*; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; @@ -35,6 +33,7 @@ import io.metersphere.system.domain.OperationHistoryExample; import io.metersphere.system.dto.request.OperationHistoryRequest; import io.metersphere.system.dto.request.OperationHistoryVersionRequest; import io.metersphere.system.dto.sdk.BaseCondition; +import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.mapper.OperationHistoryMapper; import io.metersphere.system.utils.Pager; @@ -248,7 +247,7 @@ public class ApiDefinitionControllerTests extends BaseTest { request.setVersionId(defaultVersion); request.setDescription("描述内容"); request.setTags(new LinkedHashSet<>(List.of("tag1", "tag2"))); - List customFields= createCustomFields(); + List customFields = createCustomFields(); request.setCustomFields(customFields); return request; } @@ -1047,6 +1046,24 @@ public class ApiDefinitionControllerTests extends BaseTest { Assertions.assertNotNull(comparisonNewVersion); } + @Test + @Order(9) + public void testPos() throws Exception { + + apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001"); + ApiDefinition apiDefinition1 = apiDefinitionMapper.selectByPrimaryKey("1002"); + PosRequest posRequest = new PosRequest(); + posRequest.setProjectId(DEFAULT_PROJECT_ID); + posRequest.setTargetId(apiDefinition.getId()); + posRequest.setMoveId(apiDefinition1.getId()); + posRequest.setMoveMode("AFTER"); + this.requestPostWithOkAndReturn(BASE_PATH + "edit/pos", posRequest); + + posRequest.setMoveMode("BEFORE"); + this.requestPostWithOkAndReturn(BASE_PATH + "edit/pos", posRequest); + + } + @Test @Order(13) public void testOperationHistoryRecover() throws Exception { diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java index cdf680401e..68b78bd56c 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiScenarioControllerTests.java @@ -53,6 +53,7 @@ import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.domain.Plugin; import io.metersphere.system.domain.Schedule; import io.metersphere.system.dto.request.PluginUpdateRequest; +import io.metersphere.system.dto.sdk.request.PosRequest; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.mapper.ScheduleMapper; import io.metersphere.system.service.PluginLoadService; @@ -2062,8 +2063,20 @@ public class ApiScenarioControllerTests extends BaseTest { } } - @Resource - private ExtApiTestCaseMapper extApiTestCaseMapper; + @Test + @Order(9) + public void testPos() throws Exception { + PosRequest posRequest = new PosRequest(); + posRequest.setProjectId(DEFAULT_PROJECT_ID); + posRequest.setTargetId(addApiScenario.getId()); + posRequest.setMoveId(anOtherAddApiScenario.getId()); + posRequest.setMoveMode("AFTER"); + this.requestPostWithOkAndReturn("/edit/pos", posRequest); + + posRequest.setMoveMode("BEFORE"); + this.requestPostWithOkAndReturn("/edit/pos", posRequest); + + } @Test @Order(35) diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtEnvironmentMapper.xml b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtEnvironmentMapper.xml index 03cef4d124..472e7b093f 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtEnvironmentMapper.xml +++ b/backend/services/project-management/src/main/java/io/metersphere/project/mapper/ExtEnvironmentMapper.xml @@ -19,7 +19,7 @@ ) - ORDER BY update_time DESC + ORDER BY pos DESC