StationStatus.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using IntelligentControlForsx.Common;
  2. using IntelligentControlForsx.Service;
  3. using log4net;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Runtime.Serialization;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using WisdomClient;
  11. using WisdomClient.data;
  12. namespace IntelligentControlForsx.Model
  13. {
  14. public class StationStatus
  15. {
  16. private ILog logger = LogManager.GetLogger("AppInfoLog");
  17. #region 基本属性定义
  18. private string stationId;
  19. public string StationId
  20. {
  21. get
  22. {
  23. return stationId;
  24. }
  25. }
  26. private DateTime lastUpdateTime;
  27. public DateTime LastUpdateTime
  28. {
  29. get
  30. {
  31. return lastUpdateTime;
  32. }
  33. }
  34. private Dictionary<string, WindturbineStatus> windturbineStatusDictionary;
  35. public Dictionary<string, WindturbineStatus> WindturbineStatusDictionary
  36. {
  37. get
  38. {
  39. return windturbineStatusDictionary;
  40. }
  41. }
  42. #endregion
  43. #region 构造方法
  44. public StationStatus(string stationId)
  45. {
  46. this.stationId = stationId;
  47. windturbineStatusDictionary = CreateWindturbineStatusDictionary(stationId);
  48. }
  49. private Dictionary<string, WindturbineStatus> CreateWindturbineStatusDictionary(string stId)
  50. {
  51. Dictionary<string, WindturbineStatus> result = new Dictionary<string, WindturbineStatus>();
  52. try
  53. {
  54. var wtList = CacheService.Instance.GetWindturbineListByStationId(stId);
  55. foreach(var wt in wtList)
  56. {
  57. var wtId = CommonMethod.GetShortWindturbineId(wt.ID);
  58. WindturbineStatus ws = new WindturbineStatus(wtId);
  59. if (result.ContainsKey(ws.WindturbineId) == false)
  60. {
  61. result.Add(ws.WindturbineId, ws);
  62. }
  63. }
  64. }catch (Exception ex)
  65. {
  66. logger.Error(ex);
  67. }
  68. return result;
  69. }
  70. #endregion
  71. #region 属性缓存定义
  72. private Dictionary<String, TsData> attributes = new Dictionary<string, TsData>();
  73. /// <summary>
  74. /// 以索引的方式访问场站属性状态,注意用统一编码做索引
  75. /// </summary>
  76. /// <param name="key"></param>
  77. /// <returns></returns>
  78. public TsData this[string key]
  79. {
  80. get { return attributes[key]; }
  81. set
  82. {
  83. if (attributes.ContainsKey(key))
  84. {
  85. attributes[key] = value;
  86. } else
  87. {
  88. attributes.Add(key, value);
  89. }
  90. }
  91. }
  92. #endregion
  93. #region 重写比较方法
  94. public override bool Equals(object obj)
  95. {
  96. StationStatus ws = obj as StationStatus;
  97. if (ws != null && ws.StationId == this.StationId)
  98. return true;
  99. return false;
  100. }
  101. public override int GetHashCode()
  102. {
  103. return base.GetHashCode();
  104. }
  105. #endregion
  106. #region 更新场站状态
  107. #endregion
  108. #region 更新风机状态
  109. public void RefreshBasicWindturbineStatus()
  110. {
  111. string[] deviceArray = MatrixFormService.GetDeviceIdArrayByStationId(stationId);
  112. if (deviceArray == null || deviceArray.Length < 1)
  113. return;
  114. var dict = CacheService.Instance.MatrixPointMap;
  115. if (dict == null)
  116. return;
  117. var pmms = dict.Values.Where(q => q.ThingType == PointType.Windturbine && deviceArray.Contains(q.ThingId)).ToArray();
  118. var points = pmms.Select(q => q.PointId).ToArray();
  119. Dictionary<string, TsData> dictResult = RestfulClient.findLatestByTagNames(points);
  120. foreach (var tmp in dictResult)
  121. {
  122. for (int i = 0; i < points.Length; i++)
  123. {
  124. string wtId = pmms[i].ThingId;
  125. WindturbineStatus ws = windturbineStatusDictionary[wtId];
  126. if (ws == null)
  127. continue;
  128. ws[pmms[i].UniformCode] = dictResult[points[i]];
  129. double value = dictResult[points[i]].doubleValue.Value;
  130. pmms[i].Value = value;
  131. }
  132. }
  133. }
  134. #endregion
  135. }
  136. }