FfuDiffPressureDataRecorder.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Aitex.Core.RT.DBCore;
  2. using Aitex.Sorter.Common;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace MECF.Framework.Common.DBCore
  10. {
  11. public class FfuDiffPressureDataRecorder
  12. {
  13. public static List<HistoryFfuDiffPressureData> FfuDiffPressureHistory(string sql)
  14. {
  15. var strs = sql.Split(';');
  16. var beginTime = strs[0];
  17. var endTime = strs[1];
  18. DateTime beginDateTime = new DateTime(long.Parse(beginTime));
  19. DateTime endDateTime = new DateTime(long.Parse(endTime));
  20. if (endDateTime <= beginDateTime) return null;
  21. if (beginDateTime.Day != endDateTime.Day)
  22. {
  23. string sql1 = string.Format(
  24. "SELECT \"time\",\"DiffPressure.DiffPressure1\",\"DiffPressure.DiffPressure2\",\"FFU.FFU1Speed\",\"FFU.FFU2Speed\" FROM \"{2}.Data\" where \"time\" >= '{0}' and \"time\" <= '{1}' order by \"time\" ASC;",
  25. long.Parse(beginTime), DateTime.Parse(beginDateTime.ToString("yyyy-MM-dd 23:59:59")).Ticks, beginDateTime.ToString("yyyyMMdd"));
  26. DataSet ds = DB.ExecuteDataset(sql1);
  27. List<HistoryFfuDiffPressureData> result = new List<HistoryFfuDiffPressureData>();
  28. DSToList(ds, result);
  29. int daytime = 1;
  30. while (beginDateTime.AddDays(daytime).Day != endDateTime.Day)
  31. {
  32. DateTime newDate = beginDateTime.AddDays(daytime);
  33. string sql2 = string.Format(
  34. "SELECT \"time\",\"DiffPressure.DiffPressure1\",\"DiffPressure.DiffPressure2\",\"FFU.FFU1Speed\",\"FFU.FFU2Speed\" FROM \"{0}.Data\" order by \"time\" ASC;",
  35. newDate.ToString("yyyyMMdd"));
  36. DataSet ds1 = DB.ExecuteDataset(sql2);
  37. DSToList(ds1, result);
  38. daytime++;
  39. }
  40. string sql3 = string.Format(
  41. "SELECT \"time\",\"DiffPressure.DiffPressure1\",\"DiffPressure.DiffPressure2\",\"FFU.FFU1Speed\",\"FFU.FFU2Speed\" FROM \"{2}.Data\" where \"time\" >= '{0}' and \"time\" <= '{1}' order by \"time\" ASC;",
  42. DateTime.Parse(endDateTime.ToString("yyyy-MM-dd 0:0:0")).Ticks, long.Parse(endTime), endDateTime.ToString("yyyyMMdd"));
  43. DataSet ds3 = DB.ExecuteDataset(sql3);
  44. DSToList(ds3, result);
  45. return result;
  46. }
  47. else
  48. {
  49. string sql1 = string.Format(
  50. "SELECT \"time\",\"DiffPressure.DiffPressure1\",\"DiffPressure.DiffPressure2\",\"FFU.FFU1Speed\",\"FFU.FFU2Speed\" FROM \"{2}.Data\" where \"time\" >= '{0}' and \"time\" <= '{1}' order by \"time\" ASC;",
  51. long.Parse(beginTime), long.Parse(endTime), beginDateTime.ToString("yyyyMMdd"));
  52. DataSet ds = DB.ExecuteDataset(sql1);
  53. List<HistoryFfuDiffPressureData> result = new List<HistoryFfuDiffPressureData>();
  54. DSToList(ds, result);
  55. return result;
  56. }
  57. }
  58. private static void DSToList(DataSet ds, List<HistoryFfuDiffPressureData> result)
  59. {
  60. if (ds != null && ds.Tables.Count != 0)
  61. {
  62. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  63. {
  64. result.Add(new HistoryFfuDiffPressureData()
  65. {
  66. Time = ds.Tables[0].Rows[i]["time"].ToString(),
  67. DiffPressure1 = ds.Tables[0].Rows[i]["DiffPressure.DiffPressure1"].ToString(),
  68. DiffPressure2 = ds.Tables[0].Rows[i]["DiffPressure.DiffPressure2"].ToString(),
  69. FFU1Speed = ds.Tables[0].Rows[i]["FFU.FFU1Speed"].ToString(),
  70. FFU2Speed = ds.Tables[0].Rows[i]["FFU.FFU2Speed"].ToString(),
  71. });
  72. }
  73. }
  74. }
  75. }
  76. }