Ver Fonte

callqueue

admin há 2 anos atrás
pai
commit
6e6a0c3619

+ 1 - 1
src/CallCenter.Api/Controllers/TestController.cs

@@ -137,7 +137,7 @@ namespace CallCenter.Api.Controllers
         [HttpGet("callqueue")]
         public async Task CallQueueTest()
         {
-            await _realtimeService.CallQueueAsync(new List<Calls.Call>(),HttpContext.RequestAborted);
+            await _realtimeService.CallQueueAsync(new List<string>(),HttpContext.RequestAborted);
         }
 
 

+ 1 - 1
src/CallCenter.Api/Realtimes/RealtimeService.cs

@@ -75,7 +75,7 @@ namespace CallCenter.Api.Realtimes
         /// <param name="count"></param>
         /// <param name="cancellationToken"></param>
         /// <returns></returns>
-        public async Task CallQueueAsync(List<Call> list, CancellationToken cancellationToken)
+        public async Task CallQueueAsync(List<string> list, CancellationToken cancellationToken)
         {
             var works = _userCacheManager.GetWorks();
             if (works != null)

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

@@ -109,7 +109,7 @@ namespace CallCenter.Application.Handlers
                         }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
 
                         //处理队列记录 TODO
-                        //_callCacheManager.AddCallCache(model);
+                        _callCacheManager.AddCallCache(model);
                         break;
                     case EIvrAnswerType.Out:
                         var phoneNo = ivrAnswer.Content;

+ 0 - 1
src/CallCenter.Application/Handlers/CallState/DtmfNotificationHandler.cs

@@ -19,7 +19,6 @@ 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,ICallCacheManager callCacheManager) :base(newRockClient, options,callCacheManager, callRepository)

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

@@ -48,7 +48,8 @@ namespace CallCenter.Application.Handlers
                 await _callDetailRepository.AddAsync(detail, cancellationToken);
 
                 //处理排队缓存数据 TODO
-                //_callCacheManager.RemoveCallCache(model.Id);
+                _callCacheManager.RemoveCallCache(model.Id);
+                await _realtimeService.CallQueueAsync(_callCacheManager.GetCallQueueList(), cancellationToken);
 
                 //调用业务弹屏 通知前端
                 var workModel = _userCacheManager.GetWorkByTel(notification.TelNo);

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

@@ -49,7 +49,8 @@ namespace CallCenter.Application.Handlers
                 await _callDetailRepository.AddAsync(detail, cancellationToken);
 
                 //处理队列记录 TODO
-                //_callCacheManager.RemoveCallCache(model.Id);
+                _callCacheManager.RemoveCallCache(model.Id);
+                await _realtimeService.CallQueueAsync(_callCacheManager.GetCallQueueList(), cancellationToken);
 
                 //查询应答分机分机号
                 var callDetailAnswer = await _callDetailRepository.GetAsync(x => x.CallId == model.Id && x.EventName == "ANSWER", true, d => d.CreationTime);

+ 2 - 0
src/CallCenter.Application/Handlers/FlowControl/ByeVisitorAndMenuNotificationHandler.cs

@@ -18,6 +18,8 @@ namespace CallCenter.Application.Handlers.FlowControl
         private readonly ICallDetailRepository _callDetailRepository;
         private readonly IRealtimeService _realtimeService;
         private readonly IUserCacheManager _userCacheManager;
+
+
         public ByeVisitorAndMenuNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository,IRealtimeService realtimeService,IUserCacheManager userCacheManager)
         {
             _callRepository = callRepository;

+ 2 - 1
src/CallCenter.Application/Handlers/FlowControl/ByeVisitorOffNotificationHandler.cs

@@ -49,7 +49,8 @@ namespace CallCenter.Application.Handlers
                 await _callDetailRepository.AddAsync(detail, cancellationToken);
 
                 //处理队列记录 TODO
-                //_callCacheManager.RemoveCallCache(model.Id);
+                _callCacheManager.RemoveCallCache(model.Id);
+                await _realtimeService.CallQueueAsync(_callCacheManager.GetCallQueueList(), cancellationToken);
 
                 //查询应答分机分机号
                 var callDetailAnswer = await _callDetailRepository.GetAsync(x => x.CallId == model.Id && x.EventName == "ANSWER", true, d => d.CreationTime);

+ 1 - 1
src/CallCenter.Application/Handlers/FlowControl/IncomingNotificationHandler.cs

@@ -123,7 +123,7 @@ namespace CallCenter.Application.Handlers
                             model.InGroupTime = DateTime.Now;
                             await _callRepository.UpdateAsync(model, cancellationToken);
                             //处理队列记录 TODO
-                            //_callCacheManager.AddCallCache(model);
+                            _callCacheManager.AddCallCache(model);
                             break;
                         default:
                             break;

+ 7 - 26
src/CallCenter/Caches/CallCacheManager.cs

@@ -6,46 +6,27 @@ namespace CallCenter.Caches
 {
     public class CallCacheManager : ICallCacheManager, IScopeDependency
     {
-        private readonly ITypedCache<List<Call>> _cacheCall;
-        private const string CallKey = "CallQueue";
+        private readonly ITypedCache<string> _cacheCall;
 
-        public CallCacheManager(ITypedCache<List<Call>> cacheCall)
+        public CallCacheManager(ITypedCache<string> cacheCall)
         {
             _cacheCall = cacheCall;
         }
 
         public void AddCallCache(Call call)
         {
-            var list = GetCallQueueList();
-            if (list==null)
-            {
-                list = new List<Call>();
-            }
-            list.Add(call);
-            _cacheCall.Set(CallKey, list);
+            _cacheCall.Set(call.Id, call.FromNo);
         }
 
-        public List<Call>? GetCallQueueList()
+        public List<string> GetCallQueueList()
         {
-            var list = _cacheCall.GetOrSet(CallKey, k =>
-            {
-                return new List<Call>();
-            });
-            return list;
+            var list = _cacheCall.GetListByPrefix().ToList();
+            return list==null ? new List<string>() : list;
         }
 
         public void RemoveCallCache(string id)
         {
-            var list = _cacheCall.Get(CallKey)?.ToList();
-            if (list != null)
-            {
-                var model = list.FirstOrDefault(x => x.Id == id);
-                if (model != null)
-                {
-                    list.Remove(model);
-                    _cacheCall.Set(CallKey, list);
-                }
-            }
+            _cacheCall.Remove(id);
         }
     }
 }

+ 1 - 1
src/CallCenter/Caches/ICallCacheManager.cs

@@ -4,7 +4,7 @@ namespace CallCenter.Caches
 {
     public interface ICallCacheManager
     {
-        List<Call>? GetCallQueueList();
+        List<string> GetCallQueueList();
 
         void AddCallCache(Call call);
 

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

@@ -16,7 +16,7 @@ namespace CallCenter.Realtimes
 
         Task ByeAsync(string userId, ByeDto dto, CancellationToken cancellationToken);
 
-        Task CallQueueAsync(List<Call> list, CancellationToken cancellationToken);
+        Task CallQueueAsync(List<string> list, CancellationToken cancellationToken);
 
         Task AlertAsync(string userId, AlertDto dto, CancellationToken cancellationToken);