コード例 #1
0
        /// <summary>
        /// 获取空数据
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        private StatisticsRetailView GetEmptyData(DateTime startTime, DateTime endTime)
        {
            var statisticsRetailView = new StatisticsRetailView()
            {
                AreaRetails   = new List <AreaRetailView>(),
                AreaRetailSum = new AreaRetailSumView(),
                StartTime     = startTime,
                EndTime       = endTime
            };

            return(statisticsRetailView);
        }
コード例 #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);
        }