123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- 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<FaultInfo> 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<FaultInfo> 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<FaultInfo> GetFaultInfoByIdList(IList<long> 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<FaultSnap> 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<FaultSnap> GetFaultSnapByIdList(IList<long> 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<FaultInfo> 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<Warning> 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;
- }
- }
- }
|