dss 2 жил өмнө
parent
commit
9f8da1ff88

+ 10 - 1
src/CallCenter.Application/Handlers/BaseHandler.cs

@@ -7,6 +7,7 @@ using CallCenter.Share.Dtos;
 using NewRock.Sdk;
 using CallCenter.Devices;
 using Microsoft.Extensions.Options;
+using CallCenter.Caches;
 
 namespace CallCenter.Application.Handlers
 {
@@ -14,10 +15,12 @@ namespace CallCenter.Application.Handlers
     {
         private readonly INewRockClient _newRockClient;
         private readonly IOptionsSnapshot<DeviceConfigs> _options;
-        public BaseHandler(INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options)
+        private readonly ICallCacheManager _callCacheManager;
+        public BaseHandler(INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,ICallCacheManager callCacheManager)
         {
             _newRockClient = newRockClient;
             _options = options;
+            _callCacheManager = callCacheManager;
         }
 
         public async Task HandlerIvr(IvrAnswer? runResult,Call model,CancellationToken cancellationToken)
@@ -73,6 +76,12 @@ namespace CallCenter.Application.Handlers
                                     Ext = new VisitorToExtQueueExt() { Id = telNo },
                                     Visitor = new VisitorToExtQueueVisitor() { Id = model.ConversationId }
                                 }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
+
+                                //处理队列记录
+                                var list = _callCacheManager.GetCallQueueList().ToList();
+                                list.Add(model);
+                                _callCacheManager.AddOrUpdateCallCache(list);
+
                                 break;
                             case ECallType.ExtToOuter:
                                 await _newRockClient.OuterToExt(new OuterToExtRequest()

+ 4 - 2
src/CallCenter.Application/Handlers/CallState/DtmfNotificationHandler.cs

@@ -1,4 +1,5 @@
-using CallCenter.Calls;
+using CallCenter.Caches;
+using CallCenter.Calls;
 using CallCenter.Devices;
 using CallCenter.Ivrs;
 using CallCenter.Notifications;
@@ -17,9 +18,10 @@ namespace CallCenter.Application.Handlers
         private readonly IIvrDomainService _ivrDomainService;
         private readonly ICallRepository _callRepository;
         private readonly ICallDetailRepository _callDetailRepository;
+        private readonly ICallCacheManager _callCacheManager;
 
 
-        public DtmfNotificationHandler(IIvrDomainService ivrDomainService, ICallDetailRepository callDetailRepository, ICallRepository callRepository, INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options) :base(newRockClient, options)
+        public DtmfNotificationHandler(IIvrDomainService ivrDomainService, ICallDetailRepository callDetailRepository, ICallRepository callRepository, INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,ICallCacheManager callCacheManager) :base(newRockClient, options,callCacheManager)
         {
             _ivrDomainService = ivrDomainService;
             _callDetailRepository = callDetailRepository;

+ 7 - 2
src/CallCenter.Application/Handlers/CallState/RingVisitorToExtNotificationHandler.cs

@@ -13,12 +13,14 @@ namespace CallCenter.Application.Handlers
         private readonly ICallDetailRepository _callDetailRepository;
         private readonly IRealtimeService _realtimeService;
         private readonly IUserCacheManager _userCacheManager;
-        public RingVisitorToExtNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository,IRealtimeService realtimeService,IUserCacheManager userCacheManager)
+        private readonly ICallCacheManager _callCacheManager;
+        public RingVisitorToExtNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository,IRealtimeService realtimeService, IUserCacheManager userCacheManager, ICallCacheManager callCacheManager)
         {
             _callRepository = callRepository;
             _callDetailRepository = callDetailRepository;
             _realtimeService = realtimeService;
             _userCacheManager = userCacheManager;
+            _callCacheManager = callCacheManager;
         }
 
 
@@ -43,10 +45,13 @@ namespace CallCenter.Application.Handlers
                 };
                 await _callDetailRepository.AddAsync(detail, cancellationToken);
 
+                //处理排队缓存数据
+                _callCacheManager.RemoveCallCache(model.Id);
+
                 //调用业务弹屏 通知前端
                 var workModel = _userCacheManager.GetWorkByTel(notification.TelNo);
                 if (workModel!=null) {
-                    await _realtimeService.RingAsync(workModel.UserId, new RingDto() { CallType = ECallType.VisitorCallIn, From = notification.Visitor.From, To = notification.Visitor.To, Id = model.Id },cancellationToken);
+                    await _realtimeService.RingAsync(workModel.UserId, new RingDto() { CallType = ECallType.VisitorCallIn, From = notification.Visitor.From, To = notification.Visitor.To, Id = model.Id, ConversationId = notification.Visitor.Id },cancellationToken);
                 }
             }
         }

+ 6 - 1
src/CallCenter.Application/Handlers/FlowControl/ByeVisitorAndExtNotificationHandler.cs

@@ -13,13 +13,15 @@ namespace CallCenter.Application.Handlers
         private readonly ICallDetailRepository _callDetailRepository;
         private readonly IRealtimeService _realtimeService;
         private readonly IUserCacheManager _userCacheManager;
+        private readonly ICallCacheManager _callCacheManager;
 
-        public ByeVisitorAndExtNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository,IRealtimeService realtimeService,IUserCacheManager userCacheManager)
+        public ByeVisitorAndExtNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository,IRealtimeService realtimeService, IUserCacheManager userCacheManager, ICallCacheManager callCacheManager)
         {
             _callRepository = callRepository;
             _callDetailRepository = callDetailRepository;
             _realtimeService = realtimeService;
             _userCacheManager = userCacheManager;
+            _callCacheManager = callCacheManager;
         }
 
         public async Task Handle(ByeVisitorAndExtNotification notification, CancellationToken cancellationToken)
@@ -46,6 +48,9 @@ namespace CallCenter.Application.Handlers
                 };
                 await _callDetailRepository.AddAsync(detail, cancellationToken);
 
+                //处理队列记录
+                _callCacheManager.RemoveCallCache(model.Id);
+
                 //调用业务通知 通知前端
                 var workModel = _userCacheManager.GetWorkByTel(notification.TelNo);
                 if (workModel!=null)

+ 4 - 2
src/CallCenter.Application/Handlers/FlowControl/EndOfAnnOuterToMenuNotificationHandler.cs

@@ -1,4 +1,5 @@
-using CallCenter.Calls;
+using CallCenter.Caches;
+using CallCenter.Calls;
 using CallCenter.Devices;
 using CallCenter.Ivrs;
 using CallCenter.Notifications;
@@ -14,7 +15,8 @@ namespace CallCenter.Application.Handlers
         private readonly ICallRepository _callRepository;
         private readonly ICallDetailRepository _callDetailRepository;
         private readonly IIvrDomainService _ivrDomainService;
-        public EndOfAnnOuterToMenuNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IIvrDomainService ivrDomainService, INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options) : base(newRockClient, options)
+        private readonly ICallCacheManager _callCacheManager;
+        public EndOfAnnOuterToMenuNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IIvrDomainService ivrDomainService, INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,ICallCacheManager callCacheManager) : base(newRockClient, options,callCacheManager)
         {
             _callRepository = callRepository;
             _callDetailRepository = callDetailRepository;

+ 4 - 2
src/CallCenter.Application/Handlers/FlowControl/EndOfAnnVisitorToMenuNotificationHandler.cs

@@ -1,4 +1,5 @@
-using CallCenter.Calls;
+using CallCenter.Caches;
+using CallCenter.Calls;
 using CallCenter.Devices;
 using CallCenter.Ivrs;
 using CallCenter.Notifications;
@@ -15,8 +16,9 @@ namespace CallCenter.Application.Handlers.FlowControl
         private readonly ICallRepository _callRepository;
         private readonly ICallDetailRepository _callDetailRepository;
         private readonly IIvrDomainService _ivrDomainService;
+        private readonly ICallCacheManager _callCacheManager;
 
-        public EndOfAnnVisitorToMenuNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IIvrDomainService ivrDomainService,INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options):base(newRockClient,options)
+        public EndOfAnnVisitorToMenuNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IIvrDomainService ivrDomainService,INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,ICallCacheManager callCacheManager):base(newRockClient,options,callCacheManager)
         {
             _callRepository = callRepository;
             _callDetailRepository = callDetailRepository;

+ 18 - 11
src/CallCenter.Application/Handlers/FlowControl/IncomingNotificationHandler.cs

@@ -28,13 +28,14 @@ namespace CallCenter.Application.Handlers
         private readonly ITypedCache<WorkTimeSettings> _worktimeCache;
         private readonly IOptionsSnapshot<WorkTimeSettings> _worktimeOptions;
         private readonly ILogger<IncomingNotificationHandler> _logger;
+        private readonly ICallCacheManager _callCacheManager;
 
         public IncomingNotificationHandler(
             ICallRepository callRepository, ICallDetailRepository callDetailRepository,
             ISystemSettingCacheManager systemSettingCacheManager, IIvrCacheManager ivrCacheManager,
             INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,
             ITypedCache<WorkTimeSettings> worktimeCache, IOptionsSnapshot<WorkTimeSettings> worktimeOptions,
-            ILogger<IncomingNotificationHandler> logger)
+            ILogger<IncomingNotificationHandler> logger, ICallCacheManager callCacheManager)
         {
             _callRepository = callRepository;
             _callDetailRepository = callDetailRepository;
@@ -45,6 +46,7 @@ namespace CallCenter.Application.Handlers
             _worktimeCache = worktimeCache;
             _worktimeOptions = worktimeOptions;
             _logger = logger;
+            _callCacheManager = callCacheManager;
         }
 
         public async Task Handle(IncomingNotification notification, CancellationToken cancellationToken)
@@ -76,16 +78,16 @@ namespace CallCenter.Application.Handlers
                 //var ivrList = _ivrCacheManager.GetIvrs();
                 //var ivr = ivrList.First(x => x.IvrCategoryId == "08da9b9f-a35d-4ade-8ea7-55e8abbcdefd" && x.IsRoot);
 
-                var ivr = GetCorrectIvr();
-                _logger.LogInformation("transfer to ivr.no: {ivrNo}", ivr.No);
-                await _newRockClient.VisitorToMenu(
-                    new VisitorToMenuRequest()
-                    {
-                        Attribute = "Connect",
-                        Menu = new VisitorToMenuMenu() { Id = ivr.No },
-                        Visitor = new VisitorToMenuVisitor() { Id = notification.Visitor.Id }
-                    },
-                    _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
+                //var ivr = GetCorrectIvr();
+                //_logger.LogInformation("transfer to ivr.no: {ivrNo}", ivr.No);
+                //await _newRockClient.VisitorToMenu(
+                //    new VisitorToMenuRequest()
+                //    {
+                //        Attribute = "Connect",
+                //        Menu = new VisitorToMenuMenu() { Id = ivr.No },
+                //        Visitor = new VisitorToMenuVisitor() { Id = notification.Visitor.Id }
+                //    },
+                //    _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
 
                 var correct = GetCorrectIvr(notification.Visitor.To);
                 switch (correct.eCorrectIvr)
@@ -111,6 +113,11 @@ namespace CallCenter.Application.Handlers
                             Group= new VisitorToGroupQueueGroup() { Id = correct.ReturnValue }
                         },
                         _options.Value.ReceiveKey,_options.Value.Expired,cancellationToken);
+
+                        //处理队列记录
+                        var list = _callCacheManager.GetCallQueueList().ToList();
+                        list.Add(model);
+                        _callCacheManager.AddOrUpdateCallCache(list);
                         break;
                     default:
                         break;

+ 40 - 0
src/CallCenter/Caches/CallCacheManager.cs

@@ -0,0 +1,40 @@
+using CallCenter.Calls;
+using XF.Domain.Cache;
+
+namespace CallCenter.Caches
+{
+    public class CallCacheManager : ICallCacheManager
+    {
+        private readonly ITypedCache<IReadOnlyList<Call>> _cacheCall;
+        private const string CallKey = "CallQueue";
+
+        public CallCacheManager(ITypedCache<IReadOnlyList<Call>> cacheCall)
+        {
+            _cacheCall = cacheCall;
+        }
+
+        public void AddOrUpdateCallCache(List<Call> list)
+        {
+            _cacheCall.AddOrUpdate(CallKey, list);
+        }
+
+        public IReadOnlyList<Call> GetCallQueueList()
+        {
+            return _cacheCall.Get(CallKey)??new List<Call>();
+        }
+
+        public void RemoveCallCache(string id)
+        {
+            var list = _cacheCall.Get(CallKey)?.ToList();
+            if (list != null)
+            {
+                var model = list.First(x => x.Id == id);
+                if (model != null)
+                {
+                    list.Remove(model);
+                    _cacheCall.AddOrUpdate(CallKey, list);
+                }
+            }
+        }
+    }
+}

+ 13 - 0
src/CallCenter/Caches/ICallCacheManager.cs

@@ -0,0 +1,13 @@
+using CallCenter.Calls;
+
+namespace CallCenter.Caches
+{
+    public interface ICallCacheManager
+    {
+        IReadOnlyList<Call> GetCallQueueList();
+
+        void AddOrUpdateCallCache(List<Call> list);
+
+        void RemoveCallCache(string id);
+    }
+}

+ 1 - 0
src/CallCenter/Realtimes/IRealtimeService.cs

@@ -30,6 +30,7 @@ namespace CallCenter.Realtimes
 
         public string To { get; set; }
         public ECallType CallType { get; set; }
+        public string ConversationId { get; set; }
     }
 
     public record AnseredDto