Răsfoiți Sursa

ext to ext alert

admin 2 ani în urmă
părinte
comite
9c50ef2e70

+ 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);
+            }
+        }
+    }
+}