Bladeren bron

恢复Incoming事件处理IVR

Dun.Jason 2 jaren geleden
bovenliggende
commit
38c14de8fb

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

@@ -68,28 +68,28 @@ namespace CallCenter.Application.Handlers
                 await _callDetailRepository.AddAsync(detail, cancellationToken);
             }
             //TODO IVR处理
-            //var setting = _systemSettingCacheManager.GetSetting(SettingConstants.IVRConfig);
-            //if (bool.Parse(setting.SettingValue))
-            //{
-            //    //TODO 获取工作或休息时间(接听策略)
-            //    //var ivrList = _ivrCacheManager.GetIvrs();
-            //    //var ivr = ivrList.First(x => x.IvrCategoryId == "08da9b9f-a35d-4ade-8ea7-55e8abbcdefd" && x.IsRoot);
+            var setting = _systemSettingCacheManager.GetSetting(SettingConstants.IVRConfig);
+            if (bool.Parse(setting.SettingValue))
+            {
+                //TODO 获取工作或休息时间(接听策略)
+                //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);
-            //}
-            //else
-            //{
-            //    //TODO 跳转默认分机组
-            //}
+                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);
+            }
+            else
+            {
+                //TODO 跳转默认分机组
+            }
         }
 
         private Ivr GetCorrectIvr()

+ 1 - 60
src/CallCenter.Application/Handlers/FlowControl/InviteNotificationHandler.cs

@@ -27,13 +27,8 @@ namespace CallCenter.Application.Handlers
         private readonly IBlacklistDomainService _blacklistDomainService;
         private readonly INewRockClient _newRockClient;
         private readonly IOptionsSnapshot<DeviceConfigs> _options;
-        private readonly IOptionsSnapshot<WorkTimeSettings> _workTimeOptions;
-        private readonly ISystemSettingCacheManager _systemSettingCacheManager;
-        private readonly ITypedCache<WorkTimeSettings> _worktimeCache;
-        private readonly ILogger<InviteNotificationHandler> _logger;
-        private readonly IIvrCacheManager _ivrCacheManager;
 
-        public InviteNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IUserCacheManager userCacheManager, IBlacklistDomainService blacklistDomainService, INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options, IOptionsSnapshot<WorkTimeSettings> workTimeOptions, ISystemSettingCacheManager systemSettingCacheManager,ITypedCache<WorkTimeSettings> worktimeCache, ILogger<InviteNotificationHandler> logger, IIvrCacheManager ivrCacheManager)
+        public InviteNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IUserCacheManager userCacheManager, IBlacklistDomainService blacklistDomainService, INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options)
         {
             _callRepository = callRepository;
             _callDetailRepository = callDetailRepository;
@@ -41,11 +36,6 @@ namespace CallCenter.Application.Handlers
             _blacklistDomainService = blacklistDomainService;
             _newRockClient = newRockClient;
             _options = options;
-            _workTimeOptions = workTimeOptions;
-            _systemSettingCacheManager = systemSettingCacheManager;
-            _worktimeCache = worktimeCache;
-            _ivrCacheManager = ivrCacheManager;
-            _logger = logger;
         }
 
         public bool IsInWrokTime()
@@ -111,56 +101,7 @@ namespace CallCenter.Application.Handlers
                     new AcceptVisitorRequest()
                     { Attribute = "Accept", Visitor = new AcceptVisitorModel() { Id = notification.Visitor.Id } },
                     _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
-
-                var setting = _systemSettingCacheManager.GetSetting(SettingConstants.IVRConfig);
-                if (bool.Parse(setting.SettingValue))
-                {
-                    //TODO 获取工作或休息时间(接听策略)
-                    //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);
-                }
-                else
-                {
-                    //TODO 跳转默认分机组
-                }
             }
         }
-
-
-        #region private
-
-        private Ivr GetCorrectIvr()
-        {
-            var worktimeSettings = _worktimeCache.GetOrAdd("worktimesettings", d => _workTimeOptions.Value, ExpireMode.Absolute, TimeSpan.FromDays(1));
-            var categoryId = GetCorrectCategory(worktimeSettings);
-            var ivrList = _ivrCacheManager.GetIvrs();
-            var ivr = ivrList.First(x => x.IvrCategoryId == categoryId && x.IsRoot);
-            return ivr;
-        }
-
-        private string GetCorrectCategory(WorkTimeSettings settings)
-        {
-            if (!settings.WorkDay.Contains((int)DateTime.Now.DayOfWeek))
-                return settings.RestCategory;
-            var time = TimeOnly.FromDateTime(DateTime.Now);
-            if ((time >= TimeOnly.Parse(settings.MorningBegin) && time <= TimeOnly.Parse(settings.MorningEnd))
-                || (time >= TimeOnly.Parse(settings.AfterBegin) && time <= TimeOnly.Parse(settings.AfterEnd))
-                )
-                return settings.WorkCategory;
-            return settings.RestCategory;
-        }
-
-        #endregion
     }
 }