InfoManager.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using NEIntelligentControl2.Models.Alarm;
  2. using NEIntelligentControl2.Models.Datas;
  3. using NEIntelligentControl2.Models.Messages;
  4. using NEIntelligentControl2.Models.PV;
  5. using NEIntelligentControl2.Models.Windturbine;
  6. using NEIntelligentControl2.Models.WinForms;
  7. using NEIntelligentControl2.Service.WebSocket;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Configuration;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Xml;
  15. namespace NEIntelligentControl2.Service.Windturbine
  16. {
  17. /// <summary>
  18. /// 光伏和风机详情服务
  19. /// </summary>
  20. public class InfoManager
  21. {
  22. private WEBHelper _WEBHelper;
  23. private Dictionary<string, PVDetails> _PVDetails;
  24. private List<SUN2000Info> _SUN2000Info;
  25. private AlarmTypeInfo _AlarmTypeInfo;
  26. private string _Url;
  27. private string _DataUrl;
  28. private Dictionary<string, IList<UniformCodeInfo>> _UniformCodesPairs = new Dictionary<string, IList<UniformCodeInfo>>();// 节点缓存
  29. /// <summary>
  30. /// 参数对比信息
  31. /// </summary>
  32. private Dictionary<string, Dictionary<string, List<ParameterInfo>>> _ParameterInfo = new Dictionary<string, Dictionary<string, List<ParameterInfo>>>();
  33. public InfoManager(WEBHelper web, UrlManager um)
  34. {
  35. _WEBHelper = web;
  36. _Url = um.ServicePath;
  37. _DataUrl = um.DataServicePath;
  38. }
  39. public AlarmTypeInfo GetAlarmTypeInfo()
  40. {
  41. if (_AlarmTypeInfo == null)
  42. {
  43. try
  44. {
  45. string text = System.IO.File.ReadAllText("AlarmInfo.json");
  46. _AlarmTypeInfo = _WEBHelper.Deserialize<AlarmTypeInfo>(text);
  47. }
  48. catch (Exception e) { Console.WriteLine(e.Message); }
  49. }
  50. return _AlarmTypeInfo;
  51. }
  52. public Dictionary<string, PVDetails> GetPVDetails()
  53. {
  54. try
  55. {
  56. if (_PVDetails == null)
  57. {
  58. _PVDetails = _WEBHelper.HttpGetJSON<Dictionary<string, PVDetails>>($"{_Url}/api/station/pv_info");
  59. }
  60. }
  61. catch (Exception ex) { Console.WriteLine(ex.Message); }
  62. return _PVDetails;
  63. }
  64. public List<SUN2000Info> GetSUN2000Infos()
  65. {
  66. if (_SUN2000Info == null)
  67. {
  68. try
  69. {
  70. string text = System.IO.File.ReadAllText("SUN2000Info.json");
  71. _SUN2000Info = _WEBHelper.Deserialize<List<SUN2000Info>>(text);
  72. }
  73. catch (Exception ex)
  74. {
  75. Console.WriteLine(ex.ToString());
  76. }
  77. }
  78. return _SUN2000Info;
  79. }
  80. internal IList<UniformCodeInfo> GetUniformCode(string stationId, string modelId)
  81. {
  82. var key = $"{stationId}{modelId}";
  83. if (_UniformCodesPairs.ContainsKey(key))
  84. {
  85. return _UniformCodesPairs[key];
  86. }
  87. IList<UniformCodeInfo> list = new List<UniformCodeInfo>();
  88. string path = Environment.CurrentDirectory;
  89. string filePath = path + "\\UniformCode.xml";
  90. XmlDocument xdoc = new XmlDocument();
  91. xdoc.Load(filePath); //加载xml文档
  92. XmlNode root = xdoc.DocumentElement;
  93. // 找到对应station节点下的对应model节点下的part节点
  94. XmlNodeList partNodelist = root.SelectNodes("/root/station[@name='" + stationId + "']/model[@name='" + modelId + "']/part");
  95. foreach (XmlNode part in partNodelist)
  96. {
  97. foreach (XmlNode param in part.SelectNodes("param"))
  98. {
  99. try
  100. {
  101. UniformCodeInfo data = new UniformCodeInfo();
  102. data.PartIndex = part.Attributes["index"].Value;
  103. data.PartName = part.Attributes["text"].Value;
  104. data.Name = param.Attributes["name"].Value;
  105. data.UniformCode = param.Attributes["value"].Value;
  106. data.Unit = param.Attributes["unit"].Value;
  107. int tindex = 0;
  108. data.Index = int.TryParse(param.Attributes["num"].Value, out tindex) ? tindex : 0;
  109. data.PlcName = param.Attributes["plcName"] != null ? param.Attributes["plcName"].Value : "";
  110. data.WarningNum = param.Attributes["warningNum"] != null ? param.Attributes["warningNum"].Value : "";
  111. if (param.Attributes["ratio"] != null)
  112. {
  113. double.TryParse(param.Attributes["ratio"].Value, out double d);
  114. data.Ratio = d;
  115. }
  116. list.Add(data);
  117. }
  118. catch (Exception ex)
  119. {
  120. Console.WriteLine("xml配置读取错误:" + ex.StackTrace);
  121. }
  122. }
  123. }
  124. _UniformCodesPairs.Add(key, list);
  125. return list;
  126. }
  127. /// <summary>
  128. /// 获取参数对比信息
  129. /// </summary>
  130. /// <param name="stationId">场站ID</param>
  131. /// <param name="modleId">机型ID</param>
  132. /// <returns></returns>
  133. public List<ParameterInfo> GetParameterInfos(string stationId, string modleId)
  134. {
  135. if (_ParameterInfo.Count <= 0)
  136. {
  137. try
  138. {
  139. string text = System.IO.File.ReadAllText("ComparisonInfo.json");
  140. _ParameterInfo = _WEBHelper.Deserialize<Dictionary<string, Dictionary<string, List<ParameterInfo>>>>(text);
  141. }
  142. catch (Exception ex)
  143. {
  144. Console.WriteLine(ex.ToString());
  145. }
  146. }
  147. if (_ParameterInfo.Count <= 0 || !_ParameterInfo.ContainsKey(stationId) || !_ParameterInfo[stationId].ContainsKey(modleId)) return new List<ParameterInfo>();
  148. return _ParameterInfo[stationId][modleId];
  149. }
  150. public Dictionary<string ,TsData> GetPointDatas(string windturbineId, string[] ucs)
  151. {
  152. Dictionary<string, TsData> dic = _WEBHelper.HttpGetJSON<Dictionary<string, TsData>>($"{_DataUrl}/ts/latest?thingType=windturbine&thingId={windturbineId}&uniformCodes={string.Join(",", ucs)}");
  153. return dic;
  154. }
  155. public Dictionary<string, TsData> GetPointDatasByTags(string[] tags)
  156. {
  157. Dictionary<string, TsData> dic = _WEBHelper.HttpGetJSON<Dictionary<string, TsData>>($"{_DataUrl}/ts/latest?keys={string.Join(",", tags)}");
  158. return dic;
  159. }
  160. public List<PointInfo> GetAIPoints(string windId)
  161. {
  162. return _WEBHelper.HttpGetJSON<List<PointInfo>>($"{_Url}/windturbinetestingpoint/ai?windturbineid={windId}");
  163. }
  164. public List<PointInfo> GetDIPoints(string windId)
  165. {
  166. return _WEBHelper.HttpGetJSON<List<PointInfo>>($"{_Url}/windturbinetestingpoint/Di?windturbineid={windId}");
  167. }
  168. }
  169. }