public IEnumerable <OriginDomainListByHourEChartsPageItem> GetListByHour(string date, string domain = "www.baidu.com") { if (string.IsNullOrEmpty(date)) { date = DateTime.Now.ToString("yyyy-MM-dd"); } var queryResult = _originService.GetOriginDomainListByHour(domain, DateTime.Parse(date)); var originDomainList = queryResult.GroupBy(p => p.OriginDomain) .Select(p => new OriginDomainListByHourEChartsPageItem { OriginDomain = p.Key }) .OrderByDescending(p => p.OriginDomain) .ToList(); //补全24个小时段数据 foreach (var m in originDomainList) { for (var i = 0; i <= 23; i++) { var hourModel = queryResult.FirstOrDefault(p => p.TotalHour == i && p.OriginDomain == m.OriginDomain); if (hourModel == null) { m.Data.Add(0); } else { m.Data.Add(hourModel.TotalNumber); } } } return(originDomainList); }