|
@@ -10,6 +10,8 @@ import com.persagy.adm.diagram.core.model.Diagram;
|
|
|
import com.persagy.adm.diagram.core.model.DiagramNode;
|
|
|
import com.persagy.adm.diagram.core.model.Label;
|
|
|
import com.persagy.adm.diagram.core.model.legend.Legend;
|
|
|
+import com.persagy.adm.diagram.core.model.logic.DataFilter;
|
|
|
+import com.persagy.adm.diagram.core.model.logic.MatchFilter;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
@@ -36,6 +38,8 @@ public class DiagramDataLoader {
|
|
|
|
|
|
private List<ObjectNode> optionalRels;
|
|
|
|
|
|
+ private HashMap<String, List<Legend>> legendsCache = new HashMap<>();
|
|
|
+
|
|
|
public DiagramDataLoader(Diagram diagram, DataStrategy dataStrategy) {
|
|
|
this.diagram = diagram;
|
|
|
this.dataStrategy = dataStrategy;
|
|
@@ -44,7 +48,7 @@ public class DiagramDataLoader {
|
|
|
public void load(){
|
|
|
List<String> objIds = diagram.getObjIds();
|
|
|
if(objIds.size() > 0)
|
|
|
- objs = dataStrategy.loadObjectsById(objIds, diagram.getProjectId());
|
|
|
+ objs = dataStrategy.loadObjectsById(objIds, diagram.getProjectId(), diagram.getGroupCode());
|
|
|
else
|
|
|
objs = new ArrayList<>();
|
|
|
buildNodes();
|
|
@@ -79,10 +83,10 @@ public class DiagramDataLoader {
|
|
|
loadEquipTypes(con, equipTypes);
|
|
|
}
|
|
|
} else
|
|
|
- containers = null;
|
|
|
+ containers = new ArrayList<>();
|
|
|
|
|
|
if(equipTypes.size() > 0)
|
|
|
- optionalObjs = dataStrategy.loadObjectsByType(equipTypes, diagram.getProjectId(), diagram.getBuildingId(), diagram.getFloorId());
|
|
|
+ optionalObjs = dataStrategy.loadObjectsByType(equipTypes, diagram.getProjectId(), diagram.getSystemId(), diagram.getGroupCode());
|
|
|
else
|
|
|
optionalObjs = new ArrayList<>();
|
|
|
|
|
@@ -103,11 +107,12 @@ public class DiagramDataLoader {
|
|
|
}
|
|
|
|
|
|
addEquipNodes();
|
|
|
+ buildContainers();
|
|
|
|
|
|
if(optionalObjs.size() > 0) {
|
|
|
List<String> objIds = new ArrayList<>(optionalObjs.size());
|
|
|
optionalObjs.forEach(obj -> objIds.add(obj.get("id").asText()));
|
|
|
- optionalRels = dataStrategy.loadRelationsByType(null, objIds, diagram.getProjectId());
|
|
|
+ optionalRels = dataStrategy.loadRelationsByType(null, objIds, diagram.getProjectId(), diagram.getGroupCode());
|
|
|
} else
|
|
|
optionalRels = new ArrayList<>();
|
|
|
|
|
@@ -124,98 +129,125 @@ public class DiagramDataLoader {
|
|
|
}
|
|
|
|
|
|
private void addEquipNodes(){
|
|
|
-// for(Container con : containers) {
|
|
|
-// for(ObjectNode obj : optionalObjs){
|
|
|
-// if (match(obj, con)) {
|
|
|
-// EquipmentNode node = new EquipmentNode();
|
|
|
-// node.setId(IdUtil.simpleUUID());
|
|
|
-// node.setObjId(obj.get("id").asText());
|
|
|
-// node.setObjClassCode(obj.get("classCode").asText());
|
|
|
-// node.setDataObject(obj);
|
|
|
+ for(Container con : containers) {
|
|
|
+ for(ObjectNode obj : optionalObjs){
|
|
|
+ if (match(obj, con)) {
|
|
|
+ EquipmentNode node = new EquipmentNode();
|
|
|
+ node.setId(IdUtil.simpleUUID());
|
|
|
+ node.setObjId(obj.get("id").asText());
|
|
|
+ node.setObjClassCode(obj.get("classCode").asText());
|
|
|
+ node.setDataObject(obj);
|
|
|
+
|
|
|
+ Label label = new Label();
|
|
|
+ String content = null;
|
|
|
+ if(obj.get("localName") != null)
|
|
|
+ content = obj.get("localName").asText();
|
|
|
+ if(StrUtil.isBlank(content))
|
|
|
+ content = obj.get("name").asText();
|
|
|
+ label.setContent(content);
|
|
|
+ node.setLabel(label);
|
|
|
+
|
|
|
+ diagram.getNodes().add(node);
|
|
|
+
|
|
|
+ con.addComp(node);
|
|
|
+ node.setContainerId(con.getId());
|
|
|
+ node.setLayoutIndex(con.getChildren().size() - 1);
|
|
|
+
|
|
|
+ Legend legend = findLegend(node, obj);
|
|
|
+ if(legend != null) {
|
|
|
+ node.setLegendId(legend.getId());
|
|
|
+ node.setLegend(legend);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //test code
|
|
|
+// for(ObjectNode obj : optionalObjs){
|
|
|
+// EquipmentNode node = new EquipmentNode();
|
|
|
+// node.setId(IdUtil.simpleUUID());
|
|
|
+// node.setObjId(obj.get("id").asText());
|
|
|
+// node.setObjClassCode(obj.get("classCode").asText());
|
|
|
+// node.setDataObject(obj);
|
|
|
//
|
|
|
-// Label label = new Label();
|
|
|
-// String content = null;
|
|
|
-// if(obj.get("localName") != null)
|
|
|
-// content = obj.get("localName").asText();
|
|
|
-// if(StrUtil.isBlank(content))
|
|
|
-// content = obj.get("name").asText();
|
|
|
-// label.setContent(content);
|
|
|
-// node.setLabel(label);
|
|
|
+// Label label = new Label();
|
|
|
+// String content = null;
|
|
|
+// if(obj.get("localName") != null)
|
|
|
+// content = obj.get("localName").asText();
|
|
|
+// if(StrUtil.isBlank(content))
|
|
|
+// content = obj.get("name").asText();
|
|
|
+// label.setContent(content);
|
|
|
+// node.setLabel(label);
|
|
|
//
|
|
|
-// diagram.getNodes().add(node);
|
|
|
+// Container con = findContainer(node, obj);
|
|
|
+// if(con != null) {
|
|
|
+// diagram.getNodes().add(node);
|
|
|
//
|
|
|
-// con.addComp(node);
|
|
|
-// node.setContainerId(con.getId());
|
|
|
-// node.setLayoutIndex(con.getChildren().size() - 1);
|
|
|
+// con.addComp(node);
|
|
|
+// node.setContainerId(con.getId());
|
|
|
+// node.setLayoutIndex(con.getChildren().size() - 1);
|
|
|
//
|
|
|
-// Legend legend = findLegend(node, obj);
|
|
|
-// if(legend != null) {
|
|
|
-// node.setLegendId(legend.getId());
|
|
|
-// node.setLegend(legend);
|
|
|
-// }
|
|
|
+// Legend legend = findLegend(node, obj);
|
|
|
+// if(legend != null) {
|
|
|
+// node.setLegendId(legend.getId());
|
|
|
+// node.setLegend(legend);
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
-
|
|
|
- //test code
|
|
|
- for(ObjectNode obj : optionalObjs){
|
|
|
- EquipmentNode node = new EquipmentNode();
|
|
|
- node.setId(IdUtil.simpleUUID());
|
|
|
- node.setObjId(obj.get("id").asText());
|
|
|
- node.setObjClassCode(obj.get("classCode").asText());
|
|
|
- node.setDataObject(obj);
|
|
|
-
|
|
|
- Label label = new Label();
|
|
|
- String content = null;
|
|
|
- if(obj.get("localName") != null)
|
|
|
- content = obj.get("localName").asText();
|
|
|
- if(StrUtil.isBlank(content))
|
|
|
- content = obj.get("name").asText();
|
|
|
- label.setContent(content);
|
|
|
- node.setLabel(label);
|
|
|
-
|
|
|
- Container con = findContainer(node, obj);
|
|
|
- if(con != null) {
|
|
|
- diagram.getNodes().add(node);
|
|
|
-
|
|
|
- con.addComp(node);
|
|
|
- node.setContainerId(con.getId());
|
|
|
- node.setLayoutIndex(con.getChildren().size() - 1);
|
|
|
-
|
|
|
- Legend legend = findLegend(node, obj);
|
|
|
- if(legend != null) {
|
|
|
- node.setLegendId(legend.getId());
|
|
|
- node.setLegend(legend);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
//test code
|
|
|
- private Container findContainer(EquipmentNode node, ObjectNode obj){
|
|
|
- if(containers != null) {
|
|
|
- for(Container con : containers) {
|
|
|
- if(con.getEquipmentTypes() != null && con.getEquipmentTypes().contains(node.getObjClassCode())) {
|
|
|
- if(con.getChildren() == null || con.getChildren().size() == 0)
|
|
|
- return con;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
+// private Container findContainer(EquipmentNode node, ObjectNode obj){
|
|
|
+// if(containers != null) {
|
|
|
+// for(Container con : containers) {
|
|
|
+// if(con.getEquipmentTypes() != null && con.getEquipmentTypes().contains(node.getObjClassCode())) {
|
|
|
+// if(con.getChildren() == null || con.getChildren().size() == 0)
|
|
|
+// return con;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return null;
|
|
|
+// }
|
|
|
|
|
|
private boolean match(ObjectNode obj, Container con) {
|
|
|
String classCode = obj.get("classCode").asText();
|
|
|
if(con.getEquipmentTypes() != null && con.getEquipmentTypes().contains(classCode)) {
|
|
|
- //TODO filter
|
|
|
+ DataFilter filter = con.getDataFilter();
|
|
|
+ if(filter != null)
|
|
|
+ return filter.filter(getDataForFilter(filter, obj));
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ private Object getDataForFilter(DataFilter filter, ObjectNode obj){
|
|
|
+ if(filter instanceof MatchFilter) {
|
|
|
+ MatchFilter mf = (MatchFilter) filter;
|
|
|
+ if(mf.getObject().equals(MatchFilter.OBJ_NAME)) {
|
|
|
+ String name = null;
|
|
|
+ if(obj.get("localName") != null)
|
|
|
+ name = obj.get("localName").asText();
|
|
|
+ if(StrUtil.isBlank(name))
|
|
|
+ name = obj.get("name").asText();
|
|
|
+ return name;
|
|
|
+ } else if(mf.getObject().startsWith(MatchFilter.OBJ_INFOS)) {
|
|
|
+ String infoCode = mf.getObject().substring(MatchFilter.OBJ_INFOS.length());
|
|
|
+ return obj.get(infoCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
private Legend findLegend(EquipmentNode node, ObjectNode obj){
|
|
|
- List<Legend> legends = dataStrategy.getLegendsForEquipment(node.getObjClassCode());
|
|
|
- if(CollUtil.isNotEmpty(legends)) {
|
|
|
+ String classCode = node.getObjClassCode();
|
|
|
+ List<Legend> legends = legendsCache.get(classCode);
|
|
|
+ if (legends == null) {
|
|
|
+ legends = dataStrategy.getLegendsForEquipment(classCode);
|
|
|
+ if (legends == null)
|
|
|
+ legends = new ArrayList<>();
|
|
|
+ legendsCache.put(classCode, legends);
|
|
|
+ }
|
|
|
+ if(legends.size() > 0) {
|
|
|
for(Legend legend : legends) {
|
|
|
if(diagram.getType().equals(legend.getDiagramType()))
|
|
|
return legend; //优先返回适配系统图类型的图例
|
|
@@ -225,6 +257,15 @@ public class DiagramDataLoader {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private void buildContainers() {
|
|
|
+ for(Container con : containers) {
|
|
|
+ if(con.isEquipmentBox()) {
|
|
|
+ if(Boolean.TRUE.equals(con.getProp(Container.PROP_AUTO_HIDDEN)) && CollUtil.isEmpty(con.getChildren()))
|
|
|
+ con.setHidden(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void addLines(){
|
|
|
//System.out.println(optionalRels);
|
|
|
}
|