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();
-
- [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;
- }
-
- 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.resultAbnormalCnt > 0) ex.ErrorCnt++;
- if (h.endDate != null)
- sp += ((DateTime)h.endDate).Subtract(h.startDate);
- ex.PatrolHistoryId = h.PatrolHistoryId;
- }
- ex.OkCnt = ex.TotalCnt - ex.ErrorCnt;
- ex.TotalTimeMin = (int)sp.TotalMinutes;
- ex.SiteId = g.Key.SiteId;
- ex.startDate = find;
- historyEx.Add(ex);
- }
-
- }
-
-
- #region === Obslote ===
- #endregion
-
- return historyEx;
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- }
- }
|