ByeExtAndOuterOneNotificationHandler.cs 2.8 KB

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