|
@@ -1,19 +1,13 @@
|
|
|
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;
|
|
|
+import com.persagy.adm.diagram.manage.DiagramManager;
|
|
|
import com.persagy.dmp.common.constant.ResponseCode;
|
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
|
import com.persagy.dmp.common.model.response.CommonResult;
|
|
@@ -28,11 +22,8 @@ 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;
|
|
|
-import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* 系统图相关接口
|
|
@@ -48,7 +39,7 @@ public class DiagramController {
|
|
|
@Qualifier("dataStrategyImpl")
|
|
|
private DataStrategy dataStrategy;
|
|
|
@Autowired
|
|
|
- private DemoDiagramManager diagramManager;
|
|
|
+ private DiagramManager diagramManager;
|
|
|
@Autowired
|
|
|
private ContentParser parser;
|
|
|
|
|
@@ -60,15 +51,33 @@ 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的系统图列表接口
|
|
|
+ *
|
|
|
+ * @return 系统图列表
|
|
|
+ */
|
|
|
+ @ApiOperation("提供给APM的系统图列表接口")
|
|
|
+ @PostMapping("/apm/getDiagrams")
|
|
|
+ public String getDiagramsForApm() {
|
|
|
+ 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));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -84,67 +93,16 @@ public class DiagramController {
|
|
|
public CommonResult<Diagram> newDiagram(@RequestBody Map<String, Object> params,
|
|
|
@RequestParam String projectId,
|
|
|
@RequestParam String groupCode) {
|
|
|
- Diagram diagram = new Diagram();
|
|
|
+ Diagram diagram = diagramManager.fromMapData(params);
|
|
|
diagram.setGroupCode(groupCode);
|
|
|
diagram.setProjectId(projectId);
|
|
|
|
|
|
- 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);
|
|
|
- });
|
|
|
+ diagramManager.buildDiagram(diagram);
|
|
|
|
|
|
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
|
|
@@ -166,7 +124,7 @@ public class DiagramController {
|
|
|
@GetMapping("/getDiagram")
|
|
|
public CommonResult<Diagram> getDiagram(String diagramId) {
|
|
|
Diagram diagram = dataStrategy.getDiagram(diagramId);
|
|
|
- diagramManager.buildDiagram(diagram, true);
|
|
|
+ diagramManager.buildDiagram(diagram);
|
|
|
return ResultHelper.single(diagram);
|
|
|
}
|
|
|
|
|
@@ -250,7 +208,14 @@ public class DiagramController {
|
|
|
@ApiOperation("加载数据")
|
|
|
@PostMapping("/loadData")
|
|
|
public CommonResult<Diagram> loadData(@RequestBody Diagram diagram) {
|
|
|
- return ResultHelper.single(diagramManager.loadData(diagram.getId(), true));
|
|
|
+ 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));
|
|
|
}
|
|
|
|
|
|
/**
|