EndOfAnnVisitorToMenuNotificationHandler.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.CallCenter.Calls;
  3. using Hotline.CallCenter.Devices;
  4. using Hotline.CallCenter.Ivrs;
  5. using Hotline.Realtimes;
  6. using Hotline.Share.Enums.CallCenter;
  7. using Hotline.Share.Notifications;
  8. using MediatR;
  9. using Microsoft.Extensions.Options;
  10. using NewRock.Sdk;
  11. namespace Hotline.Application.Handlers.CallCenter.FlowControl
  12. {
  13. public class EndOfAnnVisitorToMenuNotificationHandler:BaseHandler,INotificationHandler<EndOfAnnVisitorToMenuNotification>
  14. {
  15. private readonly ICallRepository _callRepository;
  16. private readonly ICallDetailRepository _callDetailRepository;
  17. private readonly IIvrDomainService _ivrDomainService;
  18. public EndOfAnnVisitorToMenuNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IIvrDomainService ivrDomainService,INewRockClient newRockClient, IOptionsSnapshot<CallCenterConfiguration> options,ICallCacheManager callCacheManager,IRealtimeService realtimeService):base(newRockClient,options,callRepository,callCacheManager, realtimeService)
  19. {
  20. _callRepository = callRepository;
  21. _callDetailRepository = callDetailRepository;
  22. _ivrDomainService = ivrDomainService;
  23. }
  24. public async Task Handle(EndOfAnnVisitorToMenuNotification notification, CancellationToken cancellationToken)
  25. {
  26. var model = await _callRepository.GetAsync(
  27. x => x.ConversationId == notification.Visitor.Id && x.FromNo == notification.Visitor.From &&
  28. x.ToNo == notification.Visitor.To && x.CreationTime >= DateTime.Now.AddHours(-2),true,x=>x.CreationTime,
  29. cancellationToken);
  30. if (model!=null)
  31. {
  32. model.CallStatus = ECallStatus.EndOfAnn;
  33. await _callRepository.UpdateAsync(model, cancellationToken);
  34. var detail = new CallDetail()
  35. {
  36. CallId = model.Id,
  37. CallStatus = ECallStatus.EndOfAnn,
  38. OMCallId = notification.Visitor.CallId,
  39. ConversationId = notification.Visitor.Id,
  40. EventName = notification.Attribute,
  41. FromNo = notification.Visitor.From,
  42. ToNo = notification.Visitor.To
  43. };
  44. await _callDetailRepository.AddAsync(detail, cancellationToken);
  45. var runModel = await _ivrDomainService.GetVoiceEndAnswerAsync(notification.MenuId,cancellationToken);
  46. await HandlerIvr(runModel, model, cancellationToken);
  47. }
  48. }
  49. }
  50. }