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