/// <summary> /// 获取采购统计信息 /// </summary> /// <param name="startTime"></param> /// <param name="endTime"></param> /// <param name="statisticsPurchaseShop"></param> /// <param name="type"></param> /// <param name="areaLevel"></param> /// <returns></returns> private async Task <StatisticsPurchaseShopView> GetStatisticsPurchaseShopView(DateTime startTime, DateTime endTime, Tuple <IEnumerable <DbStatisticsPurchaseShopView>, int> statisticsPurchaseShop, int type, string areaLevel) { var statisticsPurchaseShopView = new StatisticsPurchaseShopView() { AreaShopPurchases = new List <AreaShopPurchaseView>(), StartTime = startTime, EndTime = endTime }; if (statisticsPurchaseShop == null || statisticsPurchaseShop.Item1 == null || !statisticsPurchaseShop.Item1.Any()) { return(statisticsPurchaseShopView); } var statisticsPurchase = statisticsPurchaseShop.Item1.ToList(); var areaIds = statisticsPurchase.Select(p => p.AreaId).Distinct().ToList(); var areas = await _areaBll.GetArea(areaIds); var shopIds = statisticsPurchase.Select(p => p.ShopId).Distinct().ToList(); var statisticsRetailShopCounts = await _reportBll.GetStatisticsPurchaseCount(string.Join(',', shopIds), startTime, endTime); foreach (var shopId in shopIds) { var statisticsPurchaseAboutShopId = _reportBll.GetStatisticsPurchaseByShop(shopId.ToString(), startTime, endTime).Result; var shop = statisticsPurchase.First(p => p.ShopId == shopId); var area = areas.FirstOrDefault(p => p.AreaId == shop.AreaId); var areaRetailView = new AreaShopPurchaseView() { AreaId = shop.AreaId, AreaLevel = area?.Level, AreaName = area?.AreaName, Herbicide = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.Herbicide, type), Fungicide = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.Fungicide, type), Insecticide = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.Insecticide, type), Acaricide = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.Acaricide, type), PlantGrowthRegulator = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.PlantGrowthRegulator, type), HygienicInsecticide = GetGoodsCategoryNameWeight(statisticsPurchaseAboutShopId, StatisticsCategoryName.HygienicInsecticide, type), ShopName = shop.ShopName, ShopId = shop.ShopId }; areaRetailView.Sum = statisticsPurchase.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; areaRetailView.Count = GetStatisticsPurchaseCount(statisticsRetailShopCounts, shop.ShopId, areaLevel, shop.AreaId); statisticsPurchaseShopView.AreaShopPurchases.Add(areaRetailView); } return(statisticsPurchaseShopView); }
/// <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); }