fix 优化查询

This commit is contained in:
2025-10-14 14:29:37 +08:00
parent 62e3fbe37b
commit a4c45f3ba8
2 changed files with 14 additions and 7 deletions

View File

@@ -185,13 +185,20 @@ public class BalanceSummaryService : IBalanceSummaryService
})
.ToPageListAsync(request);
var amount = await QueryableShiftAndBusinessPlaceAnalysis(request).SumAsync(record => SqlFunc.Abs(record.Amount));
var userCount = await QueryableShiftAndBusinessPlaceAnalysis(request).Select(record => record.UserCode).Distinct().CountAsync();
var data = await QueryableShiftAndBusinessPlaceAnalysis(request)
.Select(record => new
{
Amount = SqlFunc.AggregateSum(record.Amount),
UserCount = SqlFunc.AggregateDistinctCount(record.UserCode),
CostCount = SqlFunc.AggregateCount(record.Id),
})
.FirstAsync();
return new ShiftAndBusinessPlaceAnalysisResponse
{
Amount = amount,
Total = userCount,
Amount = data?.Amount ?? 0,
UserCount = data?.UserCount ?? 0,
CostCount = data?.CostCount ?? 0,
Pagination = page,
};