123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using CallCenter.Share.Notifications;
- using CallCenter.Calls;
- using CallCenter.Share.Enums;
- using MediatR;
- using CallCenter.Realtimes;
- using CallCenter.Caches;
- namespace CallCenter.Application.Handlers
- {
- public class AnswerExtToOuterNotificationHandler:INotificationHandler<AnswerExtToOuterNotification>
- {
- private readonly ICallRepository _callRepository;
- private readonly ICallDetailRepository _callDetailRepository;
- private readonly IUserCacheManager _userCacheManager;
- private readonly IRealtimeService _realtimeService;
- public AnswerExtToOuterNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository,IUserCacheManager userCacheManager, IRealtimeService realtimeService)
- {
- _callRepository = callRepository;
- _callDetailRepository = callDetailRepository;
- _userCacheManager = userCacheManager;
- _realtimeService = realtimeService;
- }
- public async Task Handle(AnswerExtToOuterNotification notification, CancellationToken cancellationToken)
- {
- var model =await _callRepository.GetAsync(
- x => x.ConversationId == notification.Outer.Id && x.ToNo == notification.Outer.To &&
- x.Trunk == notification.Outer.Trunk && x.CreationTime >= DateTime.Now.AddHours(-2),
- cancellationToken);
- if (model!=null)
- {
- model.CallStatus = ECallStatus.Answer;
- await _callRepository.UpdateAsync(model, cancellationToken);
- var detail = new CallDetail()
- {
- CallId = model.Id,
- CallStatus = ECallStatus.Answer,
- OMCallId = notification.Outer.CallId,
- ConversationId =notification.Outer.Id,
- EventName = notification.Attribute,
- FromNo = notification.Outer.From,
- ToNo = notification.Outer.To,
- AnswerNo = notification.TelNo
- };
- await _callDetailRepository.AddAsync(detail, cancellationToken);
- //调用业务通知 通知前端
- var workModel = _userCacheManager.GetWorkByTel(notification.Outer.From);
- if (workModel != null)
- {
- await _realtimeService.AnsweredAsync(workModel.UserId, new AnseredDto() { ConversationId = notification.Outer.Id, From = notification.Outer.From, Id = model.Id, To = notification.Outer.To, CallType = ECallType.ExtToOuter }, cancellationToken);
- }
- }
- }
- }
- }
|