/// <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);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取默认显示的库存信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private async Task <ResponseBase> GetStatisticsStockDefault(GetStatisticsStockRequest request)
        {
            List <DbStatisticsStockView> statisticsStockView = null;
            var limitShops = string.Empty;
            var arealevel  = string.Empty;

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

                statisticsStockView = await _reportBll.GetStatisticsStock(string.Join(',', province.Select(p => p.AreaId)), AreaLevelEnum.Province);

                arealevel = AreaLevelEnum.Province;
                break;

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

                    statisticsStockView = await _reportBll.GetStatisticsStock(areaInfo.Item1, areaInfo.Item2);

                    arealevel = areaInfo.Item2;
                }
                break;

            case (int)DataLimitTypeEnum.Shop:
                limitShops = _appTicket.DataLimitShop;
                if (!string.IsNullOrEmpty(_appTicket.DataLimitShop))
                {
                    statisticsStockView = await _reportBll.GetStatisticsStockByShop(_appTicket.DataLimitShop);

                    arealevel = AreaLevelEnum.Street;
                }
                break;
            }
            var result = await GetStatisticsStockView(statisticsStockView, request.Type, limitShops, arealevel);

            return(ResponseBase.Success(result));
        }