AlertSnapFactory.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace GDNXFD.Data
  7. {
  8. public class AlertSnapFactory
  9. {
  10. public static AlertSnap CreateAlertSnap(AlertRule ar)
  11. {
  12. AlertSnap snap = new AlertSnap();
  13. snap.Id = 0;// Guid.NewGuid().ToString();
  14. snap.AlertText = ar.Name.Trim();
  15. snap.AlertValue = ar.EdnaValue;
  16. snap.Category1 = "custom";
  17. snap.Category2 = ar.Category;
  18. snap.Rank = ar.Rank;
  19. snap.LastUpdatePerson = "system";
  20. snap.LastUpdateTime = DateTime.Now;
  21. return snap;
  22. }
  23. public static AlertSnap CreateAlertSnap(AlertRule ar, WindPowerStation wps)
  24. {
  25. AlertSnap snap = CreateAlertSnap(ar);
  26. snap.StationId = wps.Id;
  27. snap.StationName = wps.Name;
  28. return snap;
  29. }
  30. public static AlertSnap CreateAlertSnap(AlertRule ar, Project obj)
  31. {
  32. AlertSnap snap = CreateAlertSnap(ar);
  33. snap.ProjectId = obj.Id;
  34. snap.ProjectName = obj.Name;
  35. snap.StationId = obj.WindPowerStationId;
  36. WindPowerStation wps = DataCache.Instance.GetWindPowerStationByID(obj.WindPowerStationId);
  37. if (wps != null)
  38. snap.StationName = wps.Name;
  39. return snap;
  40. }
  41. public static AlertSnap CreateAlertSnap(AlertRule ar, Line obj)
  42. {
  43. AlertSnap snap = CreateAlertSnap(ar);
  44. snap.LineId = obj.Id;
  45. snap.LineName = obj.Name;
  46. snap.ProjectId = obj.ProjectId;
  47. Project prj = DataCache.Instance.GetProjectsByID(obj.ProjectId);
  48. if (prj != null)
  49. snap.ProjectName = prj.Name;
  50. snap.StationId = prj.WindPowerStationId;
  51. WindPowerStation wps = DataCache.Instance.GetWindPowerStationByID(prj.WindPowerStationId);
  52. snap.StationName = wps.Name;
  53. if (wps != null)
  54. snap.StationName = wps.Name;
  55. return snap;
  56. }
  57. public static AlertSnap CreateAlertSnap(AlertRule ar, WindTurbine obj)
  58. {
  59. AlertSnap snap = CreateAlertSnap(ar);
  60. snap.WindturbineId = obj.Id;
  61. snap.WindturbineName = obj.Name;
  62. snap.LineId = obj.LineId;
  63. snap.ModelId = obj.ModelId;
  64. Line ln = DataCache.Instance.GetLinesByID(obj.LineId);
  65. if (ln != null)
  66. snap.LineName = ln.Name;
  67. snap.ProjectId = obj.ProjectId;
  68. Project prj = DataCache.Instance.GetProjectsByID(obj.ProjectId);
  69. if (prj != null)
  70. snap.ProjectName = prj.Name;
  71. snap.StationId = obj.WindPowerStationId;
  72. WindPowerStation wps = DataCache.Instance.GetWindPowerStationByID(prj.WindPowerStationId);
  73. if (wps != null)
  74. snap.StationName = wps.Name;
  75. return snap;
  76. }
  77. public static AlertSnap CreateAlertSnap(Warning ar)
  78. {
  79. AlertSnap snap = new AlertSnap();
  80. snap.Id = 0;// Guid.NewGuid().ToString();
  81. snap.AlertText = ar.EnglishText.Trim();
  82. snap.AlertValue = ar.EDnaValue;
  83. snap.Category1 = "windturbine";
  84. snap.Category2 = ar.WarningClassifyId;
  85. snap.Rank = CommonMethod.ConvertWindturbineAlertRank(ar.LevelID);
  86. snap.LastUpdatePerson = "system";
  87. snap.LastUpdateTime = DateTime.Now;
  88. return snap;
  89. }
  90. public static AlertSnap CreateAlertSnap(Warning ar, WindTurbine obj)
  91. {
  92. AlertSnap snap = CreateAlertSnap(ar);
  93. snap.WindturbineId = obj.Id;
  94. snap.WindturbineName = obj.Name;
  95. snap.LineId = obj.LineId;
  96. snap.ModelId = obj.ModelId;
  97. Line ln = DataCache.Instance.GetLinesByID(obj.LineId);
  98. if (ln != null)
  99. snap.LineName = ln.Name;
  100. snap.ProjectId = obj.ProjectId;
  101. Project prj = DataCache.Instance.GetProjectsByID(obj.ProjectId);
  102. if (prj != null)
  103. snap.ProjectName = prj.Name;
  104. snap.StationId = obj.WindPowerStationId;
  105. WindPowerStation wps = DataCache.Instance.GetWindPowerStationByID(prj.WindPowerStationId);
  106. if (wps != null)
  107. snap.StationName = wps.Name;
  108. return snap;
  109. }
  110. public static AlertSnap CreateAlertSnap(IFixBJTestingPointDI ar)
  111. {
  112. AlertSnap snap = new AlertSnap();
  113. snap.Id = 0;// Guid.NewGuid().ToString();
  114. snap.AlertText = ar.Description.Trim();
  115. //snap.AlertValue = ar.EDnaValue;
  116. snap.Category1 = ar.Area1;
  117. if (ar.Area1 == "GF")
  118. snap.Category2 = "NBQ";
  119. else
  120. snap.Category2 = ar.Area3;
  121. //snap.Category3 = ar.Area2;
  122. snap.Rank = CommonMethod.ConvertIFixAlertRank(ar.LevelId);
  123. snap.LastUpdatePerson = "system";
  124. snap.LastUpdateTime = DateTime.Now;
  125. snap.TestingPointKey = ar.PointKey;
  126. snap.StationId = ar.StationId;
  127. snap.IFixPicture = ar.AlmExt1;
  128. snap.IFixTag = ar.AlmExt2;
  129. var obj = DataCache.Instance.DictStation2[ar.StationId] as WindPowerStation;
  130. if (obj != null)
  131. snap.StationName = obj.Name;
  132. return snap;
  133. }
  134. public static AlertHistory CreateAlertHistory(AlertSnap snap)
  135. {
  136. AlertHistory his = new AlertHistory();
  137. his.Id = 0;// Guid.NewGuid().ToString();
  138. his.SnapID = snap.Id;
  139. his.AlertTime = snap.LastUpdateTime == null ? (DateTime)snap.LastUpdateTime : DateTime.Now;
  140. his.ObjectId = snap.LastUpdatePerson;
  141. his.DataInfo = snap.DataInfo;
  142. if (snap.IsConfirmed)
  143. his.MessageType = "2"; //确认报警
  144. else if (snap.IsOpened)
  145. his.MessageType = "1"; //触发报警
  146. else
  147. {
  148. his.MessageType = "3"; //解除报警
  149. his.AlertTime = snap.LastCloseTime == null ? (DateTime)snap.LastCloseTime : DateTime.Now;
  150. his.ObjectId = snap.LastClosePerson;
  151. }
  152. return his;
  153. }
  154. }
  155. }