Sfoglia il codice sorgente

按楼层统计分组

zhaoyk 2 anni fa
parent
commit
cd6d292264

+ 8 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/build/CalcContext.java

@@ -125,6 +125,14 @@ public class CalcContext {
 		return null;
 	}
 
+	public ObjectNode getFloor(){
+		return currentGroup != null ? currentGroup.getFloor() : null;
+	}
+
+	public ObjectNode getBuilding(){
+		return currentGroup != null ? currentGroup.getBuilding() : null;
+	}
+
 	public DataStrategy getDataStrategy() {
 		return dataStrategy;
 	}

+ 35 - 0
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/build/CalcGroup.java

@@ -1,6 +1,7 @@
 package com.persagy.adm.diagram.core.build;
 
 import cn.hutool.core.collection.CollUtil;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.adm.diagram.core.model.base.IEquipHolder;
 
 import java.util.*;
@@ -19,6 +20,10 @@ public class CalcGroup {
 
 	private IEquipHolder dynSrcComp;
 
+	private ObjectNode building;
+
+	private ObjectNode floor;
+
 	public CalcGroup() {
 
 	}
@@ -32,6 +37,36 @@ public class CalcGroup {
 		return dynSrcComp;
 	}
 
+	public ObjectNode getBuilding() {
+		CalcGroup g = this;
+		while (g != null){
+			if(g.building != null) {
+				return g.building;
+			}
+			g = g.parent;
+		}
+		return null;
+	}
+
+	public void setBuilding(ObjectNode building) {
+		this.building = building;
+	}
+
+	public ObjectNode getFloor() {
+		CalcGroup g = this;
+		while (g != null){
+			if(g.floor != null) {
+				return g.floor;
+			}
+			g = g.parent;
+		}
+		return null;
+	}
+
+	public void setFloor(ObjectNode floor) {
+		this.floor = floor;
+	}
+
 	public void setCurrentIdx(int currentIdx) {
 		this.currentIdx = currentIdx;
 	}

+ 93 - 11
adm-business/adm-diagram/src/main/java/com/persagy/adm/diagram/core/build/DiagramBuilder.java

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.persagy.adm.diagram.core.ContentParser;
 import com.persagy.adm.diagram.core.model.*;
@@ -97,12 +98,13 @@ public class DiagramBuilder {
 			int pos = container.getParent().getChildren().indexOf(container);
 
 			boolean isCompSrc = dynGroup.isCompSrc();
+			boolean isBuildingSrc = DynGroup.SRC_BUILDING.equals(dynGroup.getDynSource());
+			boolean isFloorSrc = DynGroup.SRC_FLOOR.equals(dynGroup.getDynSource());
 			if(isCompSrc) {
 				IEquipHolder srcComp = context.getComp(dynGroup.getDynSource(), dynGroup.getDynSourceType());
 				dynData = findMatchedData(srcComp);
 			} else {
-				//TODO 楼层,建筑等分组方式
-				dynData = new ArrayList<>();
+				dynData = getGroupList(dynGroup);
 			}
 
 			if (CollUtil.isEmpty(dynData)) {
@@ -124,6 +126,10 @@ public class DiagramBuilder {
 
 					if(isCompSrc) {
 						group.setDynSrcComp(context.getComp(dynGroup.getDynSource(), dynGroup.getDynSourceType()), dynData.get(i));
+					} else if(isFloorSrc) {
+						group.setFloor(dynData.get(i));
+					} else if(isBuildingSrc) {
+						group.setBuilding(dynData.get(i));
 					}
 
 					loadEquipsData(subEquipBoxes, subDynCons, relMainPipes);
@@ -151,6 +157,10 @@ public class DiagramBuilder {
 
 					if(isCompSrc) {
 						group.setDynSrcComp(context.getComp(dynGroup.getDynSource(), dynGroup.getDynSourceType()), dynData.get(i));
+					} else if(isFloorSrc) {
+						group.setFloor(dynData.get(i));
+					} else if(isBuildingSrc) {
+						group.setBuilding(dynData.get(i));
 					}
 
 					loadEquipsData(newSubEquipBoxes, newSubDynCons, newMps);
@@ -165,6 +175,45 @@ public class DiagramBuilder {
 		}
 	}
 
+	private List<ObjectNode> getGroupList(DynGroup dynGroup){
+		if(DynGroup.SRC_TYPE_GROUP.equals(dynGroup.getDynSourceType())) {
+			//按设备统计
+			return getGroupList(dynGroup.getDynSource());
+		} else if(DynGroup.SRC_TYPE_DATA.equals(dynGroup.getDynSourceType())) {
+			//TODO 数据查询
+
+		}
+		return null;
+	}
+
+	private List<ObjectNode> getGroupList(String group){
+		ObjectMapper mapper = new ObjectMapper();
+		HashMap<String, ObjectNode> map = new HashMap<>();
+		//TODO 楼层和建筑对象
+		for(ObjectNode obj : context.getOptionalObjs()) {
+			if(DynGroup.SRC_FLOOR.equals(group)) {
+				String key = getFloorId(obj);
+				if(StrUtil.isNotBlank(key) && !map.containsKey(key)){
+					map.put(key, mapper.createObjectNode().put("id", key));
+				}
+			} else if(DynGroup.SRC_BUILDING.equals(group)) {
+				String key = getBuildingId(obj);
+				if(StrUtil.isNotBlank(key) && !map.containsKey(key)){
+					map.put(key, mapper.createObjectNode().put("id", key));
+				}
+			}
+		}
+
+		List<ObjectNode> list = new ArrayList<>(map.values());
+		sortBdFlList(list);
+
+		return list;
+	}
+
+	private void sortBdFlList(List<ObjectNode> list){
+
+	}
+
 	private void setGroupContainer(Container con, CalcGroup currentGroup) {
 		for (Container item : con.listContainers()) {
 			currentGroup.addComp(getSrcId(item.getId()), item);
@@ -300,7 +349,7 @@ public class DiagramBuilder {
 			if (mainPipe.isBindEquipment()) {
 				List<ObjectNode> matchedData = mainPipe.getMatchedData();
 				if(CollUtil.isNotEmpty(matchedData)) {
-					orderDataList(matchedData);
+					sortDataList(matchedData);
 
 					ObjectNode obj = (ObjectNode)mainPipe.getMatchedData().get(0);
 					mainPipe.setDataObject(obj);
@@ -314,7 +363,7 @@ public class DiagramBuilder {
 			if(con.isEquipmentBox()) {
 				List<ObjectNode> matchedData = con.getMatchedData();
 				if(CollUtil.isNotEmpty(matchedData)) {
-					orderDataList(matchedData);
+					sortDataList(matchedData);
 
 					for(ObjectNode obj : matchedData) {
 						if(con.getEquipPack() != null) {
@@ -328,7 +377,7 @@ public class DiagramBuilder {
 		}
 	}
 
-	private void orderDataList(List<ObjectNode> dataList){
+	private void sortDataList(List<ObjectNode> dataList){
 		//TODO 对设备数据进行排序操作
 	}
 
@@ -420,15 +469,35 @@ public class DiagramBuilder {
 	private boolean match(ObjectNode obj, IEquipHolder equipHolder) {
 		String classCode = DiagramBuilder.getClassCode(obj);
 		if(equipHolder.getEquipmentTypes() != null && equipHolder.getEquipmentTypes().contains(classCode)) {
-			DataFilter filter = equipHolder.getDataFilter();
-			if(filter != null) {
-				return filter.filter(obj, context);
+			if(checkBdFl(obj)){
+				DataFilter filter = equipHolder.getDataFilter();
+				if(filter != null) {
+					return filter.filter(obj, context);
+				}
+				return true;
 			}
-			return true;
 		}
 		return false;
 	}
 
+	private boolean checkBdFl(ObjectNode obj){
+		ObjectNode bd = context.getBuilding();
+		ObjectNode fl = context.getFloor();
+		if(bd != null){
+			String bdId = getBuildingId(obj);
+			if(!bd.get("id").asText().equals(bdId)){
+				return false;
+			}
+		}
+		if(fl != null){
+			String flId = getFloorId(obj);
+			if(!fl.get("id").asText().equals(flId)){
+				return false;
+			}
+		}
+		return true;
+	}
+
 	/**
 	 * 对节点进行处理,并返回图例锚点会使用到的关系类型
 	 */
@@ -631,10 +700,23 @@ public class DiagramBuilder {
 	}
 
 	public static String getClassCode(ObjectNode obj){
-		if(obj != null && obj.get("classCode") != null) {
-			return obj.get("classCode").asText();
+		return getInfo(obj, "classCode");
+	}
+
+	private static String getInfo(ObjectNode obj, String infoCode){
+		if(obj != null && obj.get(infoCode) != null) {
+			return obj.get(infoCode).asText();
 		}
 		return null;
 	}
 
+	private static String getBuildingId(ObjectNode obj){
+		return getInfo(obj, "buildingId");
+	}
+
+	private static String getFloorId(ObjectNode obj){
+		return getInfo(obj, "floorId");
+	}
+
+
 }

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

@@ -10,6 +10,14 @@ import com.persagy.adm.diagram.core.model.template.MainPipe;
  */
 public class DynGroup {
 
+	public static final String SRC_TYPE_GROUP = "group";
+
+	public static final String SRC_TYPE_DATA = "data";
+
+	public static final String SRC_BUILDING = "building";
+
+	public static final String SRC_FLOOR = "floor";
+
 	/**
 	 * 动态源(floor | building | mainPipe.id | container.id)
 	 */