ByeExtAndOuterOneNotificationHandler.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using Hotline.CallCenter.Calls;
  2. using Hotline.Share.Enums.CallCenter;
  3. using Hotline.Share.Notifications;
  4. using MediatR;
  5. namespace Hotline.Application.Handlers.CallCenter.FlowControl
  6. {
  7. public class ByeExtAndOuterOneNotificationHandler:INotificationHandler<ByeExtAndOuterOneNotification>
  8. {
  9. private readonly ICallRepository _callRepository;
  10. private readonly ICallDetailRepository _callDetailRepository;
  11. public ByeExtAndOuterOneNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository)
  12. {
  13. _callRepository = callRepository;
  14. _callDetailRepository = callDetailRepository;
  15. }
  16. public async Task Handle(ByeExtAndOuterOneNotification notification, CancellationToken cancellationToken)
  17. {
  18. var model = await _callRepository.GetAsync(
  19. x => x.ConversationId == notification.Outer.Id &&
  20. x.Trunk==notification.Outer.Trunk && x.ToNo == notification.Outer.To && x.CreationTime>=DateTime.Now.AddHours(-2),true,x=>x.CreationTime, cancellationToken);
  21. if (model != null)
  22. {
  23. model.CallStatus = ECallStatus.Bye;
  24. model.EndBy = EEndBy.From;
  25. model.RingOffType = ERingOffType.Normal;
  26. model.ByeTime = DateTime.Now;
  27. await _callRepository.UpdateAsync(model, cancellationToken);
  28. var detail = new CallDetail()
  29. {
  30. CallId = model.Id,
  31. CallStatus = ECallStatus.Bye,
  32. OMCallId = notification.Outer.CallId,
  33. ConversationId = notification.Outer.Id,
  34. EventName = notification.Attribute,
  35. FromNo = notification.Outer.From,
  36. ToNo = notification.Outer.To,
  37. Recording = notification.Recording,
  38. };
  39. await _callDetailRepository.AddAsync(detail, cancellationToken);
  40. }
  41. }
  42. }
  43. }