瀏覽代碼

first commit

admin 1 年之前
父節點
當前提交
eecfc5d062

+ 3 - 2
src/CallCenter.Api/Controllers/TestController.cs

@@ -145,9 +145,9 @@ namespace CallCenter.Api.Controllers
         public async Task CallQueueTest()
         {
             var call = await _callRepository.GetAsync("08db40b1-c96a-4b2b-8b9d-ea0e3fdabdb0", HttpContext.RequestAborted);
-            _callCacheManager.AddCallCache(call);
+            _callCacheManager.AddCallCache(call,"1");
             await _realtimeService.CallQueueAsync(_callCacheManager.GetCallQueueList(),HttpContext.RequestAborted);
-            _callCacheManager.RemoveCallCache(call.Id);
+            //_callCacheManager.RemoveCallCache(call.Id);
         }
 
 
@@ -158,5 +158,6 @@ namespace CallCenter.Api.Controllers
             var answer = await _ivrDomainService.GetVoiceEndAnswerAsync("3", HttpContext.RequestAborted);
             Console.WriteLine(answer.Content);
         }
+
     }
 }

+ 20 - 0
src/CallCenter.Api/Controllers/TestSdkController.cs

@@ -1,4 +1,5 @@
 using CallCenter.Caches;
+using CallCenter.Calls;
 using CallCenter.Devices;
 using CallCenter.Share.Enums;
 using CallCenter.Tels;
@@ -27,6 +28,7 @@ namespace CallCenter.Api.Controllers
         private readonly INewRockClient _client;
         private readonly ILogger<TestController> _logger;
         private readonly IOptionsSnapshot<DeviceConfigs> _options;
+        private readonly IOptionsSnapshot<QueueVoiceConfig> _queueVoiceConfig;
         private readonly ITelCacheManager _telCacheManager;
         private readonly ITelGroupRepository _telGroupRepository;
         private readonly ITelRestRepository _telRestRepository;
@@ -36,6 +38,7 @@ namespace CallCenter.Api.Controllers
             INewRockClient client,
             ILogger<TestController> logger,
             IOptionsSnapshot<DeviceConfigs> options,
+            IOptionsSnapshot<QueueVoiceConfig> queueVoiceConfig,
             ITelCacheManager telCacheManager,
             ITelGroupRepository  telGroupRepository,
             ITelRestRepository telRestRepository,
@@ -44,6 +47,7 @@ namespace CallCenter.Api.Controllers
             _client = client;
             _logger = logger;
             _options = options;
+            _queueVoiceConfig = queueVoiceConfig;
             _telCacheManager = telCacheManager;
             _telGroupRepository = telGroupRepository;
             _telRestRepository = telRestRepository;
@@ -956,6 +960,22 @@ namespace CallCenter.Api.Controllers
                 HttpContext.RequestAborted);
         }
 
+        /// <summary>
+        /// 测试插播语音
+        /// </summary>
+        /// <param name="visterId"></param>
+        /// <returns></returns>
+        [HttpPost("testvoice")]
+        public async Task TestVoice(string visterId)
+        {
+
+            string voiceStr = _queueVoiceConfig.Value.QueueVoice;
+            voiceStr = String.Format(voiceStr, 2, 2);
+
+            await _client.VoiceNewsFlash(new VoiceNewsFlashRequest() { Attribute= "Connect", Visitor = new VoiceNewsFlashVisitor() { Id = visterId }, VoiceFile = voiceStr }, _options.Value.ReceiveKey, _options.Value.Expired, HttpContext.RequestAborted);
+        }
+
+
         #endregion
 
         #region 处理示忙的分机

+ 18 - 18
src/CallCenter.Api/StartupExtensions.cs

@@ -46,7 +46,7 @@ internal static class StartupExtensions
         services.Configure<RecordSettings>(d => configuration.GetSection("RecordSettings").Bind(d));
         services.Configure<SendCallRecord>(d => configuration.GetSection("SendCallRecord").Bind(d));
         services.Configure<IdentityConfiguration>(d => configuration.GetSection(nameof(IdentityConfiguration)).Bind(d));
-
+        services.Configure<QueueVoiceConfig>(d => configuration.GetSection("QueueVoiceConfig").Bind(d));
         // Add services to the container.
         services
             .BatchInjectServices()
@@ -195,23 +195,23 @@ internal static class StartupExtensions
 
     internal static WebApplication ConfigurePipelines(this WebApplication app)
     {
-        app.Use(async (context, next) =>
-        {
-            var loggerFactory = context.RequestServices.GetRequiredService<ILoggerFactory>();
-            var logger = loggerFactory.CreateLogger("RequestLogger");
-
-            var traceId = context.TraceIdentifier;
-            var scheme = context.Request.Scheme;
-            var method = context.Request.Method;
-            var path = context.Request.Path;
-            var queryString = context.Request.QueryString;
-
-            var request = $"{DateTime.Now} [{traceId}] {scheme} {method} {path}{queryString}";
-            logger.LogInformation(request);
-            await next.Invoke();
-            var response = $"{DateTime.Now} [{traceId}] {scheme} {method} {path} responsed";
-            logger.LogInformation(response);
-        });
+        //app.Use(async (context, next) =>
+        //{
+        //    var loggerFactory = context.RequestServices.GetRequiredService<ILoggerFactory>();
+        //    var logger = loggerFactory.CreateLogger("RequestLogger");
+
+        //    var traceId = context.TraceIdentifier;
+        //    var scheme = context.Request.Scheme;
+        //    var method = context.Request.Method;
+        //    var path = context.Request.Path;
+        //    var queryString = context.Request.QueryString;
+
+        //    var request = $"{DateTime.Now} [{traceId}] {scheme} {method} {path}{queryString}";
+        //    logger.LogInformation(request);
+        //    await next.Invoke();
+        //    var response = $"{DateTime.Now} [{traceId}] {scheme} {method} {path} responsed";
+        //    logger.LogInformation(response);
+        //});
 
         app.UseSerilogRequestLogging();
 

+ 4 - 1
src/CallCenter.Api/appsettings.Development.json

@@ -44,7 +44,7 @@
     "Expired": 86400 //认证过期时间(秒)
   },
   "ConnectionStrings": {
-    "CallCenter": "server=db.fengwo.com;Database=callcenter;Uid=dev;Pwd=fengwo11!!;SslMode=none;",
+    "CallCenter": "server=192.168.100.121;Database=callcenter;Uid=dev;Pwd=fengwo11!!;SslMode=none;",
     "Redis": "192.168.100.223"
   },
   "Swagger": true,
@@ -352,5 +352,8 @@
       "Scope": "hotline_api",
       "Expired": 86400 //seceonds
     }
+  },
+  "QueueVoiceConfig": {
+    "QueueVoice": "user_tts161237.wav+{0}+user_tts161350.wav+user_tts161544.wav+{1}+user_tts161628.wav+fring112428.wav"
   }
 }

+ 3 - 0
src/CallCenter.Api/appsettings.json

@@ -352,5 +352,8 @@
       "Scope": "hotline_api",
       "Expired": 86400 //seceonds
     }
+  },
+  "QueueVoiceConfig": {
+    "QueueVoice": "user_tts161237.wav+{0}+user_tts161350.wav+user_tts161544.wav+{1}+user_tts161628.wav+fring112428.wav"
   }
 }

+ 15 - 3
src/CallCenter.Application/Handlers/BaseHandler.cs

@@ -10,6 +10,8 @@ using Microsoft.Extensions.Options;
 using CallCenter.Caches;
 using CallCenter.Repository.SqlSugar;
 using CallCenter.Realtimes;
+using MediatR;
+using NewRock.Sdk.Control.Response;
 
 namespace CallCenter.Application.Handlers
 {
@@ -17,13 +19,15 @@ namespace CallCenter.Application.Handlers
     {
         private readonly INewRockClient _newRockClient;
         private readonly IOptionsSnapshot<DeviceConfigs> _options;
+        private readonly IOptionsSnapshot<QueueVoiceConfig> _queueVoiceConfig;
         private readonly ICallCacheManager _callCacheManager;
         private readonly ICallRepository _callRepository;
         private readonly IRealtimeService _realtimeService;
-        public BaseHandler(INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,ICallCacheManager callCacheManager, ICallRepository callRepository,IRealtimeService realtimeService)
+        public BaseHandler(INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options, IOptionsSnapshot<QueueVoiceConfig> queueVoiceConfig,ICallCacheManager callCacheManager, ICallRepository callRepository,IRealtimeService realtimeService)
         {
             _newRockClient = newRockClient;
             _options = options;
+            _queueVoiceConfig = queueVoiceConfig;
             _callCacheManager = callCacheManager;
             _callRepository = callRepository;
             _realtimeService = realtimeService;
@@ -112,8 +116,16 @@ namespace CallCenter.Application.Handlers
                         }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
 
                         //处理队列记录 TODO
-                        _callCacheManager.AddCallCache(model);
+                        _callCacheManager.AddCallCache(model,groupId);
                         await _realtimeService.CallQueueAsync(_callCacheManager.GetCallQueueList(), cancellationToken);
+                        // TODO 插播排队语音
+                        //var groupResult = await _newRockClient.QueryExtGroup(new QueryExtGroupRequest() { Attribute = "Query", Group = new QueryExtGroup() { Id = groupId } }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
+                        //if (groupResult.Group[0].Visitor.Count > 0) 
+                        //{
+                        //    string voiceStr = _queueVoiceConfig.Value.QueueVoice;
+                        //    voiceStr = String.Format(voiceStr, groupResult.Group[0].Visitor.Count, groupResult.Group[0].Visitor.Count);
+                        //    await _newRockClient.VoiceNewsFlash(new VoiceNewsFlashRequest() { Attribute = "Connect", Visitor = new VoiceNewsFlashVisitor() { Id = model.ConversationId }, VoiceFile = voiceStr }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
+                        //}
                         break;
                     case EIvrAnswerType.Out:
                         var phoneNo = ivrAnswer.Content;
@@ -139,7 +151,7 @@ namespace CallCenter.Application.Handlers
                                     Outer = new List<OuterToOuterOuterModel>(){
                                         new(){Id = model.ConversationId},
                                             new(){To = phoneNo},
-                                        }
+                                        } 
                                 }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
                                 break;
                             default:

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

@@ -22,7 +22,7 @@ namespace CallCenter.Application.Handlers
         private readonly ICallDetailRepository _callDetailRepository;
 
 
-        public DtmfNotificationHandler(IIvrDomainService ivrDomainService, ICallDetailRepository callDetailRepository, ICallRepository callRepository, INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,ICallCacheManager callCacheManager,IRealtimeService realtimeService) :base(newRockClient, options,callCacheManager, callRepository,realtimeService)
+        public DtmfNotificationHandler(IIvrDomainService ivrDomainService, ICallDetailRepository callDetailRepository, ICallRepository callRepository, INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,ICallCacheManager callCacheManager,IRealtimeService realtimeService,IOptionsSnapshot<QueueVoiceConfig> queueVoiceOption) :base(newRockClient, options, queueVoiceOption, callCacheManager, callRepository,realtimeService)
         {
             _ivrDomainService = ivrDomainService;
             _callDetailRepository = callDetailRepository;

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

@@ -16,7 +16,7 @@ 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,ICallCacheManager callCacheManager,IRealtimeService realtimeService) : base(newRockClient, options,callCacheManager, callRepository,realtimeService)
+        public EndOfAnnOuterToMenuNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IIvrDomainService ivrDomainService, INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,ICallCacheManager callCacheManager,IRealtimeService realtimeService,IOptionsSnapshot<QueueVoiceConfig> queueVoiceOptions) : base(newRockClient, options, queueVoiceOptions, callCacheManager, callRepository,realtimeService)
         {
             _callRepository = callRepository;
             _callDetailRepository = callDetailRepository;

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

@@ -19,7 +19,7 @@ namespace CallCenter.Application.Handlers.FlowControl
         private readonly IIvrDomainService _ivrDomainService;
         private readonly ICallCacheManager _callCacheManager;
 
-        public EndOfAnnVisitorToMenuNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IIvrDomainService ivrDomainService,INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,ICallCacheManager callCacheManager,IRealtimeService realtimeService):base(newRockClient,options,callCacheManager, callRepository, realtimeService)
+        public EndOfAnnVisitorToMenuNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IIvrDomainService ivrDomainService,INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,ICallCacheManager callCacheManager,IRealtimeService realtimeService,IOptionsSnapshot<QueueVoiceConfig> queueVoiceOptions) :base(newRockClient,options, queueVoiceOptions, callCacheManager, callRepository, realtimeService)
         {
             _callRepository = callRepository;
             _callDetailRepository = callDetailRepository;

+ 17 - 4
src/CallCenter.Application/Handlers/FlowControl/IncomingNotificationHandler.cs

@@ -14,6 +14,9 @@ using CallCenter.Settings;
 using Microsoft.Extensions.Logging;
 using NewRock.Sdk.Transfer.Queue.Request;
 using CallCenter.Realtimes;
+using Microsoft.AspNetCore.Http;
+using NewRock.Sdk.Control.Request;
+using NewRock.Sdk.Control.Response;
 
 namespace CallCenter.Application.Handlers
 {
@@ -26,6 +29,7 @@ namespace CallCenter.Application.Handlers
         private readonly IIvrCacheManager _ivrCacheManager;
         private readonly INewRockClient _newRockClient;
         private readonly IOptionsSnapshot<DeviceConfigs> _options;
+        private readonly IOptionsSnapshot<QueueVoiceConfig> _queueVoiceConfig;
         private readonly ILogger<IncomingNotificationHandler> _logger;
         private readonly ICallCacheManager _callCacheManager;
         private readonly IIvrDomainService _ivrDomainService;
@@ -36,7 +40,7 @@ namespace CallCenter.Application.Handlers
             ICallRepository callRepository, ICallDetailRepository callDetailRepository,
             ISystemSettingCacheManager systemSettingCacheManager, IIvrCacheManager ivrCacheManager,
             INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,
-            ILogger<IncomingNotificationHandler> logger, ICallCacheManager callCacheManager,
+            IOptionsSnapshot<QueueVoiceConfig> queueVoiceConfig,ILogger<IncomingNotificationHandler> logger, ICallCacheManager callCacheManager,
             IIvrDomainService ivrDomainService,IRealtimeService realtimeService)
         {
             _callRepository = callRepository;
@@ -108,7 +112,7 @@ namespace CallCenter.Application.Handlers
                                 Attribute = "Connect",
                                 Menu = new VisitorToMenuMenu() { Id = ivr.No },
                                 Visitor = new VisitorToMenuVisitor() { Id = notification.Visitor.Id }
-                            },
+                            }, 
                             _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
                             model.InIvrTime = DateTime.Now;
                             await _callRepository.UpdateAsync(model, cancellationToken);
@@ -121,13 +125,22 @@ namespace CallCenter.Application.Handlers
                                 Attribute = "Queue",
                                 Visitor = new VisitorToGroupQueueVisitor() { Id = notification.Visitor.Id },
                                 Group = new VisitorToGroupQueueGroup() { Id = correct.ReturnValue }
-                            },
+                            }, 
                             _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
                             model.InGroupTime = DateTime.Now;
                             await _callRepository.UpdateAsync(model, cancellationToken);
                             //处理队列记录 TODO
-                            _callCacheManager.AddCallCache(model);
+                            _callCacheManager.AddCallCache(model,correct.ReturnValue);
                             await _realtimeService.CallQueueAsync(_callCacheManager.GetCallQueueList(), cancellationToken);
+
+                            // TODO插播排队语音
+                            //var groupResult = await _newRockClient.QueryExtGroup(new QueryExtGroupRequest() { Attribute = "Query", Group = new QueryExtGroup() { Id = correct.ReturnValue } }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
+                            //if (groupResult.Group[0].Visitor.Count > 0)
+                            //{
+                            //    string voiceStr = _queueVoiceConfig.Value.QueueVoice;
+                            //    voiceStr = String.Format(voiceStr, groupResult.Group[0].Visitor.Count, groupResult.Group[0].Visitor.Count);
+                            //    await _newRockClient.VoiceNewsFlash(new VoiceNewsFlashRequest() { Attribute = "Connect", Visitor = new VoiceNewsFlashVisitor() { Id = model.ConversationId }, VoiceFile = voiceStr }, _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
+                            //}
                             break;
                         default:
                             break;

+ 16 - 3
src/CallCenter/Caches/CallCacheManager.cs

@@ -1,4 +1,6 @@
-using CallCenter.Calls;
+using CallCenter.BlackLists;
+using CallCenter.Calls;
+using Google.Protobuf.WellKnownTypes;
 using XF.Domain.Cache;
 using XF.Domain.Dependency;
 
@@ -13,6 +15,10 @@ namespace CallCenter.Caches
             public string FromNo { get; set; }
             public string ToNo { get; set; }
             public DateTime InGroupTime { get; set; }
+
+            public string TrunkNo { get; set; }
+
+            public string GroupNo { get; set; }
         }
 
         public CallCacheManager(ITypedCache<CallDtoRedis> cacheCall)
@@ -20,9 +26,9 @@ namespace CallCenter.Caches
             _cacheCall = cacheCall;
         }
 
-        public void AddCallCache(Call call)
+        public void AddCallCache(Call call,string groupNo)
         {
-            _cacheCall.Set(call.Id,  new CallDtoRedis{ FromNo =call.FromNo,ToNo = call.ToNo, InGroupTime = DateTime.Now });
+            _cacheCall.Set(call.Id,  new CallDtoRedis{ FromNo =call.FromNo,ToNo = call.ToNo, InGroupTime = DateTime.Now, TrunkNo=call.Trunk, GroupNo = groupNo }, TimeSpan.FromSeconds(90));
         }
 
         public List<CallDtoRedis> GetCallQueueList()
@@ -31,6 +37,13 @@ namespace CallCenter.Caches
             return list==null ? new List<CallDtoRedis>() : list;
         }
 
+        public int GetCallQueueList(string groupNo)
+        {
+            return _cacheCall.GetListByPrefix().Where(x => x.GroupNo == groupNo).Count();
+        }
+
+
+
         public void RemoveCallCache(string id)
         {
             _cacheCall.Remove(id);

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

@@ -7,7 +7,8 @@ namespace CallCenter.Caches
     {
         List<CallDtoRedis> GetCallQueueList();
 
-        void AddCallCache(Call call);
+        int GetCallQueueList(string groupNo);
+        void AddCallCache(Call call,string groupNo);
 
         void RemoveCallCache(string id);
     }

+ 8 - 0
src/CallCenter/Calls/QueueVoiceConfig.cs

@@ -0,0 +1,8 @@
+
+namespace CallCenter.Calls
+{
+    public class QueueVoiceConfig
+    {
+        public string QueueVoice { get; set; }
+    }
+}

+ 4 - 2
src/CallCenter/Users/UserDomainService.cs

@@ -97,14 +97,16 @@ namespace CallCenter.Users
             _cacheWork.Remove(work.GetKey(KeyMode.UserId));
             _cacheWork.Remove(work.GetKey(KeyMode.TelNo));
 
-            //更新work缓存
-            //_userCacheManager.RemoveWorksCache(work.Id);
+            #region 初始化话机
+            //初始化解除禁音
+            await _deviceManager.UnMuteAsync(tel.No, cancellationToken);
 
             foreach (var group in tel.Groups)
             {
                 await _deviceManager.ModifyGroupExtAsync(group.No,group.Distribution ,group.Voice,"", false, cancellationToken);
             }
 
+            #endregion
             return _mapper.Map<WorkDto>(work);
         }
     }