diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java b/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java index 69742559ef..6d79390f91 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java @@ -59,4 +59,10 @@ public class ApiModuleController { public void dragNode(@RequestBody DragModuleRequest node) { apiModuleService.dragNode(node); } + + @PostMapping("/pos") + public void treeSort(@RequestBody List ids) { + apiModuleService.sort(ids); + } + } diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java b/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java index abcd2d86a5..1b6282c8a5 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java @@ -59,4 +59,10 @@ public class ApiScenarioModuleController { public void dragNode(@RequestBody DragApiScenarioModuleRequest node) { apiScenarioModuleService.dragNode(node); } + + @PostMapping("/pos") + public void treeSort(@RequestBody List ids) { + apiScenarioModuleService.sort(ids); + } + } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java index 3b8b20e811..6a06115d90 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java @@ -1,6 +1,7 @@ package io.metersphere.api.service; +import com.alibaba.fastjson.JSON; import io.metersphere.api.dto.definition.ApiDefinitionRequest; import io.metersphere.api.dto.definition.ApiDefinitionResult; import io.metersphere.api.dto.definition.ApiModuleDTO; @@ -12,11 +13,9 @@ import io.metersphere.base.mapper.ext.ExtApiDefinitionMapper; import io.metersphere.base.mapper.ext.ExtApiModuleMapper; import io.metersphere.commons.constants.TestCaseConstants; import io.metersphere.commons.exception.MSException; - import io.metersphere.i18n.Translator; import io.metersphere.service.NodeTreeService; import io.metersphere.service.ProjectService; -import io.metersphere.track.dto.TestCaseNodeDTO; import io.metersphere.track.service.TestPlanApiCaseService; import io.metersphere.track.service.TestPlanProjectService; import org.apache.commons.lang3.StringUtils; @@ -148,7 +147,19 @@ public class ApiModuleService extends NodeTreeService { private void checkApiModuleExist(ApiModule node) { if (node.getName() != null) { - if (selectSameModule(node).size() > 0) { + ApiModuleExample example = new ApiModuleExample(); + ApiModuleExample.Criteria criteria = example.createCriteria(); + criteria.andNameEqualTo(node.getName()) + .andProjectIdEqualTo(node.getProjectId()); + if (StringUtils.isNotBlank(node.getParentId())) { + criteria.andParentIdEqualTo(node.getParentId()); + } else { + criteria.andParentIdIsNull(); + } + if (StringUtils.isNotBlank(node.getId())) { + criteria.andIdNotEqualTo(node.getId()); + } + if (apiModuleMapper.selectByExample(example).size() > 0) { MSException.throwException(Translator.get("test_case_module_already_exists") + ": " + node.getName()); } } @@ -216,6 +227,18 @@ public class ApiModuleService extends NodeTreeService { sqlSession.flushStatements(); } + @Override + public ApiModuleDTO getNode(String id) { + ApiModule module = apiModuleMapper.selectByPrimaryKey(id); + ApiModuleDTO dto = JSON.parseObject(JSON.toJSONString(module), ApiModuleDTO.class); + return dto; + } + + @Override + public void updatePos(String id, Double pos) { + extApiModuleMapper.updatePos(id, pos); + } + public void dragNode(DragModuleRequest request) { checkApiModuleExist(request); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java index 44df0176fb..24134eb930 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java @@ -1,6 +1,7 @@ package io.metersphere.api.service; +import com.alibaba.fastjson.JSON; import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.ApiScenarioModuleDTO; import io.metersphere.api.dto.automation.ApiScenarioRequest; @@ -17,7 +18,6 @@ import io.metersphere.service.NodeTreeService; import io.metersphere.service.ProjectService; import io.metersphere.track.service.TestPlanProjectService; import io.metersphere.track.service.TestPlanScenarioCaseService; -import io.metersphere.track.service.TestPlanTestCaseService; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; @@ -186,6 +186,18 @@ public class ApiScenarioModuleService extends NodeTreeService records); + List getNodeTreeByProjectId(@Param("projectId") String projectId, @Param("protocol") String protocol); + + void updatePos(String id, Double pos); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiModuleMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiModuleMapper.xml index 6e68684928..8e0937ac1f 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiModuleMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiModuleMapper.xml @@ -19,6 +19,10 @@ from api_module where api_module.project_id = #{projectId} and api_module.protocol = #{protocol} - order by create_time asc + order by api_module.pos asc + + + update api_module set pos = #{pos} where id = #{id} + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.java index 73304803ea..b13d0a0e0c 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.java @@ -7,4 +7,6 @@ import java.util.List; public interface ExtApiScenarioModuleMapper { List getNodeTreeByProjectId(@Param("projectId") String projectId); + + void updatePos(String id, Double pos); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.xml index 706c83381a..85905f7c54 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.xml @@ -6,6 +6,10 @@ from api_scenario_module where api_scenario_module.project_id = #{projectId} - order by create_time asc + order by api_scenario_module.pos asc + + + update api_scenario_module set pos = #{pos} where id = #{id} + \ No newline at end of file diff --git a/backend/src/main/resources/db/migration/V56__modify_api_module_pos.sql b/backend/src/main/resources/db/migration/V56__modify_api_module_pos.sql new file mode 100644 index 0000000000..b41877b22c --- /dev/null +++ b/backend/src/main/resources/db/migration/V56__modify_api_module_pos.sql @@ -0,0 +1,3 @@ +set @rownum=0; +update api_module set pos=(select @rownum := @rownum +1) where pos is null; +update api_scenario_module set pos=(select @rownum := @rownum +1) where pos is null; \ No newline at end of file diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue index becb0bc7aa..3305b4d83b 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue @@ -154,8 +154,9 @@ }, drag(param, list) { this.$post("/api/automation/module/drag", param, () => { - // this.$post("/api/module/pos", list); //todo 排序 - this.list(); + this.$post("/api/automation/module/pos", list, () => { + this.list(); + }); }, (error) => { this.list(); }); diff --git a/frontend/src/business/components/api/definition/components/module/ApiModule.vue b/frontend/src/business/components/api/definition/components/module/ApiModule.vue index fb00c0da36..cb9844960a 100644 --- a/frontend/src/business/components/api/definition/components/module/ApiModule.vue +++ b/frontend/src/business/components/api/definition/components/module/ApiModule.vue @@ -160,8 +160,9 @@ }, drag(param, list) { this.$post("/api/module/drag", param, () => { - // this.$post("/api/module/pos", list); //todo 排序 - this.list(); + this.$post("/api/module/pos", list, () => { + this.list(); + }); }, (error) => { this.list(); });