/// <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="request"></param> /// <returns></returns> private async Task <ResponseBase> GetStatisticsPurchaseDefault(GetStatisticsPurchaseRequest request) { List <DbStatisticsPurchaseView> statisticsPurchase = 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(); statisticsPurchase = await _reportBll.GetStatisticsPurchase(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); statisticsPurchase = await _reportBll.GetStatisticsPurchase(areaInfo.Item1, statisticsTime.Item1, statisticsTime.Item2, areaInfo.Item2); arealevel = areaInfo.Item2; } break; case (int)DataLimitTypeEnum.Shop: limitShops = _appTicket.DataLimitShop; if (!string.IsNullOrEmpty(_appTicket.DataLimitShop)) { statisticsPurchase = await _reportBll.GetStatisticsPurchaseByShop(_appTicket.DataLimitShop, statisticsTime.Item1, statisticsTime.Item2); arealevel = AreaLevelEnum.Street; } break; } var result = await GetStatisticsPurchaseView(statisticsTime.Item1, statisticsTime.Item2, statisticsPurchase, request.Type, limitShops, arealevel); return(ResponseBase.Success(result)); }