123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- /*-------------------------------------------------------------------------
- * 功能描述:EquipPowerRelationshipHandler
- * 作者:xulisong
- * 创建时间: 2018/12/10 15:57:21
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Newtonsoft.Json.Linq;
- using SAGA.MBI.RequestData;
- using SAGA.Models;
- using MBIEquipItem = SAGA.Models.EquipmentItem;
- namespace SAGA.GplotRelationComputerManage
- {
- public class EquipPowerRelationshipHandler : IElectricalRelationHandler
- {
- public string ElectricalRelationType
- {
- get { return "EquipPower"; }
- }
- /// <summary>
- /// 获取解析数据源
- /// </summary>
- /// <param name="context"></param>
- /// <returns></returns>
- public List<MBIItem> GetParseData(PowerComputerContext context)
- {
- List<MBIItem> items = new List<MBIItem>();
- var types = new[] { MBIBuiltInCategory.TDHS, MBIBuiltInCategory.TDLS, MBIBuiltInCategory.TDTF, MBIBuiltInCategory.TDLSDW };
- var rootTypes = new[] {MBIBuiltInCategory.Eq, MBIBuiltInCategory.Si};
- List<JObject> nodeDatas = CommonConvert.QueryObjectInfoByTypes(rootTypes);
- foreach (var jobject in nodeDatas)
- {
- //排除没有设置主控线的设备
- //if (((JObject)jobject["infos"]).Property(MBIBuiltInParameter.CTM_MainPower) == null)
- // continue;
- var item = MBIItemFactory.Create(jobject);
- if (item != null)
- {
- if (item is MBIEquipItem mbiItem)
- {
- var useType = mbiItem.Category.Remove(0, 2);
- if (useType != null && !types.Contains(useType))
- {
- if (((JObject)jobject["infos"]).Property(MBIBuiltInParameter.CTM_MainPower) == null)
- continue;
- }
- }
- if (item is RoomItem)
- {
- if (((JObject)jobject["infos"]).Property(MBIBuiltInParameter.CTM_MainPower) == null)
- continue;
- }
- items.Add(item);
- }
- }
- return items;
- }
- /// <summary>
- /// 获取显示数据
- /// </summary>
- /// <param name="context"></param>
- /// <returns></returns>
- public List<DataNode> GetViewData(PowerComputerContext context)
- {
- var items = GetParseData(context);
- var originNodes = items.Select(i => context.ItemConvert(i)).ToList();
- #region 构建树形结构
- var tdls = originNodes.Where(t => t.Type ==MBIBuiltInCategory.TDLS).ToList();
- var types = new[] { MBIBuiltInCategory.TDHS, MBIBuiltInCategory.TDLS, MBIBuiltInCategory.TDTF, MBIBuiltInCategory.TDLSDW };
- var eqs = originNodes.Where(t => !types.Contains(t.Type)).ToList();
- foreach (var dn in tdls)
- {
- DataNodeUtil.BuildNode(dn, eqs);
- }
- #endregion
- List<DataNode> useNodes = new List<DataNode>();
- List<DataNode> ignoreNodes = new List<DataNode>();
- foreach (var originNode in originNodes)
- {
- if(originNode.Type==MBIBuiltInCategory.TDLS&&originNode.Childrens.Any()&&originNode.Childrens.All(c=>c.Type==MBIBuiltInCategory.TDLS))
- {
- ignoreNodes.Add(originNode);
- continue;
- }
- useNodes.Add(originNode);
- }
- var allDataNodes = useNodes.Where(t => t.Childrens.Count == 0 || t.Childrens.Any(n => n.Type != MBIBuiltInCategory.TDLS))
- .ToList();
- var incomingCabinet = allDataNodes.Where(t => t.Childrens.Count != 0 &&(t.Parent == null||ignoreNodes.Contains(t.Parent))).ToList();
- var orphanNodes = allDataNodes.Where(t => t.Childrens.Count == 0 && t.Parent == null).ToList();
- //DrawDataServer.SaveAsFile<DataNode>(new DataNode("root") { Childrens = incomingCabinet }, "EquipPower");
- List<DataNode> nodes = new List<DataNode>();
- nodes.Add(new DataNode() { Childrens = incomingCabinet });
- nodes.Add(new DataNode() { Childrens = orphanNodes });
- return nodes;
- }
- /// <summary>
- /// 获取计算数据
- /// </summary>
- /// <param name="context"></param>
- /// <returns></returns>
- public List<DataNode> GetComputeData(PowerComputerContext context)
- {
- return GetViewData(context);
- }
- }
- }
|