TransientOuterNotificationHandler.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.CallCenter.Calls;
  3. using Hotline.EventBus;
  4. using Hotline.Share.Enums.CallCenter;
  5. using Hotline.Share.Notifications.NewRockCallCenter;
  6. using Hotline.Tools;
  7. using MediatR;
  8. namespace Hotline.Application.Handlers.CallCenter.Transient
  9. {
  10. [HandlerInject(EventHandlerType = EEventHandlerType.CallCenter, Label = AppDefaults.CallCenterType.XunShi)]
  11. public class TransientOuterNotificationHandler : INotificationHandler<TransientOuterNotification>
  12. {
  13. private readonly ICallRepository _callRepository;
  14. private readonly ICallDetailRepository _callDetailRepository;
  15. private readonly IUserCacheManager _userCacheManager;
  16. public TransientOuterNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository, IUserCacheManager userCacheManager)
  17. {
  18. _callRepository = callRepository;
  19. _callDetailRepository = callDetailRepository;
  20. _userCacheManager = userCacheManager;
  21. }
  22. public async Task Handle(TransientOuterNotification notification, CancellationToken cancellationToken)
  23. {
  24. if (!string.IsNullOrEmpty(notification.Outer.Id))
  25. {
  26. var workModel = _userCacheManager.GetWorkByTel(notification.Outer.From);
  27. var isp = PhoneIspTool.GetPhoneIsp(notification.Outer.To);
  28. var callModel = new Call()
  29. {
  30. CallStatus = ECallStatus.ExtOuterReady,
  31. CallDirection = ECallDirection.Out,
  32. CallType = ECallType.ExtToOuter,
  33. ConversationId = notification.Outer.Id,
  34. FromNo = notification.Outer.From,
  35. ToNo = notification.Outer.To,
  36. Trunk = notification.Outer.Trunk,
  37. UserId = workModel.UserId,
  38. UserName = workModel.UserName,
  39. PhoneIsp = isp
  40. };
  41. callModel.Modified();
  42. var callId = await _callRepository.AddAsync(callModel, cancellationToken);
  43. //写入明细
  44. var detail = new CallDetail()
  45. {
  46. CallId = callId,
  47. CallStatus = ECallStatus.ExtOuterReady,
  48. ConversationId = notification.Outer.Id,
  49. OMCallId = notification.Outer.CallId,
  50. EventName = "ExtOuterReady", //去电
  51. FromNo = notification.Outer.From,
  52. ToNo = notification.Outer.To,
  53. };
  54. await _callDetailRepository.AddAsync(detail, cancellationToken);
  55. }
  56. }
  57. }
  58. }