admin 2 年 前
コミット
f45b19d93b

+ 5 - 1
src/CallCenter.Api/Controllers/TelController.cs

@@ -467,6 +467,10 @@ namespace CallCenter.Api.Controllers
             {
                 throw new UserFriendlyException("未找到当前通话");
             }
+            if (call.CallDirection!= ECallDirection.In)
+            {
+                throw new UserFriendlyException("当前通话不是来电,不能发送评价邀请");
+            }
             if (call.CallStatus ==  ECallStatus.Bye)
             {
                 throw new UserFriendlyException("当前通话已结束");
@@ -486,7 +490,7 @@ namespace CallCenter.Api.Controllers
             var ivrList = _ivrCacheManager.GetIvrs();
             var ivr = ivrList.First(x => x.IvrCategoryId == correct.ReturnValue && x.IsRoot);
 
-            _logger.LogInformation("transfer to ivr.no:{ivrNo}", ivr.No);
+            _logger.LogInformation("transfer to ivr.no:{ivrNo}", ivr.No);
 
             //写入子表
             var detail = new CallDetail()

+ 67 - 0
src/CallCenter.Application/Handlers/FlowControl/ByeVisitorAndMenuNotificationHandler.cs

@@ -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);
+                    }
+                }
+            }
+        }
+    }
+}

+ 5 - 1
src/CallCenter.NewRock/Handlers/DeviceEventHandler.cs

@@ -191,7 +191,11 @@ namespace CallCenter.NewRock.Handlers
                     case Event.BYE:
                         var byeRcv = content.DeserializeWithAuthorize<ByeEvent>();
                         //来电和分机的通话结束,来电挂断
-                        if (byeRcv.value?.Ext != null && byeRcv.value?.Visitor != null)
+                        if(byeRcv.value?.Visitor!=null && byeRcv.value?.Menu !=null)
+                        {
+                            await _mediator.Publish(_mapper.Map<ByeVisitorAndMenuNotification>(byeRcv.value!), cancellationToken);
+                        }
+                        else if (byeRcv.value?.Ext != null && byeRcv.value?.Visitor != null)
                         {
                             await _mediator.Publish(_mapper.Map<ByeVisitorAndExtNotification>(byeRcv.value!),
                                 cancellationToken);

+ 14 - 0
src/CallCenter.Share/Notifications/ByeVisitorAndMenuNotification.cs

@@ -0,0 +1,14 @@
+using CallCenter.Notifications.Base;
+using CallCenter.Share.Notifications.Base;
+using MediatR;
+
+namespace CallCenter.Share.Notifications
+{
+    public class ByeVisitorAndMenuNotification: BaseEvent, INotification
+    {
+        public BaseVisitor Visitor { get; set; }
+
+        public BaseMenu Menu { get; set; }
+
+    }
+}

+ 3 - 0
src/NewRock.Sdk/Events/ByeEvent.cs

@@ -19,5 +19,8 @@ namespace NewRock.Sdk.Events
 
         [XmlElement("recording")]
         public string Recording { get; set; }
+
+        [XmlElement("menu")]
+        public BaseMenu Menu { get; set; }
     }
 }