123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace GDNXFD.Data.Repositories
- {
- public class CustomRepository
- {
- public static IList<AlertInfo> GetAlertHistorys()
- {
- IList<AlertInfo> ret = null;
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- ret = ctx.AlertInfo.ToList();
- }
- return ret;
- }
- public static IList<RankingModel> GetStationPieChartData()
- {
- DateTime dt = DateTime.Now.AddDays(-1);
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- var query = ctx.AlertInfo
- .Where(q=>q.AlertTime > dt)
- .GroupBy(q=>q.StationName)
- .Select(g => new RankingModel { ObjectName = g.Key, Total = g.Count() });
- return query.OrderByDescending(a => a.Total).Take(10).ToList();
- }
- }
- public static IList<RankingModel> GetRankListData()
- {
- IList<RankingModel> results = new List<RankingModel>();
- DateTime dt = DateTime.Now.AddDays(-1);
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- var query = ctx.AlertInfo
- .Where(q => q.AlertTime > dt)
- .GroupBy(q => new GroupModel { StationName = q.StationName, ProjectName = q.ProjectName, LineName = q.LineName, WindturbineName = q.WindturbineName })
- .Select(g => new GroupRankModel { GM = g.Key, Total = g.Count() });
- var tmp = query.OrderByDescending(a => a.Total).Take(10).ToArray();
- if (tmp != null)
- {
- for(int i=0;i<tmp.Length;i++)
- {
- RankingModel rm = new RankingModel() { ObjectName = tmp[i].GM.ObjectName, Total = tmp[i].Total, RankingNo = i + 1 };
- results.Add(rm);
- }
- }
- }
- return results;
- }
- public static IList<InputOrOutputSpeedTotal> GetWindturbineInputWindSpeed()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- string sql = @"select id, windturbineid, recorddate, inputsmall from inputoroutputspeedtotal t where t.recorddate = (select max(recorddate) from inputoroutputspeedtotal)";
- return ctx.InputOrOutputSpeedTotal.SqlQuery(sql, new object[] { }).ToList();
- }
- }
- public static IList<WindturbineCFTSpeed> GetWindturbineCFTSpeed()
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- return ctx.WindturbineCFTSpeed.ToList();
- }
- }
- }
- }
|