/// <summary> /// 获取空数据 /// </summary> /// <returns></returns> private StatisticsStockView GetEmptyData() { var statisticsStockView = new StatisticsStockView() { AreaStocks = new List <AreaStockView>(), AreaStockSum = new AreaStockSumView() }; return(statisticsStockView); }
/// <summary> /// 获取StatisticsStockView /// </summary> /// <param name="dbStatisticsStockView"></param> /// <param name="type"></param> /// <param name="limitShops"></param> /// <param name="areaLevel"></param> /// <returns></returns> private async Task <StatisticsStockView> GetStatisticsStockView(List <DbStatisticsStockView> dbStatisticsStockView, int type, string limitShops, string areaLevel) { var statisticsStockView = new StatisticsStockView() { AreaStocks = new List <AreaStockView>(), AreaStockSum = new AreaStockSumView() }; if (dbStatisticsStockView == null || !dbStatisticsStockView.Any()) { return(statisticsStockView); } var areaIds = dbStatisticsStockView.Select(p => p.AreaId).Distinct().ToList(); var areas = await _areaBll.GetArea(areaIds); foreach (var areaId in areaIds) { var area = areas.FirstOrDefault(p => p.AreaId == areaId); var areaRetailView = new AreaStockView() { AreaId = areaId, AreaLevel = area?.Level, AreaName = area?.AreaName, Herbicide = GetGoodsCategoryNameWeight(areaId, dbStatisticsStockView, StatisticsCategoryName.Herbicide, type), Fungicide = GetGoodsCategoryNameWeight(areaId, dbStatisticsStockView, StatisticsCategoryName.Fungicide, type), Insecticide = GetGoodsCategoryNameWeight(areaId, dbStatisticsStockView, StatisticsCategoryName.Insecticide, type), Acaricide = GetGoodsCategoryNameWeight(areaId, dbStatisticsStockView, StatisticsCategoryName.Acaricide, type), PlantGrowthRegulator = GetGoodsCategoryNameWeight(areaId, dbStatisticsStockView, StatisticsCategoryName.PlantGrowthRegulator, type), HygienicInsecticide = GetGoodsCategoryNameWeight(areaId, dbStatisticsStockView, StatisticsCategoryName.HygienicInsecticide, type) }; areaRetailView.Sum = dbStatisticsStockView.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; statisticsStockView.AreaStocks.Add(areaRetailView); } statisticsStockView.AreaStockSum = new AreaStockSumView() { Sum = statisticsStockView.AreaStocks.Sum(p => p.Sum), Other = statisticsStockView.AreaStocks.Sum(p => p.Other), Acaricide = statisticsStockView.AreaStocks.Sum(p => p.Acaricide), Fungicide = statisticsStockView.AreaStocks.Sum(p => p.Fungicide), Herbicide = statisticsStockView.AreaStocks.Sum(p => p.Herbicide), HygienicInsecticide = statisticsStockView.AreaStocks.Sum(p => p.HygienicInsecticide), Insecticide = statisticsStockView.AreaStocks.Sum(p => p.Insecticide), PlantGrowthRegulator = statisticsStockView.AreaStocks.Sum(p => p.PlantGrowthRegulator) }; return(statisticsStockView); }