/// <summary> /// 获取空数据 /// </summary> /// <returns></returns> private StatisticsStockShopView GetEmptyData() { var statisticsStockShopView = new StatisticsStockShopView() { AreaStockShops = new List <AreaStockShopView>() }; return(statisticsStockShopView); }
/// <summary> /// 获取StatisticsStockShopView /// </summary> /// <param name="statisticsStockShop"></param> /// <param name="type"></param> /// <returns></returns> private async Task <StatisticsStockShopView> GetStatisticsStockShopView(Tuple <IEnumerable <DbStatisticsStockViewShop>, int> statisticsStockShop, int type) { var statisticsStockShopView = new StatisticsStockShopView() { AreaStockShops = new List <AreaStockShopView>() }; if (statisticsStockShop == null || statisticsStockShop.Item1 == null || !statisticsStockShop.Item1.Any()) { return(statisticsStockShopView); } var statisticsView = statisticsStockShop.Item1.ToList(); var areaIds = statisticsView.Select(p => p.AreaId).Distinct().ToList(); var areas = await _areaBll.GetArea(areaIds); var shopIds = statisticsView.Select(p => p.ShopId).Distinct().ToList(); foreach (var shopId in shopIds) { var statisticsViewAboutShopId = _reportBll.GetStatisticsStockByShop(shopId.ToString()).Result; var shop = statisticsView.First(p => p.ShopId == shopId); var area = areas.FirstOrDefault(p => p.AreaId == shop.AreaId); var areaRetailView = new AreaStockShopView() { AreaId = shop.AreaId, AreaLevel = area?.Level, AreaName = area?.AreaName, Herbicide = GetGoodsCategoryNameWeight(statisticsViewAboutShopId, StatisticsCategoryName.Herbicide, type), Fungicide = GetGoodsCategoryNameWeight(statisticsViewAboutShopId, StatisticsCategoryName.Fungicide, type), Insecticide = GetGoodsCategoryNameWeight(statisticsViewAboutShopId, StatisticsCategoryName.Insecticide, type), Acaricide = GetGoodsCategoryNameWeight(statisticsViewAboutShopId, StatisticsCategoryName.Acaricide, type), PlantGrowthRegulator = GetGoodsCategoryNameWeight(statisticsViewAboutShopId, StatisticsCategoryName.PlantGrowthRegulator, type), HygienicInsecticide = GetGoodsCategoryNameWeight(statisticsViewAboutShopId, StatisticsCategoryName.HygienicInsecticide, type), ShopName = shop.ShopName, ShopId = shop.ShopId }; areaRetailView.Sum = statisticsView.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; statisticsStockShopView.AreaStockShops.Add(areaRetailView); } return(statisticsStockShopView); }