MacStatusService.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using Cksoft.Unity;
  4. using Cksoft.Unity.Log4NetConfig;
  5. using DllEapDal.OFILM;
  6. using Microsoft.Extensions.Configuration;
  7. using System;
  8. namespace DllEapBll.Services
  9. {
  10. public class MacStatusService
  11. {
  12. private readonly IConfiguration configuration;
  13. public MacStatusService(IConfiguration configuration)
  14. {
  15. this.configuration = configuration;
  16. }
  17. public EapResponse GetTotalInfo(string filter, string recipe, string date, string type, int count = 0)
  18. {
  19. var res = new EapResponse { Code = 1, Msg = string.Empty };
  20. try
  21. {
  22. string errorinfo = string.Empty;
  23. using (IDatabase db = DbFactory.Base("eapslave"))
  24. {
  25. db.BeginTrans();
  26. var dal = new MacStatusTotalDal(db);
  27. var entity = dal.GetTotalInfo(filter, recipe, date, type, ref errorinfo);
  28. if (entity == null)
  29. {
  30. res.Code = -1;
  31. res.Msg = errorinfo;
  32. return res;
  33. }
  34. res.Data = entity;
  35. return res;
  36. }
  37. }
  38. catch (Exception ex)
  39. {
  40. LogHelper<MacStatusService>.LogError("查询机台看板数据错误,错误为:" + ex.ToString(),
  41. string.Empty, string.Empty);
  42. return res;
  43. }
  44. }
  45. public EapResponse GetProcessRunRate(string filter, string recipe, string date, string type)
  46. {
  47. var res = new EapResponse() { Code = 1, Msg = string.Empty };
  48. DateTime dateNow = DateTime.Now;
  49. DateTime dateStart;
  50. DateTime dateEnd;
  51. if (string.IsNullOrEmpty(date) || Convert.ToDateTime(date).ToString("yyyy-MM-dd") == dateNow.ToString("yyyy-MM-dd"))
  52. {
  53. if (dateNow <= new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, 20, 30, 0)
  54. && dateNow > new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, 8, 30, 0))
  55. {
  56. dateStart = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, 8, 30, 0);
  57. }
  58. else
  59. {
  60. var yesterday = dateNow.AddDays(-1);
  61. dateStart = new DateTime(yesterday.Year, yesterday.Month, yesterday.Day, 20, 30, 0);
  62. }
  63. dateEnd = dateNow;
  64. }
  65. else
  66. {
  67. dateNow = Convert.ToDateTime(date);
  68. if (type == "1")//白班
  69. {
  70. dateStart = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, 8, 30, 0);
  71. dateEnd = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, 20, 30, 0);
  72. }
  73. else if (type == "2")//夜班
  74. {
  75. var tomorrow = dateNow.AddDays(1);
  76. dateStart = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, 20, 30, 0);
  77. dateEnd = new DateTime(tomorrow.Year, tomorrow.Month, tomorrow.Day, 8, 30, 0);
  78. }
  79. else//整天
  80. {
  81. var tomorrow = dateNow.AddDays(1);
  82. dateStart = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, 8, 30, 0);
  83. dateEnd = new DateTime(tomorrow.Year, tomorrow.Month, tomorrow.Day, 8, 30, 0);
  84. }
  85. }
  86. string errorinfo = string.Empty;
  87. using (IDatabase db = DbFactory.Base("eapslave"))
  88. {
  89. //db.BeginTrans();
  90. var dal = new MacStatusTotalDal(db, configuration);
  91. var dto = dal.GetProcessRunRate(filter, date, type, recipe, ref errorinfo);
  92. if (dto == null)
  93. {
  94. res.Code = -1;
  95. res.Msg = errorinfo;
  96. return res;
  97. }
  98. //db.Commit();
  99. res.Data = dto;
  100. return res;
  101. }
  102. }
  103. }
  104. }