浏览代码

更新待回访查询逻辑及赋值方式

移除原 `WaitVisitd` 查询逻辑,新增 `waitVisitd` 查询逻辑:
- 使用 `LeftJoin` 和 `WhereIF` 增强查询条件。
- 通过 `SqlFunc.AggregateSum` 计算待回访数量。
更新 `centerReportVisitd.WaitVisitd` 的赋值为新查询结果。
田爽 4 天之前
父节点
当前提交
9c057b59b3
共有 1 个文件被更改,包括 13 次插入5 次删除
  1. 13 5
      src/Hotline.Api/Controllers/Bi/BiOrderController.cs

+ 13 - 5
src/Hotline.Api/Controllers/Bi/BiOrderController.cs

@@ -3031,11 +3031,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>((it, o) => it.VisitId == o.Id)
                 .Where((it, o) => it.VisitTarget == EVisitTarget.Org && o.VisitTime >= StartTime && o.VisitTime <= EndTime && o.VisitState == EVisitState.Visited)
                  .Select((it, o) => new Satisfaction
@@ -3270,13 +3278,13 @@ namespace Hotline.Api.Controllers.Bi
                   //WaitVisitd = SqlFunc.AggregateSum(SqlFunc.IIF(x.VisitState != EVisitState.None && x.VisitState != EVisitState.Visited, 1, 0)),//待回访
               }).FirstAsync();
 
-            var WaitVisitd = await _orderVisitRepository.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;
+            centerReportVisitd.WaitVisitd = waitVisitd;
 
 			//部门
 			var listOrg = await _orderVisitDetailRepository.Queryable()