123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Data;
- using System.Data.Entity;
- using System.Data.Entity.Infrastructure;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Web.Http;
- using System.Web.Http.Description;
- using System.Web.Http.OData;
- using iBemsDataService;
- using iBemsDataService.Model;
- namespace iBemsDataService.Controllers
- {
- public class CmPatrolHistoryExController : ODataController
- {
- private iBemsEntities db = new iBemsEntities();
- // GET: odata/CmPatrolHistoryEx
- [Queryable]
- public List<CmPatrolHistoryEx> GetCmPatrolHistoryEx()
- {
- var groupQuery =
- from m in db.CmPatrolHistory
- group m by new
- {
- SiteId = m.SiteId,
- Year = m.startDate.Year,
- Month = m.startDate.Month,
- Day = m.startDate.Day
- }
- into g
- select g;
- List<CmPatrolHistoryEx> historyEx = new List<CmPatrolHistoryEx>();
- if (groupQuery == null || groupQuery.Any() == false)
- {
- return historyEx;
- }
- //CalculationValue[] values = new CalculationValue[groupQuery.Count()];
- foreach (var g in groupQuery)
- {
- DateTime find = new DateTime(g.Key.Year, g.Key.Month, g.Key.Day, 0, 0, 0);
- DateTime findE = new DateTime(g.Key.Year, g.Key.Month, g.Key.Day, 23, 59, 59);
- IEnumerable<CmPatrolHistory> pHistroy = from x in db.CmPatrolHistory
- where x.SiteId == g.Key.SiteId && x.startDate >= find && x.startDate <= findE && x.endDate != null
- select x;
- if ((pHistroy != null) && (pHistroy.Count() > 0))
- {
- CmPatrolHistoryEx ex = new CmPatrolHistoryEx();
- TimeSpan sp = new TimeSpan(0);
- foreach (CmPatrolHistory h in pHistroy)
- {
- ex.TotalCnt++;
- //if (h.resultTypeId != 1) ex.ErrorCnt++;
- if (h.resultAbnormalCnt > 0) ex.ErrorCnt++;
- if (h.endDate != null)
- sp += ((DateTime)h.endDate).Subtract(h.startDate);
- ex.PatrolHistoryId = h.PatrolHistoryId; // 의미없음, 순번을위해 같은날짜중 마지막 id가설정되므로 문제없음
- }
- ex.OkCnt = ex.TotalCnt - ex.ErrorCnt;
- ex.TotalTimeMin = (int)sp.TotalMinutes;
- ex.SiteId = g.Key.SiteId;
- ex.startDate = find;
- historyEx.Add(ex);
- }
- /*{
- DateTime = new DateTime(g.Key.Year, g.Key.Month, 1),
- //Value = g.Sum(x => x.CurrentValue)
- Value = g.Sum(x => x.DailyValue)
- };
- i++; */
- }
- /*
- select new CmPatrolHistoryEx
- {
- SiteId = m.SiteId,
- PatrolHistoryId = m.PatrolHistoryId,
- PlanId = m.PlanId,
- startDate = m.startDate,
- endDate = m.endDate,
- resultTypeId = m.resultTypeId,
- resultDesc = m.resultDesc,
- TotalCnt = 100,
- OkCnt = 100,
- ErrorCnt = 100,
- TotalTimeMin = 10,
- }
- ).ToList(); */
- /*
- var historyAllList = GetCmPatrolHistoryStockHistory();
- foreach (var material in mterials)
- {
- var temp = historyAllList.Where(m => m.MaterialId == material.MaterialId).FirstOrDefault();
- if (temp != null)
- {
- material.StockCount = temp.StockCount;
- material.StockAmount = temp.StockAmount;
- //hcLee 2015 11 11
- material.WarehouseId = temp.WarehouseId;
- material.WHouseName = GetWHouseName(temp.WarehouseId);
- if (material.ReasonableStockCount == null) material.NeedCount = 0;
- else material.NeedCount = (int)material.ReasonableStockCount - material.StockCount;
- }
- }
- */
- #region === Obslote ===
- #endregion
- //return history.ToList();
- return historyEx;
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- }
- }
|