|
@@ -2,6 +2,7 @@
|
|
|
using CallCenter.Devices;
|
|
|
using CallCenter.Notifications;
|
|
|
using CallCenter.Realtimes;
|
|
|
+using CallCenter.Repository.SqlSugar;
|
|
|
using CallCenter.Share.Enums;
|
|
|
using CallCenter.Tels;
|
|
|
using MediatR;
|
|
@@ -10,79 +11,46 @@ using NewRock.Sdk;
|
|
|
using NewRock.Sdk.Control.Request;
|
|
|
using NewRock.Sdk.Control.Response;
|
|
|
using XF.Domain.Cache;
|
|
|
+using XF.Domain.Exceptions;
|
|
|
|
|
|
namespace CallCenter.Application.Handlers
|
|
|
{
|
|
|
public class IdleNotificationHandler : INotificationHandler<IdleNotification>
|
|
|
{
|
|
|
- private readonly ITelRepository _telRepository;
|
|
|
private readonly ITelCacheManager _telCacheManager;
|
|
|
private readonly ITypedCache<Tel> _typedCache;
|
|
|
private readonly IUserCacheManager _userCacheManager;
|
|
|
private readonly IRealtimeService _realtimeService;
|
|
|
- private readonly INewRockClient _newRockClient;
|
|
|
- private readonly IOptionsSnapshot<DeviceConfigs> _options;
|
|
|
+ private readonly IDeviceManager _deviceManager;
|
|
|
+ private readonly ITelRestRepository _telRestRepository;
|
|
|
|
|
|
- public IdleNotificationHandler(ITelRepository telRepository, ITelCacheManager telCacheManager, ITypedCache<Tel> typedCache, IUserCacheManager userCacheManager, IRealtimeService realtimeService,INewRockClient newRockClient,IOptionsSnapshot<DeviceConfigs> options)
|
|
|
+
|
|
|
+ public IdleNotificationHandler(ITelCacheManager telCacheManager, ITypedCache<Tel> typedCache, IUserCacheManager userCacheManager, IRealtimeService realtimeService, IDeviceManager deviceManager, ITelRestRepository telRestRepository)
|
|
|
{
|
|
|
- _telRepository = telRepository;
|
|
|
_telCacheManager = telCacheManager;
|
|
|
_typedCache = typedCache;
|
|
|
_userCacheManager = userCacheManager;
|
|
|
_realtimeService = realtimeService;
|
|
|
- _newRockClient = newRockClient;
|
|
|
- _options = options;
|
|
|
+ _deviceManager = deviceManager;
|
|
|
+ _telRestRepository = telRestRepository;
|
|
|
}
|
|
|
|
|
|
public async Task Handle(IdleNotification notification, CancellationToken cancellationToken)
|
|
|
{
|
|
|
var telModel = _telCacheManager.GetTel(notification.TelNo);
|
|
|
telModel.TelStatus = Tels.ETelStatus.Ready;
|
|
|
- //await _telRepository.UpdateAsync(telModel, cancellationToken);
|
|
|
_typedCache.Set(notification.TelNo, telModel);
|
|
|
|
|
|
+ var iswork = await _userCacheManager.IsWorkingByTelAsync(notification.TelNo, cancellationToken);
|
|
|
+ if (!iswork)
|
|
|
+ throw new UserFriendlyException(notification.TelNo + "未查询到工作记录");
|
|
|
+ var restingTel = await _telRestRepository.GetAsync(d => d.TelId == telModel.Id && !d.EndTime.HasValue, cancellationToken);
|
|
|
+ if (restingTel !=null)
|
|
|
+ throw new UserFriendlyException("未查询到分机休息信息");
|
|
|
|
|
|
foreach (var group in telModel.Groups)
|
|
|
{
|
|
|
- var result = await _newRockClient.QueryExtGroup(new QueryExtGroupRequest()
|
|
|
- {
|
|
|
- Attribute = "Query",
|
|
|
- Group = new QueryExtGroup() { Id = group.No }
|
|
|
- }, _options.Value.ReceiveKey,
|
|
|
- _options.Value.Expired,
|
|
|
- cancellationToken);
|
|
|
-
|
|
|
- var exts = result.Group.First().Ext.Select(x=>x.Id).ToList();
|
|
|
- exts.Add(notification.TelNo);
|
|
|
-
|
|
|
- //更新
|
|
|
- var groupModel = new Group()
|
|
|
- {
|
|
|
- Id = group.No,
|
|
|
- Voicefile = group.Voice,
|
|
|
- };
|
|
|
- switch (group.Distribution)
|
|
|
- {
|
|
|
- case EDistribution.Sequential:
|
|
|
- groupModel.Distribution = "sequential";
|
|
|
- break;
|
|
|
- case EDistribution.Group:
|
|
|
- groupModel.Distribution = "group";
|
|
|
- break;
|
|
|
- case EDistribution.Circular:
|
|
|
- groupModel.Distribution = "circular";
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- groupModel.Ext = exts;
|
|
|
- await _newRockClient.ConfigExtGroup(
|
|
|
- new AssginConfigGroupRequest() { Attribute = "Assign", Group = groupModel, },
|
|
|
- _options.Value.ReceiveKey,
|
|
|
- _options.Value.Expired,
|
|
|
- cancellationToken
|
|
|
- );
|
|
|
+ await _deviceManager.AssginConfigGroupAsync(group.No, group.Distribution, new List<string>() { notification.TelNo },group.Voice,cancellationToken);
|
|
|
}
|
|
|
|
|
|
|