admin 2 سال پیش
والد
کامیت
460b615f0e

+ 12 - 3
src/CallCenter.Api/Controllers/CallController.cs

@@ -1,4 +1,5 @@
-using CallCenter.Calls;
+using CallCenter.Caches;
+using CallCenter.Calls;
 using CallCenter.Share.Dtos;
 using CallCenter.Share.Enums;
 using CallCenter.Share.Requests;
@@ -6,6 +7,7 @@ using MapsterMapper;
 using MessagePack.Formatters;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Options;
+using XF.Domain.Authentications;
 
 namespace CallCenter.Api.Controllers
 {
@@ -18,13 +20,17 @@ namespace CallCenter.Api.Controllers
         private readonly ICallRepository _callRepository;
         private readonly IMapper _mapper;
         private readonly ICallDetailRepository _callDetailRepository;
+        private readonly ISessionContext _sessionContext;
+        private readonly IUserCacheManager _userCacheManager;
 
-        public CallController(ICallDomainService callDomainService, ICallRepository callRepository, IMapper mapper, ICallDetailRepository callDetailRepository)
+        public CallController(ICallDomainService callDomainService, ICallRepository callRepository, IMapper mapper, ICallDetailRepository callDetailRepository, ISessionContext sessionContext,IUserCacheManager userCacheManager)
         {
             _callDomainService = callDomainService;
             _callRepository = callRepository;
             _mapper = mapper;
             _callDetailRepository = callDetailRepository;
+            _sessionContext = sessionContext;
+            _userCacheManager = userCacheManager;
         }
 
 
@@ -36,8 +42,11 @@ namespace CallCenter.Api.Controllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("ClearExt")]
-        public async Task ClearExt([FromBody] ClearExtRequest request)
+        public async Task ClearExt()
         {
+            var userid = _sessionContext.RequiredUserId;
+            var work = _userCacheManager.GetWorkByUser(userid);
+            var request = new ClearExtRequest(work.TelNo);
             await _callDomainService.ClearExtAsync(request, HttpContext.RequestAborted);
         }
 

+ 40 - 0
src/CallCenter.Application/Handlers/CallState/RingExtToExtNotificationHandler.cs

@@ -0,0 +1,40 @@
+using CallCenter.Caches;
+using CallCenter.Calls;
+using CallCenter.Notifications;
+using CallCenter.Realtimes;
+using CallCenter.Share.Enums;
+using MediatR;
+
+namespace CallCenter.Application.Handlers.CallState
+{
+    public class RingExtToExtNotificationHandler : INotificationHandler<RingExtToExtNotification>
+    {
+        private readonly IRealtimeService _realtimeService;
+        private readonly IUserCacheManager _userCacheManager;
+
+
+        public RingExtToExtNotificationHandler(IRealtimeService realtimeService, IUserCacheManager userCacheManager)
+        {
+            _realtimeService = realtimeService;
+            _userCacheManager = userCacheManager;
+        }
+
+
+        public async Task Handle(RingExtToExtNotification notification, CancellationToken cancellationToken)
+        {
+            //通知前端主叫
+            //获取主叫工作信息
+            var fromWork = _userCacheManager.GetWorkByTel(notification.FromTelNo);
+            if (fromWork != null)
+            {
+                await _realtimeService.RingAsync(fromWork.UserId, new RingDto() { Id = notification.FromTelNo, From = notification.FromTelNo, To = notification.ToTelNo, CallType =ECallType.ExtToExt }, cancellationToken);
+            }
+            //通知前端被叫
+            var toWork = _userCacheManager.GetWorkByTel(notification.ToTelNo);
+            if (toWork != null)
+            {
+                await _realtimeService.RingAsync(toWork.UserId, new RingDto() { Id = notification.ToTelNo, From = notification.FromTelNo, To = notification.ToTelNo, CallType = ECallType.ExtToExt }, cancellationToken);
+            }
+        }
+    }
+}

+ 43 - 0
src/CallCenter.Application/Handlers/FlowControl/AnswerExtToExtNotificationHandler.cs

@@ -0,0 +1,43 @@
+using CallCenter.Caches;
+using CallCenter.Notifications;
+using CallCenter.Realtimes;
+using CallCenter.Share.Enums;
+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 AnswerExtToExtNotificationHandler : INotificationHandler<AnswerExtToExtNotification>
+    {
+        private readonly IRealtimeService _realtimeService;
+        private readonly IUserCacheManager _userCacheManager;
+
+        public AnswerExtToExtNotificationHandler(IRealtimeService realtimeService,IUserCacheManager userCacheManager)
+        {
+            _realtimeService = realtimeService;
+            _userCacheManager = userCacheManager;
+        }
+
+        public async Task Handle(AnswerExtToExtNotification notification, CancellationToken cancellationToken)
+        {
+            //通知前端主叫
+            //获取主叫工作信息
+            var fromWork = _userCacheManager.GetWorkByTel(notification.FromTelNo);
+            if (fromWork != null)
+            {
+                await _realtimeService.AnsweredAsync(fromWork.UserId, new AnseredDto() { Id = notification.FromTelNo,From= notification.FromTelNo,To = notification.ToTelNo , CallType= ECallType.ExtToExt }, cancellationToken);
+            }
+            //通知前端被叫
+            var toWork = _userCacheManager.GetWorkByTel(notification.ToTelNo);
+            if (toWork != null)
+            {
+                await _realtimeService.AnsweredAsync(toWork.UserId, new AnseredDto() { Id = notification.ToTelNo,From = notification.FromTelNo,To = notification.ToTelNo, CallType = ECallType.ExtToExt }, cancellationToken);
+            }
+        }
+    }
+}

+ 39 - 0
src/CallCenter.Application/Handlers/FlowControl/AnsweredExtToExtNotificationHandler.cs

@@ -0,0 +1,39 @@
+using CallCenter.Caches;
+using CallCenter.Notifications;
+using CallCenter.Realtimes;
+using CallCenter.Share.Enums;
+using MediatR;
+
+namespace CallCenter.Application.Handlers.FlowControl
+{
+    public class AnsweredExtToExtNotificationHandler : INotificationHandler<AnsweredExtToExtNotification>
+    {
+
+        private readonly IRealtimeService _realtimeService;
+        private readonly IUserCacheManager _userCacheManager;
+
+        public AnsweredExtToExtNotificationHandler(IRealtimeService realtimeService, IUserCacheManager userCacheManager)
+        {
+            _realtimeService = realtimeService;
+            _userCacheManager = userCacheManager;
+        }
+
+
+        public async Task Handle(AnsweredExtToExtNotification notification, CancellationToken cancellationToken)
+        {
+            //通知前端主叫
+            //获取主叫工作信息
+            var fromWork = _userCacheManager.GetWorkByTel(notification.FromTelNo);
+            if (fromWork != null)
+            {
+                await _realtimeService.AnsweredAsync(fromWork.UserId, new AnseredDto() { Id = notification.FromTelNo, From = notification.FromTelNo, To = notification.ToTelNo, CallType = ECallType.ExtToExt }, cancellationToken);
+            }
+            //通知前端被叫
+            var toWork = _userCacheManager.GetWorkByTel(notification.ToTelNo);
+            if (toWork != null)
+            {
+                await _realtimeService.AnsweredAsync(toWork.UserId, new AnseredDto() { Id = notification.ToTelNo, From = notification.FromTelNo, To = notification.ToTelNo, CallType = ECallType.ExtToExt }, cancellationToken);
+            }
+        }
+    }
+}

+ 41 - 0
src/CallCenter.Application/Handlers/FlowControl/ByeExtAndExtNotificationHandler.cs

@@ -0,0 +1,41 @@
+
+
+using CallCenter.Caches;
+using CallCenter.Notifications;
+using CallCenter.Realtimes;
+using CallCenter.Share.Enums;
+using CallCenter.Share.Notifications;
+using MediatR;
+
+namespace CallCenter.Application.Handlers.FlowControl
+{
+    public class ByeExtAndExtNotificationHandler : INotificationHandler<ByeExtAndExtNotification>
+    {
+
+        private readonly IRealtimeService _realtimeService;
+        private readonly IUserCacheManager _userCacheManager;
+
+        public ByeExtAndExtNotificationHandler(IRealtimeService realtimeService, IUserCacheManager userCacheManager)
+        {
+            _realtimeService = realtimeService;
+            _userCacheManager = userCacheManager;
+        }
+
+        public async Task Handle(ByeExtAndExtNotification notification, CancellationToken cancellationToken)
+        {
+            //通知前端主叫
+            //获取主叫工作信息
+            var fromWork = _userCacheManager.GetWorkByTel(notification.FromTelNo);
+            if (fromWork != null)
+            {
+                await _realtimeService.ByeAsync(fromWork.UserId, new ByeDto() { Id = notification.FromTelNo }, cancellationToken);
+            }
+            //通知前端被叫
+            var toWork = _userCacheManager.GetWorkByTel(notification.ToTelNo);
+            if (toWork != null)
+            {
+                await _realtimeService.ByeAsync(toWork.UserId, new ByeDto() { Id = notification.ToTelNo}, cancellationToken);
+            }
+        }
+    }
+}

+ 7 - 2
src/CallCenter.NewRock/Handlers/DeviceEventHandler.cs

@@ -86,7 +86,7 @@ namespace CallCenter.NewRock.Handlers
                         //分机呼分机
                         if (ringRcv.value?.Ext.Count > 1)
                         {
-                            //await _mediator.Publish(_mapper.Map<RingExtToExtNotification>(ringRcv.value!),cancellationToken);
+                            await _mediator.Publish(_mapper.Map<RingExtToExtNotification>(ringRcv.value!),cancellationToken);
                         }
                         //来电转分机
                         else if (ringRcv.value?.Ext.Count == 1 && ringRcv.value.Visitor != null)
@@ -195,7 +195,7 @@ namespace CallCenter.NewRock.Handlers
                         {
                             await _mediator.Publish(_mapper.Map<ByeVisitorAndMenuNotification>(byeRcv.value!), cancellationToken);
                         }
-                        else if (byeRcv.value?.Ext != null && byeRcv.value?.Visitor != null)
+                        else if (byeRcv.value?.Ext.Count == 1 && byeRcv.value?.Visitor != null)
                         {
                             await _mediator.Publish(_mapper.Map<ByeVisitorAndExtNotification>(byeRcv.value!),
                                 cancellationToken);
@@ -212,6 +212,11 @@ namespace CallCenter.NewRock.Handlers
                             await _mediator.Publish(_mapper.Map<ByeVisitorAndOuterNotification>(byeRcv.value!),
                                 cancellationToken);
                         }
+                        //分机和分机通话,分机挂断
+                        else if (byeRcv.value?.Ext.Count > 1)
+                        {
+                            await _mediator.Publish(_mapper.Map<ByeExtAndExtNotification>(byeRcv.value!), cancellationToken);
+                        }
                         //其他条件
                         else if (byeRcv.value?.Outer != null)
                         {

+ 10 - 7
src/CallCenter.NewRock/Mappers/EventConfigs.cs

@@ -44,8 +44,8 @@ namespace CallCenter.NewRock.Mappers
             #region 振铃时间
             //分机呼分机
             config.NewConfig<RingEvent, RingExtToExtNotification>()
-                .Map(d => d.FromTelNo, x => x.Ext.First().Id)
-                .Map(d => d.ToTelNo, x => x.Ext.Last().Id);
+                .Map(d => d.FromTelNo, x => x.Ext.Last().Id)
+                .Map(d => d.ToTelNo, x => x.Ext.First().Id);
             //来电转分机
             config.NewConfig<RingEvent, RingVisitorToExtNotification>()
                 .Map(d => d.TelNo, x => x.Ext.First().Id);
@@ -78,8 +78,8 @@ namespace CallCenter.NewRock.Mappers
 
             //分机呼分机,被叫分机应答
             config.NewConfig<AnswerEvent, AnswerExtToExtNotification>()
-                .Map(d => d.FromTelNo, x => x.Ext.First().Id)
-                .Map(d=>d.ToTelNo,x=>x.Ext.Last().Id);
+                .Map(d => d.FromTelNo, x => x.Ext.Last().Id)
+                .Map(d=>d.ToTelNo,x => x.Ext.First().Id);
             //来电转分机,分机应答
             config.NewConfig<AnswerEvent, AnswerViisitorToExtNotification>()
                 .Map(d => d.TelNo, x => x.Ext.First().Id);
@@ -102,11 +102,14 @@ namespace CallCenter.NewRock.Mappers
             #region 通话结束事件
             //来电和分机的通话结束,来电挂断
             config.NewConfig<ByeEvent, ByeVisitorAndExtNotification>()
-                .Map(d => d.TelNo, x => x.Ext.Id);
+                .Map(d => d.TelNo, x => x.Ext.First().Id);
             //分机和去电的通话结束,分机挂断 类型一
             config.NewConfig<ByeEvent, ByeExtAndOuterOneNotification>()
-                .Map(d => d.TelNo, x => x.Ext.Id);
-            //
+                .Map(d => d.TelNo, x => x.Ext.First().Id);
+            //分机和分机的通话结束
+            config.NewConfig<ByeEvent, ByeExtAndExtNotification>()
+                .Map(d => d.FromTelNo, x => x.Ext.Last().Id)
+                .Map(d => d.ToTelNo, x => x.Ext.First().Id);
             #endregion
 
             #region 呼叫转移事件

+ 12 - 0
src/CallCenter.Share/Notifications/ByeExtAndExtNotification.cs

@@ -0,0 +1,12 @@
+using CallCenter.Share.Notifications.Base;
+using MediatR;
+
+namespace CallCenter.Share.Notifications
+{
+    public class ByeExtAndExtNotification: BaseEvent, INotification
+    {
+        public string FromTelNo { get; set; }
+
+        public string ToTelNo { get; set; }
+    }
+}

+ 1 - 1
src/NewRock.Sdk/Events/ByeEvent.cs

@@ -9,7 +9,7 @@ namespace NewRock.Sdk.Events
     public class ByeEvent: NewRockEvent
     {
         [XmlElement("ext")]
-        public Ext Ext { get; set; }
+        public List<Ext> Ext { get; set; }
 
         [XmlElement("visitor")]
         public BaseVisitor Visitor { get; set; }