diff --git a/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseMinderEditRequest.java b/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseMinderEditRequest.java index ad6cd78cc7..3661a13f0a 100644 --- a/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseMinderEditRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/testcase/TestCaseMinderEditRequest.java @@ -11,5 +11,12 @@ import java.util.List; public class TestCaseMinderEditRequest { private String projectId; private List ids; - List data; + List data; + + @Getter + @Setter + public static class TestCaseMinderEditItem extends TestCaseWithBLOBs { + private String targetId; + private String moveMode; + } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 8f9ffc0cb2..421dad94c5 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -1427,7 +1427,7 @@ public class TestCaseService { } public void minderEdit(TestCaseMinderEditRequest request) { - List data = request.getData(); + List data = request.getData(); if (CollectionUtils.isNotEmpty(data)) { List editIds = data.stream() .filter(t -> StringUtils.isNotBlank(t.getId()) && t.getId().length() > 20) @@ -1451,12 +1451,14 @@ public class TestCaseService { item.setId(UUID.randomUUID().toString()); item.setMaintainer(SessionUtils.getUserId()); addTestCase(item); + changeOrder(item, request.getProjectId()); } else { TestCaseWithBLOBs dbCase = finalTestCaseMap.get(item.getId()); if (editCustomFieldsPriority(dbCase, item.getPriority())) { item.setCustomFields(dbCase.getCustomFields()); } editTestCase(item); + changeOrder(item, request.getProjectId()); } }); } @@ -1468,6 +1470,17 @@ public class TestCaseService { } } + private void changeOrder(TestCaseMinderEditRequest.TestCaseMinderEditItem item, String projectId) { + if (StringUtils.isNotBlank(item.getTargetId())) { + ResetOrderRequest resetOrderRequest = new ResetOrderRequest(); + resetOrderRequest.setGroupId(projectId); + resetOrderRequest.setMoveId(item.getId()); + resetOrderRequest.setTargetId(item.getTargetId()); + resetOrderRequest.setMoveMode(item.getMoveMode()); + updateOrder(resetOrderRequest); + } + } + /** * 脑图编辑之后修改用例等级,同时修改自定义字段的用例等级 * diff --git a/frontend/src/business/components/track/common/minder/TestCaseMinder.vue b/frontend/src/business/components/track/common/minder/TestCaseMinder.vue index d71be71365..fb05d4b72e 100644 --- a/frontend/src/business/components/track/common/minder/TestCaseMinder.vue +++ b/frontend/src/business/components/track/common/minder/TestCaseMinder.vue @@ -131,7 +131,7 @@ name: "TestCaseMinder", let saveCases = []; let deleteCases = []; // 包含测试用例和临时节点 let saveExtraNode = {}; - this.buildSaveCase(data.root, saveCases, deleteCases, saveExtraNode, undefined); + this.buildSaveCase(data.root, saveCases, deleteCases, saveExtraNode); let param = { projectId: this.projectId, @@ -166,10 +166,10 @@ name: "TestCaseMinder", this.setIsChange(false); }); }, - buildSaveCase(root, saveCases, deleteCases, saveExtraNode, parent) { + buildSaveCase(root, saveCases, deleteCases, saveExtraNode, parent, preNode, nextNode) { let data = root.data; if (data.resource && data.resource.indexOf(this.$t('api_test.definition.request.case')) > -1) { - this._buildSaveCase(root, saveCases, deleteCases, parent); + this._buildSaveCase(root, saveCases, deleteCases, parent, preNode, nextNode); } else { let deleteChild = data.deleteChild; if (deleteChild && deleteChild.length > 0 @@ -194,13 +194,22 @@ name: "TestCaseMinder", throw new Error(tip); } if (root.children) { - root.children.forEach((childNode) => { - this.buildSaveCase(childNode, saveCases, deleteCases, saveExtraNode, root.data); - }); + for (let i = 0; i < root.children.length; i++) { + let childNode = root.children[i]; + let preNode = null; + let nextNode = null; + if (i != 0) { + preNode = root.children[i - 1]; + } + if (i + 1 < root.children.length) { + nextNode = root.children[i + 1]; + } + this.buildSaveCase(childNode, saveCases, deleteCases, saveExtraNode, root.data, preNode, nextNode); + } } } }, - _buildSaveCase(node, saveCases, deleteCases, parent) { + _buildSaveCase(node, saveCases, deleteCases, parent, preNode, nextNode) { let data = node.data; if (!data.text) { return; @@ -264,7 +273,24 @@ name: "TestCaseMinder", }) } testCase.steps = JSON.stringify(steps); + if (isChange) { + + testCase.targetId = null; // 排序处理 + if (preNode) { + let preId = preNode.data.id; + if (preId && preId.length > 15) { + testCase.targetId = preId; + testCase.moveMode = 'AFTER'; + } + } else if (nextNode) { + let nextId = nextNode.data.id; + if (nextId && nextId.length > 15) { + testCase.targetId = nextId; + testCase.moveMode = 'BEFORE'; + } + } + saveCases.push(testCase); } if (testCase.nodeId !== 'root' && testCase.nodeId.length < 15) {