复制行为树

This commit is contained in:
MHW
2026-04-13 10:39:37 +08:00
parent 78e5833514
commit 1061020791
4 changed files with 41 additions and 52 deletions

View File

@@ -97,6 +97,18 @@ public class BehaviortreeController extends BaseController
return toAjax(behaviortreeProcessor.create(behaviortree));
}
/**
* 复制行为树
*/
@ApiOperation("复制行为树")
@PreAuthorize("@ss.hasPermi('system:behaviortree:add')")
@Log(title = "行为树主", businessType = BusinessType.INSERT)
@PostMapping("/copy")
public AjaxResult copy(@RequestBody Behaviortree behaviortree)
{
return toAjax(behaviortreeService.copy(behaviortree));
}
/**
* 修改行为树主
*/

View File

@@ -20,6 +20,7 @@ import com.solution.web.core.graph.GraphEdge;
import com.solution.web.core.graph.GraphNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
@@ -56,6 +57,7 @@ public class BehaviortreeProcessor {
return result;
}
@Transactional(rollbackFor = Exception.class)
public int update(Behaviortree behaviortree) {
int result = behaviortreeService.updateBehaviortree(behaviortree);
@@ -75,58 +77,6 @@ public class BehaviortreeProcessor {
private void processGraph(Behaviortree behaviortree) {
Graph graph = null;
try {
graph = objectMapper.readValue(behaviortree.getXmlContent(), Graph.class);
} catch (Exception e) {
// skip
e.printStackTrace();
}
if (null == graph) {
return;
}
// 插入节点 treenodeinstance
Map<String, Treenodeinstance> instanceKeyMap = new HashMap<>();
Map<String, Long> nodeKeyIndexMap = new HashMap<>();
Map<String,GraphNode> nodesMap = new HashMap<>();
if (graph.hasNodes()) {
Long index = 0L;
for (GraphNode node : graph.getNodes()) {
nodesMap.put(node.getKey(), node);
Treenodeinstance instance = createNodeInstance(behaviortree, node);
treenodeinstanceService.insertTreenodeinstance(instance);
instanceKeyMap.put(node.getKey(), instance);
if (node.hasParameters()) {
if (node.isMultiable()) {
List<Nodeparameter> nodeparameters = createMultiableNodeparameter(behaviortree, node, instance);
for (Nodeparameter nodeparameter : nodeparameters) {
nodeparameterService.insertNodeparameter(nodeparameter);
}
} else {
// 插入parameter nodeparameter
for (Templateparameterdef parameter : node.getParameters()) {
Nodeparameter nodeparameter = createNodeParameter(behaviortree, parameter, instance);
nodeparameterService.insertNodeparameter(nodeparameter);
}
}
}
nodeKeyIndexMap.put(node.getKey(), index);
index++;
}
}
// 插入连线 nodeconnection
if (graph.hasEdges()) {
for (GraphEdge edge : graph.getEdges()) {
Nodeconnection connection = createConnection(behaviortree, edge, nodesMap, instanceKeyMap, nodeKeyIndexMap);
nodeconnectionService.insertNodeconnection(connection);
}
}
}
private Nodeconnection createConnection(Behaviortree behaviortree, GraphEdge edge,