Browse Source

feat(adm-diagram): apm 和 编辑器获取系统图列表接口区分

liyang 3 years ago
parent
commit
ae4399ecec

+ 35 - 66
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/DiagramController.java

@@ -1,16 +1,10 @@
 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.DiagramManager;
@@ -21,9 +15,15 @@ import com.persagy.dmp.common.utils.ResultHelper;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 
-import java.util.*;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 系统图相关接口
@@ -51,15 +51,34 @@ public class DiagramController {
      */
     @ApiOperation("系统图列表接口")
     @PostMapping("/getDiagrams")
-    public CommonResult<List<Diagram>> getDiagrams(@RequestBody Map<String, Object> diagram) {
+    public String getDiagrams(@RequestBody Map<String, Object> diagram) {
         BdtpRequest current = BdtpRequest.getCurrent();
         String groupCode = current.getGroupCode();
         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"), true);
 
-        return ResultHelper.multi(diagramList);
+        return diagramManager.json4Edit(ResultHelper.multi(diagramList));
+    }
+
+    /**
+     * 提供给APM的系统图列表接口
+     *
+     * @param diagram 请求参数
+     * @return 系统图列表
+     */
+    @ApiOperation("提供给APM的系统图列表接口")
+    @PostMapping("/apm/getDiagrams")
+    public String getDiagramsForApm(@RequestBody Map<String, Object> diagram) {
+        BdtpRequest current = BdtpRequest.getCurrent();
+        String groupCode = current.getGroupCode();
+        String projectId = current.getProjectId();
+
+        List<Diagram> diagramList = dataStrategy.getDiagrams(null, projectId,
+                null, groupCode, null, false);
+
+        return diagramManager.json4View(ResultHelper.multi(diagramList));
     }
 
     /**
@@ -81,63 +100,10 @@ public class DiagramController {
 
         diagramManager.buildDiagram(diagram);
 
-//        Optional.ofNullable(params).ifPresent(map -> {
-//            Optional.ofNullable(map.get("id")).ifPresent(o -> diagram.setId(String.valueOf(o)));
-//            Optional.ofNullable(map.get("type")).ifPresent(o -> {
-//                if (String.valueOf(o).length() < 4) {
-//                    throw new BusinessException(ResponseCode.A0400.getCode(), "type参数非法");
-//                }
-//                diagram.setType(String.valueOf(o));
-//                diagram.setSystem(String.valueOf(o).substring(0, 4));
-//            });
-//            Optional.ofNullable(map.get("systemId")).ifPresent(o -> diagram.setSystemId(String.valueOf(o)));
-//            Optional.ofNullable(map.get("name")).ifPresent(o -> diagram.setName(String.valueOf(o)));
-//            Optional.ofNullable(map.get("remark")).ifPresent(o -> diagram.setRemark(String.valueOf(o)));
-//            Optional.ofNullable(map.get("templateId")).ifPresent(o -> diagram.setTemplateId(String.valueOf(o)));
-//            Optional.ofNullable(map.get("extraProps")).ifPresent(s -> {
-//                Map<String, Object> m = parser.parseContent(parser.toJson(s), Map.class);
-//                diagram.setExtraProp("state", m.get("state"));
-//            });
-//            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))));
-        List<DiagramNode> nodes = new ArrayList<>();
-        Optional.ofNullable(map.get("template")).flatMap(template ->
-                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
@@ -243,10 +209,13 @@ public class DiagramController {
     @ApiOperation("加载数据")
     @PostMapping("/loadData")
     public CommonResult<Diagram> loadData(@RequestBody Diagram diagram) {
-        diagram = dataStrategy.getDiagram(diagram.getId());
-        if(diagram == null) {
+        if (diagram == null || StrUtil.isBlank(diagram.getId())) {
             throw new BusinessException(ResponseCode.A0400.getCode(), "系统图id不存在");
         }
+        diagram = dataStrategy.getDiagram(diagram.getId());
+        if (diagram == null) {
+            throw new BusinessException(ResponseCode.A0400.getCode(), "数据不存在");
+        }
         return ResultHelper.single(diagramManager.loadData(diagram));
     }