diff --git a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs index baaae1c9..537d8902 100644 --- a/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs +++ b/Src/Dlhis.Canteen/Order/Services/Implements/BalanceService.cs @@ -436,14 +436,12 @@ public class BalanceService : IBalanceService .Where(x => x.Status == CanteenBusinessPlaceStatusEnumType.Opened) .ToListAsync(); - //所有消费数据 - var bs = await _dbContext.Queryable() - .Where(x => x.Type == BalanceRecordTypeEnumType.Out) - .Where(x => x.Status == BalanceRecordStatusEnumType.Valid) - .ToListAsync(); - //可消费人数 - var consumerable = bs.DistinctBy(x => x.UserCode).Count(); + var consumerable = await _dbContext.Queryable() + .Where(x => x.Type == BalanceRecordTypeEnumType.Out && x.Status == BalanceRecordStatusEnumType.Valid) + .Select(x => x.UserCode) + .Distinct() + .CountAsync(); //消费走势 var months = await GetConsumptionTrendsAsync(1); @@ -655,11 +653,12 @@ public class BalanceService : IBalanceService private async Task> GetConsumptionTrendsAsync(int type) { - var bs = await _dbContext.Queryable() - .Where(x => x.Type == BalanceRecordTypeEnumType.Out) - .ToListAsync(); + //todo + //消费总额 - var totalAmount = Math.Round(Math.Abs(bs.Sum(x => x.Amount)), 2); + var totalAmount = await _dbContext.Queryable() + .Where(x => x.Type == BalanceRecordTypeEnumType.Out && x.Status == BalanceRecordStatusEnumType.Valid) + .SumAsync(x => SqlFunc.Abs(x.Amount)); var list = new List(); if (type == 1) @@ -669,13 +668,10 @@ public class BalanceService : IBalanceService foreach (var month in months) { - var currentAmount = Math.Round(Math.Abs(bs.Where(x => x.CostDateTime.ToString("yyyy-MM") == month) - .Sum(x => x.Amount)), 2); - var res = new ConsumptionTrendResponse { DateTime = month, - CurrentAmount = currentAmount, + CurrentAmount = 0, TotalAmount = totalAmount }; list.Add(res); @@ -688,13 +684,10 @@ public class BalanceService : IBalanceService foreach (var day in days) { - var currentAmount = Math.Round(Math.Abs(bs.Where(x => x.CostDateTime.ToString("yyyy-MM-dd") == day) - .Sum(x => x.Amount)), 2); - var res = new ConsumptionTrendResponse { DateTime = day, - CurrentAmount = currentAmount, + CurrentAmount = 0, TotalAmount = totalAmount }; list.Add(res);