12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using Hotline.CallCenter.Calls;
- using Hotline.Share.Enums.CallCenter;
- using Hotline.Share.Notifications;
- using MediatR;
- namespace Hotline.Application.Handlers.CallCenter.FlowControl
- {
- public class DivertVisitorToExtNotificationHandler:INotificationHandler<DivertVisitorToExtNotification>
- {
- private readonly ICallRepository _callRepository;
- private readonly ICallDetailRepository _callDetailRepository;
- public DivertVisitorToExtNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository)
- {
- _callRepository = callRepository;
- _callDetailRepository = callDetailRepository;
- }
- public async Task Handle(DivertVisitorToExtNotification notification, CancellationToken cancellationToken)
- {
- var model = await _callRepository.GetAsync(
- x => x.ConversationId == notification.Visitor.Id && x.FromNo == notification.Visitor.From &&
- x.ToNo == notification.Visitor.To && x.CreationTime >= DateTime.Now.AddHours(-2),true,x=>x.CreationTime,
- cancellationToken);
- if (model!=null)
- {
- model.CallStatus = ECallStatus.Divert;
- await _callRepository.UpdateAsync(model, cancellationToken);
- var detail = new CallDetail()
- {
- CallId = model.Id,
- CallStatus = ECallStatus.Divert,
- OMCallId = notification.Visitor.CallId,
- ConversationId = notification.Visitor.Id,
- EventName = notification.Attribute,
- FromNo = notification.Visitor.From,
- ToNo = notification.Visitor.To
- };
- await _callDetailRepository.AddAsync(detail,cancellationToken);
- }
- }
- }
- }
|