|
@@ -0,0 +1,67 @@
|
|
|
+using CallCenter.Caches;
|
|
|
+using CallCenter.Calls;
|
|
|
+using CallCenter.Notifications;
|
|
|
+using CallCenter.Realtimes;
|
|
|
+using CallCenter.Share.Notifications;
|
|
|
+using MediatR;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace CallCenter.Application.Handlers.FlowControl
|
|
|
+{
|
|
|
+ public class ByeVisitorAndMenuNotificationHandler : INotificationHandler<ByeVisitorAndMenuNotification>
|
|
|
+ {
|
|
|
+ private readonly ICallRepository _callRepository;
|
|
|
+ private readonly ICallDetailRepository _callDetailRepository;
|
|
|
+ private readonly IRealtimeService _realtimeService;
|
|
|
+ private readonly IUserCacheManager _userCacheManager;
|
|
|
+ public ByeVisitorAndMenuNotificationHandler(ICallRepository callRepository, ICallDetailRepository callDetailRepository,IRealtimeService realtimeService,IUserCacheManager userCacheManager)
|
|
|
+ {
|
|
|
+ _callRepository = callRepository;
|
|
|
+ _callDetailRepository = callDetailRepository;
|
|
|
+ _realtimeService = realtimeService;
|
|
|
+ _userCacheManager = userCacheManager;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public async Task Handle(ByeVisitorAndMenuNotification notification, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var model = await _callRepository.GetAsync(x => x.ConversationId == notification.Visitor.Id && x.FromNo == notification.Visitor.From && x.CreationTime >= DateTime.Now.AddHours(-2), cancellationToken);
|
|
|
+ if (model!=null)
|
|
|
+ {
|
|
|
+ model.CallStatus = Share.Enums.ECallStatus.Bye;
|
|
|
+ model.EndBy = Share.Enums.EEndBy.To;
|
|
|
+ model.RingOffType = Share.Enums.ERingOffType.Normal;
|
|
|
+ await _callRepository.UpdateAsync(model, cancellationToken);
|
|
|
+ var detail = new CallDetail()
|
|
|
+ {
|
|
|
+ CallId = model.Id,
|
|
|
+ CallStatus = Share.Enums.ECallStatus.Bye,
|
|
|
+ OMCallId = notification.Visitor.CallId,
|
|
|
+ ConversationId = notification.Visitor.Id,
|
|
|
+ EventName = notification.Attribute,
|
|
|
+ FromNo = notification.Visitor.From,
|
|
|
+ ToNo = notification.Visitor.To,
|
|
|
+ Remark = notification.Menu.Id
|
|
|
+ };
|
|
|
+ await _callDetailRepository.AddAsync(detail, cancellationToken);
|
|
|
+
|
|
|
+ //查询应答分机号
|
|
|
+ var callDetailAnswer = await _callDetailRepository.GetAsync(x => x.CallId == model.Id && x.EventName == "ANSWER", true, d => d.CreationTime);
|
|
|
+ if (callDetailAnswer != null)
|
|
|
+ {
|
|
|
+ //调用业务通知 通知订阅
|
|
|
+ var workModel = _userCacheManager.GetWorkByTel(callDetailAnswer.AnswerNo);
|
|
|
+ if (workModel != null)
|
|
|
+ {
|
|
|
+ await _realtimeService.ByeAsync(workModel.UserId, new ByeDto() { Id = model.Id }, cancellationToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|