1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using Hotline.Caching.Interfaces;
- using Hotline.CallCenter.Calls;
- using Hotline.Settings;
- using Hotline.Share.Dtos.CallCenter;
- using Hotline.Share.Enums.CallCenter;
- using SqlSugar;
- using XF.Domain.Dependency;
- using XF.Domain.Exceptions;
- using XF.Domain.Repository;
- namespace Hotline.Application.StatisticalReport
- {
- public class CallReportApplication : ICallReportApplication, IScopeDependency
- {
- private readonly IRepository<TrCallRecord> _trCallRecordRepository;
- private readonly ISystemSettingCacheManager _systemSettingCacheManager;
- public CallReportApplication(
- IRepository<TrCallRecord> trCallRecordRepository,
- ISystemSettingCacheManager systemSettingCacheManager)
- {
- _trCallRecordRepository = trCallRecordRepository;
- _systemSettingCacheManager = systemSettingCacheManager;
- }
- /// <summary>
- /// 话务日期明细
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<List<QueryCallsDetailDto>> QueryCallsDetailAsync(BiQueryCallsDto dto)
- {
- //超时接通量
- int CallInOverConnRingTime = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.CallInOverConnRingTime)?.SettingValue[0]);
- //坐席超时挂断时间
- int SeatChaoTime = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.SeatChaoTime)?.SettingValue[0]);
- //未接秒挂时间
- int noConnectByeTimes = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.NoConnectByeTimes)?.SettingValue[0]);
- //呼入有效时间
- int effectiveTimes = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.EffectiveTimes)?.SettingValue[0]);
- //接通秒挂时间
- int connectByeTimes = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.ConnectByeTimes)?.SettingValue[0]);
- var callData = await _trCallRecordRepository.Queryable()
- .Where(p => p.CreatedTime >= dto.StartTime && p.CreatedTime <= dto.EndTime)
- // .Where(p => p.Gateway != "82826886" && SqlFunc.Length(p.Gateway) != 4)
- .WhereIF(!string.IsNullOrEmpty(dto.Keyword), p => p.Gateway == dto.Keyword)
- .GroupBy(p => p.CreatedTime.ToString("yyyy-MM-dd"))
- .Select(p => new QueryCallsDetailDto
- {
- Date = p.CreatedTime.ToString("yyyy-MM-dd"),
- InTotal = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.In, 1, 0)),//呼入总量
- InConnectionQuantity = SqlFunc.AggregateSum(SqlFunc.IIF(p.OnState == EOnState.On && p.CallDirection == ECallDirection.In && p.AnsweredTime != null, 1, 0)),//呼入接通量
- NotAcceptedHang = SqlFunc.AggregateSum(SqlFunc.IIF(p.Duration == 0 && p.RingTimes <= noConnectByeTimes && p.RingTimes > 0, 1, 0)), //未接通秒挂
- TotalDurationIncomingCalls = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.In && p.AnsweredTime != null && p.OnState == EOnState.On, p.Duration, 0)), //呼入总时长
- InAvailableAnswer = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.In && p.AnsweredTime != null && p.Duration >= effectiveTimes, 1, 0)),//有效接通量
- InHangupImmediateWhenAnswered = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.In && p.Duration > 0 && p.Duration <= connectByeTimes, 1, 0)), //呼入接通秒挂
- TimeoutConnection = SqlFunc.AggregateSum(SqlFunc.IIF(p.OnState == EOnState.On && p.CallDirection == ECallDirection.In && p.AnsweredTime != null && p.RingTimes >= CallInOverConnRingTime, 1, 0)),//超时接通量
- TimeoutSuspension = SqlFunc.AggregateSum(SqlFunc.IIF(p.OnState == EOnState.On && p.CallDirection == ECallDirection.In && p.AnsweredTime != null && p.Duration >= SeatChaoTime, 1, 0)),//超时挂断量
- QueueByeCount = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.In && p.QueueTims > 0 && p.RingTimes == 0 && p.OnState == EOnState.NoOn, 1, 0)), //队列挂断
- IvrByeCount = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.In && p.BeginIvrTime.HasValue && !p.BeginQueueTime.HasValue && !p.BeginRingTime.HasValue && p.OnState == EOnState.NoOn, 1, 0)), //IVR挂断
- OutTotal = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.Out, 1, 0)),//呼出总量
- OutConnectionQuantity = SqlFunc.AggregateSum(SqlFunc.IIF(p.OnState == EOnState.On && p.CallDirection == ECallDirection.Out && p.AnsweredTime != null, 1, 0))
- })
- .OrderBy(p => p.Date)
- .ToListAsync();
- return callData;
- }
- /// <summary>
- /// 话务日期明细-呼入总量/接通总量
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public ISugarQueryable<TrCallRecord> QueryCallsDetailInTotalAsync(BiQueryCallsDto dto)
- {
- if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
- throw UserFriendlyException.SameMessage("请选择时间!");
- dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
- return _trCallRecordRepository.Queryable()
- .Includes(p => p.Order)
- .Where(p => p.CreatedTime >= dto.StartTime && p.CreatedTime <= dto.EndTime && p.CallDirection == ECallDirection.In)
- .WhereIF(dto.TypeCode == "2", p => p.OnState == EOnState.On && p.AnsweredTime != null)
- // .Where(p => p.Gateway != "82826886" && SqlFunc.Length(p.Gateway) != 4)
- .WhereIF(!string.IsNullOrEmpty(dto.Keyword), p => p.Gateway == dto.Keyword)
- .OrderByDescending(p => p.CreatedTime)
- .MergeTable();
- }
- }
- }
|