Beispiel #1
0
        /// <summary>
        /// 返回空数据
        /// </summary>
        /// <param name="endTime"></param>
        /// <param name="startTime"></param>
        /// <returns></returns>
        private StatisticsPurchaseView GetEmptyData(DateTime startTime, DateTime endTime)
        {
            var statisticsPurchaseView = new StatisticsPurchaseView()
            {
                AreaPurchases   = new List <AreaPurchaseView>(),
                AreaPurchaseSum = new AreaPurchaseSumView(),
                StartTime       = startTime,
                EndTime         = endTime
            };

            return(statisticsPurchaseView);
        }
Beispiel #2
0
        /// <summary>
        /// 获取销售统计信息
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="statisticsPurchase"></param>
        /// <param name="type"></param>
        /// <param name="limitShops"></param>
        /// <param name="areaLevel"></param>
        /// <returns></returns>
        private async Task <StatisticsPurchaseView> GetStatisticsPurchaseView(DateTime startTime, DateTime endTime, List <DbStatisticsPurchaseView> statisticsPurchase, int type, string
                                                                              limitShops, string areaLevel)
        {
            var statisticsPurchaseView = new StatisticsPurchaseView()
            {
                AreaPurchases   = new List <AreaPurchaseView>(),
                AreaPurchaseSum = new AreaPurchaseSumView(),
                StartTime       = startTime,
                EndTime         = endTime
            };

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

            List <StatisticsPurchaseCount> statisticsPurchaseCounts = null;

            if (string.IsNullOrEmpty(limitShops))
            {
                statisticsPurchaseCounts = await _reportBll.GetStatisticsPurchaseCount(string.Join(',', areaIds), startTime, endTime,
                                                                                       areaLevel, string.Empty);
            }
            else
            {
                statisticsPurchaseCounts = await _reportBll.GetStatisticsPurchaseCount(limitShops, startTime, endTime);
            }
            foreach (var areaId in areaIds)
            {
                var area             = areas.FirstOrDefault(p => p.AreaId == areaId);
                var areaPurchaseView = new AreaPurchaseView()
                {
                    AreaId               = areaId,
                    AreaLevel            = area?.Level,
                    AreaName             = area?.AreaName,
                    Herbicide            = GetGoodsCategoryNameWeight(areaId, statisticsPurchase, StatisticsCategoryName.Herbicide, type),
                    Fungicide            = GetGoodsCategoryNameWeight(areaId, statisticsPurchase, StatisticsCategoryName.Fungicide, type),
                    Insecticide          = GetGoodsCategoryNameWeight(areaId, statisticsPurchase, StatisticsCategoryName.Insecticide, type),
                    Acaricide            = GetGoodsCategoryNameWeight(areaId, statisticsPurchase, StatisticsCategoryName.Acaricide, type),
                    PlantGrowthRegulator = GetGoodsCategoryNameWeight(areaId, statisticsPurchase, StatisticsCategoryName.PlantGrowthRegulator, type),
                    HygienicInsecticide  = GetGoodsCategoryNameWeight(areaId, statisticsPurchase, StatisticsCategoryName.HygienicInsecticide, type)
                };
                areaPurchaseView.Sum = statisticsPurchase.Where(p => p.AreaId == areaId).Sum(c => type == (int)StatisticsTypeEnum.ContentsWeight
                       ? c.TotalContentsWeight
                       : c.TotalWeight);
                areaPurchaseView.Other = areaPurchaseView.Sum - areaPurchaseView.Herbicide - areaPurchaseView.Fungicide -
                                         areaPurchaseView.Insecticide - areaPurchaseView.Acaricide
                                         - areaPurchaseView.PlantGrowthRegulator - areaPurchaseView.HygienicInsecticide;
                areaPurchaseView.Count = GetStatisticsPurchaseCount(statisticsPurchaseCounts, areaLevel, areaId);
                statisticsPurchaseView.AreaPurchases.Add(areaPurchaseView);
            }
            statisticsPurchaseView.AreaPurchaseSum = new AreaPurchaseSumView()
            {
                Sum                  = statisticsPurchaseView.AreaPurchases.Sum(p => p.Sum),
                Count                = statisticsPurchaseView.AreaPurchases.Sum(p => p.Count),
                Other                = statisticsPurchaseView.AreaPurchases.Sum(p => p.Other),
                Acaricide            = statisticsPurchaseView.AreaPurchases.Sum(p => p.Acaricide),
                Fungicide            = statisticsPurchaseView.AreaPurchases.Sum(p => p.Fungicide),
                Herbicide            = statisticsPurchaseView.AreaPurchases.Sum(p => p.Herbicide),
                HygienicInsecticide  = statisticsPurchaseView.AreaPurchases.Sum(p => p.HygienicInsecticide),
                Insecticide          = statisticsPurchaseView.AreaPurchases.Sum(p => p.Insecticide),
                PlantGrowthRegulator = statisticsPurchaseView.AreaPurchases.Sum(p => p.PlantGrowthRegulator)
            };
            return(statisticsPurchaseView);
        }