From b269ce034ba9c8f49ab399efc08c22b1ed4e8ff9 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 27 Aug 2024 14:48:43 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=B8=B4=E6=97=B6=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E6=85=A2=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/BalanceService.cs | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) 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);