04c8ad4430b56e9a962eb5d7fd678ae9461b8a29.svn-base 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Data;
  5. using System.Data.Entity;
  6. using System.Data.Entity.Infrastructure;
  7. using System.Linq;
  8. using System.Net;
  9. using System.Net.Http;
  10. using System.Web.Http;
  11. using System.Web.Http.Description;
  12. using System.Web.Http.OData;
  13. using iBemsDataService;
  14. using iBemsDataService.Model;
  15. namespace iBemsDataService.Controllers
  16. {
  17. public class CmPatrolHistoryExController : ODataController
  18. {
  19. private iBemsEntities db = new iBemsEntities();
  20. // GET: odata/CmPatrolHistoryEx
  21. [Queryable]
  22. public List<CmPatrolHistoryEx> GetCmPatrolHistoryEx()
  23. {
  24. var groupQuery =
  25. from m in db.CmPatrolHistory
  26. group m by new
  27. {
  28. SiteId = m.SiteId,
  29. Year = m.startDate.Year,
  30. Month = m.startDate.Month,
  31. Day = m.startDate.Day
  32. }
  33. into g
  34. select g;
  35. List<CmPatrolHistoryEx> historyEx = new List<CmPatrolHistoryEx>();
  36. if (groupQuery == null || groupQuery.Any() == false)
  37. {
  38. return historyEx;
  39. }
  40. //CalculationValue[] values = new CalculationValue[groupQuery.Count()];
  41. foreach (var g in groupQuery)
  42. {
  43. DateTime find = new DateTime(g.Key.Year, g.Key.Month, g.Key.Day, 0, 0, 0);
  44. DateTime findE = new DateTime(g.Key.Year, g.Key.Month, g.Key.Day, 23, 59, 59);
  45. IEnumerable<CmPatrolHistory> pHistroy = from x in db.CmPatrolHistory
  46. where x.SiteId == g.Key.SiteId && x.startDate >= find && x.startDate <= findE && x.endDate != null
  47. select x;
  48. if ((pHistroy != null) && (pHistroy.Count() > 0))
  49. {
  50. CmPatrolHistoryEx ex = new CmPatrolHistoryEx();
  51. TimeSpan sp = new TimeSpan(0);
  52. foreach (CmPatrolHistory h in pHistroy)
  53. {
  54. ex.TotalCnt++;
  55. //if (h.resultTypeId != 1) ex.ErrorCnt++;
  56. if (h.resultAbnormalCnt > 0) ex.ErrorCnt++;
  57. if (h.endDate != null)
  58. sp += ((DateTime)h.endDate).Subtract(h.startDate);
  59. ex.PatrolHistoryId = h.PatrolHistoryId; // 의미없음, 순번을위해 같은날짜중 마지막 id가설정되므로 문제없음
  60. }
  61. ex.OkCnt = ex.TotalCnt - ex.ErrorCnt;
  62. ex.TotalTimeMin = (int)sp.TotalMinutes;
  63. ex.SiteId = g.Key.SiteId;
  64. ex.startDate = find;
  65. historyEx.Add(ex);
  66. }
  67. /*{
  68. DateTime = new DateTime(g.Key.Year, g.Key.Month, 1),
  69. //Value = g.Sum(x => x.CurrentValue)
  70. Value = g.Sum(x => x.DailyValue)
  71. };
  72. i++; */
  73. }
  74. /*
  75. select new CmPatrolHistoryEx
  76. {
  77. SiteId = m.SiteId,
  78. PatrolHistoryId = m.PatrolHistoryId,
  79. PlanId = m.PlanId,
  80. startDate = m.startDate,
  81. endDate = m.endDate,
  82. resultTypeId = m.resultTypeId,
  83. resultDesc = m.resultDesc,
  84. TotalCnt = 100,
  85. OkCnt = 100,
  86. ErrorCnt = 100,
  87. TotalTimeMin = 10,
  88. }
  89. ).ToList(); */
  90. /*
  91. var historyAllList = GetCmPatrolHistoryStockHistory();
  92. foreach (var material in mterials)
  93. {
  94. var temp = historyAllList.Where(m => m.MaterialId == material.MaterialId).FirstOrDefault();
  95. if (temp != null)
  96. {
  97. material.StockCount = temp.StockCount;
  98. material.StockAmount = temp.StockAmount;
  99. //hcLee 2015 11 11
  100. material.WarehouseId = temp.WarehouseId;
  101. material.WHouseName = GetWHouseName(temp.WarehouseId);
  102. if (material.ReasonableStockCount == null) material.NeedCount = 0;
  103. else material.NeedCount = (int)material.ReasonableStockCount - material.StockCount;
  104. }
  105. }
  106. */
  107. #region === Obslote ===
  108. #endregion
  109. //return history.ToList();
  110. return historyEx;
  111. }
  112. protected override void Dispose(bool disposing)
  113. {
  114. if (disposing)
  115. {
  116. db.Dispose();
  117. }
  118. base.Dispose(disposing);
  119. }
  120. }
  121. }