Browse Source

系统图对应系统实例

zhaoyk 3 years ago
parent
commit
e892260eef
19 changed files with 444 additions and 154 deletions
  1. 4 4
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/DemoDiagramController.java
  2. 5 0
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/TemplateController.java
  3. 6 6
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DataStrategy.java
  4. 117 76
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DiagramDataLoader.java
  5. 2 2
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DiagramView.java
  6. 7 21
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/Diagram.java
  7. 49 13
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/base/AbstractComponent.java
  8. 28 0
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/base/Container.java
  9. 2 0
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/base/IComponent.java
  10. 38 0
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/DataFilter.java
  11. 90 0
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/MatchFilter.java
  12. 30 6
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/util/GsonUtil.java
  13. 15 11
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/demo/DemoDataStrategy.java
  14. 3 3
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/entity/DiagramEntity.java
  15. 2 2
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/entity/ModelAdapter.java
  16. 7 0
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/frame/EditRequest.java
  17. 5 5
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/DemoDiagramManager.java
  18. 30 0
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/TemplateManager.java
  19. 4 5
      adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/service/BdtpDataService.java

+ 4 - 4
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/DemoDiagramController.java

@@ -20,13 +20,13 @@ public class DemoDiagramController {
 	private DemoDiagramManager diagramManager;
 
 	@RequestMapping("getDiagrams")
-	public CommonResult<List<Folder>> getDiagrams(@RequestParam String projectId, @RequestParam(required = false) String buildingId){
-		return CommonResult.success(diagramManager.getDiagrams(projectId, buildingId));
+	public CommonResult<List<Folder>> getDiagrams(@RequestParam String projectId, @RequestParam(required = false) String systemId, @RequestParam(required = false) String groupCode){
+		return CommonResult.success(diagramManager.getDiagrams(projectId, systemId, groupCode));
 	}
 
 	@RequestMapping("newDiagram")
-	public CommonResult<Diagram> newDiagram(@RequestBody Map<String, String> params, @RequestParam String projectId, @RequestParam(required = false) String buildingId, @RequestParam(required = false) String floorId){
-		return CommonResult.success(diagramManager.createDiagram(params.get("name"), params.get("type"), projectId, buildingId, floorId));
+	public CommonResult<Diagram> newDiagram(@RequestBody Map<String, String> params, @RequestParam String projectId, @RequestParam(required = false) String systemId, @RequestParam(required = false) String groupCode){
+		return CommonResult.success(diagramManager.createDiagram(params.get("name"), params.get("type"), projectId, systemId, groupCode));
 	}
 
 	@RequestMapping("delDiagram")

+ 5 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/controller/TemplateController.java

@@ -74,4 +74,9 @@ public class TemplateController {
         return CommonResult.success(templateManager.modifyMainPipe(params.getTemplatePropsData(), params.getCurrentCompId(), params.getTemplateId()));
     }
 
+    @RequestMapping("modifyFilter")
+    public CommonResult<DiagramTemplate> modifyFilter(@RequestBody EditRequest params){
+        return CommonResult.success(templateManager.modifyFilter(params.getDataFilter(), params.getCurrentCompId(), params.getTemplateId()));
+    }
+
 }

+ 6 - 6
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DataStrategy.java

@@ -41,9 +41,9 @@ public interface DataStrategy {
 
 
 	//系统图
-	List<Diagram> getDiagrams(String projectId, String buildingId, String floorId); //根据具体情况,buildingId和floorId可以为空
+	List<Diagram> getDiagrams(String projectId, String systemId, String groupCode);
 
-	List<Diagram> getDiagrams(String diagramType, String projectId, String buildingId, String floorId); //按系统图类型查询
+	List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode); //按系统图类型查询
 
 	Diagram saveDiagram(Diagram diagram);
 
@@ -53,12 +53,12 @@ public interface DataStrategy {
 
 
 	//系统图数据
-	List<ObjectNode> loadObjectsByType(List<String> equipmentTypes, String projectId, String buildingId, String floorId);
+	List<ObjectNode> loadObjectsByType(List<String> equipmentTypes, String projectId, String systemId, String groupCode);
 
-	List<ObjectNode> loadRelationsByType(List<String[]> relationTypes, List<String> objectIds, String projectId);
+	List<ObjectNode> loadRelationsByType(List<String[]> relationTypes, List<String> objectIds, String projectId, String groupCode);
 
-	List<ObjectNode> loadObjectsById(List<String> objectIds, String projectId);
+	List<ObjectNode> loadObjectsById(List<String> objectIds, String projectId, String groupCode);
 
-	List<ObjectNode> loadRelationsById(List<String> relationIds, String projectId);
+	List<ObjectNode> loadRelationsById(List<String> relationIds, String projectId, String groupCode);
 
 }

+ 117 - 76
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/DiagramDataLoader.java

@@ -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);
 	}

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

@@ -34,7 +34,7 @@ public class DiagramView {
 
 	private String projectId;
 
-	private String buildingId;
+	private String systemId;
 
 	private XY size;
 
@@ -48,7 +48,7 @@ public class DiagramView {
 		this.lines = diagram.getLines();
 		this.mainPipes = diagram.getTemplate().getMainPipes();
 		this.projectId = diagram.getProjectId();
-		this.buildingId = diagram.getBuildingId();
+		this.systemId = diagram.getSystemId();
 		this.size = diagram.getTemplate().getFrame().getSize();
 	}
 

+ 7 - 21
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/Diagram.java

@@ -55,7 +55,7 @@ public class Diagram {
 	private List lines = new ArrayList();
 
 	/**
-	 * 所属的系统
+	 * 所属的系统类型
 	 */
 	@Expose
 	private String system;
@@ -67,16 +67,10 @@ public class Diagram {
 	private String projectId;
 
 	/**
-	 * 建筑id
+	 * 对应的系统实例id
 	 */
 	@Expose
-	private String buildingId;
-
-	/**
-	 * 楼层id
-	 */
-	@Expose
-	private String floorId;
+	private String systemId;
 
 	/**
 	 * 集团编码
@@ -217,20 +211,12 @@ public class Diagram {
 		this.projectId = projectId;
 	}
 
-	public String getBuildingId() {
-		return buildingId;
-	}
-
-	public void setBuildingId(String buildingId) {
-		this.buildingId = buildingId;
-	}
-
-	public String getFloorId() {
-		return floorId;
+	public String getSystemId() {
+		return systemId;
 	}
 
-	public void setFloorId(String floorId) {
-		this.floorId = floorId;
+	public void setSystemId(String systemId) {
+		this.systemId = systemId;
 	}
 
 	public String getGroupCode() {

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

@@ -3,6 +3,9 @@ package com.persagy.adm.diagram.core.model.base;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.google.gson.annotations.Expose;
 
+import java.util.HashMap;
+import java.util.Map;
+
 /**
  * 布局和绘制组件的基类
  * @author zhaoyk
@@ -24,12 +27,26 @@ abstract public class AbstractComponent implements IComponent {
 	@Expose
 	protected PositionData position;
 
+	/**
+	 * 布局定位
+	 */
 	protected XY location;
 
+	/**
+	 * 布局尺寸
+	 */
 	protected XY size;
 
-//	@Expose
-//	private HashMap<String, Object> datas;
+	/**
+	 * 组件的显示/隐藏状态
+	 */
+	protected boolean hidden;
+
+	/**
+	 * 属性
+	 */
+	@Expose
+	private Map<String, Object> props;
 
 	protected AbstractComponent(){
 
@@ -109,17 +126,36 @@ abstract public class AbstractComponent implements IComponent {
 		this.size = size;
 	}
 
-//	@Override
-//	public Object getData(String name){
-//		return datas != null ? datas.get(name) : null;
-//	}
-//
-//	@Override
-//	public void setData(String name, Object value){
-//		if(datas == null)
-//			datas = new HashMap<>();
-//		datas.put(name, value);
-//	}
+	@Override
+	public boolean isHidden() {
+		return hidden;
+	}
+
+	public void setHidden(boolean hidden) {
+		this.hidden = hidden;
+	}
+
+	public Object getProp(String name){
+		return props != null ? props.get(name) : null;
+	}
+
+	public void setProp(String name, Object value){
+		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)
+				props = null;
+		}
+	}
+
+	public void setProps(Map<String, Object> props) {
+		this.props = props;
+	}
 
 	/**
 	 * 相对根容器的坐标位置

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

@@ -3,6 +3,7 @@ package com.persagy.adm.diagram.core.model.base;
 import cn.hutool.core.collection.CollUtil;
 import com.google.gson.annotations.Expose;
 import com.persagy.adm.diagram.core.model.Label;
+import com.persagy.adm.diagram.core.model.logic.DataFilter;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -16,6 +17,11 @@ public class Container extends AbstractComponent implements IContainer {
 
 	public static final String TYPE = "container";
 
+	/**
+	 * 设备容器中,如果没有加载到匹配的设备,是否自动隐藏
+	 */
+	public static final String PROP_AUTO_HIDDEN = "auto_hidden";
+
 	@Expose
 	private List<IComponent> children = new ArrayList<>();
 
@@ -34,6 +40,12 @@ public class Container extends AbstractComponent implements IContainer {
 	@Expose
 	private Label groupLabel;
 
+	/**
+	 * 设备数据过滤器
+	 */
+	@Expose
+	private DataFilter dataFilter;
+
 	public Container() {
 		this.compType = TYPE;
 	}
@@ -55,6 +67,14 @@ public class Container extends AbstractComponent implements IContainer {
 		int childMax = 0;
 		int idx = 0;
 		for(IComponent comp : getArrangedElements()){
+			if(comp.isHidden()) {
+				if(comp instanceof Container) {
+					comp.setLocation(new XY(p.x, p.y)); //给定一个位置,方便计算干管
+					((Container) comp).setSize(new XY(0, 0));
+				}
+				continue;
+			}
+
 			PositionData compPd = comp.getPosition();
 			if(compPd == null)
 				compPd = new PositionData();
@@ -158,6 +178,14 @@ public class Container extends AbstractComponent implements IContainer {
 		this.remark = remark;
 	}
 
+	public DataFilter getDataFilter() {
+		return dataFilter;
+	}
+
+	public void setDataFilter(DataFilter dataFilter) {
+		this.dataFilter = dataFilter;
+	}
+
 	public Label getGroupLabel() {
 		return groupLabel;
 	}

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

@@ -36,6 +36,8 @@ public interface IComponent {
 
     boolean isAbsolutePosition();
 
+    boolean isHidden();
+
 //    Object getData(String key);
 //
 //    void setData(String key, Object value);

+ 38 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/model/logic/DataFilter.java

@@ -0,0 +1,38 @@
+package com.persagy.adm.diagram.core.model.logic;
+
+import com.google.gson.annotations.Expose;
+
+/**
+ * 设备数据过滤器
+ * @author zhaoyk
+ */
+abstract public class DataFilter {
+
+	public static final int TYPE_MATCH = 1;
+
+	public static final int TYPE_AND = 2;
+
+	public static final int TYPE_OR = 3;
+
+	public static final int TYPE_NOT = 4;
+
+	/**
+	 * 过滤器类型
+	 */
+	@Expose
+	protected int type;
+
+	public int getType() {
+		return type;
+	}
+
+	public void setType(int type) {
+		this.type = type;
+	}
+
+	/**
+	 * 过滤操作,返回true时通过
+	 */
+	abstract public boolean filter(Object data);
+
+}

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

@@ -0,0 +1,90 @@
+package com.persagy.adm.diagram.core.model.logic;
+
+import cn.hutool.core.util.StrUtil;
+import com.google.gson.annotations.Expose;
+
+import java.util.Objects;
+
+/**
+ * 匹配过滤器
+ * @author zhaoyk
+ */
+public class MatchFilter extends DataFilter {
+
+	public static final String EQUALS = "equals";
+
+	public static final String CONTAINS = "contains";
+
+	public static final String OBJ_NAME = "name";
+
+	public static final String OBJ_INFOS = "infos.";
+
+	public static final String VALUE_EMPTY = "value.empty";
+
+	@Expose
+	private String object;
+
+	@Expose
+	private String operation;
+
+	@Expose
+	private String value;
+
+	public MatchFilter(){
+		this.type = TYPE_MATCH;
+	}
+
+	@Override
+	public boolean filter(Object data) {
+		if(EQUALS.equals(operation)) {
+			if(VALUE_EMPTY.equals(value)){
+				return data == null || StrUtil.isBlank(data.toString());
+			} else {
+				Object val = value;
+				if(data instanceof Number) {
+					try {
+						val = Double.parseDouble(value);
+					}catch (Exception e) {
+
+					}
+				}
+				return Objects.equals(data, val);
+			}
+		} else if(CONTAINS.equals(operation)) {
+			//简单处理,暂时只考虑字符串,多个匹配项之间使用';'隔开
+			String strData = data != null ? data.toString() : "";
+			String[] arr = value.split(";");
+			for(String s : arr) {
+				if(!strData.contains(s))
+					return false;
+			}
+			return true;
+		}
+		return false;
+	}
+
+	public String getObject() {
+		return object;
+	}
+
+	public void setObject(String object) {
+		this.object = object;
+	}
+
+	public String getOperation() {
+		return operation;
+	}
+
+	public void setOperation(String operation) {
+		this.operation = operation;
+	}
+
+	public String getValue() {
+		return value;
+	}
+
+	public void setValue(String value) {
+		this.value = value;
+	}
+
+}

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

@@ -3,6 +3,8 @@ package com.persagy.adm.diagram.core.util;
 import com.google.gson.*;
 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.logic.DataFilter;
+import com.persagy.adm.diagram.core.model.logic.MatchFilter;
 import org.springframework.stereotype.Component;
 
 import java.lang.reflect.Type;
@@ -21,11 +23,21 @@ public class GsonUtil {
 	public GsonUtil(){
 		GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
 		gsonBuilder.registerTypeAdapter(IComponent.class, new CompAdapter());
+		gsonBuilder.registerTypeAdapter(DataFilter.class, new FilterAdapter());
 		gson = gsonBuilder.create();
 
 		formattedGson = new GsonBuilder().setPrettyPrinting().create();
 	}
 
+	public Gson gson(){
+		return gson;
+	}
+
+	public Gson formattedGson(){
+		return formattedGson;
+	}
+
+
 	class CompAdapter implements JsonDeserializer<IComponent>, JsonSerializer<IComponent> {
 
 		@Override
@@ -46,12 +58,24 @@ public class GsonUtil {
 
 	}
 
-	public Gson gson(){
-		return gson;
-	}
+	class FilterAdapter implements JsonDeserializer<DataFilter>, JsonSerializer<DataFilter> {
 
-	public Gson formattedGson(){
-		return formattedGson;
-	}
+		@Override
+		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)
+				target = MatchFilter.class;
+			else {
+				//TODO 其他类型
+			}
+			return gson.fromJson(jsonElement, target);
+		}
+
+		@Override
+		public JsonElement serialize(DataFilter filter, Type type, JsonSerializationContext jsonSerializationContext) {
+			return gson.toJsonTree(filter, filter.getClass());
+		}
 
+	}
 }

+ 15 - 11
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/demo/DemoDataStrategy.java

@@ -278,12 +278,12 @@ public class DemoDataStrategy implements DataStrategy {
 	private static final String DIR_DIAGRAM = "store/diagram/";
 
 	@Override
-	public List<Diagram> getDiagrams(String projectId, String buildingId, String floorId) {
-		return getDiagrams(null, projectId, buildingId, floorId);
+	public List<Diagram> getDiagrams(String projectId, String systemId, String groupCode) {
+		return getDiagrams(null, projectId, systemId, groupCode);
 	}
 
 	@Override
-	public List<Diagram> getDiagrams(String diagramType, String projectId, String buildingId, String floorId) {
+	public List<Diagram> getDiagrams(String diagramType, String projectId, String systemId, String groupCode) {
 		ArrayList<Diagram> diagrams = new ArrayList<>();
 
 		File dir = new File(DIR_DIAGRAM);
@@ -292,11 +292,11 @@ public class DemoDataStrategy implements DataStrategy {
 			for(File f : list) {
 				Diagram diagram = parser.parseContent(FileUtil.readUtf8String(f), Diagram.class);
 				if(projectId.equals(diagram.getProjectId())) {
-					if(StrUtil.isNotBlank(diagramType) && !diagramType.equals(diagram.getType()))
+					if(StrUtil.isNotBlank(groupCode) && !groupCode.equals(diagram.getGroupCode()))
 						continue;
-					if(StrUtil.isNotBlank(buildingId) && !buildingId.equals(diagram.getBuildingId()))
+					if(StrUtil.isNotBlank(diagramType) && !diagramType.equals(diagram.getType()))
 						continue;
-					if(StrUtil.isNotBlank(floorId) && !floorId.equals(diagram.getFloorId()))
+					if(StrUtil.isNotBlank(systemId) && !systemId.equals(diagram.getSystemId()))
 						continue;
 
 					diagrams.add(diagram);
@@ -346,28 +346,32 @@ public class DemoDataStrategy implements DataStrategy {
 	private BdtpDataService dataService;
 
 	@Override
-	public List<ObjectNode> loadObjectsByType(List<String> equipmentTypes, String projectId, String buildingId, String floorId) {
+	public List<ObjectNode> loadObjectsByType(List<String> equipmentTypes, String projectId, String systemId, String groupCode) {
 		BdtpRequest req = new BdtpRequest();
 		req.setProjectId(projectId);
-		return dataService.queryObjectsByType(req, equipmentTypes, buildingId, floorId);
+		req.setGroupCode(groupCode);
+		return dataService.queryObjectsByType(req, equipmentTypes, systemId);
 	}
 
 	@Override
-	public List<ObjectNode> loadRelationsByType(List<String[]> relationTypes, List<String> objectIds, String projectId) {
+	public List<ObjectNode> loadRelationsByType(List<String[]> relationTypes, List<String> objectIds, String projectId, String groupCode) {
 		BdtpRequest req = new BdtpRequest();
 		req.setProjectId(projectId);
+		req.setGroupCode(groupCode);
 		return dataService.queryRelsByTypeAndObj(req, relationTypes, objectIds);
 	}
 
 	@Override
-	public List<ObjectNode> loadObjectsById(List<String> objectIds, String projectId) {
+	public List<ObjectNode> loadObjectsById(List<String> objectIds, String projectId, String groupCode) {
 		BdtpRequest req = new BdtpRequest();
 		req.setProjectId(projectId);
+		req.setGroupCode(groupCode);
 		return dataService.queryObjectsById(req, objectIds);
 	}
 
 	@Override
-	public List<ObjectNode> loadRelationsById(List<String> relationIds, String projectId) {
+	public List<ObjectNode> loadRelationsById(List<String> relationIds, String projectId, String groupCode) {
+		//TODO
 		return null;
 	}
 

+ 3 - 3
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/entity/DiagramEntity.java

@@ -26,7 +26,7 @@ public class DiagramEntity {
 	private String type;
 
 	/**
-	 * 所属的系统
+	 * 所属的系统类型
 	 */
 	private String system;
 
@@ -41,9 +41,9 @@ public class DiagramEntity {
 	private String projectId;
 
 	/**
-	 * 建筑id
+	 * 对应的系统实例id
 	 */
-	private String buildingId;
+	private String systemId;
 
 	/**
 	 * 集团编码

+ 2 - 2
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/entity/ModelAdapter.java

@@ -68,7 +68,7 @@ public class ModelAdapter {
 		diagram.setTemplateId(diagramEntity.getTemplateId());
 		diagram.setSystem(diagramEntity.getSystem());
 		diagram.setProjectId(diagramEntity.getProjectId());
-		diagram.setBuildingId(diagramEntity.getBuildingId());
+		diagram.setSystemId(diagramEntity.getSystemId());
 		diagram.setGroupCode(diagramEntity.getGroupCode());
 		return diagram;
 	}
@@ -82,7 +82,7 @@ public class ModelAdapter {
 		entity.setTemplateId(diagram.getTemplateId());
 		entity.setSystem(diagram.getSystem());
 		entity.setProjectId(diagram.getProjectId());
-		entity.setBuildingId(diagram.getBuildingId());
+		entity.setSystemId(diagram.getSystemId());
 		entity.setGroupCode(diagram.getGroupCode());
 		entity.setDiagramContent(parser.toJson(diagram));
 		return entity;

+ 7 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/frame/EditRequest.java

@@ -5,6 +5,7 @@ import com.persagy.adm.diagram.core.model.legend.Legend;
 import lombok.Data;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 编辑工具通用请求封装
@@ -30,6 +31,8 @@ public class EditRequest {
 
 	private String diagramId;
 
+	private Map<String, Object> dataFilter;
+
 	@Data
 	public static class TemplatePropsData {
 
@@ -55,10 +58,14 @@ public class EditRequest {
 
 		private String pipeType;
 
+		private boolean bindEquipment;
+
 		private List<String> passbyRels;
 
 		private List<String> connectEquips;
 
+		private Map<String, Object> props;
+
 	}
 
 }

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

@@ -32,9 +32,9 @@ public class DemoDiagramManager {
 	/**
 	 * 查询系统图,树形结构
 	 */
-	public List<Folder> getDiagrams(String projectId, String buildingId) {
+	public List<Folder> getDiagrams(String projectId, String systemId, String groupCode) {
 		List<DiagramType> types = dataStrategy.getDiagramTypes();
-		List<Diagram> diagrams = dataStrategy.getDiagrams(projectId, buildingId, null);
+		List<Diagram> diagrams = dataStrategy.getDiagrams(projectId, systemId, groupCode);
 		for(Diagram diagram : diagrams) {
 			buildDiagram(diagram, true);
 		}
@@ -82,7 +82,7 @@ public class DemoDiagramManager {
 	/**
 	 * 创建新的系统图
 	 */
-	public Diagram createDiagram(String name, String type, String projectId, String buildingId, String floorId){
+	public Diagram createDiagram(String name, String type, String projectId, String systemId, String groupCode){
 		Diagram diagram = new Diagram();
 		diagram.setId(IdUtil.simpleUUID());
 
@@ -91,8 +91,8 @@ public class DemoDiagramManager {
 		diagram.setSystem(type.substring(0, 4));
 
 		diagram.setProjectId(projectId);
-		diagram.setBuildingId(buildingId);
-		diagram.setFloorId(floorId);
+		diagram.setSystemId(systemId);
+		diagram.setGroupCode(groupCode);
 
 		diagram = dataStrategy.saveDiagram(diagram);
 		buildDiagram(diagram, true);

+ 30 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/manage/TemplateManager.java

@@ -4,6 +4,8 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.IdUtil;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.adm.diagram.core.model.base.*;
+import com.persagy.adm.diagram.core.model.logic.DataFilter;
+import com.persagy.adm.diagram.core.model.logic.MatchFilter;
 import com.persagy.adm.diagram.entity.DiagramType;
 import com.persagy.adm.diagram.frame.EditRequest;
 import com.persagy.adm.diagram.core.DataStrategy;
@@ -19,6 +21,7 @@ import org.springframework.stereotype.Service;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 模板编辑的相关操作
@@ -198,6 +201,8 @@ public class TemplateManager {
 
 		con.setEquipmentTypes(CollUtil.isEmpty(propsData.getEquipTypes()) ? null : propsData.getEquipTypes());
 
+		con.setProps(propsData.getProps());
+
 		return saveTemplate(template);
 	}
 
@@ -315,6 +320,7 @@ public class TemplateManager {
 					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());
@@ -326,4 +332,28 @@ public class TemplateManager {
 		return saveTemplate(template);
 	}
 
+	/**
+	 * 修改设备数据过滤条件
+	 */
+	public DiagramTemplate modifyFilter(Map<String, Object> filter, String containerId, String templateId){
+		DiagramTemplate template = dataStrategy.getTemplate(templateId);
+		template.init();
+
+		Container con = template.getContainerById(containerId);
+		if(filter == null)
+			con.setDataFilter(null);
+		else {
+			int type = (Integer)filter.get("type");
+			if(type == DataFilter.TYPE_MATCH) {
+				MatchFilter mf = new MatchFilter();
+				mf.setObject((String) filter.get("object"));
+				mf.setOperation((String) filter.get("operation"));
+				mf.setValue((String) filter.get("value"));
+				con.setDataFilter(mf);
+			}
+		}
+
+		return saveTemplate(template);
+	}
+
 }

+ 4 - 5
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/service/BdtpDataService.java

@@ -87,7 +87,7 @@ public class BdtpDataService {
 		return rels;
 	}
 
-	public List<ObjectNode> queryObjectsByType(BdtpRequest req, List<String> equipmentTypes, String buildingId, String floorId){
+	public List<ObjectNode> queryObjectsByType(BdtpRequest req, List<String> equipmentTypes, String systemId){
 		QueryCriteria criteria = ServiceUtil.getQueryCriteria(objectMapper, "equipment");
 
 		ArrayNode types = criteria.getCriteria().putArray("classCode");
@@ -95,10 +95,9 @@ public class BdtpDataService {
 			types.add(code);
 		}
 
-		if(StrUtil.isNotBlank(buildingId))
-			criteria.getCriteria().put("buildingId", buildingId);
-		if(StrUtil.isNotBlank(floorId))
-			criteria.getCriteria().put("floorId", floorId);
+		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)