/// <summary> /// 获取空数据 /// </summary> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <returns></returns> private StatisticsRetailShopView GetEmptyData(DateTime startTime, DateTime endTime) { var statisticsRetailShopView = new StatisticsRetailShopView() { AreaShopRetails = new List <AreaShopRetailView>(), StartTime = startTime, EndTime = endTime }; return(statisticsRetailShopView); }
/// <summary> /// 获取销售统计信息 /// </summary> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <param name="statisticsRetailShop"></param> /// <param name="type"></param> /// <param name="areaLevel"></param> /// <returns></returns> private async Task <StatisticsRetailShopView> GetStatisticsRetailViewShop(DateTime startTime, DateTime endTime, Tuple <IEnumerable <DbStatisticsRetailViewShop>, int> statisticsRetailShop, int type, string areaLevel) { var statisticsRetailShopView = new StatisticsRetailShopView() { AreaShopRetails = new List <AreaShopRetailView>(), StartTime = startTime, EndTime = endTime }; if (statisticsRetailShop == null || statisticsRetailShop.Item1 == null || !statisticsRetailShop.Item1.Any()) { return(statisticsRetailShopView); } var statisticsRetail = statisticsRetailShop.Item1.ToList(); var areaIds = statisticsRetail.Select(p => p.AreaId).Distinct().ToList(); var areas = await _areaBll.GetArea(areaIds); var shopIds = statisticsRetail.Select(p => p.ShopId).Distinct().ToList(); var statisticsRetailShopCounts = await _reportBll.GetStatisticsRetailCount(string.Join(',', shopIds), startTime, endTime); foreach (var shopId in shopIds) { var statisticsRetailAboutShopId = _reportBll.GetStatisticsRetailByShop(shopId.ToString(), startTime, endTime).Result; var shop = statisticsRetail.First(p => p.ShopId == shopId); //只为获取此门店的省市区等信息 var area = areas.FirstOrDefault(p => p.AreaId == shop.AreaId); var areaRetailView = new AreaShopRetailView() { AreaId = shop.AreaId, AreaLevel = area?.Level, AreaName = area?.AreaName, Herbicide = GetGoodsCategoryNameWeight(statisticsRetailAboutShopId, StatisticsCategoryName.Herbicide, type), Fungicide = GetGoodsCategoryNameWeight(statisticsRetailAboutShopId, StatisticsCategoryName.Fungicide, type), Insecticide = GetGoodsCategoryNameWeight(statisticsRetailAboutShopId, StatisticsCategoryName.Insecticide, type), Acaricide = GetGoodsCategoryNameWeight(statisticsRetailAboutShopId, StatisticsCategoryName.Acaricide, type), PlantGrowthRegulator = GetGoodsCategoryNameWeight(statisticsRetailAboutShopId, StatisticsCategoryName.PlantGrowthRegulator, type), HygienicInsecticide = GetGoodsCategoryNameWeight(statisticsRetailAboutShopId, StatisticsCategoryName.HygienicInsecticide, type), ShopName = shop.ShopName, ShopId = shopId }; areaRetailView.Sum = statisticsRetail.Where(p => p.AreaId == shop.AreaId && p.ShopId == 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 = GetStatisticsRetailCount(statisticsRetailShopCounts, shopId, areaLevel, shop.AreaId); statisticsRetailShopView.AreaShopRetails.Add(areaRetailView); } return(statisticsRetailShopView); }