|
@@ -11,6 +11,11 @@ using Microsoft.Extensions.Options;
|
|
|
using CallCenter.Tools;
|
|
|
using NewRock.Sdk.Accept.Request;
|
|
|
using CallCenter.Settings;
|
|
|
+using NewRock.Sdk.Transfer.Connect.Request;
|
|
|
+using XF.Domain.Constants;
|
|
|
+using CallCenter.Ivrs;
|
|
|
+using XF.Domain.Cache;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
|
|
|
namespace CallCenter.Application.Handlers
|
|
|
{
|
|
@@ -23,7 +28,12 @@ namespace CallCenter.Application.Handlers
|
|
|
private readonly INewRockClient _newRockClient;
|
|
|
private readonly IOptionsSnapshot<DeviceConfigs> _options;
|
|
|
private readonly IOptionsSnapshot<WorkTimeSettings> _workTimeOptions;
|
|
|
- public InviteNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IUserCacheManager userCacheManager, IBlacklistDomainService blacklistDomainService, INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options, IOptionsSnapshot<WorkTimeSettings> workTimeOptions)
|
|
|
+ private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
+ private readonly ITypedCache<WorkTimeSettings> _worktimeCache;
|
|
|
+ private readonly ILogger<IncomingNotificationHandler> _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, IIvrCacheManager ivrCacheManager)
|
|
|
{
|
|
|
_callRepository = callRepository;
|
|
|
_callDetailRepository = callDetailRepository;
|
|
@@ -32,6 +42,9 @@ namespace CallCenter.Application.Handlers
|
|
|
_newRockClient = newRockClient;
|
|
|
_options = options;
|
|
|
_workTimeOptions = workTimeOptions;
|
|
|
+ _systemSettingCacheManager = systemSettingCacheManager;
|
|
|
+ _worktimeCache = worktimeCache;
|
|
|
+ _ivrCacheManager = ivrCacheManager;
|
|
|
}
|
|
|
|
|
|
public bool IsInWrokTime()
|
|
@@ -97,7 +110,56 @@ 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
|
|
|
}
|
|
|
}
|