3 Commits 0fc4ef8bed ... a2e4f15dc6

Author SHA1 Message Date
  liyang a2e4f15dc6 Merge remote-tracking branch 'origin/develop' into develop 2 years ago
  liyang e78cf1ae03 feat(adm-diagram): 代码规范修正 2 years ago
  liyang 06390b6706 feat(adm-diagram): 新增系统图nodes逻辑变更 2 years ago

+ 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

+ 65 - 36
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DiagramBuilder.java

@@ -88,10 +88,11 @@ public class DiagramBuilder {
 				while (iter.hasNext()) {
 					ObjectNode obj = iter.next();
 					if (match(obj, con)) {
-						if(con.getEquipPack() != null)
+						if(con.getEquipPack() != null) {
 							addPackData(con, obj);
-						else
+						} else {
 							addEquipNode(con, obj);
+						}
 
 						iter.remove();
 					}
@@ -124,8 +125,9 @@ public class DiagramBuilder {
 	}
 
 	private void addEquipNode(Container con, ObjectNode obj){
-		if(con.getChildren().size() > equipLimit)
+		if(con.getChildren().size() > equipLimit) {
 			return;
+		}
 
 		EquipmentNode node = new EquipmentNode();
 		node.setId(IdUtil.simpleUUID());
@@ -158,16 +160,20 @@ public class DiagramBuilder {
 		PackNode pn = null;
 		String classCode = getClassCode(obj);
 		Legend legend = null;
-		if(!con.getEquipPack().isPackByType()) { //single
+		//single
+		if(!con.getEquipPack().isPackByType()) {
 			String packName = con.getEquipPack().getPackName();
-			if(StrUtil.isBlank(packName))
+			if(StrUtil.isBlank(packName)) {
 				packName = getTypeName(classCode);
-			if(con.getChildren().size() == 0)
+			}
+			if(con.getChildren().size() == 0) {
 				pn = newPackNode(PackNode.SINGLE_PACK, con, packName);
-			else
+			} else {
 				pn = (PackNode) con.getChildren().get(0);
-			if(con.getEquipPack().getLegendId() != null)
+			}
+			if(con.getEquipPack().getLegendId() != null) {
 				legend = dataStrategy.getLegend(con.getEquipPack().getLegendId(), classCode.substring(0, 4));
+			}
 		} else { //group
 			for(IComponent comp : con.getChildren()) {
 				PackNode item = (PackNode) comp;
@@ -176,15 +182,18 @@ public class DiagramBuilder {
 					break;
 				}
 			}
-			if(pn == null)
+			if(pn == null) {
 				pn = newPackNode(classCode, con, getTypeName(classCode));
+			}
 		}
 
 		if (pn.getLegend() == null) {
-			if(con.getEquipPack().getLegendId() != null)
+			if(con.getEquipPack().getLegendId() != null) {
 				legend = dataStrategy.getLegend(con.getEquipPack().getLegendId(), classCode.substring(0, 4));
-			if(legend == null)
+			}
+			if(legend == null) {
 				legend = findLegend(classCode, null);
+			}
 
 			pn.setLegendId(legend.getId());
 			pn.setLegend(legend);
@@ -207,8 +216,9 @@ public class DiagramBuilder {
 		String classCode = DiagramBuilder.getClassCode(obj);
 		if(equipHolder.getEquipmentTypes() != null && equipHolder.getEquipmentTypes().contains(classCode)) {
 			DataFilter filter = equipHolder.getDataFilter();
-			if(filter != null)
+			if(filter != null) {
 				return filter.filter(obj);
+			}
 			return true;
 		}
 		return false;
@@ -217,8 +227,9 @@ public class DiagramBuilder {
 	private void buildContainers(List<Container> containers) {
 		for(Container con : containers) {
 			if(con.isEquipmentBox()) {
-				if(Boolean.TRUE.equals(con.getProp(Container.PROP_AUTO_HIDDEN)) && CollUtil.isEmpty(con.getChildren()))
+				if(Boolean.TRUE.equals(con.getProp(Container.PROP_AUTO_HIDDEN)) && CollUtil.isEmpty(con.getChildren())) {
 					con.setHidden(true);
+				}
 			}
 		}
 	}
@@ -242,8 +253,9 @@ public class DiagramBuilder {
 		List<Anchor> anchors = equipmentNode.getLegend().getAnchors();
 		if(anchors != null) {
 			for(Anchor anchor : anchors) {
-				if(anchor.getAcceptRelations() != null)
+				if(anchor.getAcceptRelations() != null) {
 					anchor.getAcceptRelations().forEach(rel -> refRelTypes.add(rel));
+				}
 			}
 		}
 	}
@@ -257,8 +269,9 @@ public class DiagramBuilder {
 		List<Legend> legends = legendsCache.get(classCode);
 		if (legends == null) {
 			legends = dataStrategy.getLegendsForEquipment(classCode);
-			if (legends == null)
+			if (legends == null) {
 				legends = new ArrayList<>();
+			}
 			legendsCache.put(classCode, legends);
 		}
 		if(legends.size() > 0) {
@@ -268,25 +281,31 @@ public class DiagramBuilder {
 				boolean typeMatch = CollUtil.isNotEmpty(legend.getDiagramTypes()) && legend.getDiagramTypes().contains(diagram.getType());
 				//过滤条件匹配
 				boolean filterMatch;
-				if(obj != null && legend.getDataFilter() != null)
+				if(obj != null && legend.getDataFilter() != null) {
 					filterMatch = legend.getDataFilter().filter(obj);
-				else
+				} else {
 					filterMatch = true;
+				}
 
-				if(typeMatch && filterMatch)
+				if(typeMatch && filterMatch) {
 					return legend;
+				}
 
-				if(typeMatch && l0 == null)
+				if(typeMatch && l0 == null) {
 					l0 = legend;
-				if(filterMatch && l1 == null)
+				}
+				if(filterMatch && l1 == null) {
 					l1 = legend;
+				}
 			}
-			if(l0 != null)
+			if(l0 != null) {
 				return l0;
-			if(l1 != null)
+			}
+			if(l1 != null) {
 				return l1;
-
-			return legends.get(0); //没有优先匹配的话取第一个
+			}
+			//没有优先匹配的话取第一个
+			return legends.get(0);
 		}
 
 		//返回一个缺省图例
@@ -320,10 +339,11 @@ public class DiagramBuilder {
 
 	private ConnectPoint getConnectPoint(Object obj, String  relType, Object theOtherEnd){
 		ObjectNode theOtherData = null;
-		if(theOtherEnd instanceof EquipmentNode)
+		if(theOtherEnd instanceof EquipmentNode) {
 			theOtherData = (ObjectNode) ((EquipmentNode) theOtherEnd).getDataObject();
-		else if(theOtherEnd instanceof MainPipe)
+		} else if(theOtherEnd instanceof MainPipe) {
 			theOtherData = (ObjectNode) ((MainPipe) theOtherEnd).getDataObject();
+		}
 		String theOtherType = getClassCode(theOtherData);
 
 		if(obj instanceof EquipmentNode) {
@@ -336,35 +356,41 @@ public class DiagramBuilder {
 					Boolean relMatch = null; //关系匹配
 					Boolean equipMatch = null; //另一端设备匹配
 
-					if(CollUtil.isNotEmpty(a.getAcceptRelations()))
+					if(CollUtil.isNotEmpty(a.getAcceptRelations())) {
 						relMatch = a.getAcceptRelations().contains(relType);
+					}
 
 					if(!Boolean.FALSE.equals(relMatch)) {
-						if(CollUtil.isNotEmpty(a.getToEquipmentTypes()))
+						if(CollUtil.isNotEmpty(a.getToEquipmentTypes())) {
 							equipMatch = a.getToEquipmentTypes().contains(theOtherType);
-						if(!Boolean.FALSE.equals(equipMatch) && a.getToDataFilter() != null)
+						}
+						if(!Boolean.FALSE.equals(equipMatch) && a.getToDataFilter() != null) {
 							equipMatch = a.getToDataFilter().filter(theOtherData);
+						}
 					}
 
 					if(!Boolean.FALSE.equals(relMatch) && !Boolean.FALSE.equals(equipMatch)) {
 						if(relMatch == null || equipMatch == null) {
 							//部分匹配
-							if(anchor1 == null)
+							if(anchor1 == null) {
 								anchor1 = a;
-							else if(CollUtil.isNotEmpty(anchor1.getLines()) && CollUtil.isEmpty(a.getLines()))
+							} else if(CollUtil.isNotEmpty(anchor1.getLines()) && CollUtil.isEmpty(a.getLines())) {
 								anchor1 = a;
+							}
 						} else {
 							//完全匹配
 							if(CollUtil.isEmpty(a.getLines())) { //优先每个锚点只有一条连线
 								anchor = a;
 								break;
-							} else if(anchor == null)
+							} else if(anchor == null) {
 								anchor = a;
+							}
 						}
 					}
 				}
-				if(anchor == null && anchor1 != null)
+				if(anchor == null && anchor1 != null) {
 					anchor = anchor1;
+				}
 			}
 
 			if(anchor != null) {
@@ -424,16 +450,19 @@ public class DiagramBuilder {
 
 	public static String getName(ObjectNode obj){
 		String name = null;
-		if(obj.get("localName") != null)
+		if(obj.get("localName") != null) {
 			name = obj.get("localName").asText();
-		if(StrUtil.isBlank(name))
+		}
+		if(StrUtil.isBlank(name)) {
 			name = obj.get("name").asText();
+		}
 		return name;
 	}
 
 	public static String getClassCode(ObjectNode obj){
-		if(obj != null && obj.get("classCode") != null)
+		if(obj != null && obj.get("classCode") != null) {
 			return obj.get("classCode").asText();
+		}
 		return null;
 	}
 

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

@@ -63,10 +63,11 @@ public class DiagramDataLoader {
 				EquipmentNode en = (EquipmentNode) node;
 				obj = objMap.get(en.getObjId());
 
-				if(en.getLegendId() != null)
+				if(en.getLegendId() != null) {
 					en.setLegend(dataStrategy.getLegend(en.getLegendId(), en.getObjSystemCode())); //TODO 批量查询优化
-				else
+				} else {
 					en.setLegend(DiagramBuilder.emptyLegend());
+				}
 			}
 
 			if(obj != null) {

+ 15 - 8
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/line/LineLayoutManager.java

@@ -30,8 +30,9 @@ public class LineLayoutManager {
 
 	private void initBlocks(){
 		for(Object o : diagramBuilder.getEquipMap().values()){
-			if (o instanceof DiagramNode)
+			if (o instanceof DiagramNode) {
 				blocks.add(new Block((DiagramNode)o));
+			}
 		}
 	}
 
@@ -40,9 +41,11 @@ public class LineLayoutManager {
 		ConnectPoint p2 = line.getTo();
 
 		boolean exchange = false;
-		if(p1.getEquipmentNode() == null) { //先计算点模型的终点
-			if(p2.getEquipmentNode() == null)
+		//先计算点模型的终点
+		if(p1.getEquipmentNode() == null) {
+			if(p2.getEquipmentNode() == null) {
 				throw new RuntimeException("do not support 2 main pipe connect");
+			}
 
 			ConnectPoint tmp = p2;
 			p2 = p1;
@@ -74,8 +77,10 @@ public class LineLayoutManager {
 				XY pre = null;
 				for(XY xy : list) {
 					if(pre != null) {
-						XY[] line = new XY[]{pre.copy(), xy.copy()}; //复制坐标
-						LineEnd.orderLine(line); //起点终点排序
+						//复制坐标
+						XY[] line = new XY[]{pre.copy(), xy.copy()};
+						//起点终点排序
+						LineEnd.orderLine(line);
 
 						//线需要留头
 						if(LineEnd.isHorizontal(line)){
@@ -89,8 +94,8 @@ public class LineLayoutManager {
 								line[1].y -= LineEnd.offset;
 							}
 						}
-
-						double distance = point1.distance(GeomUtil.getLine(line)); //计算点和线段的最短距离
+						//计算点和线段的最短距离
+						double distance = point1.distance(GeomUtil.getLine(line));
 						if(distance < min){
 							min = distance;
 							nearLine = line;
@@ -110,8 +115,9 @@ public class LineLayoutManager {
 	 * 锚点出线
 	 */
 	private XY anchorEmerge(ConnectPoint point){
-		if(point.getLocation() == null)
+		if(point.getLocation() == null) {
 			point.layout();
+		}
 
 		XY xy = new XY(point.getLocation());
 		switch (point.getAnchorCode().charAt(0)) {
@@ -127,6 +133,7 @@ public class LineLayoutManager {
 			case 'R':
 				xy.x += LineEnd.offset;
 				break;
+			default:
 		}
 		return xy;
 	}

File diff suppressed because it is too large
+ 539 - 515
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/line/PathBuilder.java


+ 15 - 8
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/Diagram.java

@@ -92,8 +92,9 @@ public class Diagram {
 
 
 	public void init(){
-		if (template != null)
+		if (template != null) {
 			template.init();
+		}
 
 		nodes.sort(new Comparator<DiagramNode>() {
 			@Override
@@ -103,8 +104,9 @@ public class Diagram {
 		});
 		for (DiagramNode node : nodes) {
 			Container con = template.getContainerById(node.getContainerId());
-			if (con != null)
+			if (con != null) {
 				con.addComp(node);
+			}
 		}
 	}
 
@@ -144,13 +146,15 @@ public class Diagram {
 	public List<String> getObjIds(){
 		List<String> ids = new ArrayList<>();
 		for(DiagramNode node : nodes) {
-			if(EquipmentNode.TYPE.equals(node.getCompType()))
+			if(EquipmentNode.TYPE.equals(node.getCompType())) {
 				ids.add(((EquipmentNode) node).getObjId());
+			}
 		}
 		if(template.getMainPipes() != null) {
 			for(MainPipe mainPipe : template.getMainPipes()) {
-				if(mainPipe.isBindEquipment() && StrUtil.isNotBlank(mainPipe.getDataObjectId()))
+				if(mainPipe.isBindEquipment() && StrUtil.isNotBlank(mainPipe.getDataObjectId())) {
 					ids.add(mainPipe.getDataObjectId());
+				}
 			}
 		}
 		return ids;
@@ -159,8 +163,9 @@ public class Diagram {
 	public List<String> getRelIds(){
 		List<String> ids = new ArrayList<>();
 		for(Line line : lines) {
-			if(StrUtil.isNotBlank(line.getDataObjectId()))
+			if(StrUtil.isNotBlank(line.getDataObjectId())) {
 				ids.add(line.getDataObjectId());
+			}
 		}
 		return ids;
 	}
@@ -258,13 +263,15 @@ public class Diagram {
 	}
 
 	public void setExtraProp(String propName, Object propValue) {
-		if(extraProps == null)
+		if(extraProps == null) {
 			extraProps = new HashMap<>();
+		}
 
-		if(propValue != null)
+		if(propValue != null) {
 			extraProps.put(propName, propValue);
-		else
+		} else {
 			extraProps.remove(propName);
+		}
 	}
 
 	public DiagramTemplate getTemplate() {

+ 4 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/Line.java

@@ -12,8 +12,11 @@ import java.util.List;
  */
 public class Line extends AbstractLine {
 
+	/**
+	 * 连线的方向(1:from->to, 0:无方向, -1:to->from)
+	 */
 	@Expose
-	private int direction; //连线的方向(1:from->to, 0:无方向, -1:to->from)
+	private int direction;
 
 	/**
 	 * 起点