3 Commitit 8741df7c43 ... e50340a0b1

Tekijä SHA1 Viesti Päivämäärä
  liyang e50340a0b1 refactor(adm-diagram): 代码规范修正 2 vuotta sitten
  liyang d4dbe5800e Merge remote-tracking branch 'origin/develop' into develop 2 vuotta sitten
  liyang 2a6ba9889c refactor(adm-diagram): 代码规范修正 2 vuotta sitten
30 muutettua tiedostoa jossa 1264 lisäystä ja 1068 poistoa
  1. 13 1
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/config/CustomThreadPoolConfig.java
  2. 6 1
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/CommonController.java
  3. 85 45
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DiagramBuilder.java
  4. 129 116
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DiagramDataLoader.java
  5. 13 5
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/line/LineLayoutManager.java
  6. 4 2
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/ConnectPoint.java
  7. 25 8
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/Diagram.java
  8. 14 7
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/base/AbstractComponent.java
  9. 24 12
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/base/Container.java
  10. 2 1
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/base/PositionData.java
  11. 12 6
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/legend/Anchor.java
  12. 2 1
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/legend/Legend.java
  13. 2 1
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/AndFilter.java
  14. 2 1
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/LogicFilter.java
  15. 2 1
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/MatchFilter.java
  16. 2 1
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/OrFilter.java
  17. 2 1
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/template/ContainerRefPoint.java
  18. 14 7
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/template/DiagramTemplate.java
  19. 4 0
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/template/MainPipe.java
  20. 2 1
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/virtual/PackNode.java
  21. 10 5
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/util/GeomUtil.java
  22. 10 10
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/util/GsonUtil.java
  23. 365 346
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/demo/DemoDataStrategy.java
  24. 8 5
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/DemoDiagramManager.java
  25. 5 3
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/Folder.java
  26. 3 4
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/LegendManager.java
  27. 373 358
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/TemplateManager.java
  28. 121 112
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/service/BdtpDataService.java
  29. 3 2
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/util/Pagination.java
  30. 7 5
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/util/ServiceUtil.java

+ 13 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/config/CustomThreadPoolConfig.java

@@ -7,13 +7,25 @@ import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
+/**
+ * 自定义线程池
+ *
+ * @author liyang
+ * @date 2021-12-31
+ */
 @Configuration
 public class CustomThreadPoolConfig {
 
+    /**
+     * 发布自定义线程池
+     *
+     * @return 线程池
+     */
     @Bean("customThreadPool")
     public ThreadPoolExecutor executor() {
         return new ThreadPoolExecutor(4, 10,
                 2000, TimeUnit.MICROSECONDS,
-                new LinkedBlockingDeque<>(20));
+                new LinkedBlockingDeque<>(20),
+                r -> new Thread(r, "diagram_pool_" + r.hashCode()));
     }
 }

+ 6 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/CommonController.java

@@ -19,6 +19,11 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * 公共接口
+ * @author zhaoyk
+ * @date 2021-12-27
+ */
 @RestController
 @CrossOrigin
 public class CommonController {
@@ -27,7 +32,7 @@ public class CommonController {
 	private BdtpDataService bdtpDataService;
 
 	@Autowired
-	@Qualifier(DataStrategy.implQualifier)
+	@Qualifier(DataStrategy.IMPL_QUALIFIER)
 	private DataStrategy dataStrategy;
 
 	@GetMapping("equipTypes")

+ 85 - 45
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DiagramBuilder.java

@@ -55,19 +55,25 @@ public class DiagramBuilder {
 	private void init(){
 		//记录节点中已使用的数据id
 		diagram.getNodes().forEach(node -> {
-			if (EquipmentNode.TYPE.equals(node.getCompType()))
+			if (EquipmentNode.TYPE.equals(node.getCompType())) {
 				equipMap.put(((EquipmentNode) node).getObjId(), node);
+			}
 		});
 		//记录干管中已使用的数据id
 		if(template.getMainPipes() != null) {
 			template.getMainPipes().forEach(mainPipe -> {
-				if(StrUtil.isNotBlank(mainPipe.getDataObjectId()))
+				if(StrUtil.isNotBlank(mainPipe.getDataObjectId())) {
 					equipMap.put(mainPipe.getDataObjectId(), mainPipe);
+				}
 			});
 		}
 	}
 
-	//加载设备数据,并进行计算处理
+	/**
+	 * 加载设备数据,并进行计算处理
+	 * @param containers 容器列表
+	 * @param optionalObjs 节点列表
+	 */
 	public void buildEquipNodeAndContainer(List<Container> containers, List<ObjectNode> optionalObjs){
 		for(Container con : containers) {
 			if(con.isEquipmentBox()) {
@@ -75,10 +81,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();
 					}
@@ -111,8 +118,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());
@@ -145,16 +153,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;
@@ -163,15 +175,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);
@@ -194,8 +209,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;
@@ -204,8 +220,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);
+				}
 			}
 		}
 	}
@@ -229,8 +246,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));
+				}
 			}
 		}
 	}
@@ -244,8 +262,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) {
@@ -255,25 +274,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);
 		}
 
 		//返回一个缺省图例
@@ -312,10 +337,11 @@ public class DiagramBuilder {
 		for(Object o : equipMap.values()) {
 			if(o instanceof EquipmentNode){
 				String txt = ((EquipmentNode) o).getLabel().getContent();
-				if("1#进线柜".equals(txt))
+				if("1#进线柜".equals(txt)) {
 					n1 = (EquipmentNode) o;
-				else if("1#计量柜".equals(txt))
+				} else if("1#计量柜".equals(txt)) {
 					n2 = (EquipmentNode) o;
+				}
 			}
 		}
 		if(n1 != null && n2 != null) {
@@ -338,10 +364,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) {
@@ -349,40 +376,50 @@ public class DiagramBuilder {
 			Anchor anchor = null;
 			List<Anchor> anchors = en.getLegend().getAnchors();
 			if(CollUtil.isNotEmpty(anchors)) {
-				Anchor anchor1 = null; //部分匹配
+				//部分匹配
+				Anchor anchor1 = null;
 				for (Anchor a : anchors) {
-					Boolean relMatch = null; //关系匹配
-					Boolean equipMatch = null; //另一端设备匹配
+					//关系匹配
+					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())) { //优先每个锚点只有一条连线
+							//优先每个锚点只有一条连线
+							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) {
@@ -438,16 +475,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;
 	}
 

+ 129 - 116
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DiagramDataLoader.java

@@ -14,135 +14,148 @@ import java.util.stream.Collectors;
 
 /**
  * 系统图数据加载
+ *
  * @author zhaoyk
  */
 public class DiagramDataLoader {
 
-	private Diagram diagram;
-
-	private DataStrategy dataStrategy;
-
-	private List<ObjectNode> rels;
-
-	private List<ObjectNode> optionalObjs;
-
-	private List<ObjectNode> optionalRels;
-
-	public DiagramDataLoader(Diagram diagram, DataStrategy dataStrategy) {
-		this.diagram = diagram;
-		this.dataStrategy = dataStrategy;
-	}
-
-	/**
-	 * 加载已经保存的数据
-	 */
-	public void initLoad(){
-		List<String> objIds = diagram.getObjIds();
-		if(objIds.size() > 0) {
-			List<ObjectNode> objs = dataStrategy.loadObjectsById(objIds, diagram.getProjectId(), diagram.getGroupCode());
-			if(CollUtil.isNotEmpty(objs))
-				initNodes(objs);
-			else
-				throw new DiagramException("对象数据加载失败");
-		}
-
-		List<String> relIds = diagram.getRelIds();
-		if(relIds.size() > 0) {
-			List<ObjectNode> rels = dataStrategy.loadRelationsById(relIds, diagram.getProjectId(), diagram.getGroupCode());
-			if(CollUtil.isNotEmpty(rels))
-				initLines(rels);
-			else
-				throw new DiagramException("关系数据加载失败");
-		}
-	}
-
-	private void initNodes(List<ObjectNode> objs) {
-		HashMap<String, ObjectNode> objMap = new HashMap<>();
-		objs.forEach(obj -> objMap.put(obj.get("id").asText(), obj));
-
-		for (DiagramNode node : diagram.getNodes()) {
-			ObjectNode obj = null;
-
-			if(EquipmentNode.TYPE.equals(node.getCompType())) { //设备节点
-				EquipmentNode en = (EquipmentNode) node;
-				obj = objMap.get(en.getObjId());
-
-				if(en.getLegendId() != null)
-					en.setLegend(dataStrategy.getLegend(en.getLegendId(), en.getObjSystemCode()));
-				else
-					en.setLegend(DiagramBuilder.emptyLegend());
-			}
-
-			if(obj != null)
-				node.setDataObject(obj);
-		}
-
-		//设备类干管
-		if(diagram.getTemplate().getMainPipes() != null) {
-			for(MainPipe mainPipe : diagram.getTemplate().getMainPipes()) {
-				if(mainPipe.isBindEquipment()){
-					ObjectNode obj = objMap.get(mainPipe.getDataObjectId());
-					if(obj != null)
-						mainPipe.setDataObject(obj);
-				}
-			}
-		}
-	}
-
-	private void initLines(List<ObjectNode> rels){
-		HashMap<String, ObjectNode> relMap = new HashMap<>();
-		rels.forEach(obj -> relMap.put(obj.get("id").asText(), obj));
-
-		for(Line line : diagram.getLines()) {
-			if(line.getDataObjectId() != null){
-				ObjectNode rel = relMap.get(line.getDataObjectId());
-				if(rel != null)
+    private Diagram diagram;
+
+    private DataStrategy dataStrategy;
+
+    private List<ObjectNode> rels;
+
+    private List<ObjectNode> optionalObjs;
+
+    private List<ObjectNode> optionalRels;
+
+    public DiagramDataLoader(Diagram diagram, DataStrategy dataStrategy) {
+        this.diagram = diagram;
+        this.dataStrategy = dataStrategy;
+    }
+
+    /**
+     * 加载已经保存的数据
+     */
+    public void initLoad() {
+        List<String> objIds = diagram.getObjIds();
+        if (objIds.size() > 0) {
+            List<ObjectNode> objs = dataStrategy.loadObjectsById(objIds, diagram.getProjectId(), diagram.getGroupCode());
+            if (CollUtil.isNotEmpty(objs)) {
+                initNodes(objs);
+            } else {
+                throw new DiagramException("对象数据加载失败");
+            }
+        }
+
+        List<String> relIds = diagram.getRelIds();
+        if (relIds.size() > 0) {
+            List<ObjectNode> rels = dataStrategy.loadRelationsById(relIds, diagram.getProjectId(), diagram.getGroupCode());
+            if (CollUtil.isNotEmpty(rels)) {
+                initLines(rels);
+            } else {
+                throw new DiagramException("关系数据加载失败");
+            }
+        }
+    }
+
+    private void initNodes(List<ObjectNode> objs) {
+        HashMap<String, ObjectNode> objMap = new HashMap<>();
+        objs.forEach(obj -> objMap.put(obj.get("id").asText(), obj));
+
+        for (DiagramNode node : diagram.getNodes()) {
+            ObjectNode obj = null;
+            //设备节点
+            if (EquipmentNode.TYPE.equals(node.getCompType())) {
+                EquipmentNode en = (EquipmentNode) node;
+                obj = objMap.get(en.getObjId());
+
+                if (en.getLegendId() != null) {
+                    en.setLegend(dataStrategy.getLegend(en.getLegendId(), en.getObjSystemCode()));
+                } else {
+                    en.setLegend(DiagramBuilder.emptyLegend());
+                }
+            }
+
+            if (obj != null) {
+                node.setDataObject(obj);
+            }
+        }
+
+        //设备类干管
+        if (diagram.getTemplate().getMainPipes() != null) {
+            for (MainPipe mainPipe : diagram.getTemplate().getMainPipes()) {
+                if (mainPipe.isBindEquipment()) {
+                    ObjectNode obj = objMap.get(mainPipe.getDataObjectId());
+                    if (obj != null) {
+                        mainPipe.setDataObject(obj);
+                    }
+                }
+            }
+        }
+    }
+
+    private void initLines(List<ObjectNode> rels) {
+        HashMap<String, ObjectNode> relMap = new HashMap<>();
+        rels.forEach(obj -> relMap.put(obj.get("id").asText(), obj));
+
+        for (Line line : diagram.getLines()) {
+            if (line.getDataObjectId() != null) {
+                ObjectNode rel = relMap.get(line.getDataObjectId());
+                if (rel != null) {
 					line.setDataObject(rel);
-			}
-		}
-	}
-
-	/**
-	 * 搜索数据并自动加载
-	 */
-	public void autoLoad(DiagramBuilder builder) {
-		//查询备选数据
-		HashSet<String> equipTypes = new HashSet<>();
-		List<Container> containers = diagram.getTemplate().getContainers();
-		for(Container con : containers) {
-			if(con.getEquipmentTypes() != null)
-				equipTypes.addAll(con.getEquipmentTypes());
-		}
-		if(diagram.getTemplate().getMainPipes() != null) {
-			for(MainPipe mainPipe : diagram.getTemplate().getMainPipes()) {
-				if(mainPipe.getEquipmentTypes() != null) //TODO 过滤已经初始化加载数据的干管
-					equipTypes.addAll(mainPipe.getEquipmentTypes());
-			}
-		}
-
-		//TODO 打包设备查询性能优化
-		if(equipTypes.size() > 0)
+				}
+            }
+        }
+    }
+
+    /**
+     * 搜索数据并自动加载
+     */
+    public void autoLoad(DiagramBuilder builder) {
+        //查询备选数据
+        HashSet<String> equipTypes = new HashSet<>();
+        List<Container> containers = diagram.getTemplate().getContainers();
+        for (Container con : containers) {
+            if (con.getEquipmentTypes() != null) {
+                equipTypes.addAll(con.getEquipmentTypes());
+            }
+        }
+        if (diagram.getTemplate().getMainPipes() != null) {
+            for (MainPipe mainPipe : diagram.getTemplate().getMainPipes()) {
+                //TODO 过滤已经初始化加载数据的干管
+                if (mainPipe.getEquipmentTypes() != null) {
+                    equipTypes.addAll(mainPipe.getEquipmentTypes());
+                }
+            }
+        }
+
+        //TODO 打包设备查询性能优化
+        if (equipTypes.size() > 0) {
 			optionalObjs = dataStrategy.loadObjectsByType(new ArrayList<>(equipTypes), diagram.getProjectId(), diagram.getSystemId(), diagram.getGroupCode());
-		else
+		} else {
 			optionalObjs = new ArrayList<>();
-		//记录备选对象id列表
-		List<String> objIds = optionalObjs.stream().map(obj -> obj.get("id").asText()).collect(Collectors.toList());
+		}
+        //记录备选对象id列表
+        List<String> objIds = optionalObjs.stream().map(obj -> obj.get("id").asText()).collect(Collectors.toList());
 
-		//去掉已经使用的数据项
-		HashMap<String, Object> equipMap = builder.getEquipMap();
-		if(equipMap.size() > 0)
+        //去掉已经使用的数据项
+        HashMap<String, Object> equipMap = builder.getEquipMap();
+        if (equipMap.size() > 0) {
 			optionalObjs = optionalObjs.stream().filter(obj -> !equipMap.containsKey(obj.get("id").asText())).collect(Collectors.toList());
+		}
 
-		builder.buildEquipNodeAndContainer(containers, optionalObjs);
-		List<String[]> relTypes = builder.getRefRelTypes().stream().map(type -> type.split("/")).collect(Collectors.toList());
+        builder.buildEquipNodeAndContainer(containers, optionalObjs);
+        List<String[]> relTypes = builder.getRefRelTypes().stream().map(type -> type.split("/")).collect(Collectors.toList());
 
-		//TODO 关系查询,需要区分打包设备
-		if(objIds.size() > 0 && relTypes.size() > 0)
+        //TODO 关系查询,需要区分打包设备
+        if (objIds.size() > 0 && relTypes.size() > 0) {
 			optionalRels = dataStrategy.loadRelationsByType(relTypes, objIds, diagram.getProjectId(), diagram.getGroupCode());
-		else
+		} else {
 			optionalRels = new ArrayList<>();
+		}
 
-		builder.buildLines(optionalRels);
-	}
+        builder.buildLines(optionalRels);
+    }
 
 }

+ 13 - 5
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/line/LineLayoutManager.java

@@ -13,6 +13,8 @@ import java.util.List;
 
 /**
  * 连线布局计算
+ * @author zhaoyk
+ * @date 2022-01-12
  */
 public class LineLayoutManager {
 
@@ -27,8 +29,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));
+			}
 		}
 	}
 
@@ -37,9 +40,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;
@@ -90,15 +95,17 @@ public class LineLayoutManager {
 	 * 就算点和线段的最短距离
 	 */
 	private double distance(XY[] line, XY xy){
-		return 0; //TODO
+		//TODO
+		return 0;
 	}
 
 	/**
 	 * 锚点出线
 	 */
 	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)) {
@@ -114,6 +121,7 @@ public class LineLayoutManager {
 			case 'R':
 				xy.x += LineEnd.offset;
 				break;
+			default:
 		}
 		return xy;
 	}

+ 4 - 2
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/ConnectPoint.java

@@ -52,8 +52,9 @@ public class ConnectPoint {
 	 * 如果hostObj为EquipmentNode类型,则返回
 	 */
 	public EquipmentNode getEquipmentNode(){
-		if(hostObj instanceof EquipmentNode)
+		if(hostObj instanceof EquipmentNode) {
 			return (EquipmentNode) hostObj;
+		}
 		return null;
 	}
 
@@ -61,8 +62,9 @@ public class ConnectPoint {
 	 * 如果hostObj为MainPipe类型,则返回
 	 */
 	public MainPipe getMainPipe(){
-		if(hostObj instanceof MainPipe)
+		if(hostObj instanceof MainPipe) {
 			return (MainPipe) hostObj;
+		}
 		return null;
 	}
 

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

@@ -8,6 +8,7 @@ import com.persagy.adm.diagram.core.model.base.Container;
 import com.persagy.adm.diagram.core.model.base.XY;
 import com.persagy.adm.diagram.core.model.template.DiagramTemplate;
 import com.persagy.adm.diagram.core.model.template.MainPipe;
+import com.persagy.dmp.common.lang.PsDateTime;
 
 import java.util.*;
 
@@ -86,13 +87,15 @@ public class Diagram {
 	@Expose
 	private List<Line> lines = new ArrayList();
 
+	private PsDateTime createTime;
 	//运行时
 	private DiagramTemplate template;
 
 
 	public void init(){
-		if (template != null)
+		if (template != null) {
 			template.init();
+		}
 
 		nodes.sort(new Comparator<DiagramNode>() {
 			@Override
@@ -102,8 +105,9 @@ public class Diagram {
 		});
 		for (DiagramNode node : nodes) {
 			Container con = template.getContainerById(node.getContainerId());
-			if (con != null)
+			if (con != null) {
 				con.addComp(node);
+			}
 		}
 	}
 
@@ -143,13 +147,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;
@@ -158,8 +164,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;
 	}
@@ -257,13 +264,23 @@ 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 PsDateTime getCreateTime() {
+		return createTime;
+	}
+
+	public void setCreateTime(PsDateTime createTime) {
+		this.createTime = createTime;
 	}
 
 	public DiagramTemplate getTemplate() {

+ 14 - 7
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/base/AbstractComponent.java

@@ -11,8 +11,10 @@ import java.util.Map;
  * @author zhaoyk
  */
 abstract public class AbstractComponent implements IComponent {
-
-	@Expose //使用gson保存文件
+	/**
+	 * 使用gson保存文件
+	 */
+	@Expose
 	protected String id;
 
 	@Expose
@@ -20,8 +22,10 @@ abstract public class AbstractComponent implements IComponent {
 
 	@Expose
 	protected String compType;
-
-	@JsonIgnore //使用jackson输出到web端
+	/**
+	 * 使用jackson输出到web端
+	 */
+	@JsonIgnore
 	protected IContainer parent;
 
 	@Expose
@@ -140,16 +144,18 @@ abstract public class AbstractComponent implements IComponent {
 	}
 
 	public void setProp(String name, Object value){
-		if (props == null)
+		if (props == null) {
 			props = new HashMap<>();
+		}
 		props.put(name, value);
 	}
 
 	public void removeProp(String name) {
 		if (props != null) {
 			props.remove(name);
-			if (props.size() == 0)
+			if (props.size() == 0) {
 				props = null;
+			}
 		}
 	}
 
@@ -165,8 +171,9 @@ abstract public class AbstractComponent implements IComponent {
 		IComponent c = this;
 		while (c != null){
 			XY pos = c.getLocation();
-			if(pos == null)
+			if(pos == null) {
 				return null;
+			}
 
 			p.x += pos.x;
 			p.y += pos.y;

+ 24 - 12
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/base/Container.java

@@ -68,6 +68,7 @@ public class Container extends AbstractComponent implements IContainer {
 		return layout;
 	}
 
+	@Override
 	public void setLayout(Layout layout) {
 		this.layout = layout;
 	}
@@ -82,22 +83,26 @@ public class Container extends AbstractComponent implements IContainer {
 		for(IComponent comp : getArrangedElements()){
 			if(comp.isHidden()) {
 				if(comp instanceof Container) {
-					comp.setLocation(new XY(p.x, p.y)); //给定一个位置,方便计算干管
+					//给定一个位置,方便计算干管
+					comp.setLocation(new XY(p.x, p.y));
 					((Container) comp).setSize(new XY(0, 0));
 				}
 				continue;
 			}
 
 			PositionData compPd = comp.getPosition();
-			if(compPd == null)
+			if(compPd == null) {
 				compPd = new PositionData();
+			}
 
 			if(row){
-				if(idx != 0)
+				if(idx != 0) {
 					p.y += layout.spaceV;
+				}
 			} else {
-				if(idx != 0)
+				if(idx != 0) {
 					p.x += layout.spaceH;
+				}
 			}
 
 			comp.setLocation(new XY(p.x + compPd.paddingLeft, p.y + compPd.paddingTop));
@@ -124,17 +129,20 @@ public class Container extends AbstractComponent implements IContainer {
 			size.y = layout.marginTop + childMax + layout.marginBottom;
 		}
 
-		if(size.y < position.minH)
+		if(size.y < position.minH) {
 			size.y = position.minH;
-		if(size.x < position.minW)
+		}
+		if(size.x < position.minW) {
 			size.x = position.minW;
+		}
 
 		//自由定位的组件
 		for(IComponent comp : getScatteredElements()) {
 			comp.layout();
 
-			if(comp.getPosition().getAbsolutePoint() != null)
+			if(comp.getPosition().getAbsolutePoint() != null) {
 				comp.setLocation(comp.getPosition().getAbsolutePoint());
+			}
 		}
 	}
 
@@ -148,8 +156,9 @@ public class Container extends AbstractComponent implements IContainer {
 		children.add(child);
 		child.setParent(this);
 
-		if(child.getPosition() == null)
+		if(child.getPosition() == null) {
 			child.setPosition(child.defaultPosition());
+		}
 	}
 
 	@Override
@@ -167,7 +176,7 @@ public class Container extends AbstractComponent implements IContainer {
 	}
 
 	public List<IComponent> getScatteredElements(){
-		return children.stream().filter(comp -> comp.isAbsolutePosition()).collect(Collectors.toList());
+		return children.stream().filter(IComponent::isAbsolutePosition).collect(Collectors.toList());
 	}
 
 	@Override
@@ -230,19 +239,22 @@ public class Container extends AbstractComponent implements IContainer {
 
 		for (IComponent comp : cs) {
 			addComp(comp);
-			if (comp instanceof Container)
+			if (comp instanceof Container) {
 				((Container) comp).initParent();
+			}
 		}
 	}
 
 	public IComponent findComponent(String componentId){
 		for(IComponent comp : children) {
-			if(comp.getId().equals(componentId))
+			if(comp.getId().equals(componentId)) {
 				return comp;
+			}
 			if(comp instanceof Container) {
 				IComponent rtn = ((Container) comp).findComponent(componentId);
-				if(rtn != null)
+				if(rtn != null) {
 					return rtn;
+				}
 			}
 		}
 		return null;

+ 2 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/base/PositionData.java

@@ -45,8 +45,9 @@ public class PositionData {
 	public void setAbsolute(boolean absolute) {
 		this.absolute = absolute;
 
-		if(!absolute)
+		if(!absolute) {
 			absolutePoint = null;
+		}
 	}
 
 	public XY getAbsolutePoint() {

+ 12 - 6
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/legend/Anchor.java

@@ -74,8 +74,9 @@ public class Anchor {
 	}
 
 	public void addLine(Line line) {
-		if(lines == null)
+		if(lines == null) {
 			lines = new ArrayList<>();
+		}
 		lines.add(line);
 	}
 
@@ -159,23 +160,28 @@ public class Anchor {
 		int part = 6;
 		switch (c1){
 			case 'T':
-				if(c2 == 'L')
+				if(c2 == 'L') {
 					return new XY(legendLocation);
-				if(c2 == 'R')
+				}
+				if(c2 == 'R') {
 					return new XY(legendLocation.x + legendSize.x, legendLocation.y);
+				}
 				return new XY(legendLocation.x + legendSize.x / part * idx, legendLocation.y);
 			case 'B':
-				if(c2 == 'L')
+				if(c2 == 'L') {
 					return new XY(legendLocation.x, legendLocation.y + legendSize.y);
-				if(c2 == 'R')
+				}
+				if(c2 == 'R') {
 					return new XY(legendLocation.x + legendSize.x, legendLocation.y + legendSize.y);
+				}
 				return new XY(legendLocation.x + legendSize.x / part * idx, legendLocation.y + legendSize.y);
 			case 'L':
 				return new XY(legendLocation.x, legendLocation.y + legendSize.y / part * idx);
 			case 'R':
 				return new XY(legendLocation.x + legendSize.x, legendLocation.y + legendSize.y / part * idx);
+			default:
+				return null;
 		}
-		return null;
 	}
 
 }

+ 2 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/legend/Legend.java

@@ -69,8 +69,9 @@ public class Legend {
 	public Anchor getAnchor(String code){
 		if(anchors != null){
 			for(Anchor anchor : anchors) {
-				if(anchor.getCode().equals(code))
+				if(anchor.getCode().equals(code)) {
 					return anchor;
+				}
 			}
 		}
 		return null;

+ 2 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/AndFilter.java

@@ -13,8 +13,9 @@ public class AndFilter extends LogicFilter {
 	@Override
 	protected boolean judge(Object data) {
 		for(DataFilter item : items) {
-			if(!item.filter(data))
+			if(!item.filter(data)) {
 				return false;
+			}
 		}
 		return true;
 	}

+ 2 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/LogicFilter.java

@@ -26,8 +26,9 @@ abstract public class LogicFilter extends DataFilter {
 	}
 
 	public void addItem(DataFilter item) {
-		if(items == null)
+		if(items == null) {
 			items = new ArrayList<>();
+		}
 		items.add(item);
 	}
 

+ 2 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/MatchFilter.java

@@ -67,8 +67,9 @@ public class MatchFilter extends DataFilter {
 			String strData = data != null ? data.toString() : "";
 			String[] arr = value.split(";");
 			for(String s : arr) {
-				if(!strData.contains(s))
+				if(!strData.contains(s)) {
 					return false;
+				}
 			}
 			return true;
 		}

+ 2 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/OrFilter.java

@@ -13,8 +13,9 @@ public class OrFilter extends LogicFilter {
 	@Override
 	protected boolean judge(Object data) {
 		for(DataFilter item : items) {
-			if(!item.filter(data))
+			if(!item.filter(data)) {
 				return true;
+			}
 		}
 		return false;
 	}

+ 2 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/template/ContainerRefPoint.java

@@ -79,8 +79,9 @@ public class ContainerRefPoint {
 	public static ContainerRefPoint getRefPoint(Container container, String name, XY conLocation) {
 		List<ContainerRefPoint> list = getRefPoints(container, conLocation);
 		for(ContainerRefPoint p : list) {
-			if(p.getName().equalsIgnoreCase(name))
+			if(p.getName().equalsIgnoreCase(name)) {
 				return p;
+			}
 		}
 		return null;
 	}

+ 14 - 7
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/template/DiagramTemplate.java

@@ -143,8 +143,9 @@ public class DiagramTemplate {
 				if (comp instanceof Container) {
 					Container subCon = (Container)comp;
 					if(subCon.isAbsolutePosition()){
-						if(scatteredContainers == null)
+						if(scatteredContainers == null) {
 							scatteredContainers = new ArrayList<>();
+						}
 						scatteredContainers.add(subCon);
 
 						con.getChildren().remove(i);
@@ -169,17 +170,20 @@ public class DiagramTemplate {
 	}
 
 	public Container getContainerById(String containerId) {
-		if(frame.getId().equals(containerId))
+		if(frame.getId().equals(containerId)) {
 			return frame;
+		}
 
 		IComponent comp = frame.findComponent(containerId);
-		if(comp instanceof Container)
+		if(comp instanceof Container) {
 			return (Container)comp;
+		}
 
 		if (scatteredContainers != null) {
 			for(Container con : scatteredContainers){
-				if(con.getId().equals(containerId))
+				if(con.getId().equals(containerId)) {
 					return con;
+				}
 			}
 		}
 
@@ -189,8 +193,9 @@ public class DiagramTemplate {
 	public MainPipe getMainPipeById(String mainPipeId) {
 		if(mainPipes != null) {
 			for (MainPipe mainPipe : mainPipes) {
-				if (mainPipe.getId().equals(mainPipeId))
+				if (mainPipe.getId().equals(mainPipeId)) {
 					return mainPipe;
+				}
 			}
 		}
 		return null;
@@ -217,8 +222,9 @@ public class DiagramTemplate {
 		List<Container> list = new ArrayList<>();
 		getContainers(frame, list);
 
-		if(scatteredContainers != null)
+		if(scatteredContainers != null) {
 			list.addAll(scatteredContainers);
+		}
 
 		return list;
 	}
@@ -228,8 +234,9 @@ public class DiagramTemplate {
 
 		if(con.getChildren() != null) {
 			for(IComponent comp : con.getChildren()) {
-				if (comp instanceof Container)
+				if (comp instanceof Container) {
 					getContainers((Container) comp, list);
+				}
 			}
 		}
 	}

+ 4 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/template/MainPipe.java

@@ -50,18 +50,22 @@ public class MainPipe extends AbstractLine implements IEquipHolder {
 	 */
 	private List<List<XY>> locationPath;
 
+	@Override
 	public String getId() {
 		return id;
 	}
 
+	@Override
 	public void setId(String id) {
 		this.id = id;
 	}
 
+	@Override
 	public String getName() {
 		return name;
 	}
 
+	@Override
 	public void setName(String name) {
 		this.name = name;
 	}

+ 2 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/virtual/PackNode.java

@@ -35,8 +35,9 @@ public class PackNode extends EquipmentNode {
 	}
 
 	public void add(String equipClassCode) {
-		if(statInfo == null)
+		if(statInfo == null) {
 			statInfo = new HashMap<>();
+		}
 
 		Integer i = statInfo.get(equipClassCode);
 		statInfo.put(equipClassCode, i == null ? 1 : i + 1);

+ 10 - 5
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/util/GeomUtil.java

@@ -67,15 +67,17 @@ public class GeomUtil {
 	}
 
 	public static boolean checkPolygon(ArrayList<ArrayList<ArrayList<CaseInsensitiveMap>>> outline){
-		if(CollUtil.isEmpty(outline))
+		if(CollUtil.isEmpty(outline)) {
 			return false;
+		}
 
 		try {
 			Polygon[] ps = new Polygon[outline.size()];
 			for (int i = 0; i < ps.length; i++) {
 				List space = (List) outline.get(i);
-				if(CollUtil.isEmpty(space))
+				if(CollUtil.isEmpty(space)) {
 					return false;
+				}
 
 				List<Map> shellList = (List) space.get(0);
 				LinearRing shell = geometryFactory.createLinearRing(buildCoords(shellList));
@@ -104,15 +106,17 @@ public class GeomUtil {
 	}
 
 	public static boolean checkPolygon(ArrayNode outline){
-		if(outline == null || outline.size() == 0)
+		if(outline == null || outline.size() == 0) {
 			return false;
+		}
 
 		try {
 			Polygon[] ps = new Polygon[outline.size()];
 			for (int i = 0; i < ps.length; i++) {
 				ArrayNode space = (ArrayNode) outline.get(i);
-				if(space == null || space.size() == 0)
+				if(space == null || space.size() == 0) {
 					return false;
+				}
 
 				ArrayNode shellList = (ArrayNode) space.get(0);
 				LinearRing shell = geometryFactory.createLinearRing(buildCoords(shellList));
@@ -141,7 +145,8 @@ public class GeomUtil {
 		WKTReader reader = new WKTReader( geometryFactory );
 		LineString geometry1 = (LineString) reader.read("LINESTRING(0 0, 2 0, 5 0)");
 		LineString geometry2 = (LineString) reader.read("LINESTRING(5 0, 0 0)");
-		return geometry1.equals(geometry2);//true
+		//true
+		return geometry1.equals(geometry2);
 	}
 
 	/**

+ 10 - 10
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/util/GsonUtil.java

@@ -52,17 +52,17 @@ public class GsonUtil {
 		public IComponent deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
 			Class<? extends IComponent> target = null;
 			String compType = jsonElement.getAsJsonObject().get("compType").getAsString();
-			if(Container.TYPE.equals(compType))
+			if(Container.TYPE.equals(compType)) {
 				target = Container.class;
-			else if(EquipmentNode.TYPE.equals(compType))
+			} else if(EquipmentNode.TYPE.equals(compType)) {
 				target = EquipmentNode.class;
-			else if(PackNode.TYPE.equals(compType))
+			} else if(PackNode.TYPE.equals(compType)) {
 				target = PackNode.class;
-			else if(Label.TYPE.equals(compType))
+			} else if(Label.TYPE.equals(compType)) {
 				target = Label.class;
-			else if(DataPanelNode.TYPE.equals(compType))
+			} else if(DataPanelNode.TYPE.equals(compType)) {
 				target = DataPanelNode.class;
-			else {
+			} else {
 				//TODO 其他类型
 			}
 			return gson.fromJson(jsonElement, target);
@@ -81,13 +81,13 @@ public class GsonUtil {
 		public DataFilter deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
 			Class<? extends DataFilter> target = null;
 			int fType = jsonElement.getAsJsonObject().get("type").getAsInt();
-			if(fType == DataFilter.TYPE_MATCH)
+			if(fType == DataFilter.TYPE_MATCH) {
 				target = MatchFilter.class;
-			else if(fType == AndFilter.TYPE_AND)
+			} else if(fType == AndFilter.TYPE_AND) {
 				target = AndFilter.class;
-			else if(fType == OrFilter.TYPE_OR)
+			} else if(fType == OrFilter.TYPE_OR) {
 				target = OrFilter.class;
-			else {
+			} else {
 				//TODO 其他类型
 			}
 			return gson.fromJson(jsonElement, target);

+ 365 - 346
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/demo/DemoDataStrategy.java

@@ -23,372 +23,391 @@ import java.util.List;
 
 /**
  * 测试开发使用的io策略实现类
+ *
  * @author zhaoyk
  */
 @Service
 @Qualifier("demo")
 public class DemoDataStrategy implements DataStrategy {
 
-	@Autowired
-	private ContentParser parser;
-
-	@Override
-	public List<DiagramType> getDiagramTypes() {
-		List<DiagramType> types = new ArrayList<>();
-
-		readFiles((majCode, sysCode, typeCode, typeDir) -> {
-			DiagramType diagramType = new DiagramType();
-			diagramType.setMajor(majCode);
-			diagramType.setDSystem(sysCode);
-			diagramType.setCode(typeCode);
-			diagramType.setName(typeDir.getName());
-
-			types.add(diagramType);
-			return null;
-		});
-
-		return types;
-	}
-
-	/* 模板部分 */
-	private static final String DIR_TEMPLATE = "store/template/";
-
-	@Override
-	public List<DiagramTemplate> getTemplates() {
-		List<DiagramTemplate> rtn = new ArrayList<>();
-
-		readFiles((majCode, sysCode, typeCode, typeDir) -> {
-			File[] files = typeDir.listFiles();
-			if(files != null) {
-				for (File f : files) {
-					try {
-						DiagramTemplate template = parser.parseContent(FileUtil.readUtf8String(f), DiagramTemplate.class);
-						rtn.add(template);
-					} catch (Exception e) {
-						e.printStackTrace();
-					}
-				}
-			}
-			return null;
-		});
-
-		return rtn;
-	}
-
-	private <T> T readFiles(Handler<T> handler){
-		File dir = new File(DIR_TEMPLATE);
-		File[] majList = dir.listFiles();
-		if(majList == null)
-			return null;
-
-		for(File fm : majList) {
-			String majCode = fm.getName().substring(0, 2);
-
-			File[] sysList = fm.listFiles();
-			if(sysList == null)
-				continue;
-
-			for(File fs : sysList) {
-				String sysCode = majCode + fs.getName().substring(0, 2);
-				File[] typeList = fs.listFiles();
-				if(typeList != null) {
-					for (File ft : typeList) {
-						String typeCode = sysCode + "_" + ft.getName();
-
-						T result = handler.handle(majCode, sysCode, typeCode, ft);
-						if(result != null)
-							return result;
-					}
-				}
-			}
-		}
-
-		return null;
-	}
-
-	interface Handler<T> {
-		T handle(String majCode, String sysCode, String typeCode, File typeDir);
-	}
-
-	@Override
-	public List<DiagramTemplate> getTemplates(String diagramType) {
-		List<DiagramTemplate> rtn = new ArrayList<>();
-
-		readFiles((majCode, sysCode, typeCode, typeDir) -> {
-			if(diagramType.equals(typeCode)) {
-				File[] files = typeDir.listFiles();
-				if(files != null) {
-					for (File f : files) {
-						try {
-							DiagramTemplate template = parser.parseContent(FileUtil.readUtf8String(f), DiagramTemplate.class);
-							rtn.add(template);
-						} catch (Exception e) {
-							e.printStackTrace();
-						}
-					}
-				}
-			}
-			return null;
-		});
-
-		return rtn;
-	}
-
-	@Override
-	public DiagramTemplate saveTemplate(DiagramTemplate template) {
-		return readFiles((majCode, sysCode, typeCode, typeDir) -> {
-			if(typeCode.equals(template.getDiagramType())) {
-				try {
-					String json = parser.toJson(template);
-					FileUtil.writeUtf8String(json, new File(typeDir, template.getName() + ".json"));
-					return parser.parseContent(json, DiagramTemplate.class);
-				} catch (Exception e) {
-					throw new RuntimeException(e);
-				}
-			}
-			return null;
-		});
-	}
-
-	@Override
-	public boolean deleteTemplate(String templateId) {
-		File del = readFiles((majCode, sysCode, typeCode, typeDir) -> {
-			File[] files = typeDir.listFiles();
-			if(files != null) {
-				for (File f : files) {
-					try {
-						DiagramTemplate template = parser.parseContent(FileUtil.readUtf8String(f), DiagramTemplate.class);
-						if(template.getId().equals(templateId)) {
-							f.delete();
-							return f;
-						}
-					} catch (Exception e) {
-						throw new RuntimeException(e);
-					}
-				}
-			}
-			return null;
-		});
-		return del != null;
-	}
-
-	@Override
-	public DiagramTemplate getTemplate(String templateId) {
-		return readFiles((majCode, sysCode, typeCode, typeDir) -> {
-			File[] files = typeDir.listFiles();
-			if(files != null) {
-				for (File f : files) {
-					try {
-						DiagramTemplate template = parser.parseContent(FileUtil.readUtf8String(f), DiagramTemplate.class);
-						if(template.getId().equals(templateId))
-							return template;
-					} catch (Exception e) {
-						throw new RuntimeException(e);
-					}
-				}
-			}
-			return null;
-		});
-
-	}
-
-
-	/* 图例部分 */
-	private static final String DIR_LEGEND = "store/legend/";
-
-	@Override
-	public List<Legend> getLegends(String systemCode) {
-		File file = new File(DIR_LEGEND, systemCode + ".json");
-		if(!file.exists())
+    @Autowired
+    private ContentParser parser;
+
+    @Override
+    public List<DiagramType> getDiagramTypes() {
+        List<DiagramType> types = new ArrayList<>();
+
+        readFiles((majCode, sysCode, typeCode, typeDir) -> {
+            DiagramType diagramType = new DiagramType();
+            diagramType.setMajor(majCode);
+            diagramType.setDSystem(sysCode);
+            diagramType.setCode(typeCode);
+            diagramType.setName(typeDir.getName());
+
+            types.add(diagramType);
+            return null;
+        });
+
+        return types;
+    }
+
+    /* 模板部分 */
+    private static final String DIR_TEMPLATE = "store/template/";
+
+    @Override
+    public List<DiagramTemplate> getTemplates() {
+        List<DiagramTemplate> rtn = new ArrayList<>();
+
+        readFiles((majCode, sysCode, typeCode, typeDir) -> {
+            File[] files = typeDir.listFiles();
+            if (files != null) {
+                for (File f : files) {
+                    try {
+                        DiagramTemplate template = parser.parseContent(FileUtil.readUtf8String(f), DiagramTemplate.class);
+                        rtn.add(template);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+            return null;
+        });
+
+        return rtn;
+    }
+
+    private <T> T readFiles(Handler<T> handler) {
+        File dir = new File(DIR_TEMPLATE);
+        File[] majList = dir.listFiles();
+        if (majList == null) {
+            return null;
+        }
+
+        for (File fm : majList) {
+            String majCode = fm.getName().substring(0, 2);
+
+            File[] sysList = fm.listFiles();
+            if (sysList == null) {
+                continue;
+            }
+
+            for (File fs : sysList) {
+                String sysCode = majCode + fs.getName().substring(0, 2);
+                File[] typeList = fs.listFiles();
+                if (typeList != null) {
+                    for (File ft : typeList) {
+                        String typeCode = sysCode + "_" + ft.getName();
+
+                        T result = handler.handle(majCode, sysCode, typeCode, ft);
+                        if (result != null) {
+                            return result;
+                        }
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+    interface Handler<T> {
+        T handle(String majCode, String sysCode, String typeCode, File typeDir);
+    }
+
+    @Override
+    public List<DiagramTemplate> getTemplates(String diagramType) {
+        List<DiagramTemplate> rtn = new ArrayList<>();
+
+        readFiles((majCode, sysCode, typeCode, typeDir) -> {
+            if (diagramType.equals(typeCode)) {
+                File[] files = typeDir.listFiles();
+                if (files != null) {
+                    for (File f : files) {
+                        try {
+                            DiagramTemplate template = parser.parseContent(FileUtil.readUtf8String(f), DiagramTemplate.class);
+                            rtn.add(template);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
+            }
+            return null;
+        });
+
+        return rtn;
+    }
+
+    @Override
+    public DiagramTemplate saveTemplate(DiagramTemplate template) {
+        return readFiles((majCode, sysCode, typeCode, typeDir) -> {
+            if (typeCode.equals(template.getDiagramType())) {
+                try {
+                    String json = parser.toJson(template);
+                    FileUtil.writeUtf8String(json, new File(typeDir, template.getName() + ".json"));
+                    return parser.parseContent(json, DiagramTemplate.class);
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+            return null;
+        });
+    }
+
+    @Override
+    public boolean deleteTemplate(String templateId) {
+        File del = readFiles((majCode, sysCode, typeCode, typeDir) -> {
+            File[] files = typeDir.listFiles();
+            if (files != null) {
+                for (File f : files) {
+                    try {
+                        DiagramTemplate template = parser.parseContent(FileUtil.readUtf8String(f), DiagramTemplate.class);
+                        if (template.getId().equals(templateId)) {
+                            f.delete();
+                            return f;
+                        }
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+            }
+            return null;
+        });
+        return del != null;
+    }
+
+    @Override
+    public DiagramTemplate getTemplate(String templateId) {
+        return readFiles((majCode, sysCode, typeCode, typeDir) -> {
+            File[] files = typeDir.listFiles();
+            if (files != null) {
+                for (File f : files) {
+                    try {
+                        DiagramTemplate template = parser.parseContent(FileUtil.readUtf8String(f), DiagramTemplate.class);
+                        if (template.getId().equals(templateId)) {
+                            return template;
+                        }
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+            }
+            return null;
+        });
+
+    }
+
+
+    /**
+     * 图例部分
+     */
+    private static final String DIR_LEGEND = "store/legend/";
+
+    @Override
+    public List<Legend> getLegends(String systemCode) {
+        File file = new File(DIR_LEGEND, systemCode + ".json");
+        if (!file.exists()) {
 			FileUtil.writeUtf8String("[]", file);
-
-		Legend[] legends = parser.parseContent(FileUtil.readUtf8String(file), Legend[].class);
-		ArrayList<Legend> list = new ArrayList<>();
-		Collections.addAll(list, legends);
-		return list;
-	}
-
-	@Override
-	public Legend saveLegend(Legend legend, String systemCode) {
-		List<Legend> list = getLegends(systemCode);
-
-		if(StrUtil.isBlank(legend.getId())) {
-			legend.setId(IdUtil.simpleUUID());
-			list.add(legend);
-		} else {
-			for (int i = 0; i < list.size(); i++) {
-				Legend l = list.get(i);
-				if (l.getId().equals(legend.getId())) {
-					list.set(i, legend);
-					break;
-				}
-			}
 		}
 
-		File file = new File(DIR_LEGEND, systemCode + ".json");
-		FileUtil.writeUtf8String(parser.toJson(list), file);
-
-		return legend;
-	}
-
-	@Override
-	public boolean deleteLegend(String legendId, String systemCode) {
-		List<Legend> list = getLegends(systemCode);
-
-		boolean flag = false;
-		for (int i = 0; i < list.size(); i++) {
-			Legend l = list.get(i);
-			if (l.getId().equals(legendId)) {
-				list.remove(l);
-				flag = true;
-				break;
-			}
-		}
-
-		File file = new File(DIR_LEGEND, systemCode + ".json");
-		FileUtil.writeUtf8String(parser.toJson(list), file);
-
-		return flag;
-	}
-
-	@Override
-	public Legend getLegend(String legendId, String systemCode) {
-		List<Legend> list = getLegends(systemCode);
-		for(Legend legend : list) {
-			if(legend.getId().equals(legendId))
+        Legend[] legends = parser.parseContent(FileUtil.readUtf8String(file), Legend[].class);
+        ArrayList<Legend> list = new ArrayList<>();
+        Collections.addAll(list, legends);
+        return list;
+    }
+
+    @Override
+    public Legend saveLegend(Legend legend, String systemCode) {
+        List<Legend> list = getLegends(systemCode);
+
+        if (StrUtil.isBlank(legend.getId())) {
+            legend.setId(IdUtil.simpleUUID());
+            list.add(legend);
+        } else {
+            for (int i = 0; i < list.size(); i++) {
+                Legend l = list.get(i);
+                if (l.getId().equals(legend.getId())) {
+                    list.set(i, legend);
+                    break;
+                }
+            }
+        }
+
+        File file = new File(DIR_LEGEND, systemCode + ".json");
+        FileUtil.writeUtf8String(parser.toJson(list), file);
+
+        return legend;
+    }
+
+    @Override
+    public boolean deleteLegend(String legendId, String systemCode) {
+        List<Legend> list = getLegends(systemCode);
+
+        boolean flag = false;
+        for (int i = 0; i < list.size(); i++) {
+            Legend l = list.get(i);
+            if (l.getId().equals(legendId)) {
+                list.remove(l);
+                flag = true;
+                break;
+            }
+        }
+
+        File file = new File(DIR_LEGEND, systemCode + ".json");
+        FileUtil.writeUtf8String(parser.toJson(list), file);
+
+        return flag;
+    }
+
+    @Override
+    public Legend getLegend(String legendId, String systemCode) {
+        List<Legend> list = getLegends(systemCode);
+        for (Legend legend : list) {
+            if (legend.getId().equals(legendId)) {
 				return legend;
-		}
-		return null;
-	}
-
-	@Override
-	public List<Legend> getLegendsForEquipment(String equipmentType) {
-		String systemCode = equipmentType.substring(0, 4);
-
-		List<Legend> rtn = new ArrayList<>();
-		List<Legend> list = getLegends(systemCode);
-		for (Legend legend : list) {
-			if (legend.getEquipmentTypes() != null && legend.getEquipmentTypes().contains(equipmentType))
+			}
+        }
+        return null;
+    }
+
+    @Override
+    public List<Legend> getLegendsForEquipment(String equipmentType) {
+        String systemCode = equipmentType.substring(0, 4);
+
+        List<Legend> rtn = new ArrayList<>();
+        List<Legend> list = getLegends(systemCode);
+        for (Legend legend : list) {
+            if (legend.getEquipmentTypes() != null && legend.getEquipmentTypes().contains(equipmentType)) {
 				rtn.add(legend);
-		}
+			}
+        }
 
-		return rtn;
-	}
+        return rtn;
+    }
 
 
-	/* 系统图部分 */
-	private static final String DIR_DIAGRAM = "store/diagram/";
+    /** 系统图部分 */
+    private static final String DIR_DIAGRAM = "store/diagram/";
 
-	@Override
-	public List<Diagram> getDiagrams(String projectId, String systemId, String groupCode) {
-		return getDiagrams(null, projectId, systemId, groupCode,null);
-	}
+    @Override
+    public List<Diagram> getDiagrams(String projectId, String systemId, String groupCode) {
+        return getDiagrams(null, projectId, systemId, groupCode, null);
+    }
 
-	@Override
-	public List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode,String name) {
-		ArrayList<Diagram> diagrams = new ArrayList<>();
+    @Override
+    public List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode, String name) {
+        ArrayList<Diagram> diagrams = new ArrayList<>();
 
-		File dir = new File(DIR_DIAGRAM);
-		File[] list = dir.listFiles();
-		if(list != null) {
-			for(File f : list) {
-				Diagram diagram = parser.parseContent(FileUtil.readUtf8String(f), Diagram.class);
-				if(projectId.equals(diagram.getProjectId())) {
-					if(StrUtil.isNotBlank(groupCode) && !groupCode.equals(diagram.getGroupCode()))
+        File dir = new File(DIR_DIAGRAM);
+        File[] list = dir.listFiles();
+        if (list != null) {
+            for (File f : list) {
+                Diagram diagram = parser.parseContent(FileUtil.readUtf8String(f), Diagram.class);
+                if (projectId.equals(diagram.getProjectId())) {
+                    if (StrUtil.isNotBlank(groupCode) && !groupCode.equals(diagram.getGroupCode())) {
 						continue;
-					if(StrUtil.isNotBlank(diagramType) && !diagramType.equals(diagram.getType()))
+					}
+                    if (StrUtil.isNotBlank(diagramType) && !diagramType.equals(diagram.getType())) {
 						continue;
-					if(StrUtil.isNotBlank(systemId) && !systemId.equals(diagram.getSystemId()))
+					}
+                    if (StrUtil.isNotBlank(systemId) && !systemId.equals(diagram.getSystemId())) {
 						continue;
+					}
 
-					diagrams.add(diagram);
-				}
-			}
-		}
-
-		return diagrams;
-	}
-
-	@Override
-	public Diagram saveDiagram(Diagram diagram) {
-		File file = new File(DIR_DIAGRAM, diagram.getId() + ".json");
-		FileUtil.writeUtf8String(parser.toJson(diagram), file);
-
-		return diagram;
-	}
-
-	@Override
-	public boolean deleteDiagram(String diagramId) {
-		File dir = new File(DIR_DIAGRAM);
-		File[] list = dir.listFiles();
-		if(list != null) {
-			for(File f : list) {
-				String fn = f.getName();
-				fn = fn.substring(0, fn.lastIndexOf('.'));
-				if(diagramId.equals(fn)) {
-					f.delete();
-					return true;
-				}
-			}
-		}
-		return false;
-	}
-
-	@Override
-	public Diagram getDiagram(String diagramId) {
-		File file = new File(DIR_DIAGRAM, diagramId + ".json");
-		if(file.exists())
+                    diagrams.add(diagram);
+                }
+            }
+        }
+
+        return diagrams;
+    }
+
+    @Override
+    public Diagram saveDiagram(Diagram diagram) {
+        File file = new File(DIR_DIAGRAM, diagram.getId() + ".json");
+        FileUtil.writeUtf8String(parser.toJson(diagram), file);
+
+        return diagram;
+    }
+
+    @Override
+    public boolean deleteDiagram(String diagramId) {
+        File dir = new File(DIR_DIAGRAM);
+        File[] list = dir.listFiles();
+        if (list != null) {
+            for (File f : list) {
+                String fn = f.getName();
+                fn = fn.substring(0, fn.lastIndexOf('.'));
+                if (diagramId.equals(fn)) {
+                    f.delete();
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public Diagram getDiagram(String diagramId) {
+        File file = new File(DIR_DIAGRAM, diagramId + ".json");
+        if (file.exists()) {
 			return parser.parseContent(FileUtil.readUtf8String(file), Diagram.class);
-		return null;
-	}
-
-
-	//系统图数据加载
-	@Autowired
-	private BdtpDataService dataService;
-
-	@Override
-	public List<ObjectNode> loadObjectsByType(List<String> equipmentTypes, String projectId, String systemId, String groupCode) {
-		BdtpRequest req = BdtpRequest.getCurrent();
-		req.setProjectId(projectId);
-		req.setGroupCode(groupCode);
-		return dataService.queryObjectsByType(req, equipmentTypes, systemId);
-	}
-
-	@Override
-	public List<ObjectNode> loadRelationsByType(List<String[]> relationTypes, List<String> objectIds, String projectId, String groupCode) {
-		BdtpRequest req = BdtpRequest.getCurrent();
-		req.setProjectId(projectId);
-		req.setGroupCode(groupCode);
-		return dataService.queryRelsByTypeAndObj(req, relationTypes, objectIds);
-	}
-
-	@Override
-	public List<ObjectNode> loadObjectsById(List<String> objectIds, String projectId, String groupCode) {
-		BdtpRequest req = BdtpRequest.getCurrent();
-		req.setProjectId(projectId);
-		req.setGroupCode(groupCode);
-		return dataService.queryObjectsById(req, objectIds);
-	}
-
-	@Override
-	public List<ObjectNode> loadRelationsById(List<String> relationIds, String projectId, String groupCode) {
-		//TODO
-		return null;
-	}
-
-	@Override
-	public List<ObjectNode> loadSystemInstance(String projectId, String groupCode) {
-		return null;
-	}
-
-	@Override
-	public List<ObjectNode> loadMajorSystemInstance() {
-		return null;
-	}
-
-	@Override
-	public List<ObjectNode> loadSystemTypeTemplate(Diagram diagram) {
-		return null;
-	}
+		}
+        return null;
+    }
+
+
+    //系统图数据加载
+    @Autowired
+    private BdtpDataService dataService;
+
+    @Override
+    public List<ObjectNode> loadObjectsByType(List<String> equipmentTypes, String projectId, String systemId, String groupCode) {
+        BdtpRequest req = BdtpRequest.getCurrent();
+        req.setProjectId(projectId);
+        req.setGroupCode(groupCode);
+        return dataService.queryObjectsByType(req, equipmentTypes, systemId);
+    }
+
+    @Override
+    public List<ObjectNode> loadRelationsByType(List<String[]> relationTypes, List<String> objectIds, String projectId, String groupCode) {
+        BdtpRequest req = BdtpRequest.getCurrent();
+        req.setProjectId(projectId);
+        req.setGroupCode(groupCode);
+        return dataService.queryRelsByTypeAndObj(req, relationTypes, objectIds);
+    }
+
+    @Override
+    public List<ObjectNode> loadObjectsById(List<String> objectIds, String projectId, String groupCode) {
+        BdtpRequest req = BdtpRequest.getCurrent();
+        req.setProjectId(projectId);
+        req.setGroupCode(groupCode);
+        return dataService.queryObjectsById(req, objectIds);
+    }
+
+    @Override
+    public List<ObjectNode> loadRelationsById(List<String> relationIds, String projectId, String groupCode) {
+        //TODO
+        return null;
+    }
+
+    @Override
+    public List<ObjectNode> loadSystemInstance(String projectId, String groupCode) {
+        return null;
+    }
+
+    @Override
+    public List<ObjectNode> loadMajorSystemInstance() {
+        return null;
+    }
+
+    @Override
+    public List<ObjectNode> loadSystemTypeTemplate(Diagram diagram) {
+        return null;
+    }
+
+    @Override
+    public boolean updateState(String state, String id) {
+        return false;
+    }
 }

+ 8 - 5
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/DemoDiagramManager.java

@@ -31,7 +31,7 @@ public class DemoDiagramManager {
 	private ContentParser parser;
 
 	@Autowired
-	public DemoDiagramManager(@Qualifier(DataStrategy.implQualifier) DataStrategy dataStrategy) {
+	public DemoDiagramManager(@Qualifier(DataStrategy.IMPL_QUALIFIER) DataStrategy dataStrategy) {
 		this.dataStrategy = dataStrategy;
 	}
 
@@ -64,8 +64,9 @@ public class DemoDiagramManager {
 			ft.setType(Folder.TYPE_TYPE);
 
 			for(Diagram diagram : diagrams){
-				if(diagram.getType().equals(type.getCode()))
+				if(diagram.getType().equals(type.getCode())) {
 					ft.getChildren().add(diagram);
+				}
 			}
 		}
 
@@ -73,17 +74,19 @@ public class DemoDiagramManager {
 	}
 
 	private void loadTemplate(Diagram diagram){
-		if (diagram.getTemplateId() != null)
+		if (diagram.getTemplateId() != null) {
 			diagram.setTemplate(dataStrategy.getTemplate(diagram.getTemplateId()));
+		}
 	}
 
-	private void buildDiagram(Diagram diagram, boolean layout){
+	public void buildDiagram(Diagram diagram, boolean layout){
 		loadTemplate(diagram);
 		diagram.init();
 		new DiagramDataLoader(diagram, dataStrategy).initLoad();
 
-		if(layout)
+		if(layout) {
 			diagram.layout(new DiagramBuilder(diagram, dataStrategy));
+		}
 	}
 
 	/**

+ 5 - 3
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/Folder.java

@@ -45,10 +45,11 @@ public class Folder {
 			target.setId(code);
 			target.setType(type);
 
-			if(Folder.TYPE_MAJ.equals(type))
+			if(Folder.TYPE_MAJ.equals(type)) {
 				target.setName(getFolderName(code, dictInfoList));
-			else if(Folder.TYPE_SYS.equals(type))
+			} else if(Folder.TYPE_SYS.equals(type)) {
 				target.setName(getFolderName(code, dictInfoList));
+			}
 
 			folders.add(target);
 		}
@@ -59,8 +60,9 @@ public class Folder {
 		for(ObjectNode node : dictInfoList) {
 			if(node.get("code").asText().equals(code)) {
 				JsonNode nameNode = node.get("name");
-				if(nameNode == null)
+				if(nameNode == null) {
 					nameNode = node.get("label");
+				}
 				return nameNode.asText();
 			}
 		}

+ 3 - 4
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/LegendManager.java

@@ -14,7 +14,6 @@ import org.springframework.stereotype.Service;
 
 import java.io.File;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -31,7 +30,7 @@ public class LegendManager {
 	private ContentParser parser;
 
 	@Autowired
-	public LegendManager(@Qualifier(DataStrategy.implQualifier) DataStrategy dataStrategy) {
+	public LegendManager(@Qualifier(DataStrategy.IMPL_QUALIFIER) DataStrategy dataStrategy) {
 		this.dataStrategy = dataStrategy;
 	}
 
@@ -113,8 +112,8 @@ public class LegendManager {
 	@Autowired
 	private GsonUtil gsonUtil;
 	public boolean fixDiagramType(){
-		String DIR_LEGEND = "store/legend/";
-		File dir = new File(DIR_LEGEND);
+		String dirLegend = "store/legend/";
+		File dir = new File(dirLegend);
 		for(File file : dir.listFiles()) {
 			String fn = file.getName();
 			String sys = fn.substring(0, fn.lastIndexOf('.'));

+ 373 - 358
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/TemplateManager.java

@@ -28,384 +28,399 @@ import java.util.Map;
 
 /**
  * 模板编辑的相关操作
+ *
  * @author zhaoyk
  */
 @Service
 public class TemplateManager {
 
-	private final DataStrategy dataStrategy;
+    private final DataStrategy dataStrategy;
 
-	@Autowired
-	public TemplateManager(@Qualifier(DataStrategy.implQualifier) DataStrategy dataStrategy) {
-		this.dataStrategy = dataStrategy;
-	}
+    @Autowired
+    public TemplateManager(@Qualifier(DataStrategy.IMPL_QUALIFIER) DataStrategy dataStrategy) {
+        this.dataStrategy = dataStrategy;
+    }
 
-	@Autowired
-	private ContentParser contentParser;
+    @Autowired
+    private ContentParser contentParser;
 
-	@Autowired
-	private BdtpDataService bdtpDataService;
+    @Autowired
+    private BdtpDataService bdtpDataService;
 
-	/**
-	 * 查询系统图模板,树形结构
-	 */
-	public List<Folder> getTemplates(){
-		List<DiagramType> types = dataStrategy.getDiagramTypes();
+    /**
+     * 查询系统图模板,树形结构
+     */
+    public List<Folder> getTemplates() {
+        List<DiagramType> types = dataStrategy.getDiagramTypes();
 
-		List<DiagramTemplate> templates = dataStrategy.getTemplates();
-		for(DiagramTemplate template : templates) {
-			buildTemplate(template);
-		}
+        List<DiagramTemplate> templates = dataStrategy.getTemplates();
+        for (DiagramTemplate template : templates) {
+            buildTemplate(template);
+        }
 
-		BdtpRequest req = BdtpRequest.getCurrent();
+        BdtpRequest req = BdtpRequest.getCurrent();
 //		List<ObjectNode> maj = bdtpDataService.getMajorList(req);
 //		List<ObjectNode> sys = bdtpDataService.getSystemList(req);
-		//TODO debug
-		List<ObjectNode> maj = new ArrayList<>();
-		List<ObjectNode> sys = new ArrayList<>();
-
-		List<Folder> folders = new ArrayList<>();
-		for (DiagramType type : types) {
-			Folder fm = Folder.getFolder(type.getMajor(), Folder.TYPE_MAJ, folders, maj);
-			Folder fs = Folder.getFolder(type.getDSystem(), Folder.TYPE_SYS, (List)fm.getChildren(), sys);
-
-			Folder ft = new Folder();
-			fs.getChildren().add(ft);
-			ft.setName(type.getName());
-			ft.setId(type.getCode());
-			ft.setType(Folder.TYPE_TYPE);
-
-			for(DiagramTemplate template : templates){
-				if(template.getDiagramType().equals(type.getCode()))
+        //TODO debug
+        List<ObjectNode> maj = new ArrayList<>();
+        List<ObjectNode> sys = new ArrayList<>();
+
+        List<Folder> folders = new ArrayList<>();
+        for (DiagramType type : types) {
+            Folder fm = Folder.getFolder(type.getMajor(), Folder.TYPE_MAJ, folders, maj);
+            Folder fs = Folder.getFolder(type.getDSystem(), Folder.TYPE_SYS, (List) fm.getChildren(), sys);
+
+            Folder ft = new Folder();
+            fs.getChildren().add(ft);
+            ft.setName(type.getName());
+            ft.setId(type.getCode());
+            ft.setType(Folder.TYPE_TYPE);
+
+            for (DiagramTemplate template : templates) {
+                if (template.getDiagramType().equals(type.getCode())) {
 					ft.getChildren().add(template);
-			}
-		}
-
-		return folders;
-	}
-
-	/**
-	 * 查询某个系统图类型下的模板列表
-	 */
-	public List<DiagramTemplate> getTemplates(String diagramType) {
-		return dataStrategy.getTemplates(diagramType);
-	}
-
-	/**
-	 * 创建新的模板
-	 */
-	public DiagramTemplate createTemplate(String name, String type){
-		DiagramTemplate template = DiagramTemplate.defaultTemplate();
-
-		template.setName(name);
-		template.setDiagramType(type);
-		template.setId(IdUtil.simpleUUID());
-
-		template.setMainPipes(new ArrayList<>());
-
-		return saveTemplate(template);
-	}
-
-	/**
-	 * 删除模板
-	 */
-	public boolean deleteTemplate(String id){
-		return dataStrategy.deleteTemplate(id);
-	}
-
-	@Autowired
-	private TemplateMapper templateMapper;
-	/**
-	 * 编辑模板的基本信息
-	 */
-	public boolean editTemplateInfo(String id, Map<String, String> infos) {
-		TemplateEntity entity = templateMapper.selectById(id);
-		if(entity != null){
-			if(infos.containsKey("name"))
+				}
+            }
+        }
+
+        return folders;
+    }
+
+    /**
+     * 查询某个系统图类型下的模板列表
+     */
+    public List<DiagramTemplate> getTemplates(String diagramType) {
+        return dataStrategy.getTemplates(diagramType);
+    }
+
+    /**
+     * 创建新的模板
+     */
+    public DiagramTemplate createTemplate(String name, String type) {
+        DiagramTemplate template = DiagramTemplate.defaultTemplate();
+
+        template.setName(name);
+        template.setDiagramType(type);
+        template.setId(IdUtil.simpleUUID());
+
+        template.setMainPipes(new ArrayList<>());
+
+        return saveTemplate(template);
+    }
+
+    /**
+     * 删除模板
+     */
+    public boolean deleteTemplate(String id) {
+        return dataStrategy.deleteTemplate(id);
+    }
+
+    @Autowired
+    private TemplateMapper templateMapper;
+
+    /**
+     * 编辑模板的基本信息
+     */
+    public boolean editTemplateInfo(String id, Map<String, String> infos) {
+        TemplateEntity entity = templateMapper.selectById(id);
+        if (entity != null) {
+            if (infos.containsKey("name")) {
 				entity.setName(infos.get("name"));
-			if(infos.containsKey("code"))
+			}
+            if (infos.containsKey("code")) {
 				entity.setCode(infos.get("code"));
-			if(infos.containsKey("remark"))
+			}
+            if (infos.containsKey("remark")) {
 				entity.setRemark(infos.get("remark"));
-			templateMapper.updateById(entity);
-			return true;
-		}
-		return false;
-	}
-
-	/**
-	 * 保存模板
-	 */
-	public DiagramTemplate saveTemplate(DiagramTemplate template){
-		template = dataStrategy.saveTemplate(template);
-		buildTemplate(template);
-		return template;
-	}
-
-	private void buildTemplate(DiagramTemplate template){
-		template.init();
-		template.layout(new XY(0, 0));
-	}
-
-	/**
-	 * 添加容器
-	 */
-	public DiagramTemplate addCon(String newContainerId, String containerId, String templateId){
-		DiagramTemplate template = dataStrategy.getTemplate(templateId);
-
-		Container newCon = new Container();
-		newCon.setId(newContainerId);
-		newCon.setLayout(Layout.defaultLayout(Layout.ROW));
-
-		Container parent = template.getContainerById(containerId);
-		parent.addComp(newCon);
-
-		return saveTemplate(template);
-	}
-
-	/**
-	 * 删除容器
-	 */
-	public DiagramTemplate delCon(String containerId, String templateId){
-		DiagramTemplate template = dataStrategy.getTemplate(templateId);
-		template.init();
-
-		Container con = template.getContainerById(containerId);
-		if(con.isAbsolutePosition())
+			}
+            templateMapper.updateById(entity);
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 保存模板
+     */
+    public DiagramTemplate saveTemplate(DiagramTemplate template) {
+        template = dataStrategy.saveTemplate(template);
+        buildTemplate(template);
+        return template;
+    }
+
+    private void buildTemplate(DiagramTemplate template) {
+        template.init();
+        template.layout(new XY(0, 0));
+    }
+
+    /**
+     * 添加容器
+     */
+    public DiagramTemplate addCon(String newContainerId, String containerId, String templateId) {
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+
+        Container newCon = new Container();
+        newCon.setId(newContainerId);
+        newCon.setLayout(Layout.defaultLayout(Layout.ROW));
+
+        Container parent = template.getContainerById(containerId);
+        parent.addComp(newCon);
+
+        return saveTemplate(template);
+    }
+
+    /**
+     * 删除容器
+     */
+    public DiagramTemplate delCon(String containerId, String templateId) {
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+        template.init();
+
+        Container con = template.getContainerById(containerId);
+        if (con.isAbsolutePosition()) {
 			template.getScatteredContainers().remove(con);
-		else if(con.getParent() != null)
+		} else if (con.getParent() != null) {
 			con.getParent().removeComp(containerId);
-
-		return saveTemplate(template);
-	}
-
-	/**
-	 * 移动容器
-	 */
-	public DiagramTemplate moveCon(String containerId, String templateId, int offset){
-		DiagramTemplate template = dataStrategy.getTemplate(templateId);
-		template.init();
-
-		Container con = template.getContainerById(containerId);
-		IContainer parent = con.getParent();
-		if(parent != null) {
-			List<IComponent> list = parent.getChildren();
-
-			int idx = list.indexOf(con);
-			idx += offset;
-
-			if(idx >=0 && idx < list.size()) {
-				list.remove(con);
-				list.add(idx, con);
-
-				return saveTemplate(template);
-			}
-		}
-
-		return null;
-	}
-
-	/**
-	 * 修改容器
-	 */
-	public DiagramTemplate modifyCon(EditRequest.TemplatePropsData propsData, String containerId, String templateId){
-		DiagramTemplate template = dataStrategy.getTemplate(templateId);
-		template.init();
-
-		Container con = template.getContainerById(containerId);
-
-		con.setId(propsData.getId());
-		con.setName(propsData.getName());
-		con.setRemark(propsData.getRemark());
-
-		con.getLayout().setLayout(propsData.getLayout());
-		con.getLayout().setMarginHeight(propsData.getMargin());
-		con.getLayout().setMarginWidth(propsData.getMargin());
-		con.getLayout().spaceH = con.getLayout().spaceV = propsData.getSpace();
-
-		con.getPosition().minH = propsData.getMinH();
-		con.getPosition().minW = propsData.getMinW();
-		con.getPosition().setAbsolute(propsData.isAbsolute());
-
-		con.setEquipmentTypes(CollUtil.isEmpty(propsData.getEquipTypes()) ? null : propsData.getEquipTypes());
-
-		con.setProps(propsData.getProps());
-
-		return saveTemplate(template);
-	}
-
-	/**
-	 * 绘制新的干管
-	 */
-	public DiagramTemplate addMainPipe(List<List<XY>> lines, String templateId){
-		//合并同一条线上的多个点
-		List<List<XY>> fixed = new ArrayList<>();
-		for(List<XY> line : lines) {
-			List<XY> fixedLine = new ArrayList<>();
-			fixed.add(fixedLine);
-
-			XY p1 = null;
-			XY p2 = null;
-			for (XY point : line) {
-				if(p1 == null)
-					p1 = point;
-				else if(p2 == null)
-					p2 = point;
-				else {
-					if ((p1.x == p2.x && p2.x == point.x)
-							|| (p1.y == p2.y && p2.y == point.y)) {
-						fixedLine.remove(p2);
-					} else
-						p1 = p2;
-					p2 = point;
-				}
-				fixedLine.add(point);
-			}
-		}
-
-		DiagramTemplate template = dataStrategy.getTemplate(templateId);
-		buildTemplate(template);
-
-		List<ContainerRefPoint> allRefPoints = new ArrayList<>();
-
-		LinkedList<Container> cons = new LinkedList<>();
-		cons.add(template.getFrame());
-		while (cons.size() > 0) {
-			Container con = cons.removeFirst();
-
-			if(con.getParent() != null && !con.isAbsolutePosition()) //不使用frame和自由定位容器做定位
-				allRefPoints.addAll(ContainerRefPoint.getRefPoints(con, con.locationToRoot()));
-
-			for(IComponent comp : con.getChildren()){
-				if(comp instanceof Container)
-					cons.add((Container) comp);
-			}
-		}
-
-		MainPipe mainPipe = new MainPipe();
-		mainPipe.setId(IdUtil.simpleUUID()); //TODO
-
-		for(List<XY> line : fixed) {
-			List<MainPipePoint> ps = new ArrayList<>();
-			mainPipe.getPath().add(ps);
-
-			for (XY point : line) {
-				double min = Double.MAX_VALUE;
-				ContainerRefPoint targetRp = null;
-				for(ContainerRefPoint rp : allRefPoints) {
-					double d = distance(point, rp.getLocation());
-					if(d < min) {
-						min = d;
-						targetRp = rp;
-					}
-				}
-				MainPipePoint mp = new MainPipePoint();
-				mp.setContainerId(targetRp.getContainerId());
-				mp.setRefPointName(targetRp.getName());
-				mp.setOffset(new XY(point.x - targetRp.getLocation().x, point.y - targetRp.getLocation().y));
-				ps.add(mp);
-			}
-		}
-		if(template.getMainPipes() == null)
-			template.setMainPipes(new ArrayList<>());
-		template.getMainPipes().add(mainPipe);
-
-		return saveTemplate(template);
-	}
-
-	private double distance(XY p1, XY p2){
-		return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
-	}
-
-	/**
-	 * 删除干管
-	 */
-	public DiagramTemplate delMainPipe(String mainPipeId, String templateId){
-		DiagramTemplate template = dataStrategy.getTemplate(templateId);
-
-		if(template.getMainPipes() != null) {
-			for(MainPipe mainPipe : template.getMainPipes()) {
-				if(mainPipe.getId().equals(mainPipeId)) {
-					template.getMainPipes().remove(mainPipe);
-					break;
-				}
-			}
-		}
-
-		return saveTemplate(template);
-	}
-
-	/**
-	 * 修改干管
-	 */
-	public DiagramTemplate modifyMainPipe(EditRequest.TemplatePropsData propsData, String mainPipeId, String templateId){
-		DiagramTemplate template = dataStrategy.getTemplate(templateId);
-
-		MainPipe mainPipe = template.getMainPipeById(mainPipeId);
-		if(mainPipe != null) {
-			mainPipe.setId(propsData.getId());
-			mainPipe.setName(propsData.getName());
-			mainPipe.setRemark(propsData.getRemark());
-			mainPipe.setPipeType(propsData.getPipeType());
-			mainPipe.setBindEquipment(propsData.isBindEquipment());
-			mainPipe.setEquipmentTypes(propsData.getEquipTypes());
-			mainPipe.setPassbyRels(propsData.getPassbyRels());
-			mainPipe.setConnectEquips(propsData.getConnectEquips());
 		}
 
-		return saveTemplate(template);
-	}
-
-	/**
-	 * 修改设备数据过滤条件
-	 * filter可能是多种类型,通过Map转换
-	 */
-	public DiagramTemplate modifyFilter(Map<String, Object> filter, String compId, String templateId){
-		DiagramTemplate template = dataStrategy.getTemplate(templateId);
-		template.init();
-
-		DataFilter dataFilter;
-		if(filter != null)
-			dataFilter = contentParser.parseContent(contentParser.toJson(filter), DataFilter.class);
-		else
-			dataFilter = null;
-
-		Container con = template.getContainerById(compId);
-		if(con != null)
-			con.setDataFilter(dataFilter);
-		else {
-			MainPipe mainPipe = template.getMainPipeById(compId);
-			if(mainPipe != null)
-				mainPipe.setDataFilter(dataFilter);
-		}
-
-		return saveTemplate(template);
-	}
-
-	/**
-	 * 修改设备打包配置
-	 */
-	public DiagramTemplate modifyPack(EquipPack pack, String containerId, String templateId){
-		DiagramTemplate template = dataStrategy.getTemplate(templateId);
-		template.init();
-
-		Container con = template.getContainerById(containerId);
-		con.setEquipPack(pack);
-
-		return saveTemplate(template);
-	}
-
-	/**
-	 * 修改容器的动态组配置
-	 */
-	public DiagramTemplate modifyDynGroup(DynGroup dynGroup, String containerId, String templateId){
-		DiagramTemplate template = dataStrategy.getTemplate(templateId);
-		template.init();
-
-		Container con = template.getContainerById(containerId);
-		con.setDynGroup(dynGroup);
-
-		return saveTemplate(template);
-	}
+        return saveTemplate(template);
+    }
+
+    /**
+     * 移动容器
+     */
+    public DiagramTemplate moveCon(String containerId, String templateId, int offset) {
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+        template.init();
+
+        Container con = template.getContainerById(containerId);
+        IContainer parent = con.getParent();
+        if (parent != null) {
+            List<IComponent> list = parent.getChildren();
+
+            int idx = list.indexOf(con);
+            idx += offset;
+
+            if (idx >= 0 && idx < list.size()) {
+                list.remove(con);
+                list.add(idx, con);
+
+                return saveTemplate(template);
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * 修改容器
+     */
+    public DiagramTemplate modifyCon(EditRequest.TemplatePropsData propsData, String containerId, String templateId) {
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+        template.init();
+
+        Container con = template.getContainerById(containerId);
+
+        con.setId(propsData.getId());
+        con.setName(propsData.getName());
+        con.setRemark(propsData.getRemark());
+
+        con.getLayout().setLayout(propsData.getLayout());
+        con.getLayout().setMarginHeight(propsData.getMargin());
+        con.getLayout().setMarginWidth(propsData.getMargin());
+        con.getLayout().spaceH = con.getLayout().spaceV = propsData.getSpace();
+
+        con.getPosition().minH = propsData.getMinH();
+        con.getPosition().minW = propsData.getMinW();
+        con.getPosition().setAbsolute(propsData.isAbsolute());
+
+        con.setEquipmentTypes(CollUtil.isEmpty(propsData.getEquipTypes()) ? null : propsData.getEquipTypes());
+
+        con.setProps(propsData.getProps());
+
+        return saveTemplate(template);
+    }
+
+    /**
+     * 绘制新的干管
+     */
+    public DiagramTemplate addMainPipe(List<List<XY>> lines, String templateId) {
+        //合并同一条线上的多个点
+        List<List<XY>> fixed = new ArrayList<>();
+        for (List<XY> line : lines) {
+            List<XY> fixedLine = new ArrayList<>();
+            fixed.add(fixedLine);
+
+            XY p1 = null;
+            XY p2 = null;
+            for (XY point : line) {
+                if (p1 == null) {
+                    p1 = point;
+                } else if (p2 == null) {
+                    p2 = point;
+                } else {
+                    boolean b = p1.x == p2.x && p2.x == point.x;
+                    boolean b1 = p1.y == p2.y && p2.y == point.y;
+                    if (b || b1) {
+                        fixedLine.remove(p2);
+                    } else {
+                        p1 = p2;
+                    }
+                    p2 = point;
+                }
+                fixedLine.add(point);
+            }
+        }
+
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+        buildTemplate(template);
+
+        List<ContainerRefPoint> allRefPoints = new ArrayList<>();
+
+        LinkedList<Container> cons = new LinkedList<>();
+        cons.add(template.getFrame());
+        while (cons.size() > 0) {
+            Container con = cons.removeFirst();
+            //不使用frame和自由定位容器做定位
+            if (con.getParent() != null && !con.isAbsolutePosition()) {
+                allRefPoints.addAll(ContainerRefPoint.getRefPoints(con, con.locationToRoot()));
+            }
+
+            for (IComponent comp : con.getChildren()) {
+                if (comp instanceof Container) {
+                    cons.add((Container) comp);
+                }
+            }
+        }
+
+        MainPipe mainPipe = new MainPipe();
+        //TODO
+        mainPipe.setId(IdUtil.simpleUUID());
+
+        for (List<XY> line : fixed) {
+            List<MainPipePoint> ps = new ArrayList<>();
+            mainPipe.getPath().add(ps);
+
+            for (XY point : line) {
+                double min = Double.MAX_VALUE;
+                ContainerRefPoint targetRp = null;
+                for (ContainerRefPoint rp : allRefPoints) {
+                    double d = distance(point, rp.getLocation());
+                    if (d < min) {
+                        min = d;
+                        targetRp = rp;
+                    }
+                }
+                MainPipePoint mp = new MainPipePoint();
+                mp.setContainerId(targetRp.getContainerId());
+                mp.setRefPointName(targetRp.getName());
+                mp.setOffset(new XY(point.x - targetRp.getLocation().x, point.y - targetRp.getLocation().y));
+                ps.add(mp);
+            }
+        }
+        if (template.getMainPipes() == null) {
+            template.setMainPipes(new ArrayList<>());
+        }
+        template.getMainPipes().add(mainPipe);
+
+        return saveTemplate(template);
+    }
+
+    private double distance(XY p1, XY p2) {
+        return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
+    }
+
+    /**
+     * 删除干管
+     */
+    public DiagramTemplate delMainPipe(String mainPipeId, String templateId) {
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+
+        if (template.getMainPipes() != null) {
+            for (MainPipe mainPipe : template.getMainPipes()) {
+                if (mainPipe.getId().equals(mainPipeId)) {
+                    template.getMainPipes().remove(mainPipe);
+                    break;
+                }
+            }
+        }
+
+        return saveTemplate(template);
+    }
+
+    /**
+     * 修改干管
+     */
+    public DiagramTemplate modifyMainPipe(EditRequest.TemplatePropsData propsData, String mainPipeId, String templateId) {
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+
+        MainPipe mainPipe = template.getMainPipeById(mainPipeId);
+        if (mainPipe != null) {
+            mainPipe.setId(propsData.getId());
+            mainPipe.setName(propsData.getName());
+            mainPipe.setRemark(propsData.getRemark());
+            mainPipe.setPipeType(propsData.getPipeType());
+            mainPipe.setBindEquipment(propsData.isBindEquipment());
+            mainPipe.setEquipmentTypes(propsData.getEquipTypes());
+            mainPipe.setPassbyRels(propsData.getPassbyRels());
+            mainPipe.setConnectEquips(propsData.getConnectEquips());
+        }
+
+        return saveTemplate(template);
+    }
+
+    /**
+     * 修改设备数据过滤条件
+     * filter可能是多种类型,通过Map转换
+     */
+    public DiagramTemplate modifyFilter(Map<String, Object> filter, String compId, String templateId) {
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+        template.init();
+
+        DataFilter dataFilter;
+        if (filter != null) {
+            dataFilter = contentParser.parseContent(contentParser.toJson(filter), DataFilter.class);
+        } else {
+            dataFilter = null;
+        }
+
+        Container con = template.getContainerById(compId);
+        if (con != null) {
+            con.setDataFilter(dataFilter);
+        } else {
+            MainPipe mainPipe = template.getMainPipeById(compId);
+            if (mainPipe != null) {
+                mainPipe.setDataFilter(dataFilter);
+            }
+        }
+
+        return saveTemplate(template);
+    }
+
+    /**
+     * 修改设备打包配置
+     */
+    public DiagramTemplate modifyPack(EquipPack pack, String containerId, String templateId) {
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+        template.init();
+
+        Container con = template.getContainerById(containerId);
+        con.setEquipPack(pack);
+
+        return saveTemplate(template);
+    }
+
+    /**
+     * 修改容器的动态组配置
+     */
+    public DiagramTemplate modifyDynGroup(DynGroup dynGroup, String containerId, String templateId) {
+        DiagramTemplate template = dataStrategy.getTemplate(templateId);
+        template.init();
+
+        Container con = template.getContainerById(containerId);
+        con.setDynGroup(dynGroup);
+
+        return saveTemplate(template);
+    }
 
 }

+ 121 - 112
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/service/BdtpDataService.java

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.adm.diagram.client.DicClient;
+import com.persagy.adm.diagram.constant.Constants;
 import com.persagy.adm.diagram.util.Pagination;
 import com.persagy.adm.diagram.util.ServiceUtil;
 import com.persagy.adm.diagram.client.RwdClient;
@@ -23,121 +24,129 @@ import java.util.Map;
 
 /**
  * bdtp数据服务调用服务封装
+ * @author zhaoyk
+ * @date 2021-12-27
  */
 @Service
 public class BdtpDataService {
 
-	@Autowired
-	private RwdClient rwdClient;
-
-	@Autowired
-	private DicClient dicClient;
-
-	@Autowired
-	private DigitalObjectClient objectClient;
-
-	@Autowired
-	private ObjectMapper objectMapper;
-
-	public List<ObjectNode> getMajorList(BdtpRequest req){
-		//查询专业定义
-		QueryCriteria majorCriteria = ServiceUtil.getQueryCriteria(objectMapper);
-		majorCriteria.getCriteria().put("type", "major");
-		return ServiceUtil.call (() -> dicClient.dataQuery(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), majorCriteria));
-	}
-
-	public List<ObjectNode> getSystemList(BdtpRequest req){
-		//查询系统定义
-		QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "system");
-		return ServiceUtil.queryAllPage(() -> rwdClient.queryObjectType(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
-	}
-
-	/**
-	 * 查询系统下的设备类型定义
-	 */
-	public List<ObjectNode> getEquipTypeList(BdtpRequest req, String system){
-		QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "equipment");
-		if(StrUtil.isNotBlank(system))
-			criteria.getCriteria().put("systemCode", system);
-		return ServiceUtil.queryAllPage(() -> rwdClient.queryObjectType(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
-	}
-
-	/**
-	 * 查询数据字典关系类型
-	 */
-	public List<Map<String, Object>> getRelTypeTree(BdtpRequest req){
-		List<RelationDefine> relList = ServiceUtil.call(() -> rwdClient.queryRelDef(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), new QueryCriteria()));
-		List<GraphDefine> graph = ServiceUtil.call (() -> rwdClient.queryGraphDef(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), new QueryCriteria()));
-
-		List<Map<String, Object>> rels = new ArrayList<>();
-		for(GraphDefine gd : graph){
-			HashMap<String, Object> m = new HashMap<>();
-			m.put("code", gd.getCode());
-			m.put("name", gd.getName());
-			m.put("type", "graph");
-			rels.add(m);
-
-			ArrayList<RelationDefine> chidren = new ArrayList<>();
-			m.put("children", chidren);
-			for(RelationDefine relDef : relList) {
-				if(relDef.getGraphCode().equals(gd.getCode()))
-					chidren.add(relDef);
-			}
-		}
-		return rels;
-	}
-
-	public List<ObjectNode> queryObjectsByType(BdtpRequest req, List<String> equipmentTypes, String systemId){
-		QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "equipment");
-
-		ArrayNode types = criteria.getCriteria().putArray("classCode");
-		for(String code : equipmentTypes) {
-			types.add(code);
-		}
-
-		if(StrUtil.isNotBlank(systemId)){
-			//TODO 按系统实例进行过滤
-		}
-
-		List<ObjectNode> objs = ServiceUtil.queryAllPage(() -> objectClient.query(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
-		if(objs == null)
-			objs = new ArrayList<>(0);
-		return objs;
-	}
-
-	public List<ObjectNode> queryObjectsById(BdtpRequest req, List<String> ids){
-		QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "equipment");
-		ArrayNode arr = criteria.getCriteria().putArray("id");
-		for(String id : ids) {
-			arr.add(id);
-		}
-
-		List<ObjectNode> objs = ServiceUtil.queryAllPage(() -> objectClient.query(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
-		if(objs == null)
-			objs = new ArrayList<>(0);
-		return objs;
-	}
-
-	public List<ObjectNode> queryRelsByTypeAndObj(BdtpRequest req, List<String[]> relTypes, List<String> objIds){
-		List<ObjectNode> rtn = new ArrayList<>();
-
-		QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper);
-		ArrayNode arr = criteria.getCriteria().putArray("objFrom");
-		for(String id : objIds) {
-			arr.add(id);
-		}
-		List<ObjectNode> rels = ServiceUtil.queryAllPage(() -> rwdClient.queryRelation(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
-		if(rels != null)
-			rtn.addAll(rels);
-
-		criteria.getCriteria().set("objTo", criteria.getCriteria().remove("objFrom"));
-		rels = ServiceUtil.queryAllPage(() -> rwdClient.queryRelation(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
-		if(rels != null)
-			rtn.addAll(rels);
-
-		//TODO relTypes参数处理
-
-		return rtn;
-	}
+    @Autowired
+    private RwdClient rwdClient;
+
+    @Autowired
+    private DicClient dicClient;
+
+    @Autowired
+    private DigitalObjectClient objectClient;
+
+    @Autowired
+    private ObjectMapper objectMapper;
+
+    public List<ObjectNode> getMajorList(BdtpRequest req) {
+        //查询专业定义
+        QueryCriteria majorCriteria = ServiceUtil.getQueryCriteria(objectMapper);
+        majorCriteria.getCriteria().put("type", "major");
+        return ServiceUtil.call(() -> dicClient.dataQuery(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), majorCriteria));
+    }
+
+    public List<ObjectNode> getSystemList(BdtpRequest req) {
+        //查询系统定义
+        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, Constants.SYSTEM);
+        return ServiceUtil.queryAllPage(() -> rwdClient.queryObjectType(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
+    }
+
+    /**
+     * 查询系统下的设备类型定义
+     */
+    public List<ObjectNode> getEquipTypeList(BdtpRequest req, String system) {
+        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, Constants.EQUIPMENT);
+        if (StrUtil.isNotBlank(system)) {
+            criteria.getCriteria().put("systemCode", system);
+        }
+        return ServiceUtil.queryAllPage(() -> rwdClient.queryObjectType(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
+    }
+
+    /**
+     * 查询数据字典关系类型
+     */
+    public List<Map<String, Object>> getRelTypeTree(BdtpRequest req) {
+        List<RelationDefine> relList = ServiceUtil.call(() -> rwdClient.queryRelDef(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), new QueryCriteria()));
+        List<GraphDefine> graph = ServiceUtil.call(() -> rwdClient.queryGraphDef(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), new QueryCriteria()));
+
+        List<Map<String, Object>> rels = new ArrayList<>();
+        for (GraphDefine gd : graph) {
+            HashMap<String, Object> m = new HashMap<>();
+            m.put("code", gd.getCode());
+            m.put("name", gd.getName());
+            m.put("type", "graph");
+            rels.add(m);
+
+            ArrayList<RelationDefine> children = new ArrayList<>();
+            m.put("children", children);
+            for (RelationDefine relDef : relList) {
+                if (relDef.getGraphCode().equals(gd.getCode())) {
+                    children.add(relDef);
+                }
+            }
+        }
+        return rels;
+    }
+
+    public List<ObjectNode> queryObjectsByType(BdtpRequest req, List<String> equipmentTypes, String systemId) {
+        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "equipment");
+
+        ArrayNode types = criteria.getCriteria().putArray("classCode");
+        for (String code : equipmentTypes) {
+            types.add(code);
+        }
+
+        if (StrUtil.isNotBlank(systemId)) {
+            //TODO 按系统实例进行过滤
+        }
+
+        List<ObjectNode> objs = ServiceUtil.queryAllPage(() -> objectClient.query(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
+        if (objs == null) {
+            objs = new ArrayList<>(0);
+        }
+        return objs;
+    }
+
+    public List<ObjectNode> queryObjectsById(BdtpRequest req, List<String> ids) {
+        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "equipment");
+        ArrayNode arr = criteria.getCriteria().putArray("id");
+        for (String id : ids) {
+            arr.add(id);
+        }
+
+        List<ObjectNode> objs = ServiceUtil.queryAllPage(() -> objectClient.query(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
+        if (objs == null) {
+            objs = new ArrayList<>(0);
+        }
+        return objs;
+    }
+
+    public List<ObjectNode> queryRelsByTypeAndObj(BdtpRequest req, List<String[]> relTypes, List<String> objIds) {
+        List<ObjectNode> rtn = new ArrayList<>();
+
+        QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper);
+        ArrayNode arr = criteria.getCriteria().putArray("objFrom");
+        for (String id : objIds) {
+            arr.add(id);
+        }
+        List<ObjectNode> rels = ServiceUtil.queryAllPage(() -> rwdClient.queryRelation(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
+        if (rels != null) {
+            rtn.addAll(rels);
+        }
+
+        criteria.getCriteria().set("objTo", criteria.getCriteria().remove("objFrom"));
+        rels = ServiceUtil.queryAllPage(() -> rwdClient.queryRelation(req.getGroupCode(), req.getProjectId(), req.getAppId(), req.getUserId(), criteria), criteria, new Pagination(500));
+        if (rels != null) {
+            rtn.addAll(rels);
+        }
+
+        //TODO relTypes参数处理
+
+        return rtn;
+    }
 
 }

+ 3 - 2
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/util/Pagination.java

@@ -22,10 +22,11 @@ public class Pagination {
 
 	public void next() {
 		pageNum++;
-		if ((pageNum - 1) * pageSize >= total)
+		if ((pageNum - 1) * pageSize >= total) {
 			hasNext = false;
-		else
+		} else {
 			hasNext = true;
+		}
 	}
 
 }

+ 7 - 5
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/util/ServiceUtil.java

@@ -22,9 +22,9 @@ public class ServiceUtil {
 		QueryCriteria queryCriteria = new QueryCriteria();
 
 		ObjectNode objectNode = objectMapper.createObjectNode();
-		if(objType.length  == 1)
+		if(objType.length  == 1) {
 			objectNode.put("objType", objType[0]);
-		else if(objType.length > 1) {
+		} else if(objType.length > 1) {
 			ArrayNode arrayNode = objectNode.putArray("objType");
 			for(String type : objType) {
 				arrayNode.add(type);
@@ -42,8 +42,9 @@ public class ServiceUtil {
 	private static <T> T call(Supplier<CommonResult<T>> action, Pagination pagination) {
 		CommonResult<T> result = action.get();
 		if(SUCCESS.equals(result.getResult())) {
-			if(pagination != null)
+			if(pagination != null) {
 				pagination.setTotal(result.getCount().intValue());
+			}
 			return result.getData();
 		}
 		throw new CallException(new CommonResult<>(result.getResult(), result.getMessage()));
@@ -54,10 +55,11 @@ public class ServiceUtil {
 		while (pagination.isHasNext()){
 			criteria.setPage((long)pagination.getPageNum());
 			criteria.setSize((long)pagination.getPageSize());
-			if(list == null)
+			if(list == null) {
 				list = ServiceUtil.call(action, pagination);
-			else
+			} else {
 				list.addAll(ServiceUtil.call(action, pagination));
+			}
 			pagination.next();
 		}
 		return list;