拖拽节点更新模块字段
This commit is contained in:
parent
c88030d1d2
commit
8c286795f7
|
@ -2,6 +2,7 @@ package io.metersphere.track.controller;
|
||||||
|
|
||||||
import io.metersphere.base.domain.TestCaseNode;
|
import io.metersphere.base.domain.TestCaseNode;
|
||||||
import io.metersphere.track.dto.TestCaseNodeDTO;
|
import io.metersphere.track.dto.TestCaseNodeDTO;
|
||||||
|
import io.metersphere.track.request.testcase.DragNodeRequest;
|
||||||
import io.metersphere.track.service.TestCaseNodeService;
|
import io.metersphere.track.service.TestCaseNodeService;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -45,4 +46,9 @@ public class TestCaseNodeController {
|
||||||
//nodeIds 包含删除节点ID及其所有子节点ID
|
//nodeIds 包含删除节点ID及其所有子节点ID
|
||||||
return testCaseNodeService.deleteNode(nodeIds);
|
return testCaseNodeService.deleteNode(nodeIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/drag")
|
||||||
|
public void dragNode(@RequestBody DragNodeRequest node){
|
||||||
|
testCaseNodeService.dragNode(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package io.metersphere.track.request.testcase;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.TestCaseNode;
|
||||||
|
import io.metersphere.track.dto.TestCaseNodeDTO;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DragNodeRequest extends TestCaseNode {
|
||||||
|
|
||||||
|
List<String> nodeIds;
|
||||||
|
TestCaseNodeDTO nodeTree;
|
||||||
|
}
|
|
@ -6,13 +6,21 @@ import io.metersphere.base.mapper.TestCaseMapper;
|
||||||
import io.metersphere.base.mapper.TestCaseNodeMapper;
|
import io.metersphere.base.mapper.TestCaseNodeMapper;
|
||||||
import io.metersphere.base.mapper.TestPlanMapper;
|
import io.metersphere.base.mapper.TestPlanMapper;
|
||||||
import io.metersphere.base.mapper.TestPlanTestCaseMapper;
|
import io.metersphere.base.mapper.TestPlanTestCaseMapper;
|
||||||
|
import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
|
||||||
import io.metersphere.commons.constants.TestCaseConstants;
|
import io.metersphere.commons.constants.TestCaseConstants;
|
||||||
import io.metersphere.commons.utils.BeanUtils;
|
import io.metersphere.commons.utils.BeanUtils;
|
||||||
|
import io.metersphere.track.dto.TestCaseDTO;
|
||||||
import io.metersphere.track.dto.TestCaseNodeDTO;
|
import io.metersphere.track.dto.TestCaseNodeDTO;
|
||||||
import io.metersphere.exception.ExcelException;
|
import io.metersphere.exception.ExcelException;
|
||||||
|
import io.metersphere.track.request.testcase.DragNodeRequest;
|
||||||
|
import io.metersphere.track.request.testcase.QueryTestCaseRequest;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.ibatis.session.ExecutorType;
|
||||||
|
import org.apache.ibatis.session.SqlSession;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.yaml.snakeyaml.nodes.NodeId;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -30,6 +38,10 @@ public class TestCaseNodeService {
|
||||||
TestPlanMapper testPlanMapper;
|
TestPlanMapper testPlanMapper;
|
||||||
@Resource
|
@Resource
|
||||||
TestPlanTestCaseMapper testPlanTestCaseMapper;
|
TestPlanTestCaseMapper testPlanTestCaseMapper;
|
||||||
|
@Resource
|
||||||
|
ExtTestCaseMapper extTestCaseMapper;
|
||||||
|
@Resource
|
||||||
|
SqlSessionFactory sqlSessionFactory;
|
||||||
|
|
||||||
public String addNode(TestCaseNode node) {
|
public String addNode(TestCaseNode node) {
|
||||||
|
|
||||||
|
@ -340,4 +352,45 @@ public class TestCaseNodeService {
|
||||||
testCaseNodeMapper.insert(testCaseNode);
|
testCaseNodeMapper.insert(testCaseNode);
|
||||||
return testCaseNode.getId();
|
return testCaseNode.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dragNode(DragNodeRequest request) {
|
||||||
|
|
||||||
|
editNode(request);
|
||||||
|
|
||||||
|
QueryTestCaseRequest testCaseRequest = new QueryTestCaseRequest();
|
||||||
|
testCaseRequest.setNodeIds(request.getNodeIds());
|
||||||
|
|
||||||
|
List<TestCaseDTO> testCases = extTestCaseMapper.list(testCaseRequest);
|
||||||
|
|
||||||
|
TestCaseNodeDTO nodeTree = request.getNodeTree();
|
||||||
|
|
||||||
|
request.getId();
|
||||||
|
buildUpdateTestCase(nodeTree, testCases, "/");
|
||||||
|
|
||||||
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
|
TestCaseMapper testCaseMapper = sqlSession.getMapper(TestCaseMapper.class);
|
||||||
|
testCases.forEach((value) -> {
|
||||||
|
testCaseMapper.updateByPrimaryKey(value);
|
||||||
|
});
|
||||||
|
sqlSession.flushStatements();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildUpdateTestCase(TestCaseNodeDTO rootNode, List<TestCaseDTO> testCases, String rootPath) {
|
||||||
|
|
||||||
|
rootPath = rootPath + rootNode.getName();
|
||||||
|
|
||||||
|
for (TestCaseDTO item : testCases) {
|
||||||
|
if (StringUtils.equals(item.getNodeId(), rootNode.getId())) {
|
||||||
|
item.setNodePath(rootPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<TestCaseNodeDTO> children = rootNode.getChildren();
|
||||||
|
if (children != null && children.size() > 0){
|
||||||
|
for (int i = 0; i < children.size(); i++) {
|
||||||
|
buildUpdateTestCase(children.get(i), testCases, rootPath + '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
:type="'edit'"
|
:type="'edit'"
|
||||||
:draggable="true"
|
:draggable="true"
|
||||||
:select-node.sync="selectNode"
|
:select-node.sync="selectNode"
|
||||||
|
@refreshTable="refreshTable"
|
||||||
ref="nodeTree"/>
|
ref="nodeTree"/>
|
||||||
</el-aside>
|
</el-aside>
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,34 @@ export default {
|
||||||
param.level = dropNode.parent.data.level + 1;
|
param.level = dropNode.parent.data.level + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.$post("/case/node/edit", param);
|
let nodeIds = [];
|
||||||
|
this.getChildNodeId(draggingNode, nodeIds);
|
||||||
|
if (dropNode.level == 1 && dropType != "inner") {
|
||||||
|
param.nodeTree = draggingNode.data;
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < this.treeNodes.length; i++) {
|
||||||
|
param.nodeTree = this.findTreeByNodeId(this.treeNodes[i], dropNode.data.id);
|
||||||
|
if (param.nodeTree) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
param.nodeIds = nodeIds;
|
||||||
|
this.$post("/case/node/drag", param, () => {
|
||||||
|
this.$emit('refreshTable');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
findTreeByNodeId(rootNode, nodeId) {
|
||||||
|
if (rootNode.id == nodeId) {
|
||||||
|
return rootNode;
|
||||||
|
}
|
||||||
|
if (rootNode.children) {
|
||||||
|
for (let i = 0; i < rootNode.children.length; i++) {
|
||||||
|
if (this.findTreeByNodeId(rootNode.children[i], nodeId)) {
|
||||||
|
return rootNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
remove(node, data) {
|
remove(node, data) {
|
||||||
this.$alert(
|
this.$alert(
|
||||||
|
|
Loading…
Reference in New Issue