/// <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);
        }
Example #2
0
        /// <summary>
        /// 获取默认数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private async Task <ResponseBase> GetStatisticsRetailDefault(GetStatisticsRetailRequest request)
        {
            List <DbStatisticsRetailView> statisticsRetail = null;
            var statisticsTime = ComLib.GetAreaStatisticsTime(request.StartTime, request.EndTime);
            var limitShops     = string.Empty;
            var arealevel      = string.Empty;

            switch (_appTicket.DataLimitType)
            {
            case (int)DataLimitTypeEnum.All:
                var province = await _areaBll.GetProvince();

                statisticsRetail = await _reportBll.GetStatisticsRetail(string.Join(',', province.Select(p => p.AreaId)),
                                                                        statisticsTime.Item1, statisticsTime.Item2, AreaLevelEnum.Province);

                arealevel = AreaLevelEnum.Province;
                break;

            case (int)DataLimitTypeEnum.Area:
                if (!string.IsNullOrEmpty(_appTicket.DataLimitArea))
                {
                    var areaInfo = await ComLib.GetGetAreaStatisticsAreaId(_areaBll, _appTicket.DataLimitArea);

                    statisticsRetail = await _reportBll.GetStatisticsRetail(areaInfo.Item1, statisticsTime.Item1,
                                                                            statisticsTime.Item2, areaInfo.Item2);

                    arealevel = areaInfo.Item2;
                }
                break;

            case (int)DataLimitTypeEnum.Shop:
                limitShops = _appTicket.DataLimitShop;
                if (!string.IsNullOrEmpty(_appTicket.DataLimitShop))
                {
                    statisticsRetail = await _reportBll.GetStatisticsRetailByShop(_appTicket.DataLimitShop,
                                                                                  statisticsTime.Item1, statisticsTime.Item2);

                    arealevel = AreaLevelEnum.Street;
                }
                break;
            }
            var result = await GetStatisticsRetailView(statisticsTime.Item1, statisticsTime.Item2, statisticsRetail, request.Type, limitShops, arealevel);

            return(ResponseBase.Success(result));
        }