Dun.Jason 5 місяців тому
батько
коміт
e119fba298
1 змінених файлів з 16 додано та 8 видалено
  1. 16 8
      src/Hotline.Api/Controllers/WebPortalController.cs

+ 16 - 8
src/Hotline.Api/Controllers/WebPortalController.cs

@@ -959,14 +959,22 @@ namespace Hotline.Api.Controllers
         {
             var startDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
             var endDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
-            GetStatistDto getStatistDto = new()
-            {
-                AllCount = await _orderRepository.Queryable().Where(p => p.Status > EOrderStatus.WaitForAccept).CountAsync(),
-                AllTrandCount = await _orderRepository.Queryable().Where(p => p.Status >= EOrderStatus.Filed).CountAsync(),
-                DayCount = await _orderRepository.Queryable().Where(p => p.StartTime >= startDate && p.StartTime <= endDate && p.Status > EOrderStatus.WaitForAccept).CountAsync(),
-                DayTrandCount = await _orderRepository.Queryable().Where(p => p.ActualHandleTime >= startDate && p.ActualHandleTime <= endDate && p.Status >= EOrderStatus.Filed).CountAsync()
-            };
-
+            //GetStatistDto getStatistDto = new()
+            //{
+            //    AllCount = await _orderRepository.Queryable().Where(p => p.Status > EOrderStatus.WaitForAccept).CountAsync(),
+            //    AllTrandCount = await _orderRepository.Queryable().Where(p => p.Status >= EOrderStatus.Filed).CountAsync(),
+            //    DayCount = await _orderRepository.Queryable().Where(p => p.StartTime >= startDate && p.StartTime <= endDate && p.Status > EOrderStatus.WaitForAccept).CountAsync(),
+            //    DayTrandCount = await _orderRepository.Queryable().Where(p => p.ActualHandleTime >= startDate && p.ActualHandleTime <= endDate && p.Status >= EOrderStatus.Filed).CountAsync()
+            //};
+            var getStatistDto = await _orderRepository.Queryable()
+          .Select(p => new GetStatistDto
+          {
+              AllCount = SqlFunc.AggregateSum(SqlFunc.IIF(p.Status > EOrderStatus.WaitForAccept, 1, 0)),
+              AllTrandCount = SqlFunc.AggregateSum(SqlFunc.IIF(p.Status >= EOrderStatus.Filed, 1, 0)),
+              DayCount = SqlFunc.AggregateSum(SqlFunc.IIF(p.StartTime >= startDate && p.StartTime <= endDate && p.Status > EOrderStatus.WaitForAccept, 1, 0)),
+              DayTrandCount = SqlFunc.AggregateSum(SqlFunc.IIF(p.ActualHandleTime >= startDate && p.ActualHandleTime <= endDate && p.Status >= EOrderStatus.Filed, 1, 0)),
+          })
+          .FirstAsync();
             return OpenResponse.Ok(WebPortalDeResponse<GetStatistDto>.Success(getStatistDto));
         }
         #endregion