ByeOuterAndOuterNotificationHandler.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Hotline.CallCenter.Calls;
  2. using Hotline.Share.Enums.CallCenter;
  3. using Hotline.Share.Notifications.NewRockCallCenter;
  4. using MediatR;
  5. namespace Hotline.Application.Handlers.CallCenter.FlowControl
  6. {
  7. public class ByeOuterAndOuterNotificationHandler:INotificationHandler<ByeOuterAndOuterNotification>
  8. {
  9. private readonly ICallRepository _callRepository;
  10. private readonly ICallDetailRepository _callDetailRepository;
  11. public ByeOuterAndOuterNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository)
  12. {
  13. _callRepository = callRepository;
  14. _callDetailRepository = callDetailRepository;
  15. }
  16. public async Task Handle(ByeOuterAndOuterNotification notification, CancellationToken cancellationToken)
  17. {
  18. var model = await _callRepository.GetAsync(x =>
  19. x.ConversationId == notification.Outer.Id && x.FromNo == notification.Outer.From &&
  20. 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.RingOffType = ERingOffType.Normal;
  25. model.ByeTime = DateTime.Now;
  26. await _callRepository.UpdateAsync(model, cancellationToken);
  27. var detail = new CallDetail()
  28. {
  29. CallId = model.Id,
  30. CallStatus = ECallStatus.Answered,
  31. ConversationId = notification.Outer.Id,
  32. OMCallId = notification.Outer.CallId,
  33. EventName = notification.Attribute,
  34. AnswerNo = notification.Outer.To,
  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. }