admin 1 year ago
parent
commit
698f18f8f9

+ 4 - 3
src/CallCenter.Api/appsettings.Development.json

@@ -44,15 +44,16 @@
     "Expired": 86400 //认证过期时间(秒)
   },
   "ConnectionStrings": {
-    "CallCenter": "server=192.168.100.121;Database=callcenter;Uid=dev;Pwd=fengwo11!!;SslMode=none;",
-    "Redis": "192.168.100.223"
+    "CallCenter": "server=110.188.24.182;Database=callcenter;Uid=dev;Pwd=fengwo11!!;SslMode=none;",
+    "Redis": "110.188.24.182"
   },
   "Swagger": true,
   "Cors": {
     "Origins": [ "http://localhost:8888", "http://callcenter-admin.fengwo.com", "http://admin.call.fengwo.com" ]
   },
   "SendCallRecord": {
-    "FwUrl": "http://192.168.100.195:8066/api/call/insertcalls"
+    "FwUrl": "http://192.168.100.195:8066/api/call/insertcalls",
+    "NotReceivedUrl": "http://192.168.100.195:8066/api/call/insertringnotanswered"
   },
   "WorkTimeSettings": {
     "LineSetting": [

+ 2 - 2
src/CallCenter.Api/appsettings.json

@@ -44,8 +44,8 @@
     "Expired": 86400 //认证过期时间(秒)
   },
   "ConnectionStrings": {
-    "CallCenter": "server=db.fengwo.com;Database=callcenter;Uid=dev;Pwd=fengwo11!!;SslMode=none;",
-    "Redis": "192.168.100.223"
+    "CallCenter": "server=110.188.24.182;Database=callcenter;Uid=dev;Pwd=fengwo11!!;SslMode=none;",
+    "Redis": "110.188.24.182"
   },
   "Swagger": true,
   "Cors": {

+ 67 - 4
src/CallCenter.Application/Handlers/FlowControl/CdrNotificationHandler.cs

@@ -5,6 +5,7 @@ using CallCenter.Notifications;
 using CallCenter.Realtimes;
 using CallCenter.Share.Dtos;
 using CallCenter.Share.Enums;
+using CallCenter.Users;
 using MediatR;
 using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Options;
@@ -26,8 +27,10 @@ namespace CallCenter.Application.Handlers
         private readonly ILogger<CdrNotificationHandler> _logger;
         private readonly IRealtimeService _realtimeService;
         private readonly IUserCacheManager _userCacheManager;
+        private readonly IWorkRepository _workRepository;
 
-        public CdrNotificationHandler(ICallRecordRepository callRecordRepository, ICallDetailRepository callDetailRepository, ICallRepository callRepository, IOptionsSnapshot<SendCallRecord> sendCallRecordOptions, IHttpClientFactory httpClientFactory,ILogger<CdrNotificationHandler> logger,IRealtimeService realtimeService,IUserCacheManager userCacheManager)
+
+        public CdrNotificationHandler(ICallRecordRepository callRecordRepository, ICallDetailRepository callDetailRepository, ICallRepository callRepository, IOptionsSnapshot<SendCallRecord> sendCallRecordOptions, IHttpClientFactory httpClientFactory,ILogger<CdrNotificationHandler> logger,IRealtimeService realtimeService,IUserCacheManager userCacheManager,IWorkRepository workRepository)
         {
             _callRecordRepository = callRecordRepository;
             _callDetailRepository = callDetailRepository;
@@ -37,6 +40,7 @@ namespace CallCenter.Application.Handlers
             _logger = logger;
             _realtimeService = realtimeService;
             _userCacheManager = userCacheManager;
+            _workRepository = workRepository;
         }
 
 
@@ -107,11 +111,13 @@ namespace CallCenter.Application.Handlers
                     {
                         if (callModel != null)
                         {
+                            #region 推送通话记录报告
+
                             callModel.Duration = double.Parse(model.Duration);
                             await _callRepository.UpdateAsync(callModel, cancellationToken);
 
                             var call = await _callRepository.GetExtAsync(callModel.Id, x => x.Includes(d => d.CallDetails));
-                            //TODO 推送通话报告
+                            //推送通话报告
                             OutCallDto callDto = new OutCallDto();
                             callDto.CallId = callDetail.CallId;
                             callDto.InfoType = EInfoType.Call;
@@ -168,13 +174,70 @@ namespace CallCenter.Application.Handlers
                                 var respContent = responseMessage.Content;
                                 var respContentString = await respContent.ReadAsStringAsync(cancellationToken);
                                 var result = JsonSerializer.Deserialize<FwResult>(respContentString);
-                                _logger.LogInformation("推送报告结果:" + respContentString);
+                                _logger.LogInformation("推送通话报告结果:" + respContentString);
                             }
                             catch (Exception ex)
                             {
                                 throw new UserFriendlyException(ex.Message);
                             }
-                            //HttpContent content = new 
+                            #endregion
+
+                            #region 推送超时未接记录报告
+                            //准备报告
+                            //查询是否有15秒未接
+                             var ringList = call.CallDetails?.Where(x => x.CallStatus == ECallStatus.Ring).ToList();
+                            //多个振铃,包括转接(需要验证转接分机)
+                            if (ringList!=null && ringList.Count>1)
+                            {
+                                List<OutCallNotReceivedDto> NotReceivedList = new List<OutCallNotReceivedDto>();
+                                //验证是否被接过
+                                for (int i = 0; i < ringList.Count; i++)
+                                {
+                                    bool IsReceived = call.CallDetails?.Any(x => x.CallStatus == ECallStatus.Answer && x.AnswerNo == ringList[i].AnswerNo)??false;
+                                    //未接听 加入到集合中
+                                    if (!IsReceived)
+                                    {
+                                        var notReceivedEntity = new OutCallNotReceivedDto();
+                                        notReceivedEntity.CallId = ringList[i].CallId;
+                                        notReceivedEntity.Cpn = ringList[i].FromNo;
+                                        notReceivedEntity.Cdpn = ringList[i].ToNo;
+                                        notReceivedEntity.Answered = ringList[i].AnswerNo;
+                                        notReceivedEntity.RingTime = ringList[i].CreationTime;
+                                        //验证是否在签入状态振铃
+                                        var iswork = await _workRepository.AnyAsync(x => x.TelNo == notReceivedEntity.Answered && !x.EndTime.HasValue);
+                                        notReceivedEntity.IsWorkRing = iswork;
+                                        NotReceivedList.Add(notReceivedEntity);
+                                    }
+                                }
+                                if (NotReceivedList.Count>0)
+                                {
+                                    //推送报告
+                                    try
+                                    {
+                                        using var client = _httpClientFactory.CreateClient();
+                                        client.DefaultRequestHeaders.ConnectionClose = true;
+                                        var requestContent = JsonSerializer.Serialize(NotReceivedList);
+                                        _logger.LogInformation(requestContent);
+                                        var content = new StringContent(requestContent, Encoding.UTF8, "application/json");
+                                        var responseMessage = await client.PostAsync(_sendCallRecordOptions.Value.NotReceivedUrl, content, cancellationToken);
+                                        var respContent = responseMessage.Content;
+                                        var respContentString = await respContent.ReadAsStringAsync(cancellationToken);
+                                        var result = JsonSerializer.Deserialize<FwResult>(respContentString);
+                                        _logger.LogInformation("推送未接听报告结果:" + respContentString);
+                                    }
+                                    catch (Exception ex)
+                                    {
+                                        throw new UserFriendlyException(ex.Message);
+                                    }
+                                }
+
+                            }
+                            //////////如果只有一条振铃记录或没有 就不推送
+
+                            #endregion
+
+
+
                         }
                     }
                 }

+ 31 - 0
src/CallCenter.Share/Dtos/OutCallDto.cs

@@ -114,4 +114,35 @@ namespace CallCenter.Share.Dtos
         #endregion
 
     }
+
+    public class OutCallNotReceivedDto
+    {
+        /// <summary>
+        /// 通话ID
+        /// </summary>
+        public string CallId { get; set; }
+        /// <summary>
+        /// 主叫
+        /// </summary>
+        public string Cpn { get; set; }
+        /// <summary>
+        /// 被叫
+        /// </summary>
+        public string Cdpn { get; set;}
+
+        /// <summary>
+        /// 响应分机
+        /// </summary>
+        public string Answered { get; set; }
+
+        /// <summary>
+        /// 振铃时间
+        /// </summary>
+        public DateTime RingTime { get; set; }
+
+        /// <summary>
+        /// 是否在签入时振铃
+        /// </summary>
+        public bool IsWorkRing { get; set; }
+    }
 }

+ 2 - 0
src/CallCenter/Calls/SendCallRecord.cs

@@ -9,5 +9,7 @@ namespace CallCenter.Calls
     public class SendCallRecord
     {
         public string FwUrl { get; set; }
+
+        public string NotReceivedUrl { get; set; }
     }
 }