FaultSnapRepository.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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.Repositories
  7. {
  8. public class FaultSnapRepository
  9. {
  10. public static IList<FaultInfo> GetRealTimeFaultInfos()
  11. {
  12. try
  13. {
  14. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  15. {
  16. DateTime startTime = DateTime.Now.AddDays(-3);
  17. var results = ctx.FaultInfo
  18. .Where(q => q.ConfirmType == 0)
  19. .Where(q => q.IsOpened == true)
  20. .Where(q => q.AlertTime > startTime)
  21. .Where(q => q.MessageType == 1)
  22. .OrderByDescending(q => q.AlertTime)
  23. .ToList();
  24. return results;
  25. }
  26. }
  27. catch (Exception ex)
  28. {
  29. var o = ex;
  30. return null;
  31. }
  32. }
  33. public static IList<FaultInfo> GetLatestFaultInfos(int count)
  34. {
  35. try
  36. {
  37. if (count < 1)
  38. count = 1;
  39. else if (count > 100)
  40. count = 100;
  41. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  42. {
  43. var results = ctx.FaultInfo
  44. .OrderByDescending(q => q.AlertTime)
  45. .Take(count)
  46. .ToList();
  47. return results;
  48. }
  49. }
  50. catch (Exception ex)
  51. {
  52. var o = ex;
  53. System.Diagnostics.Debug.WriteLine("[+]数据库中的是否最近添加了新的报警信息,请确认字段是否为空,没有默认为0\r\n"+ex.ToString());
  54. Console.WriteLine("[+]数据库中的是否最近添加了新的报警信息,请确认字段是否为空,没有默认为0\r\n"+ex.ToString());
  55. return null;
  56. }
  57. }
  58. public static IList<FaultInfo> GetFaultInfoByIdList(IList<long> idList)
  59. {
  60. try
  61. {
  62. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  63. {
  64. var results = ctx.FaultInfo.Where(s => idList.Contains(s.Id)).ToList();
  65. return results;
  66. }
  67. }
  68. catch (Exception ex)
  69. {
  70. var o = ex;
  71. return null;
  72. }
  73. }
  74. public static IList<FaultSnap> GetRealTimeFaultSnaps()
  75. {
  76. try
  77. {
  78. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  79. {
  80. DateTime startTime = DateTime.Now.AddDays(-1);
  81. var results = ctx.FaultSnap
  82. .Where(q => q.IsOpened == true)
  83. .Where(q => q.LastUpdateTime > startTime)
  84. .OrderByDescending(q => q.LastUpdateTime)
  85. .ToList();
  86. return results;
  87. }
  88. }
  89. catch (Exception ex)
  90. {
  91. var o = ex;
  92. return null;
  93. }
  94. }
  95. public static IList<FaultSnap> GetFaultSnapByIdList(IList<long> snapIdList)
  96. {
  97. try
  98. {
  99. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  100. {
  101. var results = ctx.FaultSnap
  102. .Where(q => snapIdList.Contains(q.Id))
  103. .ToList();
  104. return results;
  105. }
  106. }
  107. catch (Exception ex)
  108. {
  109. var o = ex;
  110. return null;
  111. }
  112. }
  113. public static IList<FaultInfo> GetFaultInfosPage(string filter, int pageIndex, int pageSize, ref int total)
  114. {
  115. try
  116. {
  117. string[] cri = filter.Split(',');
  118. DateTime startDt = DateTime.Parse(cri[0]);
  119. DateTime endDt = DateTime.Parse(cri[1]);
  120. string stationId = cri[2];
  121. string rank = cri[3];
  122. string category1 = cri[4];
  123. string category2 = cri[5];
  124. string keyWords = cri[6];
  125. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  126. {
  127. var r1 = ctx.FaultInfo.AsQueryable();
  128. r1 = r1.Where(q => q.AlertTime > startDt && q.AlertTime < endDt);
  129. if (!string.IsNullOrWhiteSpace(stationId))
  130. {
  131. r1 = r1.Where(q => q.StationId == stationId);
  132. }
  133. else
  134. {
  135. r1 = r1.Where(q => q.StationId != null);
  136. }
  137. if (!string.IsNullOrWhiteSpace(rank))
  138. {
  139. r1 = r1.Where(q => q.Rank == rank);
  140. }
  141. if (!string.IsNullOrWhiteSpace(category1))
  142. {
  143. r1 = r1.Where(q => q.Category1 == category1);
  144. }
  145. if (!string.IsNullOrWhiteSpace(category2))
  146. {
  147. r1 = r1.Where(q => q.Category2 == category2);
  148. }
  149. if (!string.IsNullOrWhiteSpace(keyWords))
  150. {
  151. r1 = r1.Where(q => q.AlertText.Contains(keyWords));
  152. }
  153. // r1 = r1.Where(q => q.MessageType == 1);
  154. //AlertValue 为自定义报警,
  155. // r1 = r1.Where(q => q.AlertValue > 0);
  156. r1 = r1.Where(q => q.SnapID > 0);
  157. total = r1.Count();
  158. var results = r1.OrderByDescending(q => q.AlertTime)
  159. .Skip(--pageIndex * pageSize)
  160. .Take(pageSize)
  161. .ToList();
  162. return results;
  163. }
  164. }
  165. catch (Exception ex)
  166. {
  167. var o = ex;
  168. return null;
  169. }
  170. }
  171. //1-确认 2-复位 3-生成缺陷单
  172. public static void ConfirmFault(long id, int confirmType, string confirmPerson, long alertSnapId)
  173. {
  174. try
  175. {
  176. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  177. {
  178. string sql = String.Format("update faulthistory set confirmtype='{0}', confirmtime=sysdate , confirmperson='{1}',alertsnapid='{3}' where snapid='{2}' and faulttime > sysdate-3 ", confirmType, confirmPerson, id, alertSnapId);
  179. ctx.Database.ExecuteSqlCommand(sql, new object[] { });
  180. }
  181. }
  182. catch (Exception ex)
  183. {
  184. var x = ex.Message;
  185. }
  186. }
  187. public static IList<Warning> getUnabledResetWarning()
  188. {
  189. try
  190. {
  191. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  192. {
  193. var results = ctx.Warning
  194. .Where(q => q.IsReset == 1)
  195. .ToList();
  196. return results;
  197. }
  198. }
  199. catch (Exception ex)
  200. {
  201. var x = ex.Message;
  202. }
  203. return null;
  204. }
  205. }
  206. }