2 Commitit 833c22e788 ... c13f2a25c9

Tekijä SHA1 Viesti Päivämäärä
  zhaoyk c13f2a25c9 Merge branch 'develop' of http://39.106.8.246:3003/BDTP/digital-delivery 2 vuotta sitten
  zhaoyk 6155e8d4d3 动态组相关代码;模板检查和修正 2 vuotta sitten

+ 17 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DiagramBuilder.java

@@ -53,6 +53,15 @@ public class DiagramBuilder {
 		this.context.setDataStrategy(dataStrategy);
 	}
 
+	private boolean hasDynGroup(List<Container> containers) {
+		for(Container con : containers) {
+			if(con.getDynGroup() != null){
+				return true;
+			}
+		}
+		return false;
+	}
+
 	//加载设备数据,并进行计算处理
 	public void buildEquipNodeAndContainer(List<Container> containers, List<ObjectNode> optionalObjs){
 		//去掉已经使用的数据项
@@ -62,6 +71,10 @@ public class DiagramBuilder {
 			optionalObjs = new ArrayList<>(optionalObjs);
 		}
 
+		if(hasDynGroup(containers)) {
+			//TODO 动态组计算
+		}
+
 		if(template.getMainPipes() != null) {
 			for(MainPipe mainPipe : template.getMainPipes()) {
 				if (mainPipe.isBindEquipment() && mainPipe.getDataObject() == null){
@@ -104,6 +117,10 @@ public class DiagramBuilder {
 		handleContainers(containers);
 	}
 
+	private void buildMainPipe(){
+
+	}
+
 	private void addEquipNode(Container con, ObjectNode obj){
 		if(con.getChildren().size() > equipLimit) {
 			return;

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

@@ -62,6 +62,11 @@ public class Container extends AbstractComponent implements IContainer, IEquipHo
 	private Label groupLabel;
 
 	/**
+	 * 该容器为动态源时,驱动的目标组件id
+	 */
+	private String dynTarget;
+
+	/**
 	 * 直接包含的干管
 	 */
 	@JsonIgnore
@@ -279,6 +284,25 @@ public class Container extends AbstractComponent implements IContainer, IEquipHo
 		return null;
 	}
 
+	public boolean isParentOf(IComponent comp){
+		IContainer p = comp.getParent();
+		while (p != null) {
+			if(p == this){
+				return true;
+			}
+			p = p.getParent();
+		}
+		return false;
+	}
+
+	public String getDynTarget() {
+		return dynTarget;
+	}
+
+	public void setDynTarget(String dynTarget) {
+		this.dynTarget = dynTarget;
+	}
+
 	public void addChildMainPipe(MainPipe mainPipe) {
 		if(childMainPipes == null) {
 			childMainPipes = new ArrayList<>();

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

@@ -1,10 +1,12 @@
 package com.persagy.adm.diagram.core.model.template;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.google.gson.annotations.Expose;
 import com.persagy.adm.diagram.core.model.base.Container;
 import com.persagy.adm.diagram.core.model.base.IComponent;
 import com.persagy.adm.diagram.core.model.base.Layout;
 import com.persagy.adm.diagram.core.model.base.XY;
+import com.persagy.adm.diagram.core.model.logic.DynGroup;
 
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -66,6 +68,12 @@ public class DiagramTemplate {
 	@Expose
 	private List<MainPipe> mainPipes;
 
+	/**
+	 * 初始化状态
+	 */
+	@JsonIgnore
+	private boolean initialized;
+
 	public String getDiagramType() {
 		return diagramType;
 	}
@@ -131,6 +139,9 @@ public class DiagramTemplate {
 	}
 
 	public void init() {
+		if(initialized)
+			return;
+
 		frame.initParent();
 		initScattered(frame);
 
@@ -139,6 +150,35 @@ public class DiagramTemplate {
 				mainPipe.init(this);
 			}
 		}
+
+		setDynTarget();
+
+		initialized = true;
+	}
+
+	public void setDynTarget(){
+		List<Container> containers = getContainers();
+		containers.forEach(container -> container.setDynTarget(null));
+		if(mainPipes != null){
+			mainPipes.forEach(mainPipe -> mainPipe.setDynTarget(null));
+		}
+
+		for(Container con : containers) {
+			DynGroup dynGroup = con.getDynGroup();
+			if(dynGroup != null) {
+				if(Container.TYPE.equals(dynGroup.getDynSourceType())) {
+					Container conSrc = getContainerById(dynGroup.getDynSource());
+					if(conSrc != null){
+						conSrc.setDynTarget(con.getId());
+					}
+				} else if(MainPipe.TYPE.equals(dynGroup.getDynSourceType())) {
+					MainPipe mpSrc = getMainPipeById(dynGroup.getDynSource());
+					if(mpSrc != null){
+						mpSrc.setDynTarget(con.getId());
+					}
+				}
+			}
+		}
 	}
 
 	private void initScattered(Container con){

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

@@ -61,11 +61,19 @@ public class MainPipe extends AbstractLine implements IEquipHolder {
 	private List<List<XY>> locationPath;
 
 	/**
+	 * 该干管为动态源时,驱动的目标组件id
+	 */
+	private String dynTarget;
+
+	/**
 	 * 关联的容器对象,运行时
 	 */
 	@JsonIgnore
 	private List<Container> relatedContainerList;
 
+	/**
+	 * 父容器对象,运行时
+	 */
 	@JsonIgnore
 	private Container parentContainer;
 
@@ -318,4 +326,12 @@ public class MainPipe extends AbstractLine implements IEquipHolder {
 		this.locationPath = locationPath;
 	}
 
+	public String getDynTarget() {
+		return dynTarget;
+	}
+
+	public void setDynTarget(String dynTarget) {
+		this.dynTarget = dynTarget;
+	}
+
 }

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

@@ -0,0 +1,56 @@
+package com.persagy.adm.diagram.core.model.template;
+
+import cn.hutool.core.collection.CollUtil;
+import com.persagy.adm.diagram.core.model.base.Container;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 模板检查修正
+ * @author zhaoyk
+ */
+public class TemplateChecker {
+
+	private DiagramTemplate template;
+
+	public TemplateChecker(DiagramTemplate template) {
+		this.template = template;
+	}
+
+	public void checkAndFix(){
+		template.init();
+
+		if(template.getMainPipes() != null){
+			for(MainPipe mainPipe : template.getMainPipes()) {
+				fixMainPipeRelCons(mainPipe);
+			}
+		}
+
+		//TODO 动态组设置检查,关系过滤条件检查
+	}
+
+	private void fixMainPipeRelCons(MainPipe mainPipe){
+		List<Container> relCons = mainPipe.getRelatedContainerList();
+		if(CollUtil.isNotEmpty(relCons)){
+			for (int i = 0; i < relCons.size(); i++) {
+				Container c1 = relCons.get(i);
+				for (int j = i + 1; j < relCons.size(); j++) {
+					Container c2 = relCons.get(j);
+					if(c1.isParentOf(c2)){
+						relCons.remove(j);
+						j--;
+					} else if(c2.isParentOf(c1)){
+						relCons.remove(i);
+						i--;
+						break;
+					}
+				}
+			}
+			mainPipe.setRelatedContainers(relCons.stream().map(con -> con.getId()).collect(Collectors.toList()));
+		} else {
+			mainPipe.setRelatedContainers(null);
+		}
+	}
+
+}

+ 0 - 2
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/DemoDiagramManager.java

@@ -143,9 +143,7 @@ public class DemoDiagramManager {
 		Diagram diagram = dataStrategy.getDiagram(diagramId);
 		manager.resetDiagram(diagram);
 
-		dataStrategy.saveDiagram(diagram);
 		manager.buildDiagram(diagram);
-
 		return diagram;
 	}
 

+ 11 - 7
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/DiagramManager.java

@@ -35,9 +35,10 @@ public class DiagramManager {
 
 	/**
 	 * 对系统图进行初始化构建操作
+	 * @param autoLayout 是否自动执行布局计算
 	 */
-	public void buildDiagram(Diagram diagram){
-		boolean autoLayout = diagram.getTemplate() == null;
+	public void buildDiagram(Diagram diagram, boolean autoLayout){
+		autoLayout = autoLayout && diagram.getTemplate() == null;
 
 		if(diagram.getTemplate() == null){
 			loadTemplate(diagram);
@@ -51,6 +52,13 @@ public class DiagramManager {
 		}
 	}
 
+	/**
+	 * 对系统图进行初始化构建操作,并根据需要自动执行布局计算
+	 */
+	public void buildDiagram(Diagram diagram){
+		buildDiagram(diagram, true);
+	}
+
 	private void loadTemplate(Diagram diagram){
 		if (diagram.getTemplateId() != null) {
 			diagram.setTemplate(dataStrategy.getTemplate(diagram.getTemplateId()));
@@ -78,11 +86,7 @@ public class DiagramManager {
 	 * 自动加载数据(设备、关系)
 	 */
 	public Diagram loadData(Diagram diagram){
-		if(diagram.getTemplate() == null){
-			loadTemplate(diagram);//先加载template,避免buildDiagram时执行layout
-		}
-
-		buildDiagram(diagram);
+		buildDiagram(diagram, false);
 
 		CalcContext context = new CalcContext(diagram);
 		new DiagramDataLoader(diagram, dataStrategy).autoLoad(context);

+ 9 - 1
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/TemplateManager.java

@@ -12,6 +12,7 @@ import com.persagy.adm.diagram.core.model.logic.DynGroup;
 import com.persagy.adm.diagram.core.model.logic.EquipPack;
 import com.persagy.adm.diagram.core.model.template.DiagramTemplate;
 import com.persagy.adm.diagram.core.model.template.MainPipe;
+import com.persagy.adm.diagram.core.model.template.TemplateChecker;
 import com.persagy.adm.diagram.dao.TemplateMapper;
 import com.persagy.adm.diagram.entity.DiagramType;
 import com.persagy.adm.diagram.entity.TemplateEntity;
@@ -143,7 +144,12 @@ public class TemplateManager {
      * 保存模板
      */
     public DiagramTemplate saveTemplate(DiagramTemplate template) {
-        template.clearLayout(); //保存模板之前,清除布局数据
+        //保存模板之前,清除布局数据
+        template.clearLayout();
+
+        //执行模板检查和修正
+        new TemplateChecker(template).checkAndFix();
+
         DiagramTemplate rtn = dataStrategy.saveTemplate(template);
         buildTemplate(rtn);
         return rtn;
@@ -399,6 +405,8 @@ public class TemplateManager {
         Container con = template.getContainerById(containerId);
         con.setDynGroup(dynGroup);
 
+        template.setDynTarget();
+
         return saveTemplate(template);
     }