|
@@ -1,8 +1,14 @@
|
|
|
|
|
|
using CallCenter.Caches;
|
|
|
+using CallCenter.Devices;
|
|
|
using CallCenter.Notifications;
|
|
|
+using CallCenter.Realtimes;
|
|
|
using CallCenter.Tels;
|
|
|
+using CallCenter.Users;
|
|
|
using MediatR;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Polly.Caching;
|
|
|
+using XF.Domain.Authentications;
|
|
|
using XF.Domain.Cache;
|
|
|
|
|
|
namespace CallCenter.Application.Handlers
|
|
@@ -12,11 +18,26 @@ namespace CallCenter.Application.Handlers
|
|
|
private readonly ITelRepository _telRepository;
|
|
|
private readonly ITelCacheManager _telCacheManager;
|
|
|
private readonly ITypedCache<Tel> _typedCache;
|
|
|
- public OfflineNotificationHandler(ITelRepository telRepository, ITelCacheManager telCacheManager, ITypedCache<Tel> typedCache)
|
|
|
+ private readonly IUserDomainService _userDomainService;
|
|
|
+ private readonly IUserCacheManager _userCacheManager;
|
|
|
+ private readonly ITelRestRepository _telRestRepository;
|
|
|
+ private readonly IWorkRepository _workRepository;
|
|
|
+ private readonly ITypedCache<Work> _cacheWork;
|
|
|
+ private readonly IDeviceManager _deviceManager;
|
|
|
+ private readonly IRealtimeService _realtimeService;
|
|
|
+
|
|
|
+ public OfflineNotificationHandler(ITelRepository telRepository, ITelCacheManager telCacheManager, ITypedCache<Tel> typedCache,IUserDomainService userDomainService,IUserCacheManager userCacheManager, ITelRestRepository telRestRepository, IWorkRepository workRepository,ITypedCache<Work> cacheWork, IDeviceManager deviceManager, IRealtimeService realtimeService)
|
|
|
{
|
|
|
_telRepository = telRepository;
|
|
|
_telCacheManager = telCacheManager;
|
|
|
_typedCache = typedCache;
|
|
|
+ _userDomainService = userDomainService;
|
|
|
+ _userCacheManager = userCacheManager;
|
|
|
+ _telRestRepository = telRestRepository;
|
|
|
+ _workRepository = workRepository;
|
|
|
+ _cacheWork = cacheWork;
|
|
|
+ _deviceManager = deviceManager;
|
|
|
+ _realtimeService = realtimeService;
|
|
|
}
|
|
|
|
|
|
public async Task Handle(OfflineNotification notification, CancellationToken cancellationToken)
|
|
@@ -25,6 +46,38 @@ namespace CallCenter.Application.Handlers
|
|
|
telModel.TelStatus = ETelStatus.Offline;
|
|
|
await _telRepository.UpdateAsync(telModel, cancellationToken);
|
|
|
_typedCache.Set(notification.TelNo, telModel);
|
|
|
+
|
|
|
+ //下线自动签出(处理小休)
|
|
|
+ var work =_userCacheManager.GetWorkByTel(telModel.No);
|
|
|
+ if (work!=null)
|
|
|
+ {
|
|
|
+ //处理小休
|
|
|
+ var restList = await _telRestRepository.QueryAsync(x => x.TelNo == telModel.No && !x.EndTime.HasValue);
|
|
|
+ restList.ForEach(x =>
|
|
|
+ {
|
|
|
+ x.EndRest();
|
|
|
+ });
|
|
|
+ await _telRestRepository.UpdateRangeAsync(restList,cancellationToken);
|
|
|
+
|
|
|
+ await _realtimeService.OffDutyAsync(work.UserId, cancellationToken);
|
|
|
+
|
|
|
+ work.OffDuty();
|
|
|
+ await _workRepository.UpdateAsync(work,cancellationToken);
|
|
|
+
|
|
|
+ _cacheWork.Remove(work.GetKey(KeyMode.UserId));
|
|
|
+ _cacheWork.Remove(work.GetKey(KeyMode.TelNo));
|
|
|
+
|
|
|
+ #region 初始化话机
|
|
|
+ //初始化解除禁音
|
|
|
+ await _deviceManager.UnMuteAsync(telModel.No, cancellationToken);
|
|
|
+
|
|
|
+ foreach (var group in telModel.Groups)
|
|
|
+ {
|
|
|
+ await _deviceManager.ModifyGroupExtAsync(group.No, group.Distribution, group.Voice, "", false, cancellationToken);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|