/// <summary> /// 返回空数据 /// </summary> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <returns></returns> private StatisticsPurchaseShopView GetEmptyData(DateTime startTime, DateTime endTime) { var statisticsPurchaseShopView = new StatisticsPurchaseShopView() { AreaShopPurchases = new List <AreaShopPurchaseView>(), StartTime = startTime, EndTime = endTime }; return(statisticsPurchaseShopView); }
/// <summary> /// 获取采购统计信息 /// </summary> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <param name="statisticsPurchaseShop"></param> /// <param name="type"></param> /// <param name="areaLevel"></param> /// <returns></returns> private async Task <StatisticsPurchaseShopView> GetStatisticsPurchaseShopView(DateTime startTime, DateTime endTime, Tuple <IEnumerable <DbStatisticsPurchaseShopView>, int> statisticsPurchaseShop, int type, string areaLevel) { var statisticsPurchaseShopView = new StatisticsPurchaseShopView() { AreaShopPurchases = new List <AreaShopPurchaseView>(), StartTime = startTime, EndTime = endTime }; if (statisticsPurchaseShop == null || statisticsPurchaseShop.Item1 == null || !statisticsPurchaseShop.Item1.Any()) { return(statisticsPurchaseShopView); } var statisticsPurchase = statisticsPurchaseShop.Item1.ToList(); var areaIds = statisticsPurchase.Select(p => p.AreaId).Distinct().ToList(); var areas = await _areaBll.GetArea(areaIds); var shopIds = statisticsPurchase.Select(p => p.ShopId).Distinct().ToList(); var statisticsRetailShopCounts = await _reportBll.GetStatisticsPurchaseCount(string.Join(',', shopIds), startTime, endTime); foreach (var shopId in shopIds) { var statisticsPurchaseAboutShopId = _reportBll.GetStatisticsPurchaseByShop(shopId.ToString(), startTime, endTime).Result; var shop = statisticsPurchase.First(p => p.ShopId == shopId); var area = areas.FirstOrDefault(p => p.AreaId == shop.AreaId); var areaRetailView = new AreaShopPurchaseView() { AreaId = shop.AreaId, AreaLevel = area?.Level, AreaName = area?.AreaName, Herbicide = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.Herbicide, type), Fungicide = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.Fungicide, type), Insecticide = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.Insecticide, type), Acaricide = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.Acaricide, type), PlantGrowthRegulator = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.PlantGrowthRegulator, type), HygienicInsecticide = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.HygienicInsecticide, type), ShopName = shop.ShopName, ShopId = shop.ShopId }; areaRetailView.Sum = statisticsPurchase.Where(p => p.AreaId == shop.AreaId && p.ShopId == shop.ShopId).Sum(c => type == (int)StatisticsTypeEnum.ContentsWeight ? c.TotalContentsWeight : c.TotalWeight); areaRetailView.Other = areaRetailView.Sum - areaRetailView.Herbicide - areaRetailView.Fungicide - areaRetailView.Insecticide - areaRetailView.Acaricide - areaRetailView.PlantGrowthRegulator - areaRetailView.HygienicInsecticide; areaRetailView.Count = GetStatisticsPurchaseCount(statisticsRetailShopCounts, shop.ShopId, areaLevel, shop.AreaId); statisticsPurchaseShopView.AreaShopPurchases.Add(areaRetailView); } return(statisticsPurchaseShopView); }