| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- /*-------------------------------------------------------------------------
- * 功能描述:ComputerRelationFromPhysicalWorld
- * 作者:李勇
- * 创建时间: 2018/11/1 9:43:35
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using Newtonsoft.Json.Linq;
- using SAGA.MBI.DataArrange;
- using SAGA.MBI.RequestData;
- using SAGA.Models;
- namespace SAGA.GplotRelationComputerManage
- {
- public abstract class ComputerRelationFromPhysicalWorld
- {
-
- private Dictionary<string, string> floorNameAndId;
- /// <summary>
- /// 计算服务端配电
- /// </summary>
- public List<DataNode> ComputerFromServer()
- {
- var str = new[] { "TDHS", "TDLS", "TDTF", "TDLSDW" };
- List<JObject> datas = CommonConvert.QueryObjectInfoByTypes(str);
- var result = new List<DataNode>();
- floorNameAndId = DalProjectTree.GetFloorNameAndId();
- var allDataNodes = ConvertToDataNode(datas);
- DealServerDatas(allDataNodes);
- //独立树形:有子节点,父节点为空
- var incomingCabinet = allDataNodes.Where(t => t.Childrens.Count != 0 && t.Parent == null).ToList();
- //孤立节点:无父无子
- var orphanNodes = allDataNodes.Where(t => t.Childrens.Count == 0 && t.Parent == null).ToList();
- DrawDataServer.SaveAsFile<DataNode>(new DataNode("root") { Childrens = incomingCabinet }, "LUDistribution");
- result.Add(new DataNode() { Childrens = incomingCabinet });
- result.Add(new DataNode() { Childrens = orphanNodes });
- return result;
- }
- private List<DataNode> DealDatas(List<DataNode> familyInstances, out List<DataNode> incomingCabinet)
- {
- var allDataNodes = familyInstances;
- //无信息节点的孤儿节点
- var orphanNodes = allDataNodes.Where(t => t.Sno == "" || t.Type == "" || t.EName == "").ToList();
- //正常数据
- var dataNodes = allDataNodes.Where(t => t.Sno != "" && t.Type != "" && t.EName != "").ToList();
- //找出所有出线柜(outgoingCubicle)
- //找出所有进线柜
- incomingCabinet = dataNodes.Where(t => t.Type == "进线柜" || t.Type == "母联柜").ToList();
- //总数据里面移除所有进线柜,并移除进线柜中非根节点的进线柜(进线柜的进线号为变压器)
- for (var i = 0; i < incomingCabinet.Count; i++)
- {
- var node = incomingCabinet[i];
- if ((dataNodes.Any(t => t.Sno == node.InLineNo && t.Type == "低压变压器") || node.Type == "母联柜" ||
- node.InLineNo == "") && node.EName != "")
- {
- dataNodes.Remove(node);
- }
- else
- {
- incomingCabinet.Remove(node);
- i--;
- }
- }
- //incomingCabinet.ForEach(d => );
- //List<DataNode> incomingCabinetNode =
- incomingCabinet.ForEach(d =>
- {
- if (d.Type != "母联柜")
- {
- GetRelationNode(d, dataNodes);
- }
- RemoveNode(d, dataNodes); //剩余的节点中去除已成数列的节点
- });
- //剩余节点中找到进线号不存在或者为空的节点,作为孤立点的子节点
- var oroot = dataNodes.Where(t => t.InLineNo == "" || dataNodes.All(o => o.Sno != t.InLineNo)).ToList();
- oroot.ForEach(d => { GetRelationNode(d, dataNodes); });
- orphanNodes.AddRange(oroot);
- return orphanNodes;
- }
- private void DealServerDatas(List<DataNode> familyInstances)
- {
- for (int i = 0; i < familyInstances.Count; i++)
- {
- var dn = familyInstances[i];
- GetRelationNodes(dn, familyInstances);
- }
- }
- public List<DataNode> ConvertToDataNode(List<JObject> datas)
- {
- var allDataNodes = datas.Select(f =>
- {
- var node = new DataNode(GetValue(f, "EquipLocalName"))//设备本地名称,
- {
- EId = GetValue(f, "EquipID"),
- Sno = GetValue(f, "EquipLocalID"),//设备本地编码
- InLineNo = GetValue(f, "ctm-MainPower"), //进线号,主电
- InLineNo1 = GetValue(f, "ctm-StandbyPower"), //进线号,主电
- FloorName = GetFloorNameByBimId(GetValue(f, "BIMID")), //+ //+ f.GetParameterString("所属柜号"),
- Infos = f,
- Type = (f["category"] + "").Remove(0, 2)//设备类型编码
- };
- return node;
- });
- return allDataNodes.ToList();
- }
- string GetFloorNameByBimId(string bimId)
- {
- if (string.IsNullOrEmpty(bimId)) return "";
- var id = bimId.Split(':')[0];
- if (floorNameAndId.ContainsKey(id))
- return floorNameAndId[id];
- return id;
- }
- public string GetValue(JObject equip, string propertyName)
- {
- string result = "";
- if (equip != null)
- {
- result = equip["infos"][propertyName] + "";
- //本地名称为空显示设备名称
- if (propertyName == "EquipLocalName" && result == "")
- {
- result = equip["infos"]["EquipName"] + "";
- }
- }
- return result;
- }
- void GetRelationNode(DataNode dn, List<DataNode> datas)
- {
- var nodes = datas.Where(t => t.InLineNo == dn.Sno).ToList();
- if (nodes.Count > 0)
- {
- dn.Childrens.AddRange(nodes);
- datas.Remove(dn);
- foreach (var dataNode in nodes)
- {
- GetRelationNode(dataNode, datas);
- }
- }
- }
- void GetRelationNodes(DataNode dn, List<DataNode> datas)
- {
- var nodes = datas.Where(t => t.InLineNo == dn.Sno && dn.Sno != "").ToList();
- if (nodes.Count > 0 && dn.Childrens.Count == 0)
- {
- dn.Childrens.AddRange(nodes);
- foreach (var dataNode in nodes)
- {
- dataNode.Parent = dn;
- if (dataNode.Childrens.Count > 0) continue;//已查找过子节点
- GetRelationNodes(dataNode, datas);
- }
- }
- }
- void RemoveNode(DataNode dn, List<DataNode> datas)
- {
- datas.Remove(dn);
- if (dn.Childrens.Count > 0)
- {
- foreach (var dataNode in dn.Childrens)
- {
- RemoveNode(dataNode, datas);
- }
- }
- }
- }
- }
|