using iWareCommon.Utils; using iWareLog.ORM; using iWareLog.Report.Helper; using System; using System.Collections.Generic; using System.Linq; namespace iWareLog.Report.Service { public class AlertService { private static object Lock = new object(); private static AlertService Instance = null; /// /// 获取单例的方法 /// /// 单例实体 public static AlertService GetInstance() { if (Instance == null) { lock (Lock) { if (Instance == null) { Instance = new AlertService(); } } } return Instance; } /// /// 查询时间内故障出现次数,总时间,以设备分组 /// /// /// /// public List GetAlertByMachine(DateTime start, DateTime end) { using (DbModelLog context = new DbModelLog()) { try { string sql = "SELECT name,COUNT(equipid) as devalertcount, sum(DATEDIFF(SECOND,createtime,finishtime)) as datediffs FROM DEVAlert WHERE createtime >= @p0 and createtime < @p1 group by name"; List data = context.Database.SqlQuery(sql, start, end).ToList(); return data; } catch (Exception ex) { LogTextHelper.WriteLine("AlertService", "GetAlertByMachine", ex.ToString()); return null; } } } /// /// 查询时间内故障出现次数,总时间,以故障代码分组 /// /// /// /// public List GetAlertByAlertCode(DateTime start, DateTime end) { using (DbModelLog context = new DbModelLog()) { try { string sql = "SELECT alertcode, COUNT(alertcode) as alertcount, sum(DATEDIFF(SECOND,createtime,finishtime)) as datediffs FROM DEVAlert WHERE createtime >= @p0 and createtime < @p1 group by alertcode"; List data = context.Database.SqlQuery(sql, start, end).ToList(); return data; } catch (Exception ex) { LogTextHelper.WriteLine("AlertService", "GetAlertByAlertCode", ex.ToString()); return null; } } } } }