Browse Source

重构回访统计逻辑,优化查询性能

重构了 `WaitVisitd` 的计算逻辑,将其从内联查询中分离出来,改为单独的查询实现,提升代码可读性和维护性。
重写了 `listOrg` 的查询逻辑,增加多表关联和更复杂的筛选条件,优化了查询的准确性和灵活性。
删除了原有的冗余代码,简化了逻辑结构。
田爽 4 days ago
parent
commit
4e79d10aab

+ 11 - 3
src/Hotline.Api/Controllers/Bi/BiOrderController.cs

@@ -3267,11 +3267,19 @@ namespace Hotline.Api.Controllers.Bi
                   CallVisitd = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitState == EVisitState.Visited && x.VisitType == EVisitType.CallVisit, 1, 0)),// 已回访--电话
                   SmsVisitd = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitState == EVisitState.Visited && x.VisitType == EVisitType.SmsVisit, 1, 0)),//已回访--短信
                   OtherVisitd = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitState == EVisitState.Visited && x.VisitType != EVisitType.CallVisit && x.VisitType != EVisitType.SmsVisit, 1, 0)),//其他回访
-                  WaitVisitd = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitState != EVisitState.None && x.VisitState != EVisitState.Visited, 1, 0)),//待回访
+                  //WaitVisitd = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitState != EVisitState.None && x.VisitState != EVisitState.Visited, 1, 0)),//待回访
               }).FirstAsync();
 
-            //部门
-            var listOrg = await _orderVisitDetailRepository.Queryable()
+            var WaitVisitd = await _orderVisitRepository.Queryable()
+			  .LeftJoin<Order>((x, o) => x.OrderId == o.Id)
+			  .WhereIF(IdentityType.HasValue, (x, o) => o.IdentityType == IdentityType)
+			  .Where((x, o) => x.CreationTime >= StartTime && x.CreationTime <= EndTime).Select((x, o) => 
+                    SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitState != EVisitState.None && x.VisitState != EVisitState.Visited, 1, 0)) //待回访
+               ).FirstAsync();
+            centerReportVisitd.WaitVisitd = WaitVisitd;
+
+			//部门
+			var listOrg = await _orderVisitDetailRepository.Queryable()
                 .LeftJoin<OrderVisit>((x, ov) => x.VisitId == ov.Id)
                 .LeftJoin<Order>((x, ov, o) => ov.OrderId == o.Id)
                 .WhereIF(IdentityType.HasValue, (x, ov, o) => o.IdentityType == IdentityType)

+ 1 - 1
src/Hotline.Api/config/appsettings.Development.json

@@ -1,7 +1,7 @@
 {
   "AllowedHosts": "*",
   "AppConfiguration": {
-    "AppScope": "YiBin",
+    "AppScope": "LuZhou",
     "YiBin": {
       "AreaCode": "511500",
       "CallCenterType": "TianRun", //XunShi、WeiErXin、TianRun、XingTang