OnlineNotificationHandler.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.CallCenter.Tels;
  3. using Hotline.EventBus;
  4. using Hotline.Share.Enums.CallCenter;
  5. using Hotline.Share.Notifications.NewRockCallCenter;
  6. using MediatR;
  7. using XF.Domain.Cache;
  8. namespace Hotline.Application.Handlers.CallCenter.ExtState
  9. {
  10. [HandlerInject(EventHandlerType = EEventHandlerType.CallCenter, Label = AppDefaults.CallCenterType.XunShi)]
  11. public class OnlineNotificationHandler : INotificationHandler<OnlineNotification>
  12. {
  13. private readonly ITelRepository _telRepository;
  14. private readonly ITelCacheManager _telCacheManager;
  15. private readonly ITypedCache<Tel> _typedCache;
  16. public OnlineNotificationHandler(ITelRepository telRepository, ITelCacheManager telCacheManager, ITypedCache<Tel> typedCache)
  17. {
  18. _telRepository = telRepository;
  19. _telCacheManager = telCacheManager;
  20. _typedCache = typedCache;
  21. }
  22. /// <summary>Handles a notification</summary>
  23. /// <param name="notification">The notification</param>
  24. /// <param name="cancellationToken">Cancellation token</param>
  25. public async Task Handle(OnlineNotification notification, CancellationToken cancellationToken)
  26. {
  27. var telModel = _telCacheManager.GetTel(notification.TelNo);
  28. telModel.TelStatus = ETelStatus.Ready;
  29. telModel.RegisterIP = notification.RegisterIP;
  30. await _telRepository.UpdateAsync(telModel,cancellationToken);
  31. _typedCache.Set(notification.TelNo, telModel);
  32. }
  33. }
  34. }