|
@@ -10,6 +10,8 @@ using Microsoft.Extensions.Logging;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using NewRock.Sdk;
|
|
|
using NewRock.Sdk.Transfer.Connect.Request;
|
|
|
+using NewRock.Sdk.Transfer.Queue.Request;
|
|
|
+using Oracle.ManagedDataAccess.Types;
|
|
|
using XF.Domain.Cache;
|
|
|
using XF.Domain.Constants;
|
|
|
|
|
@@ -20,25 +22,29 @@ namespace Hotline.Application.Handlers.CallCenter.FlowControl
|
|
|
private readonly ICallRepository _callRepository;
|
|
|
private readonly ICallDetailRepository _callDetailRepository;
|
|
|
private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
- //private readonly ITelCacheManager _telCacheManager;
|
|
|
private readonly IIvrCacheManager _ivrCacheManager;
|
|
|
private readonly INewRockClient _newRockClient;
|
|
|
private readonly IOptionsSnapshot<DeviceConfigs> _options;
|
|
|
- private readonly ITypedCache<WorkTimeSettings> _worktimeCache;
|
|
|
- private readonly IOptionsSnapshot<WorkTimeSettings> _worktimeOptions;
|
|
|
+ private readonly ITypedCache<List<TrunkIvrManager>> _worktimeCache;
|
|
|
private readonly ILogger<IncomingNotificationHandler> _logger;
|
|
|
private readonly ISystemSettingGroupRepository _systemSettingGroupRepository;
|
|
|
private readonly ISystemSettingRepository _systemSettingRepository;
|
|
|
-
|
|
|
+ private readonly ITrunkIvrManagerRepository _trunkIvrManagerRepository;
|
|
|
+ private readonly ICallCacheManager _callCacheManager;
|
|
|
|
|
|
public IncomingNotificationHandler(
|
|
|
- ICallRepository callRepository, ICallDetailRepository callDetailRepository,
|
|
|
- ISystemSettingCacheManager systemSettingCacheManager, IIvrCacheManager ivrCacheManager,
|
|
|
- INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,
|
|
|
- ITypedCache<WorkTimeSettings> worktimeCache, IOptionsSnapshot<WorkTimeSettings> worktimeOptions,
|
|
|
+ ICallRepository callRepository,
|
|
|
+ ICallDetailRepository callDetailRepository,
|
|
|
+ ISystemSettingCacheManager systemSettingCacheManager,
|
|
|
+ IIvrCacheManager ivrCacheManager,
|
|
|
+ INewRockClient newRockClient,
|
|
|
+ IOptionsSnapshot<DeviceConfigs> options,
|
|
|
+ ITypedCache<List<TrunkIvrManager>> worktimeCache,
|
|
|
ILogger<IncomingNotificationHandler> logger,
|
|
|
ISystemSettingGroupRepository systemSettingGroupRepository,
|
|
|
- ISystemSettingRepository systemSettingRepository)
|
|
|
+ ISystemSettingRepository systemSettingRepository,
|
|
|
+ ITrunkIvrManagerRepository trunkIvrManagerRepository,
|
|
|
+ ICallCacheManager callCacheManager)
|
|
|
{
|
|
|
_callRepository = callRepository;
|
|
|
_callDetailRepository = callDetailRepository;
|
|
@@ -47,10 +53,11 @@ namespace Hotline.Application.Handlers.CallCenter.FlowControl
|
|
|
_newRockClient = newRockClient;
|
|
|
_options = options;
|
|
|
_worktimeCache = worktimeCache;
|
|
|
- _worktimeOptions = worktimeOptions;
|
|
|
_logger = logger;
|
|
|
_systemSettingGroupRepository = systemSettingGroupRepository;
|
|
|
_systemSettingRepository = systemSettingRepository;
|
|
|
+ _trunkIvrManagerRepository = trunkIvrManagerRepository;
|
|
|
+ _callCacheManager = callCacheManager;
|
|
|
}
|
|
|
|
|
|
public async Task Handle(IncomingNotification notification, CancellationToken cancellationToken)
|
|
@@ -77,36 +84,62 @@ namespace Hotline.Application.Handlers.CallCenter.FlowControl
|
|
|
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 correct = GetCorrectIvr(notification.Visitor.To);
|
|
|
|
|
|
- var ivr = GetCorrectIvr();
|
|
|
- _logger.LogInformation("transfer to ivr.no: {ivrNo}", ivr.No);
|
|
|
- //写入进入IVR流程
|
|
|
- model.InIvrTime = DateTime.Now;
|
|
|
- await _callRepository.UpdateAsync(model, cancellationToken);
|
|
|
- var detailTwo = new CallDetail()
|
|
|
+ //var ivr = GetCorrectIvr();
|
|
|
+
|
|
|
+
|
|
|
+ switch (correct.eCorrectIvr)
|
|
|
{
|
|
|
- CallId = model.Id,
|
|
|
- CallStatus = ECallStatus.InIvr,
|
|
|
- OMCallId = notification.Visitor.CallId,
|
|
|
- ConversationId = notification.Visitor.Id,
|
|
|
- EventName = notification.Attribute,
|
|
|
- FromNo = notification.Visitor.From,
|
|
|
- ToNo = notification.Visitor.To,
|
|
|
- };
|
|
|
- await _callDetailRepository.AddAsync(detail, cancellationToken);
|
|
|
+ case ECorrectIvr.Ivr:
|
|
|
+
|
|
|
+ var ivrList = _ivrCacheManager.GetIvrs();
|
|
|
+ var ivr = ivrList.First(x => x.IvrCategoryId == correct.ReturnValue && x.IsRoot);
|
|
|
+
|
|
|
+ _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);
|
|
|
+
|
|
|
+ //写入进入IVR流程
|
|
|
+ model.InIvrTime = DateTime.Now;
|
|
|
+ await _callRepository.UpdateAsync(model, cancellationToken);
|
|
|
+ var detailTwo = new CallDetail()
|
|
|
+ {
|
|
|
+ CallId = model.Id,
|
|
|
+ CallStatus = ECallStatus.InIvr,
|
|
|
+ OMCallId = notification.Visitor.CallId,
|
|
|
+ ConversationId = notification.Visitor.Id,
|
|
|
+ EventName = notification.Attribute,
|
|
|
+ FromNo = notification.Visitor.From,
|
|
|
+ ToNo = notification.Visitor.To,
|
|
|
+ };
|
|
|
+ await _callDetailRepository.AddAsync(detail, cancellationToken);
|
|
|
|
|
|
- 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);
|
|
|
- //处理队列
|
|
|
+ break;
|
|
|
+ case ECorrectIvr.Group:
|
|
|
+ _logger.LogInformation("transfer to group.no:{groupNo}", correct.ReturnValue);
|
|
|
+ await _newRockClient.VisitorToGroupQueue(new VisitorToGroupQueueRequest()
|
|
|
+ {
|
|
|
+ Attribute = "Queue",
|
|
|
+ Visitor = new VisitorToGroupQueueVisitor() { Id = notification.Visitor.Id },
|
|
|
+ Group = new VisitorToGroupQueueGroup() { Id = correct.ReturnValue }
|
|
|
+ },
|
|
|
+ _options.Value.ReceiveKey, _options.Value.Expired, cancellationToken);
|
|
|
+ model.InQueueTime = DateTime.Now;
|
|
|
+ await _callRepository.UpdateAsync(model, cancellationToken);
|
|
|
+ //处理队列记录
|
|
|
+ _callCacheManager.AddCallCache(model);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //TODO 跳转默认分机组
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -115,49 +148,46 @@ namespace Hotline.Application.Handlers.CallCenter.FlowControl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Ivr GetCorrectIvr()
|
|
|
+ private CorrectIvr GetCorrectIvr(string to)
|
|
|
{
|
|
|
- //从数据库或缓存中获取配置信息
|
|
|
- //var worktimeSettings = _worktimeCache.GetOrAdd("worktimesettings", d => _worktimeOptions.Value, ExpireMode.Absolute, TimeSpan.FromDays(1));
|
|
|
var worktimeSettings = _worktimeCache.GetOrAdd("worktimesettings", d =>
|
|
|
{
|
|
|
- WorkTimeSettings model = new WorkTimeSettings();
|
|
|
- var settingslist = _systemSettingGroupRepository.Get(x => x.GroupCode == "WorkTimeSetting").SystemSettings;
|
|
|
- if (settingslist !=null)
|
|
|
- {
|
|
|
- //上午开始时间
|
|
|
- model.MorningBegin = settingslist.First(x => x.Code == SettingConstants.MorningBegin).SettingValue;
|
|
|
- //上午结束时间
|
|
|
- model.MorningEnd = settingslist.First(x => x.Code == SettingConstants.MorningEnd).SettingValue;
|
|
|
- //下午开始时间
|
|
|
- model.AfterBegin = settingslist.First(x => x.Code == SettingConstants.AfterBegin).SettingValue;
|
|
|
- //下午结束时间
|
|
|
- model.AfterEnd = settingslist.First(x=>x.Code == SettingConstants.AfterEnd).SettingValue;
|
|
|
- //工作日
|
|
|
- model.WorkDay = settingslist.First(x => x.Code == SettingConstants.WorkTimeSetting).SettingValue;
|
|
|
- //工作时间IVR
|
|
|
- model.WorkCategory = _systemSettingRepository.Get(x => x.Code == SettingConstants.WorkCategory).SettingValue;
|
|
|
- //休息时间IVR
|
|
|
- model.RestCategory = _systemSettingRepository.Get(x => x.Code == SettingConstants.RestCategory).SettingValue;
|
|
|
- }
|
|
|
- return model;
|
|
|
+ var settings = _trunkIvrManagerRepository.QueryAsync(x=>x.IsEnable).GetAwaiter().GetResult();
|
|
|
+ return settings;
|
|
|
}, ExpireMode.Absolute);
|
|
|
- var categoryId = GetCorrectCategory(worktimeSettings);
|
|
|
- var ivrList = _ivrCacheManager.GetIvrs();
|
|
|
- var ivr = ivrList.First(x => x.IvrCategoryId == categoryId && x.IsRoot);
|
|
|
- return ivr;
|
|
|
+ var correct = GetCorrectCategory(worktimeSettings.First(x=>x.TrunkId == to));
|
|
|
+ return correct;
|
|
|
+ }
|
|
|
+
|
|
|
+ public class CorrectIvr
|
|
|
+ {
|
|
|
+ public string ReturnValue { get; set; }
|
|
|
+
|
|
|
+ public ECorrectIvr eCorrectIvr { get; set; }
|
|
|
}
|
|
|
|
|
|
- private string GetCorrectCategory(WorkTimeSettings settings)
|
|
|
+ public enum ECorrectIvr
|
|
|
+ {
|
|
|
+ Ivr = 0,
|
|
|
+ Group = 1,
|
|
|
+ }
|
|
|
+
|
|
|
+ private CorrectIvr GetCorrectCategory(TrunkIvrManager settings)
|
|
|
{
|
|
|
if (!settings.WorkDay.Contains(((int)DateTime.Now.DayOfWeek).ToString()))
|
|
|
- return settings.RestCategory;
|
|
|
+ return new CorrectIvr() { eCorrectIvr = settings.RestCategory != "" ? ECorrectIvr.Ivr : ECorrectIvr.Group, ReturnValue = settings.RestCategory != "" ? settings.RestCategory : settings.RestToGroup };
|
|
|
+
|
|
|
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;
|
|
|
+ {
|
|
|
+ return new CorrectIvr() { eCorrectIvr = settings.WorkCategory != "" ? ECorrectIvr.Ivr : ECorrectIvr.Group, ReturnValue = settings.WorkCategory != "" ? settings.WorkCategory : settings.WorkToGroup };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return new CorrectIvr() { eCorrectIvr = settings.RestCategory != "" ? ECorrectIvr.Ivr : ECorrectIvr.Group, ReturnValue = settings.RestCategory != "" ? settings.RestCategory : settings.RestToGroup };
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|