/// <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);
        }
Beispiel #2
0
        /// <summary>
        /// 获取销售统计信息
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="statisticsRetail"></param>
        /// <param name="type"></param>
        /// <param name="limitShops"></param>
        /// <param name="areaLevel"></param>
        /// <returns></returns>
        private async Task <StatisticsRetailView> GetStatisticsRetailView(DateTime startTime, DateTime endTime, List <DbStatisticsRetailView> statisticsRetail, int type, string
                                                                          limitShops, string areaLevel)
        {
            var statisticsRetailView = new StatisticsRetailView()
            {
                AreaRetails   = new List <AreaRetailView>(),
                AreaRetailSum = new AreaRetailSumView(),
                StartTime     = startTime,
                EndTime       = endTime
            };

            if (statisticsRetail == null || !statisticsRetail.Any())
            {
                return(statisticsRetailView);
            }
            var areaIds = statisticsRetail.Select(p => p.AreaId).Distinct().ToList();
            var areas   = await _areaBll.GetArea(areaIds);

            List <StatisticsRetailCount> statisticsRetailCounts;

            if (string.IsNullOrEmpty(limitShops))
            {
                statisticsRetailCounts = await _reportBll.GetStatisticsRetailCount(string.Join(',', areaIds), startTime, endTime,
                                                                                   areaLevel, string.Empty);
            }
            else
            {
                statisticsRetailCounts = await _reportBll.GetStatisticsRetailCount(limitShops, startTime, endTime);
            }
            foreach (var areaId in areaIds)
            {
                var area           = areas.FirstOrDefault(p => p.AreaId == areaId);
                var areaRetailView = new AreaRetailView()
                {
                    AreaId               = areaId,
                    AreaLevel            = area?.Level,
                    AreaName             = area?.AreaName,
                    Herbicide            = GetGoodsCategoryNameWeight(areaId, statisticsRetail, StatisticsCategoryName.Herbicide, type),
                    Fungicide            = GetGoodsCategoryNameWeight(areaId, statisticsRetail, StatisticsCategoryName.Fungicide, type),
                    Insecticide          = GetGoodsCategoryNameWeight(areaId, statisticsRetail, StatisticsCategoryName.Insecticide, type),
                    Acaricide            = GetGoodsCategoryNameWeight(areaId, statisticsRetail, StatisticsCategoryName.Acaricide, type),
                    PlantGrowthRegulator = GetGoodsCategoryNameWeight(areaId, statisticsRetail, StatisticsCategoryName.PlantGrowthRegulator, type),
                    HygienicInsecticide  = GetGoodsCategoryNameWeight(areaId, statisticsRetail, StatisticsCategoryName.HygienicInsecticide, type)
                };
                areaRetailView.Sum = statisticsRetail.Where(p => p.AreaId == areaId).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(statisticsRetailCounts, areaLevel, areaId);
                statisticsRetailView.AreaRetails.Add(areaRetailView);
            }
            statisticsRetailView.AreaRetailSum = new AreaRetailSumView()
            {
                Sum                  = statisticsRetailView.AreaRetails.Sum(p => p.Sum),
                Count                = statisticsRetailView.AreaRetails.Sum(p => p.Count),
                Other                = statisticsRetailView.AreaRetails.Sum(p => p.Other),
                Acaricide            = statisticsRetailView.AreaRetails.Sum(p => p.Acaricide),
                Fungicide            = statisticsRetailView.AreaRetails.Sum(p => p.Fungicide),
                Herbicide            = statisticsRetailView.AreaRetails.Sum(p => p.Herbicide),
                HygienicInsecticide  = statisticsRetailView.AreaRetails.Sum(p => p.HygienicInsecticide),
                Insecticide          = statisticsRetailView.AreaRetails.Sum(p => p.Insecticide),
                PlantGrowthRegulator = statisticsRetailView.AreaRetails.Sum(p => p.PlantGrowthRegulator)
            };
            return(statisticsRetailView);
        }