Kaynağa Gözat

Merge remote-tracking branch 'origin/develop' into develop

lijie 2 yıl önce
ebeveyn
işleme
90b2db21f5

+ 8 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/DemoDiagramController.java

@@ -102,4 +102,12 @@ public class DemoDiagramController {
         return ResultHelper.single(diagramManager.saveDiagram(req.getDiagram()));
     }
 
+    /**
+     * 重置系统图
+     */
+    @PostMapping("resetDiagram")
+    public CommonResult<Diagram> resetDiagram(@RequestBody EditRequest req) {
+        return ResultHelper.single(diagramManager.resetDiagram(req.getDiagramId()));
+    }
+
 }

+ 34 - 69
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/DiagramController.java

@@ -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));
     }
 
     /**

+ 3 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DiagramBuilder.java

@@ -422,9 +422,11 @@ public class DiagramBuilder {
 		if(obj.get("localName") != null) {
 			name = obj.get("localName").asText();
 		}
-		if(StrUtil.isBlank(name)) {
+		if(StrUtil.isBlank(name) && obj.get("name") != null) {
 			name = obj.get("name").asText();
 		}
+		if(name == null)
+			System.out.println();
 		return name;
 	}
 

+ 2 - 3
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/Diagram.java

@@ -87,7 +87,6 @@ public class Diagram {
 	@Expose
 	private XY size;
 
-
 	/**
 	 * 节点列表,运行时&显示态数据结构
 	 */
@@ -126,14 +125,14 @@ public class Diagram {
 	public void layout(CalcContext context){
 		if(template != null) {
 			template.layout(new XY(0, 0));
+
+			size = template.getFrame().getSize();
 		}
 
 		LineLayoutManager lineLayoutManager = new LineLayoutManager(context);
 		for(Line line : lines) {
 			line.layout(lineLayoutManager);
 		}
-
-		this.size = template.getFrame().getSize();
 	}
 
 	public void clearLayout(){

+ 0 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/frame/EditRequest.java

@@ -1,7 +1,6 @@
 package com.persagy.adm.diagram.frame;
 
 import com.persagy.adm.diagram.core.model.base.XY;
-import com.persagy.adm.diagram.core.model.legend.Legend;
 import com.persagy.adm.diagram.core.model.logic.DynGroup;
 import com.persagy.adm.diagram.core.model.logic.EquipPack;
 import lombok.Data;

+ 24 - 48
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/DemoDiagramManager.java

@@ -28,7 +28,7 @@ public class DemoDiagramManager {
 	private final DataStrategy dataStrategy;
 
 	@Autowired
-	private ContentParser parser;
+	private DiagramManager manager;
 
 	@Autowired
 	public DemoDiagramManager(@Qualifier(DataStrategy.IMPL_QUALIFIER) DataStrategy dataStrategy) {
@@ -42,7 +42,7 @@ public class DemoDiagramManager {
 		List<DiagramType> types = dataStrategy.getDiagramTypes();
 		List<Diagram> diagrams = dataStrategy.getDiagrams(projectId, systemId, groupCode);
 		for(Diagram diagram : diagrams) {
-			buildDiagram(diagram, true);
+			manager.buildDiagram(diagram);
 		}
 
 		BdtpRequest req = BdtpRequest.getCurrent();
@@ -73,22 +73,6 @@ public class DemoDiagramManager {
 		return folders;
 	}
 
-	private void loadTemplate(Diagram diagram){
-		if (diagram.getTemplateId() != null) {
-			diagram.setTemplate(dataStrategy.getTemplate(diagram.getTemplateId()));
-		}
-	}
-
-	public void buildDiagram(Diagram diagram, boolean layout){
-		loadTemplate(diagram);
-		diagram.init();
-		new DiagramDataLoader(diagram, dataStrategy).initLoad();
-
-		if(layout) {
-			diagram.layout(new CalcContext(diagram));
-		}
-	}
-
 	/**
 	 * 创建新的系统图
 	 */
@@ -105,7 +89,7 @@ public class DemoDiagramManager {
 		diagram.setGroupCode(groupCode);
 
 		diagram = dataStrategy.saveDiagram(diagram);
-		buildDiagram(diagram, true);
+		manager.buildDiagram(diagram);
 
 		return diagram;
 	}
@@ -124,44 +108,21 @@ public class DemoDiagramManager {
 		Diagram diagram = dataStrategy.getDiagram(diagramId);
 		diagram.setTemplateId(templateId);
 
-		//重设模板时,清空节点和连线
-		diagram.getNodes().clear();
-		diagram.getLines().clear();
+		//重设模板时,重置系统图
+		manager.resetDiagram(diagram);
 
 		dataStrategy.saveDiagram(diagram);
-		buildDiagram(diagram, true);
+		manager.buildDiagram(diagram);
 
 		return diagram;
 	}
 
-	@Autowired
-	private MyObjectMapper myObjectMapper;
 	/**
 	 * 加载数据
 	 */
 	public Diagram loadData(String diagramId, boolean autoLoad){
 		Diagram diagram = dataStrategy.getDiagram(diagramId);
-		buildDiagram(diagram, false);
-
-		CalcContext context = new CalcContext(diagram);
-		new DiagramDataLoader(diagram, dataStrategy).autoLoad(context);
-
-		diagram.layout(context);
-
-		//test 输出数据结构
-//		try {
-//			System.out.println("----------------------------------------------");
-//			System.out.println("edit json : ");
-//			System.out.println(myObjectMapper.mapper4Edit().writeValueAsString(diagram));
-//
-//			System.out.println("----------------------------------------------");
-//			System.out.println("view json : ");
-//			diagram.toAbsoluteLocation();
-//			System.out.println(myObjectMapper.mapper4View().writeValueAsString(diagram));
-//		}catch (Exception e){
-//			e.printStackTrace();
-//		}
-
+		manager.loadData(diagram);
 		return diagram;
 	}
 
@@ -169,8 +130,23 @@ public class DemoDiagramManager {
 	 * 保存系统图
 	 */
 	public Diagram saveDiagram(Map<String, Object> diagramMap) {
-		Diagram diagram = parser.parseContent(parser.toJson(diagramMap), Diagram.class);
-		return dataStrategy.saveDiagram(diagram);
+		Diagram diagram = manager.fromMapData(diagramMap);
+		dataStrategy.saveDiagram(diagram);
+		manager.buildDiagram(diagram);
+		return diagram;
+	}
+
+	/**
+	 * 重置系统图
+	 */
+	public Diagram resetDiagram(String diagramId) {
+		Diagram diagram = dataStrategy.getDiagram(diagramId);
+		manager.resetDiagram(diagram);
+
+		dataStrategy.saveDiagram(diagram);
+		manager.buildDiagram(diagram);
+
+		return diagram;
 	}
 
 }

+ 124 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/DiagramManager.java

@@ -0,0 +1,124 @@
+package com.persagy.adm.diagram.manage;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.persagy.adm.diagram.core.ContentParser;
+import com.persagy.adm.diagram.core.DataStrategy;
+import com.persagy.adm.diagram.core.DiagramDataLoader;
+import com.persagy.adm.diagram.core.model.Diagram;
+import com.persagy.adm.diagram.core.model.logic.CalcContext;
+import com.persagy.adm.diagram.core.util.MyObjectMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Service;
+
+import java.util.Map;
+
+/**
+ * 系统图的相关操作
+ * @author zhaoyk
+ */
+@Service
+public class DiagramManager {
+
+	private final DataStrategy dataStrategy;
+
+	@Autowired
+	private ContentParser parser;
+
+	@Autowired
+	private MyObjectMapper myObjectMapper;
+
+	@Autowired
+	public DiagramManager(@Qualifier(DataStrategy.IMPL_QUALIFIER) DataStrategy dataStrategy) {
+		this.dataStrategy = dataStrategy;
+	}
+
+	/**
+	 * 对系统图进行初始化构建操作
+	 */
+	public void buildDiagram(Diagram diagram){
+		boolean autoLayout = diagram.getTemplate() == null;
+
+		if(diagram.getTemplate() == null){
+			loadTemplate(diagram);
+		}
+
+		diagram.init();
+		new DiagramDataLoader(diagram, dataStrategy).initLoad();
+
+		if(autoLayout) {
+			diagram.layout(new CalcContext(diagram));
+		}
+	}
+
+	private void loadTemplate(Diagram diagram){
+		if (diagram.getTemplateId() != null) {
+			diagram.setTemplate(dataStrategy.getTemplate(diagram.getTemplateId()));
+		}
+	}
+
+	/**
+	 * 重置diagram
+	 */
+	public void resetDiagram(Diagram diagram) {
+		diagram.setTemplate(null);
+		diagram.getLines().clear();
+		diagram.getNodes().clear();
+	}
+
+	/**
+	 * 系统图自动布局计算
+	 */
+	public void layout(Diagram diagram) {
+		diagram.clearLayout();
+		diagram.layout(new CalcContext(diagram));
+	}
+
+	/**
+	 * 自动加载数据(设备、关系)
+	 */
+	public Diagram loadData(Diagram diagram){
+		if(diagram.getTemplate() == null){
+			loadTemplate(diagram);//先加载template,避免buildDiagram时执行layout
+		}
+
+		buildDiagram(diagram);
+
+		CalcContext context = new CalcContext(diagram);
+		new DiagramDataLoader(diagram, dataStrategy).autoLoad(context);
+
+		diagram.layout(context);
+
+		return diagram;
+	}
+
+	/**
+	 * 给显示层的json数据
+	 */
+	public String json4View(Object data){
+		try{
+			return myObjectMapper.mapper4View().writeValueAsString(data);
+		}catch (JsonProcessingException e){
+			throw new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * 给编辑层的json数据
+	 */
+	public String json4Edit(Object data){
+		try{
+			return myObjectMapper.mapper4Edit().writeValueAsString(data);
+		}catch (JsonProcessingException e){
+			throw new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * 解析Map格式的数据(来自web端编辑器),转换为Diagram对象
+	 */
+	public Diagram fromMapData(Map<String, Object> map){
+		return parser.parseContent(parser.toJson(map), Diagram.class);
+	}
+
+}

+ 0 - 3
adm-business/adm-middleware/src/main/java/com/persagy/proxy/migration/service/Impl/MigrationAbstractServiceImpl.java

@@ -11,7 +11,6 @@ import com.persagy.dmp.basic.model.QueryCriteria;
 import com.persagy.dmp.basic.utils.JsonNodeUtils;
 import com.persagy.dmp.common.constant.ResponseCode;
 import com.persagy.dmp.common.model.entity.AuditableEntity;
-import com.persagy.dmp.common.model.entity.BaseEntity;
 import com.persagy.dmp.common.model.response.CommonResult;
 import com.persagy.dmp.common.utils.JsonHelper;
 import com.persagy.dmp.migrate.client.DigitalMigrateLogFacade;
@@ -241,10 +240,8 @@ public class MigrationAbstractServiceImpl<T> implements IMigrationAbstractServic
                         || fieldKey.equals(AuditableEntity.PROP_CREATOR)
                         || fieldKey.equals(AuditableEntity.DO_PROP_MODIFIEDTIME)
                         || fieldKey.equals(AuditableEntity.PROP_MODIFIER)
-                        || fieldKey.equals(BaseEntity.PROP_TS)
                         || fieldKey.equals("createApp")
                         || fieldKey.equals("updateApp")
-                        || fieldKey.equals(BaseEntity.PROP_TS)
                         || fieldKey.equals("dataSource")
                 ){
                     continue;

+ 0 - 2
adm-business/adm-middleware/src/main/java/com/persagy/proxy/report/service/impl/RelationReportService.java

@@ -1051,8 +1051,6 @@ public class RelationReportService implements IRelationReportService {
 			String valKey = key+StrUtil.UNDERLINE+zoneType;
 			result.put("count",relCountMap.getOrDefault(valKey,0));
 		}
-		//关系采集范围 默认全部,不做限制 0 项目交付 1现场交付
-		result.put("deliveryType", -1);
 		return result;
 	}