EndOfAnnVisitorToMenuNotificationHandler.cs 2.8 KB

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