using Hotline.Caching.Interfaces; using Hotline.CallCenter.Tels; using Hotline.EventBus; using Hotline.Share.Enums.CallCenter; using Hotline.Share.Notifications.NewRockCallCenter; using MediatR; using XF.Domain.Cache; namespace Hotline.Application.Handlers.CallCenter.ExtState { [HandlerInject(EventHandlerType = EEventHandlerType.CallCenter, Label = AppDefaults.CallCenterType.XunShi)] public class OnlineNotificationHandler : INotificationHandler { private readonly ITelRepository _telRepository; private readonly ITelCacheManager _telCacheManager; private readonly ITypedCache _typedCache; public OnlineNotificationHandler(ITelRepository telRepository, ITelCacheManager telCacheManager, ITypedCache typedCache) { _telRepository = telRepository; _telCacheManager = telCacheManager; _typedCache = typedCache; } /// Handles a notification /// The notification /// Cancellation token public async Task Handle(OnlineNotification notification, CancellationToken cancellationToken) { var telModel = _telCacheManager.GetTel(notification.TelNo); telModel.TelStatus = ETelStatus.Ready; telModel.RegisterIP = notification.RegisterIP; await _telRepository.UpdateAsync(telModel,cancellationToken); _typedCache.Set(notification.TelNo, telModel); } } }