|
@@ -3,16 +3,24 @@ using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
+using DotNetCore.CAP;
|
|
|
using Hotline.Caching.Interfaces;
|
|
|
using Hotline.Caching.Services;
|
|
|
using Hotline.CallCenter.BlackLists;
|
|
|
using Hotline.CallCenter.Calls;
|
|
|
using Hotline.CallCenter.Tels;
|
|
|
+using Hotline.Orders;
|
|
|
using Hotline.Repository.SqlSugar.CallCenter;
|
|
|
+using Hotline.Repository.SqlSugar.Extensions;
|
|
|
+using Hotline.Repository.SqlSugar.Orders;
|
|
|
using Hotline.Settings;
|
|
|
using Hotline.Share.Dtos.CallCenter;
|
|
|
+using Hotline.Share.Dtos.Order;
|
|
|
using Hotline.Share.Dtos.TrCallCenter;
|
|
|
+using Hotline.Share.Enums.CallCenter;
|
|
|
using Hotline.Users;
|
|
|
+using MapsterMapper;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
using XF.Domain.Authentications;
|
|
|
using XF.Domain.Cache;
|
|
|
using XF.Domain.Exceptions;
|
|
@@ -27,10 +35,14 @@ namespace Hotline.Application.CallCenter
|
|
|
private readonly IWorkRepository _workRepository;
|
|
|
private readonly ITelRestRepository _telRestRepository;
|
|
|
private readonly IRepository<CallNative> _callNativeRepository;
|
|
|
+ private readonly IOrderRepository _orderRepository;
|
|
|
+ private readonly IRepository<OrderVisit> _orderVisitRepository;
|
|
|
private readonly ITypedCache<Work> _cacheWork;
|
|
|
private readonly IUserCacheManager _userCacheManager;
|
|
|
private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
+ private readonly ICapPublisher _capPublisher;
|
|
|
private readonly ISessionContext _sessionContext;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
|
|
|
public XingTangCallApplication(
|
|
|
IRepository<Tel> telRepository,
|
|
@@ -38,20 +50,28 @@ namespace Hotline.Application.CallCenter
|
|
|
IWorkRepository workRepository,
|
|
|
ITelRestRepository telRestRepository,
|
|
|
IRepository<CallNative> callNativeRepository,
|
|
|
+ IOrderRepository orderRepository,
|
|
|
+ IRepository<OrderVisit> orderVisitRepository,
|
|
|
ITypedCache<Work> cacheWork,
|
|
|
IUserCacheManager userCacheManager,
|
|
|
ISystemSettingCacheManager systemSettingCacheManager,
|
|
|
- ISessionContext sessionContext)
|
|
|
+ ICapPublisher capPublisher,
|
|
|
+ ISessionContext sessionContext,
|
|
|
+ IMapper mapper)
|
|
|
{
|
|
|
_telRepository = telRepository;
|
|
|
_telGroupRepository = telGroupRepository;
|
|
|
_workRepository = workRepository;
|
|
|
_telRestRepository = telRestRepository;
|
|
|
_callNativeRepository = callNativeRepository;
|
|
|
+ _orderRepository = orderRepository;
|
|
|
+ _orderVisitRepository = orderVisitRepository;
|
|
|
_cacheWork = cacheWork;
|
|
|
_userCacheManager = userCacheManager;
|
|
|
_systemSettingCacheManager = systemSettingCacheManager;
|
|
|
+ _capPublisher = capPublisher;
|
|
|
_sessionContext = sessionContext;
|
|
|
+ _mapper = mapper;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -184,12 +204,64 @@ namespace Hotline.Application.CallCenter
|
|
|
/// <summary>
|
|
|
/// 定量查询通话记录
|
|
|
/// </summary>
|
|
|
- public async Task<IReadOnlyList<CallNative>> QueryCallsFixedAsync(QueryCallsFixedDto dto, CancellationToken cancellationToken)
|
|
|
+ public async Task<IReadOnlyList<CallNativeDto>> QueryCallsFixedAsync(QueryCallsFixedDto dto, CancellationToken cancellationToken)
|
|
|
{
|
|
|
var count = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.FixedQueryCount).SettingValue[0]);
|
|
|
- var calls = await _callNativeRepository.Queryable()
|
|
|
- .WhereIF(!string.IsNullOrEmpty(dto.OrderNo), d=>d.OrderNo == dto.OrderNo)
|
|
|
+ return await _callNativeRepository.Queryable()
|
|
|
+ .LeftJoin<Order>((d, o) => d.CallNo == o.CallId)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.OrderNo), (d, o) => o.No == dto.OrderNo)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.FromNo), d => d.FromNo == dto.FromNo)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.ToNo), d => d.FromNo == dto.ToNo)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.UserName), d => d.FromNo == dto.UserName)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.TelNo), d => d.FromNo == dto.TelNo)
|
|
|
+ .WhereIF(dto.HangupBy != null, d => d.HangupBy == dto.HangupBy)
|
|
|
+ .WhereIF(dto.CallStartTimeBT != null, d => d.BeginIvrTime >= dto.CallStartTimeBT)
|
|
|
+ .WhereIF(dto.CallStartTimeLT != null, d => d.BeginIvrTime <= dto.CallStartTimeLT)
|
|
|
+ .WhereIF(dto.IsConnected != null, d => d.AnsweredTime != null)
|
|
|
+ .WhereIF(dto.Direction != null, d => d.Direction == dto.Direction)
|
|
|
+ .Select((d, o) => new CallNativeDto
|
|
|
+ {
|
|
|
+ OrderId = o.Id,
|
|
|
+ OrderNo = o.No,
|
|
|
+ Title = o.Title,
|
|
|
+ }, true)
|
|
|
+ .ToFixedListAsync(dto, count, cancellationToken);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 关联通话记录与工单或回访
|
|
|
+ /// </summary>
|
|
|
+ public async Task RelateCallToOrderAsync(LinkCallRecordDto dto, CancellationToken cancellationToken)
|
|
|
+ {
|
|
|
+ var call = await _callNativeRepository.GetAsync(d => d.CallNo == dto.CallId, cancellationToken);
|
|
|
+ if (call is null) throw UserFriendlyException.SameMessage("无效通话记录编号");
|
|
|
+ if (dto.IsOrder)
|
|
|
+ {
|
|
|
+ //工单
|
|
|
+ var order = await _orderRepository.GetAsync(x => x.Id == dto.Id, cancellationToken);
|
|
|
+ if (order is null) throw UserFriendlyException.SameMessage("无效工单编号");
|
|
|
+ if (!string.IsNullOrEmpty(order.CallId))
|
|
|
+ throw UserFriendlyException.SameMessage("通话记录已经关联工单");
|
|
|
+
|
|
|
+ order.CallId = dto.CallId;
|
|
|
+ order.FromPhone = call.FromNo;
|
|
|
+ order.TransferPhone = call.ToNo;
|
|
|
+ await _orderRepository.UpdateAsync(order, cancellationToken);
|
|
|
|
|
|
+ //推省上
|
|
|
+ await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineCallConnectWithOrder,
|
|
|
+ new PublishCallRecrodDto() {
|
|
|
+ Order = _mapper.Map<OrderDto>(order),
|
|
|
+ TrCallRecordDto = _mapper.Map<TrCallDto>(call) });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //回访
|
|
|
+ var visit = await _orderVisitRepository.GetAsync(x => x.Id == dto.Id, cancellationToken);
|
|
|
+ if (visit is null) throw UserFriendlyException.SameMessage("无效回访记录编号");
|
|
|
+ visit.CallId = dto.CallId;
|
|
|
+ await _orderVisitRepository.UpdateAsync(visit, cancellationToken);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|