EquipPowerRelationshipHandler.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:EquipPowerRelationshipHandler
  3. * 作者:xulisong
  4. * 创建时间: 2018/12/10 15:57:21
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Newtonsoft.Json.Linq;
  13. using SAGA.MBI.RequestData;
  14. using SAGA.Models;
  15. using MBIEquipItem = SAGA.Models.EquipmentItem;
  16. namespace SAGA.GplotRelationComputerManage
  17. {
  18. public class EquipPowerRelationshipHandler : IElectricalRelationHandler
  19. {
  20. public string ElectricalRelationType
  21. {
  22. get { return "EquipPower"; }
  23. }
  24. /// <summary>
  25. /// 获取解析数据源
  26. /// </summary>
  27. /// <param name="context"></param>
  28. /// <returns></returns>
  29. public List<MBIItem> GetParseData(PowerComputerContext context)
  30. {
  31. List<MBIItem> items = new List<MBIItem>();
  32. var types = new[] { MBIBuiltInCategory.TDHS, MBIBuiltInCategory.TDLS, MBIBuiltInCategory.TDTF, MBIBuiltInCategory.TDLSDW };
  33. var rootTypes = new[] {MBIBuiltInCategory.Eq, MBIBuiltInCategory.Si};
  34. List<JObject> nodeDatas = CommonConvert.QueryObjectInfoByTypes(rootTypes);
  35. foreach (var jobject in nodeDatas)
  36. {
  37. //排除没有设置主控线的设备
  38. //if (((JObject)jobject["infos"]).Property(MBIBuiltInParameter.CTM_MainPower) == null)
  39. // continue;
  40. var item = MBIItemFactory.Create(jobject);
  41. if (item != null)
  42. {
  43. if (item is MBIEquipItem mbiItem)
  44. {
  45. var useType = mbiItem.Category.Remove(0, 2);
  46. if (useType != null && !types.Contains(useType))
  47. {
  48. if (((JObject)jobject["infos"]).Property(MBIBuiltInParameter.CTM_MainPower) == null)
  49. continue;
  50. }
  51. }
  52. if (item is RoomItem)
  53. {
  54. if (((JObject)jobject["infos"]).Property(MBIBuiltInParameter.CTM_MainPower) == null)
  55. continue;
  56. }
  57. items.Add(item);
  58. }
  59. }
  60. return items;
  61. }
  62. /// <summary>
  63. /// 获取显示数据
  64. /// </summary>
  65. /// <param name="context"></param>
  66. /// <returns></returns>
  67. public List<DataNode> GetViewData(PowerComputerContext context)
  68. {
  69. var items = GetParseData(context);
  70. var originNodes = items.Select(i => context.ItemConvert(i)).ToList();
  71. #region 构建树形结构
  72. var tdls = originNodes.Where(t => t.Type ==MBIBuiltInCategory.TDLS).ToList();
  73. var types = new[] { MBIBuiltInCategory.TDHS, MBIBuiltInCategory.TDLS, MBIBuiltInCategory.TDTF, MBIBuiltInCategory.TDLSDW };
  74. var eqs = originNodes.Where(t => !types.Contains(t.Type)).ToList();
  75. foreach (var dn in tdls)
  76. {
  77. DataNodeUtil.BuildNode(dn, eqs);
  78. }
  79. #endregion
  80. List<DataNode> useNodes = new List<DataNode>();
  81. List<DataNode> ignoreNodes = new List<DataNode>();
  82. foreach (var originNode in originNodes)
  83. {
  84. if(originNode.Type==MBIBuiltInCategory.TDLS&&originNode.Childrens.Any()&&originNode.Childrens.All(c=>c.Type==MBIBuiltInCategory.TDLS))
  85. {
  86. ignoreNodes.Add(originNode);
  87. continue;
  88. }
  89. useNodes.Add(originNode);
  90. }
  91. var allDataNodes = useNodes.Where(t => t.Childrens.Count == 0 || t.Childrens.Any(n => n.Type != MBIBuiltInCategory.TDLS))
  92. .ToList();
  93. var incomingCabinet = allDataNodes.Where(t => t.Childrens.Count != 0 &&(t.Parent == null||ignoreNodes.Contains(t.Parent))).ToList();
  94. var orphanNodes = allDataNodes.Where(t => t.Childrens.Count == 0 && t.Parent == null).ToList();
  95. //DrawDataServer.SaveAsFile<DataNode>(new DataNode("root") { Childrens = incomingCabinet }, "EquipPower");
  96. List<DataNode> nodes = new List<DataNode>();
  97. nodes.Add(new DataNode() { Childrens = incomingCabinet });
  98. nodes.Add(new DataNode() { Childrens = orphanNodes });
  99. return nodes;
  100. }
  101. /// <summary>
  102. /// 获取计算数据
  103. /// </summary>
  104. /// <param name="context"></param>
  105. /// <returns></returns>
  106. public List<DataNode> GetComputeData(PowerComputerContext context)
  107. {
  108. return GetViewData(context);
  109. }
  110. }
  111. }