ByeExtAndOuterTwoNotificationHandler.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.Caching.Services;
  3. using Hotline.CallCenter.Calls;
  4. using Hotline.Realtimes;
  5. using Hotline.Share.Dtos.Realtime;
  6. using Hotline.Share.Enums.CallCenter;
  7. using Hotline.Share.Notifications;
  8. using MediatR;
  9. namespace Hotline.Application.Handlers.CallCenter.FlowControl
  10. {
  11. public class ByeExtAndOuterTwoNotificationHandler : INotificationHandler<ByeExtAndOuterTwoNotification>
  12. {
  13. private readonly ICallRepository _callRepository;
  14. private readonly ICallDetailRepository _callDetailRepository;
  15. private readonly IUserCacheManager _userCacheManager;
  16. private readonly IRealtimeService _realtimeService;
  17. public ByeExtAndOuterTwoNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository,IUserCacheManager userCacheManager,IRealtimeService realtimeService)
  18. {
  19. _callRepository = callRepository;
  20. _callDetailRepository = callDetailRepository;
  21. _userCacheManager = userCacheManager;
  22. _realtimeService = realtimeService;
  23. }
  24. public async Task Handle(ByeExtAndOuterTwoNotification notification, CancellationToken cancellationToken)
  25. {
  26. var model = await _callRepository.GetAsync(
  27. x => x.ConversationId == notification.Outer.Id && x.ToNo == notification.Outer.To && x.Trunk==notification.Outer.Trunk && x.CreationTime>=DateTime.Now.AddHours(-2),true,x=>x.CreationTime, cancellationToken);
  28. if (model != null)
  29. {
  30. model.CallStatus = ECallStatus.Bye;
  31. model.EndBy = EEndBy.To;
  32. model.RingOffType = ERingOffType.Normal;
  33. model.ByeTime = DateTime.Now;
  34. await _callRepository.UpdateAsync(model, cancellationToken);
  35. var detail = new CallDetail()
  36. {
  37. CallId = model.Id,
  38. CallStatus = ECallStatus.Bye,
  39. OMCallId = notification.Outer.CallId,
  40. ConversationId = notification.Outer.Id,
  41. EventName = notification.Attribute,
  42. FromNo = notification.Outer.From,
  43. ToNo = notification.Outer.To,
  44. Recording = notification.Recording
  45. };
  46. await _callDetailRepository.AddAsync(detail, cancellationToken);
  47. //调用业务通知 通知前端
  48. var workModel = _userCacheManager.GetWorkByTel(notification.Outer.From);
  49. if (workModel != null)
  50. {
  51. await _realtimeService.ByeAsync(workModel.UserId, new ByeDto() { Id = model.Id }, cancellationToken);
  52. }
  53. }
  54. }
  55. }
  56. }