Ver Fonte

callqueue

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

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

@@ -1,6 +1,7 @@
 using CallCenter.Api.Realtimes;
 using CallCenter.BlackLists;
 using CallCenter.Caches;
+using CallCenter.Calls;
 using CallCenter.Devices;
 using CallCenter.Ivrs;
 using CallCenter.Realtimes;
@@ -27,6 +28,7 @@ namespace CallCenter.Api.Controllers
         private readonly IBlacklistDomainService _blacklistDomainService;
         private readonly IIvrDomainService _ivrDomainService;
         private readonly ICallCacheManager _callCacheManager;
+        private readonly ICallRepository _callRepository;
         //private readonly ITypedCache<List<User>> _cache;
         //private readonly ICacheManager<User> _cache;
 
@@ -43,7 +45,8 @@ namespace CallCenter.Api.Controllers
             IRealtimeService realtimeService,
             IBlacklistDomainService blacklistDomainService,
             IIvrDomainService ivrDomainService,
-            ICallCacheManager callCacheManager
+            ICallCacheManager callCacheManager,
+            ICallRepository callRepository
             )
         {
             _logger = logger;
@@ -56,6 +59,7 @@ namespace CallCenter.Api.Controllers
             _blacklistDomainService = blacklistDomainService;
             _ivrDomainService = ivrDomainService;
             _callCacheManager = callCacheManager;
+            _callRepository = callRepository;
         }
 
         [HttpGet]
@@ -140,7 +144,10 @@ namespace CallCenter.Api.Controllers
         [HttpGet("callqueue")]
         public async Task CallQueueTest()
         {
+            var call = await _callRepository.GetAsync("08db40b1-c96a-4b2b-8b9d-ea0e3fdabdb0", HttpContext.RequestAborted);
+            _callCacheManager.AddCallCache(call);
             await _realtimeService.CallQueueAsync(_callCacheManager.GetCallQueueList(),HttpContext.RequestAborted);
+            _callCacheManager.RemoveCallCache(call.Id);
         }
 
 

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

@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.SignalR;
 using System.Text.Json;
 using XF.Domain.Dependency;
 using XF.Domain.Exceptions;
+using static CallCenter.Caches.CallCacheManager;
 
 namespace CallCenter.Api.Realtimes
 {
@@ -77,7 +78,7 @@ namespace CallCenter.Api.Realtimes
         /// <param name="count"></param>
         /// <param name="cancellationToken"></param>
         /// <returns></returns>
-        public async Task CallQueueAsync(List<string> list, CancellationToken cancellationToken)
+        public async Task CallQueueAsync(List<CallDtoRedis> list, CancellationToken cancellationToken)
         {
             var works = _userCacheManager.GetWorks();
             if (works != null)

+ 12 - 5
src/CallCenter/Caches/CallCacheManager.cs

@@ -6,22 +6,29 @@ namespace CallCenter.Caches
 {
     public class CallCacheManager : ICallCacheManager, IScopeDependency
     {
-        private readonly ITypedCache<string> _cacheCall;
+        private readonly ITypedCache<CallDtoRedis> _cacheCall;
 
-        public CallCacheManager(ITypedCache<string> cacheCall)
+        public class CallDtoRedis
+        {
+            public string FromNo { get; set; }
+            public string ToNo { get; set; }
+            public DateTime InGroupTime { get; set; }
+        }
+
+        public CallCacheManager(ITypedCache<CallDtoRedis> cacheCall)
         {
             _cacheCall = cacheCall;
         }
 
         public void AddCallCache(Call call)
         {
-            _cacheCall.Set(call.Id, call.FromNo);
+            _cacheCall.Set(call.Id,  new CallDtoRedis{ FromNo =call.FromNo,ToNo = call.ToNo, InGroupTime = DateTime.Now });
         }
 
-        public List<string> GetCallQueueList()
+        public List<CallDtoRedis> GetCallQueueList()
         {
             var list = _cacheCall.GetListByPrefix().ToList();
-            return list==null ? new List<string>() : list;
+            return list==null ? new List<CallDtoRedis>() : list;
         }
 
         public void RemoveCallCache(string id)

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

@@ -1,10 +1,11 @@
 using CallCenter.Calls;
+using static CallCenter.Caches.CallCacheManager;
 
 namespace CallCenter.Caches
 {
     public interface ICallCacheManager
     {
-        List<string> GetCallQueueList();
+        List<CallDtoRedis> GetCallQueueList();
 
         void AddCallCache(Call call);
 

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

@@ -5,6 +5,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using static CallCenter.Caches.CallCacheManager;
 
 namespace CallCenter.Realtimes
 {
@@ -16,7 +17,7 @@ namespace CallCenter.Realtimes
 
         Task ByeAsync(string userId, ByeDto dto, CancellationToken cancellationToken);
 
-        Task CallQueueAsync(List<string> list, CancellationToken cancellationToken);
+        Task CallQueueAsync(List<CallDtoRedis> list, CancellationToken cancellationToken);
 
         Task AlertAsync(string userId, AlertDto dto, CancellationToken cancellationToken);