ElectricalCalculator.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. namespace GDNXFD.Alert.Interpreter
  9. {
  10. public class ElectricalCalculator
  11. {
  12. private ILog logger = LogManager.GetLogger("AppLog");
  13. private WindPowerStation station;
  14. private EDosProxy eDos;
  15. public ElectricalCalculator(WindPowerStation wt)
  16. {
  17. station = wt;
  18. eDos = EDosProxyFactory.Instance.Proxy;
  19. }
  20. /// <summary>
  21. /// 计算电气所有关联规则的值,并保存
  22. /// </summary>
  23. /// <returns>电气报警测点的值,关联到AlertRule表</returns>
  24. public void Calculate()
  25. {
  26. IList<AlertRuleInterpreter> interpreters = InterpreterFactory.Instance.GetInterpretersByElectricalId(station.Id);
  27. if (interpreters != null && interpreters.Count > 0)
  28. {
  29. logger.Debug("适用规则数:" + interpreters.Count);
  30. foreach(AlertRuleInterpreter ari in interpreters)
  31. {
  32. logger.Debug("处理报警规则:" + ari.AlertRule.Expression);
  33. ari.DataInfo = "";
  34. bool ruleResult = ari.Interpret(station.Id, AlertObjectType.Electrical);
  35. AlertSnap snap = AlertSnapRepository.GetAlertSnap(AlertObjectType.Electrical, station.Id, ari.AlertRule.EdnaValue);
  36. if (ruleResult)
  37. {
  38. double interval = 0;
  39. if (snap == null)
  40. {
  41. snap = AlertSnapFactory.CreateAlertSnap(ari.AlertRule, station);
  42. }
  43. else if (snap.IsOpened)
  44. {
  45. TimeSpan ts = DateTime.Now.Subtract((DateTime)snap.LastUpdateTime);
  46. interval = ts.TotalHours;
  47. }
  48. if (snap.IsOpened == false || interval > 1)
  49. {
  50. snap.IsOpened = true;
  51. snap.DataInfo = CommonMethod.StringCopy(ari.DataInfo, 2000);
  52. snap.LastUpdatePerson = "system";
  53. snap.LastUpdateTime = DateTime.Now;
  54. if (snap.IsConfirmed == true && interval > 8)
  55. snap.IsConfirmed = false;
  56. AlertSnapRepository.SaveAlertSnap(snap);
  57. //写实时库
  58. string key = GetWindPowerStationAlertPoint(station.Id);
  59. logger.InfoFormat("写报警测点,key={0}, value={1}", key, ari.AlertRule.EdnaValue);
  60. eDos.SendSinglePoint(key, ari.AlertRule.EdnaValue);
  61. logger.InfoFormat("触发报警!电气:{0},{1},规则:{2},{3}",
  62. station.Id, station.Name, ari.AlertRule.Id, ari.AlertRule.Expression);
  63. }
  64. }
  65. else
  66. {
  67. //解除报警
  68. if (snap != null && snap.IsOpened)
  69. {
  70. snap.IsOpened = false;
  71. snap.DataInfo = CommonMethod.StringCopy(ari.DataInfo, 2000);
  72. snap.IsConfirmed = false;
  73. snap.LastUpdatePerson = "system";
  74. snap.LastCloseTime = DateTime.Now;
  75. AlertSnapRepository.SaveAlertSnap(snap);
  76. logger.InfoFormat("解除报警!电气:{0},{1},规则:{2},{3}",
  77. station.Id, station.Name, ari.AlertRule.Id, ari.AlertRule.Expression);
  78. }
  79. }
  80. }
  81. }
  82. }
  83. private string GetWindPowerStationAlertPoint(string id)
  84. {
  85. string ret = WindPowerStationRepository.GetWindPowerStationPointId(id, "FJBJ3");
  86. return BuildPointId(ret);
  87. }
  88. private string BuildPointId(string PointID)
  89. {
  90. string[] ids = PointID.Split('.');
  91. if (ids != null && ids.Length == 3)
  92. {
  93. PointID = ids[1] + "_" + ids[2];
  94. }
  95. return PointID;
  96. }
  97. }
  98. }