using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GDNXFD.Data.Repositories { public class FaultSnapRepository { public static IList GetRealTimeFaultInfos() { try { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { DateTime startTime = DateTime.Now.AddDays(-3); var results = ctx.FaultInfo .Where(q => q.ConfirmType == 0) .Where(q => q.IsOpened == true) .Where(q => q.AlertTime > startTime) .Where(q => q.MessageType == 1) .OrderByDescending(q => q.AlertTime) .ToList(); return results; } } catch (Exception ex) { var o = ex; return null; } } public static IList GetLatestFaultInfos(int count) { try { if (count < 1) count = 1; else if (count > 100) count = 100; using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { var results = ctx.FaultInfo .OrderByDescending(q => q.AlertTime) .Take(count) .ToList(); return results; } } catch (Exception ex) { var o = ex; System.Diagnostics.Debug.WriteLine("[+]数据库中的是否最近添加了新的报警信息,请确认字段是否为空,没有默认为0\r\n"+ex.ToString()); Console.WriteLine("[+]数据库中的是否最近添加了新的报警信息,请确认字段是否为空,没有默认为0\r\n"+ex.ToString()); return null; } } public static IList GetFaultInfoByIdList(IList idList) { try { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { var results = ctx.FaultInfo.Where(s => idList.Contains(s.Id)).ToList(); return results; } } catch (Exception ex) { var o = ex; return null; } } public static IList GetRealTimeFaultSnaps() { try { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { DateTime startTime = DateTime.Now.AddDays(-1); var results = ctx.FaultSnap .Where(q => q.IsOpened == true) .Where(q => q.LastUpdateTime > startTime) .OrderByDescending(q => q.LastUpdateTime) .ToList(); return results; } } catch (Exception ex) { var o = ex; return null; } } public static IList GetFaultSnapByIdList(IList snapIdList) { try { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { var results = ctx.FaultSnap .Where(q => snapIdList.Contains(q.Id)) .ToList(); return results; } } catch (Exception ex) { var o = ex; return null; } } public static IList GetFaultInfosPage(string filter, int pageIndex, int pageSize, ref int total) { try { string[] cri = filter.Split(','); DateTime startDt = DateTime.Parse(cri[0]); DateTime endDt = DateTime.Parse(cri[1]); string stationId = cri[2]; string rank = cri[3]; string category1 = cri[4]; string category2 = cri[5]; string keyWords = cri[6]; using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { var r1 = ctx.FaultInfo.AsQueryable(); r1 = r1.Where(q => q.AlertTime > startDt && q.AlertTime < endDt); if (!string.IsNullOrWhiteSpace(stationId)) { r1 = r1.Where(q => q.StationId == stationId); } else { r1 = r1.Where(q => q.StationId != null); } if (!string.IsNullOrWhiteSpace(rank)) { r1 = r1.Where(q => q.Rank == rank); } if (!string.IsNullOrWhiteSpace(category1)) { r1 = r1.Where(q => q.Category1 == category1); } if (!string.IsNullOrWhiteSpace(category2)) { r1 = r1.Where(q => q.Category2 == category2); } if (!string.IsNullOrWhiteSpace(keyWords)) { r1 = r1.Where(q => q.AlertText.Contains(keyWords)); } // r1 = r1.Where(q => q.MessageType == 1); //AlertValue 为自定义报警, // r1 = r1.Where(q => q.AlertValue > 0); r1 = r1.Where(q => q.SnapID > 0); total = r1.Count(); var results = r1.OrderByDescending(q => q.AlertTime) .Skip(--pageIndex * pageSize) .Take(pageSize) .ToList(); return results; } } catch (Exception ex) { var o = ex; return null; } } //1-确认 2-复位 3-生成缺陷单 public static void ConfirmFault(long id, int confirmType, string confirmPerson, long alertSnapId) { try { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { 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); ctx.Database.ExecuteSqlCommand(sql, new object[] { }); } } catch (Exception ex) { var x = ex.Message; } } public static IList getUnabledResetWarning() { try { using (GDNXFDDbContext ctx = new GDNXFDDbContext()) { var results = ctx.Warning .Where(q => q.IsReset == 1) .ToList(); return results; } } catch (Exception ex) { var x = ex.Message; } return null; } } }