CustomRepository.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 CustomRepository
  9. {
  10. public static IList<AlertInfo> GetAlertHistorys()
  11. {
  12. IList<AlertInfo> ret = null;
  13. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  14. {
  15. ret = ctx.AlertInfo.ToList();
  16. }
  17. return ret;
  18. }
  19. public static IList<RankingModel> GetStationPieChartData()
  20. {
  21. DateTime dt = DateTime.Now.AddDays(-1);
  22. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  23. {
  24. var query = ctx.AlertInfo
  25. .Where(q=>q.AlertTime > dt)
  26. .GroupBy(q=>q.StationName)
  27. .Select(g => new RankingModel { ObjectName = g.Key, Total = g.Count() });
  28. return query.OrderByDescending(a => a.Total).Take(10).ToList();
  29. }
  30. }
  31. public static IList<RankingModel> GetRankListData()
  32. {
  33. IList<RankingModel> results = new List<RankingModel>();
  34. DateTime dt = DateTime.Now.AddDays(-1);
  35. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  36. {
  37. var query = ctx.AlertInfo
  38. .Where(q => q.AlertTime > dt)
  39. .GroupBy(q => new GroupModel { StationName = q.StationName, ProjectName = q.ProjectName, LineName = q.LineName, WindturbineName = q.WindturbineName })
  40. .Select(g => new GroupRankModel { GM = g.Key, Total = g.Count() });
  41. var tmp = query.OrderByDescending(a => a.Total).Take(10).ToArray();
  42. if (tmp != null)
  43. {
  44. for(int i=0;i<tmp.Length;i++)
  45. {
  46. RankingModel rm = new RankingModel() { ObjectName = tmp[i].GM.ObjectName, Total = tmp[i].Total, RankingNo = i + 1 };
  47. results.Add(rm);
  48. }
  49. }
  50. }
  51. return results;
  52. }
  53. public static IList<InputOrOutputSpeedTotal> GetWindturbineInputWindSpeed()
  54. {
  55. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  56. {
  57. string sql = @"select id, windturbineid, recorddate, inputsmall from inputoroutputspeedtotal t where t.recorddate = (select max(recorddate) from inputoroutputspeedtotal)";
  58. return ctx.InputOrOutputSpeedTotal.SqlQuery(sql, new object[] { }).ToList();
  59. }
  60. }
  61. public static IList<WindturbineCFTSpeed> GetWindturbineCFTSpeed()
  62. {
  63. using (GDNXFDDbContext ctx = new GDNXFDDbContext())
  64. {
  65. return ctx.WindturbineCFTSpeed.ToList();
  66. }
  67. }
  68. }
  69. }