瀏覽代碼

ext to ext alert

admin 2 年之前
父節點
當前提交
9c50ef2e70
共有 1 個文件被更改,包括 37 次插入0 次删除
  1. 37 0
      src/CallCenter.Application/Handlers/CallState/AlertExtToExtNotificationHandler.cs

+ 37 - 0
src/CallCenter.Application/Handlers/CallState/AlertExtToExtNotificationHandler.cs

@@ -0,0 +1,37 @@
+using CallCenter.Caches;
+using CallCenter.Notifications;
+using CallCenter.Realtimes;
+using MediatR;
+
+
+namespace CallCenter.Application.Handlers.CallState
+{
+    public class AlertExtToExtNotificationHandler : INotificationHandler<AlertExtToExtNotification>
+    {
+        private readonly IRealtimeService _realtimeService;
+        private readonly IUserCacheManager _userCacheManager;
+
+        public AlertExtToExtNotificationHandler(IRealtimeService realtimeService,IUserCacheManager userCacheManager)
+        {
+            _realtimeService = realtimeService;
+            _userCacheManager = userCacheManager;
+        }
+
+        public async Task Handle(AlertExtToExtNotification notification, CancellationToken cancellationToken)
+        {
+            //通知前端主叫
+            //获取主叫工作信息
+            var fromWork = _userCacheManager.GetWorkByTel(notification.FromTelNo);
+            if (fromWork != null)
+            {
+                await _realtimeService.AlertAsync(fromWork.UserId, new AlertDto() { Id = notification.FromTelNo,From= notification.FromTelNo, To= notification.ToTelNo, CallType= Share.Enums.ECallType.ExtToExt }, cancellationToken);
+            }
+            //通知前端被叫
+            var toWork = _userCacheManager.GetWorkByTel(notification.ToTelNo);
+            if (toWork != null)
+            {
+                await _realtimeService.AlertAsync(toWork.UserId, new AlertDto() { Id = notification.ToTelNo, From = notification.FromTelNo, To = notification.ToTelNo, CallType = Share.Enums.ECallType.ExtToExt }, cancellationToken);
+            }
+        }
+    }
+}