OfflineNotificationHandler.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.CallCenter.Tels;
  3. using Hotline.DI;
  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. [Injection(EventHandlerType = EEventHandlerType.CallCenter, Label = AppDefaults.CallCenterType.XunShi)]
  11. public class OfflineNotificationHandler: INotificationHandler<OfflineNotification>
  12. {
  13. private readonly ITelRepository _telRepository;
  14. private readonly ITelCacheManager _telCacheManager;
  15. private readonly ITypedCache<Tel> _typedCache;
  16. public OfflineNotificationHandler(ITelRepository telRepository, ITelCacheManager telCacheManager, ITypedCache<Tel> typedCache)
  17. {
  18. _telRepository = telRepository;
  19. _telCacheManager = telCacheManager;
  20. _typedCache = typedCache;
  21. }
  22. public async Task Handle(OfflineNotification notification, CancellationToken cancellationToken)
  23. {
  24. var telModel = _telCacheManager.GetTel(notification.TelNo);
  25. telModel.TelStatus = ETelStatus.Offline;
  26. await _telRepository.UpdateAsync(telModel, cancellationToken);
  27. _typedCache.Set(notification.TelNo, telModel);
  28. }
  29. }
  30. }