|
@@ -10,6 +10,7 @@ import com.persagy.adm.diagram.core.model.base.IComponent;
|
|
|
import com.persagy.adm.diagram.core.model.base.IEquipHolder;
|
|
|
import com.persagy.adm.diagram.core.model.legend.Anchor;
|
|
|
import com.persagy.adm.diagram.core.model.legend.Legend;
|
|
|
+import com.persagy.adm.diagram.core.model.logic.CalcContext;
|
|
|
import com.persagy.adm.diagram.core.model.logic.DataFilter;
|
|
|
import com.persagy.adm.diagram.core.model.template.DiagramTemplate;
|
|
|
import com.persagy.adm.diagram.core.model.template.MainPipe;
|
|
@@ -17,6 +18,7 @@ import com.persagy.adm.diagram.core.model.virtual.PackNode;
|
|
|
import com.persagy.dmp.digital.entity.ObjectRelation;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 处理系统图的计算逻辑
|
|
@@ -29,6 +31,8 @@ public class DiagramBuilder {
|
|
|
*/
|
|
|
public static int equipLimit = 50;
|
|
|
|
|
|
+ private CalcContext context;
|
|
|
+
|
|
|
private Diagram diagram;
|
|
|
|
|
|
private DiagramTemplate template;
|
|
@@ -39,66 +43,24 @@ public class DiagramBuilder {
|
|
|
|
|
|
private HashSet<String> refRelTypes = new HashSet<>();
|
|
|
|
|
|
- /**
|
|
|
- * 记录已经使用的数据id和对应的组件
|
|
|
- */
|
|
|
- private HashMap<String, Object> equipMap = new HashMap<>();
|
|
|
-
|
|
|
- /**
|
|
|
- * 记录已经使用的关系id和对应的连线
|
|
|
- */
|
|
|
- private HashMap<String, Line> lineMap = new HashMap<>();
|
|
|
-
|
|
|
- public DiagramBuilder(Diagram diagram, DataStrategy dataStrategy) {
|
|
|
- this.diagram = diagram;
|
|
|
- this.template = diagram.getTemplate();
|
|
|
+ public DiagramBuilder(CalcContext context, DataStrategy dataStrategy) {
|
|
|
+ this.context = context;
|
|
|
+ this.diagram = context.getDiagram();
|
|
|
+ this.template = context.getTemplate();
|
|
|
this.dataStrategy = dataStrategy;
|
|
|
|
|
|
- init();
|
|
|
- }
|
|
|
-
|
|
|
- private void init(){
|
|
|
- //记录节点中已使用的数据id
|
|
|
- diagram.getNodes().forEach(node -> {
|
|
|
- if (EquipmentNode.TYPE.equals(node.getCompType())) {
|
|
|
- equipMap.put(((EquipmentNode) node).getObjId(), node);
|
|
|
- }
|
|
|
- });
|
|
|
- //记录干管中已使用的数据id
|
|
|
- if(template != null && template.getMainPipes() != null) {
|
|
|
- template.getMainPipes().forEach(mainPipe -> {
|
|
|
- if(StrUtil.isNotBlank(mainPipe.getDataObjectId())) {
|
|
|
- equipMap.put(mainPipe.getDataObjectId(), mainPipe);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- diagram.getLines().forEach(line -> {
|
|
|
- if (StrUtil.isNotBlank(line.getDataObjectId())){
|
|
|
- lineMap.put(line.getDataObjectId(), line);
|
|
|
- }
|
|
|
- });
|
|
|
+ this.context.setDataStrategy(dataStrategy);
|
|
|
}
|
|
|
|
|
|
//加载设备数据,并进行计算处理
|
|
|
public void buildEquipNodeAndContainer(List<Container> containers, List<ObjectNode> optionalObjs){
|
|
|
- for(Container con : containers) {
|
|
|
- if(con.isEquipmentBox()) {
|
|
|
- Iterator<ObjectNode> iter = optionalObjs.iterator();
|
|
|
- while (iter.hasNext()) {
|
|
|
- ObjectNode obj = iter.next();
|
|
|
- if (match(obj, con)) {
|
|
|
- if(con.getEquipPack() != null) {
|
|
|
- addPackData(con, obj);
|
|
|
- } else {
|
|
|
- addEquipNode(con, obj);
|
|
|
- }
|
|
|
-
|
|
|
- iter.remove();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ //去掉已经使用的数据项
|
|
|
+ if(context.getEquipMap().size() > 0) {
|
|
|
+ optionalObjs = optionalObjs.stream().filter(obj -> !context.getEquipMap().containsKey(obj.get("id").asText())).collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ optionalObjs = new ArrayList<>(optionalObjs);
|
|
|
}
|
|
|
+
|
|
|
if(template.getMainPipes() != null) {
|
|
|
for(MainPipe mainPipe : template.getMainPipes()) {
|
|
|
if (mainPipe.isBindEquipment() && mainPipe.getDataObject() == null){
|
|
@@ -109,7 +71,7 @@ public class DiagramBuilder {
|
|
|
mainPipe.setDataObject(obj);
|
|
|
mainPipe.setDataObjectId(obj.get("id").asText());
|
|
|
|
|
|
- equipMap.put(mainPipe.getDataObjectId(), mainPipe);
|
|
|
+ context.getEquipMap().put(mainPipe.getDataObjectId(), mainPipe);
|
|
|
|
|
|
iter.remove();
|
|
|
break;
|
|
@@ -118,6 +80,23 @@ public class DiagramBuilder {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ for(Container con : containers) {
|
|
|
+ if(con.isEquipmentBox()) {
|
|
|
+ Iterator<ObjectNode> iter = optionalObjs.iterator();
|
|
|
+ while (iter.hasNext()) {
|
|
|
+ ObjectNode obj = iter.next();
|
|
|
+ if (match(obj, con)) {
|
|
|
+ if(con.getEquipPack() != null) {
|
|
|
+ addPackData(con, obj);
|
|
|
+ } else {
|
|
|
+ addEquipNode(con, obj);
|
|
|
+ }
|
|
|
+
|
|
|
+ iter.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
handleNodes();
|
|
|
|
|
@@ -140,8 +119,6 @@ public class DiagramBuilder {
|
|
|
Legend legend = findLegend(node.getObjClassCode(), obj);
|
|
|
node.setLegendId(legend.getId());
|
|
|
node.setLegend(legend);
|
|
|
-
|
|
|
- equipMap.put(node.getObjId(), node);
|
|
|
}
|
|
|
|
|
|
private void initNode(EquipmentNode node, String name, Container con){
|
|
@@ -154,6 +131,7 @@ public class DiagramBuilder {
|
|
|
node.setLabel(label);
|
|
|
|
|
|
diagram.getNodes().add(node);
|
|
|
+ context.getEquipMap().put(node.getObjId(), node);
|
|
|
}
|
|
|
|
|
|
private void addPackData(Container con, ObjectNode obj){
|
|
@@ -171,9 +149,6 @@ public class DiagramBuilder {
|
|
|
} else {
|
|
|
pn = (PackNode) con.getChildren().get(0);
|
|
|
}
|
|
|
- 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;
|
|
@@ -217,7 +192,7 @@ public class DiagramBuilder {
|
|
|
if(equipHolder.getEquipmentTypes() != null && equipHolder.getEquipmentTypes().contains(classCode)) {
|
|
|
DataFilter filter = equipHolder.getDataFilter();
|
|
|
if(filter != null) {
|
|
|
- return filter.filter(obj);
|
|
|
+ return filter.filter(obj, context);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@@ -282,7 +257,7 @@ public class DiagramBuilder {
|
|
|
//过滤条件匹配
|
|
|
boolean filterMatch;
|
|
|
if(obj != null && legend.getDataFilter() != null) {
|
|
|
- filterMatch = legend.getDataFilter().filter(obj);
|
|
|
+ filterMatch = legend.getDataFilter().filter(obj, context);
|
|
|
} else {
|
|
|
filterMatch = true;
|
|
|
}
|
|
@@ -313,9 +288,14 @@ public class DiagramBuilder {
|
|
|
}
|
|
|
|
|
|
public void buildLines(List<ObjectNode> optionalRels){
|
|
|
+ //去掉已经使用的关系项
|
|
|
+ if(context.getLineMap().size() > 0) {
|
|
|
+ optionalRels = optionalRels.stream().filter(obj -> !context.getLineMap().containsKey(obj.get("id").asText())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
for(ObjectNode rel : optionalRels) {
|
|
|
- Object fromObj = equipMap.get(rel.get(ObjectRelation.OBJ_FROM_HUM).asText());
|
|
|
- Object toObj = equipMap.get(rel.get(ObjectRelation.OBJ_TO_HUM).asText());
|
|
|
+ Object fromObj = context.getEquipMap().get(rel.get(ObjectRelation.OBJ_FROM_HUM).asText());
|
|
|
+ Object toObj = context.getEquipMap().get(rel.get(ObjectRelation.OBJ_TO_HUM).asText());
|
|
|
|
|
|
if(fromObj != null && toObj != null) {
|
|
|
String relType = rel.get(ObjectRelation.GRAPH_CODE_HUM).asText() + '/' + rel.get(ObjectRelation.REL_CODE_HUM).asText();
|
|
@@ -366,7 +346,7 @@ public class DiagramBuilder {
|
|
|
equipMatch = a.getToEquipmentTypes().contains(theOtherType);
|
|
|
}
|
|
|
if(!Boolean.FALSE.equals(equipMatch) && a.getToDataFilter() != null) {
|
|
|
- equipMatch = a.getToDataFilter().filter(theOtherData);
|
|
|
+ equipMatch = a.getToDataFilter().filter(theOtherData, context);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -429,14 +409,6 @@ public class DiagramBuilder {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public HashMap<String, Object> getEquipMap() {
|
|
|
- return equipMap;
|
|
|
- }
|
|
|
-
|
|
|
- public HashMap<String, Line> getLineMap() {
|
|
|
- return lineMap;
|
|
|
- }
|
|
|
-
|
|
|
public HashSet<String> getRefRelTypes() {
|
|
|
return refRelTypes;
|
|
|
}
|