Explorar el Código

feat(adm-diagram): 新增系统图nodes逻辑变更

liyang hace 2 años
padre
commit
06390b6706

+ 42 - 6
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/DiagramController.java

@@ -1,10 +1,16 @@
 package com.persagy.adm.diagram.controller;
 
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.adm.diagram.core.ContentParser;
 import com.persagy.adm.diagram.core.DataStrategy;
 import com.persagy.adm.diagram.core.model.Diagram;
 import com.persagy.adm.diagram.core.model.DiagramNode;
+import com.persagy.adm.diagram.core.model.EquipmentNode;
+import com.persagy.adm.diagram.core.model.Line;
+import com.persagy.adm.diagram.core.model.base.Container;
+import com.persagy.adm.diagram.core.model.base.IComponent;
 import com.persagy.adm.diagram.core.model.template.DiagramTemplate;
 import com.persagy.adm.diagram.frame.BdtpRequest;
 import com.persagy.adm.diagram.manage.DemoDiagramManager;
@@ -23,6 +29,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -61,7 +68,7 @@ public class DiagramController {
         String projectId = current.getProjectId();
 
         List<Diagram> diagramList = dataStrategy.getDiagrams(null, projectId,
-                (String)diagram.get("systemId"), groupCode, (String)diagram.get("name"), (Boolean) diagram.get("flag"));
+                (String) diagram.get("systemId"), groupCode, (String) diagram.get("name"), (Boolean) diagram.get("flag"));
 
         return ResultHelper.multi(diagramList);
     }
@@ -100,17 +107,46 @@ public class DiagramController {
                 Map<String, Object> m = parser.parseContent(parser.toJson(s), Map.class);
                 diagram.setExtraProp("state", m.get("state"));
             });
-            Optional.ofNullable(map.get("lines")).ifPresent(lines ->
-                    diagram.setLines(parser.parseContent(parser.toJson(lines), List.class)));
-            Optional.ofNullable(map.get("nodes")).ifPresent(nodes -> {
-                diagram.setNodes(Arrays.asList(parser.parseContent(parser.toJson(nodes), DiagramNode[].class)));
-            });
+            buildLinesAndNodes(diagram, map);
         });
 
         return ResultHelper.single(dataStrategy.saveDiagram(diagram));
     }
 
     /**
+     * 构建lines modes 数据
+     *
+     * @param diagram 系统图对象
+     * @param map     输入参数集合
+     */
+    private void buildLinesAndNodes(Diagram diagram, Map<String, Object> map) {
+        Optional.ofNullable(map.get("lines")).ifPresent(lines ->
+                diagram.setLines(Arrays.asList(parser.parseContent(parser.toJson(lines), Line[].class))));
+        Optional.ofNullable(map.get("template")).ifPresent(template -> {
+            List<DiagramNode> nodes = new ArrayList<>();
+            Optional.ofNullable(parser.parseContent(parser.toJson(template), DiagramTemplate.class)).ifPresent(diagramTemplate -> {
+                List<Container> containers = diagramTemplate.getContainers();
+                if (CollectionUtil.isNotEmpty(containers)) {
+                    containers.forEach(container -> {
+                        if (container.isEquipmentBox()) {
+                            List<IComponent> children = container.getChildren();
+                            if (CollectionUtil.isNotEmpty(children)) {
+                                children.forEach(iComponent -> {
+                                    if (StrUtil.equalsIgnoreCase(iComponent.getCompType(), EquipmentNode.TYPE)) {
+                                        DiagramNode node = parser.parseContent(parser.toJson(iComponent), DiagramNode.class);
+                                        nodes.add(node);
+                                    }
+                                });
+                            }
+                        }
+                    });
+                }
+            });
+            diagram.setNodes(nodes);
+        });
+    }
+
+    /**
      * 系统图删除功能
      *
      * @param diagramId 系统图id