EDosBJMonitor.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. using EDosApiWrapper;
  2. using GDNXFD.Data;
  3. using GDNXFD.Data.Repositories;
  4. using log4net;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Threading;
  9. namespace GDNXFD.Alert.Interpreter
  10. {
  11. public class EDosBJMonitor
  12. {
  13. private ILog logger = LogManager.GetLogger("AppLog");
  14. private IDictionary<string, eDOSApi.HISTORY_VALUE> dictWtBJ;
  15. private IDictionary<string, eDOSApi.HISTORY_VALUE> dictIFixBJ;
  16. private string[] arrWtPoints;
  17. private string[] arrFixPoints;
  18. private string eDosServerIP;
  19. private ushort eDosServerPort;
  20. private EDosProxy eDos;
  21. public EDosBJMonitor()
  22. {
  23. eDosServerIP = GlobalVar.EDosServerIP;
  24. eDosServerPort = GlobalVar.EDosServerPort;
  25. eDos = new EDosProxy(eDosServerIP, eDosServerPort);
  26. }
  27. public void WindTurbineBJMonitor()
  28. {
  29. if (dictWtBJ == null)
  30. {
  31. dictWtBJ = CreateDictWindturbineBJ();
  32. arrWtPoints = dictWtBJ.Keys.ToArray();
  33. }
  34. if (dictWtBJ == null || dictWtBJ.Count == 0)
  35. return;
  36. string[] narr = arrWtPoints;// dictWtBJ.Keys.ToArray();
  37. int len = narr.Length;
  38. int currentTime = CommonMethod.ConvertDateTimeInt(DateTime.Now);
  39. eDOSApi.HISTORY_VALUE[] results = eDos.GetRTValueList(narr);
  40. for (int i = 0; i < results.Length; i++)
  41. {
  42. try
  43. {
  44. int valueTime = results[i].tTime;
  45. //有效时间外的值不处理,单位秒, 有效时间暂定义为1小时
  46. if (currentTime - valueTime > 60 * 60)
  47. continue;
  48. //与上次扫描读取的值比对,如果没有更新则不处理
  49. string key = narr[i];
  50. int preTime = dictWtBJ[key].tTime;
  51. if (valueTime <= preTime)
  52. continue;
  53. //触发报警
  54. int ednaValue = (int)results[i].dValue;
  55. if (ednaValue != 0)
  56. {
  57. double interval = 0;
  58. string wId = DataCache.Instance.DictWTP[key].WindturbineId;
  59. AlertSnap snap = AlertSnapRepository.GetWindturbineAlertSnap(wId, ednaValue);
  60. if (snap == null)
  61. {
  62. Warning warn = DataCache.Instance.DictWarning[ednaValue];
  63. WindTurbine wt = (WindTurbine)DataCache.Instance.DictWindturbine2[wId];
  64. snap = AlertSnapFactory.CreateAlertSnap(warn, wt);
  65. }
  66. if (snap.IsOpened)
  67. {
  68. TimeSpan ts = DateTime.Now.Subtract((DateTime)snap.LastUpdateTime);
  69. interval = ts.TotalHours;
  70. if (interval < 1)
  71. continue;
  72. }
  73. snap.IsOpened = true;
  74. snap.DataInfo = string.Format("EDNAVALUE={0}", ednaValue);
  75. snap.LastUpdatePerson = "system";
  76. snap.LastUpdateTime = DateTime.Now;
  77. if (snap.IsConfirmed && interval > 8)
  78. snap.IsConfirmed = false;
  79. AlertSnapRepository.SaveAlertSnap(snap);
  80. logger.InfoFormat("收到报警:{0}, EDnaValue={1}", snap.AlertText, snap.AlertValue);
  81. }
  82. //更新DictBJ
  83. dictWtBJ[key] = results[i];
  84. }
  85. catch (Exception ex)
  86. {
  87. logger.ErrorFormat("处理风机报警时异常:{0}", ex.Message);
  88. //System.Threading.Thread.Sleep(1000);
  89. }
  90. }
  91. }
  92. public void IFixBJMonitor()
  93. {
  94. if (dictIFixBJ == null)
  95. {
  96. dictIFixBJ = CreateDictIFixBJ2();
  97. arrFixPoints = dictIFixBJ.Keys.ToArray();
  98. }
  99. if (dictIFixBJ == null || dictIFixBJ.Count == 0)
  100. return;
  101. //string[] narr = arrFixPoints;// dictIFixBJ.Keys.ToArray();
  102. int len = arrFixPoints.Length;
  103. for(int j=0;j<len;j+=200)
  104. {
  105. string[] narr;
  106. if ((j + 200) > len)
  107. {
  108. narr = new string[len - j];
  109. Array.Copy(arrFixPoints, j, narr, 0, len - j);
  110. } else
  111. {
  112. narr = new string[200];
  113. Array.Copy(arrFixPoints, j, narr, 0, 200);
  114. }
  115. #region 从实时库中取点比较变化
  116. int currentTime = CommonMethod.ConvertDateTimeInt(DateTime.Now);
  117. eDOSApi.HISTORY_VALUE[] results = eDos.GetRTValueList(narr);
  118. for (int i = 0; i < results.Length; i++)
  119. {
  120. try
  121. {
  122. int valueTime = results[i].tTime;
  123. //有效时间外的值不处理,单位秒, 有效时间暂定义为1小时
  124. //if (currentTime - valueTime > 60 * 60)
  125. // continue;
  126. //与上次扫描读取的值比对,如果没有更新则不处理
  127. string key = narr[i];
  128. int preTime = dictIFixBJ[key].tTime;
  129. if (valueTime <= preTime)
  130. continue;
  131. //触发报警
  132. int ednaValue = (int)results[i].dValue;
  133. int preValue = (int)dictIFixBJ[key].dValue;
  134. if (ednaValue == preValue)
  135. continue;
  136. bool ifBJ = true;// ednaValue == 0 ? false : true;
  137. //if (ifBJ == false)
  138. // continue;
  139. AlertSnap snap = AlertSnapRepository.GetIFixAlertSnap(key);
  140. if (snap == null)
  141. {
  142. IFixBJTestingPointDI ftpd = DataCache.Instance.DictFixTP[key];
  143. snap = AlertSnapFactory.CreateAlertSnap(ftpd);
  144. }
  145. snap.AlertValue = ednaValue;
  146. //double interval = 0;
  147. //if (snap.IsOpened)
  148. //{
  149. // TimeSpan ts = DateTime.Now.Subtract((DateTime)snap.LastUpdateTime);
  150. // interval = ts.TotalHours;
  151. // //if (interval < 1)
  152. // // continue;
  153. //}
  154. if (ifBJ == true)
  155. {
  156. snap.IsOpened = true;
  157. snap.DataInfo = string.Format("{0}={1}", snap.TestingPointKey, ednaValue.ToString());
  158. snap.LastUpdatePerson = "system";
  159. snap.LastUpdateTime = DateTime.Now;
  160. if (snap.IsConfirmed)
  161. snap.IsConfirmed = false;
  162. }
  163. else
  164. {
  165. snap.IsOpened = false;
  166. snap.DataInfo = string.Format("{0}={1}", snap.TestingPointKey, ednaValue.ToString());
  167. snap.IsConfirmed = false;
  168. snap.LastClosePerson = "system";
  169. snap.LastCloseTime = DateTime.Now;
  170. }
  171. AlertSnapRepository.SaveAlertSnap(snap);
  172. if (ifBJ)
  173. logger.InfoFormat("收到报警:{0}, key={1}", snap.AlertText, snap.TestingPointKey);
  174. else
  175. {
  176. logger.InfoFormat("解除报警:{0}, key={1}", snap.AlertText, snap.TestingPointKey);
  177. }
  178. //}
  179. //更新DictBJ
  180. dictIFixBJ[key] = results[i];
  181. }
  182. catch (Exception ex)
  183. {
  184. logger.ErrorFormat("处理升压站报警时异常:{0}", ex.Message);
  185. //System.Threading.Thread.Sleep(1000);
  186. continue;
  187. }
  188. }
  189. #endregion
  190. }
  191. }
  192. private IDictionary<string, eDOSApi.HISTORY_VALUE> CreateDictWindturbineBJ()
  193. {
  194. IDictionary<string, eDOSApi.HISTORY_VALUE> dictBJ = new Dictionary<string, eDOSApi.HISTORY_VALUE>();
  195. IList<WindTurbineTestingPointAI> lstWTA = DataCache.Instance.WtBJPoints;
  196. foreach (WindTurbineTestingPointAI wai in lstWTA)
  197. {
  198. string pointA = CommonMethod.BuildPointId(wai.Id);
  199. if (string.IsNullOrWhiteSpace(pointA))
  200. continue;
  201. dictBJ.Add(pointA, new eDOSApi.HISTORY_VALUE());
  202. }
  203. return dictBJ;
  204. }
  205. private IDictionary<string, eDOSApi.HISTORY_VALUE> CreateDictIFixBJ()
  206. {
  207. IDictionary<string, eDOSApi.HISTORY_VALUE> dictBJ = new Dictionary<string, eDOSApi.HISTORY_VALUE>();
  208. IList<IFixBJTestingPointDI> lstWTA = DataCache.Instance.IFixBJPoints;
  209. foreach (IFixBJTestingPointDI wai in lstWTA)
  210. {
  211. //string pointA = CommonMethod.BuildPointId(wai.Id);
  212. //if (string.IsNullOrWhiteSpace(pointA))
  213. // continue;
  214. var hv = new eDOSApi.HISTORY_VALUE();
  215. AlertSnap snap = AlertSnapRepository.GetIFixAlertSnap(wai.PointKey);
  216. if (snap != null)
  217. {
  218. hv.dValue = snap.AlertValue;
  219. }
  220. dictBJ.Add(wai.PointKey, hv);
  221. }
  222. return dictBJ;
  223. }
  224. Dictionary<string, long> dictSnapValue = null;
  225. private Dictionary<string, long> CreateDictSnapValue()
  226. {
  227. dictSnapValue = new Dictionary<string, long>();
  228. var lst = AlertSnapRepository.GetTestingPointAlertSnap();
  229. if (lst != null && lst.Count > 0)
  230. {
  231. foreach(var snap in lst)
  232. {
  233. if (dictSnapValue.ContainsKey(snap.TestingPointKey) == false)
  234. dictSnapValue.Add(snap.TestingPointKey, snap.AlertValue);
  235. }
  236. }
  237. return dictSnapValue;
  238. }
  239. private IDictionary<string, eDOSApi.HISTORY_VALUE> CreateDictIFixBJ2()
  240. {
  241. if (dictSnapValue == null)
  242. dictSnapValue = CreateDictSnapValue();
  243. //var obj = AlertSnapRepository.GetAlertSnaps()
  244. IDictionary<string, eDOSApi.HISTORY_VALUE> dictBJ = new Dictionary<string, eDOSApi.HISTORY_VALUE>();
  245. IList<IFixBJTestingPointDI> lstWTA = DataCache.Instance.IFixBJPoints;
  246. foreach (IFixBJTestingPointDI wai in lstWTA)
  247. {
  248. //string pointA = CommonMethod.BuildPointId(wai.Id);
  249. //if (string.IsNullOrWhiteSpace(pointA))
  250. // continue;
  251. var hv = new eDOSApi.HISTORY_VALUE();
  252. if (dictSnapValue.ContainsKey(wai.PointKey))
  253. hv.dValue = dictSnapValue[wai.PointKey];
  254. //AlertSnap snap = AlertSnapRepository.GetIFixAlertSnap(wai.PointKey);
  255. //if (snap != null)
  256. //{
  257. // hv.dValue = snap.AlertValue;
  258. //}
  259. dictBJ.Add(wai.PointKey, hv);
  260. }
  261. return dictBJ;
  262. }
  263. }
  264. }