CallReportApplication.cs 6.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.CallCenter.Calls;
  3. using Hotline.Settings;
  4. using Hotline.Share.Dtos.CallCenter;
  5. using Hotline.Share.Enums.CallCenter;
  6. using SqlSugar;
  7. using XF.Domain.Dependency;
  8. using XF.Domain.Exceptions;
  9. using XF.Domain.Repository;
  10. namespace Hotline.Application.StatisticalReport
  11. {
  12. public class CallReportApplication : ICallReportApplication, IScopeDependency
  13. {
  14. private readonly IRepository<TrCallRecord> _trCallRecordRepository;
  15. private readonly ISystemSettingCacheManager _systemSettingCacheManager;
  16. public CallReportApplication(
  17. IRepository<TrCallRecord> trCallRecordRepository,
  18. ISystemSettingCacheManager systemSettingCacheManager)
  19. {
  20. _trCallRecordRepository = trCallRecordRepository;
  21. _systemSettingCacheManager = systemSettingCacheManager;
  22. }
  23. /// <summary>
  24. /// 话务日期明细
  25. /// </summary>
  26. /// <param name="dto"></param>
  27. /// <returns></returns>
  28. public async Task<List<QueryCallsDetailDto>> QueryCallsDetailAsync(BiQueryCallsDto dto)
  29. {
  30. //超时接通量
  31. int CallInOverConnRingTime = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.CallInOverConnRingTime)?.SettingValue[0]);
  32. //坐席超时挂断时间
  33. int SeatChaoTime = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.SeatChaoTime)?.SettingValue[0]);
  34. //未接秒挂时间
  35. int noConnectByeTimes = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.NoConnectByeTimes)?.SettingValue[0]);
  36. //呼入有效时间
  37. int effectiveTimes = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.EffectiveTimes)?.SettingValue[0]);
  38. //接通秒挂时间
  39. int connectByeTimes = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.ConnectByeTimes)?.SettingValue[0]);
  40. var callData = await _trCallRecordRepository.Queryable()
  41. .Where(p => p.CreatedTime >= dto.StartTime && p.CreatedTime <= dto.EndTime)
  42. // .Where(p => p.Gateway != "82826886" && SqlFunc.Length(p.Gateway) != 4)
  43. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), p => p.Gateway == dto.Keyword)
  44. .GroupBy(p => p.CreatedTime.ToString("yyyy-MM-dd"))
  45. .Select(p => new QueryCallsDetailDto
  46. {
  47. Date = p.CreatedTime.ToString("yyyy-MM-dd"),
  48. InTotal = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.In, 1, 0)),//呼入总量
  49. InConnectionQuantity = SqlFunc.AggregateSum(SqlFunc.IIF(p.OnState == EOnState.On && p.CallDirection == ECallDirection.In && p.AnsweredTime != null, 1, 0)),//呼入接通量
  50. NotAcceptedHang = SqlFunc.AggregateSum(SqlFunc.IIF(p.Duration == 0 && p.RingTimes <= noConnectByeTimes && p.RingTimes > 0, 1, 0)), //未接通秒挂
  51. TotalDurationIncomingCalls = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.In && p.AnsweredTime != null && p.OnState == EOnState.On, p.Duration, 0)), //呼入总时长
  52. InAvailableAnswer = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.In && p.AnsweredTime != null && p.Duration >= effectiveTimes, 1, 0)),//有效接通量
  53. InHangupImmediateWhenAnswered = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.In && p.Duration > 0 && p.Duration <= connectByeTimes, 1, 0)), //呼入接通秒挂
  54. TimeoutConnection = SqlFunc.AggregateSum(SqlFunc.IIF(p.OnState == EOnState.On && p.CallDirection == ECallDirection.In && p.AnsweredTime != null && p.RingTimes >= CallInOverConnRingTime, 1, 0)),//超时接通量
  55. TimeoutSuspension = SqlFunc.AggregateSum(SqlFunc.IIF(p.OnState == EOnState.On && p.CallDirection == ECallDirection.In && p.AnsweredTime != null && p.Duration >= SeatChaoTime, 1, 0)),//超时挂断量
  56. QueueByeCount = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.In && p.QueueTims > 0 && p.RingTimes == 0 && p.OnState == EOnState.NoOn, 1, 0)), //队列挂断
  57. 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挂断
  58. OutTotal = SqlFunc.AggregateSum(SqlFunc.IIF(p.CallDirection == ECallDirection.Out, 1, 0)),//呼出总量
  59. OutConnectionQuantity = SqlFunc.AggregateSum(SqlFunc.IIF(p.OnState == EOnState.On && p.CallDirection == ECallDirection.Out && p.AnsweredTime != null, 1, 0))
  60. })
  61. .OrderBy(p => p.Date)
  62. .ToListAsync();
  63. return callData;
  64. }
  65. /// <summary>
  66. /// 话务日期明细-呼入总量/接通总量
  67. /// </summary>
  68. /// <param name="dto"></param>
  69. /// <returns></returns>
  70. public ISugarQueryable<TrCallRecord> QueryCallsDetailInTotalAsync(BiQueryCallsDto dto)
  71. {
  72. if (!dto.StartTime.HasValue || !dto.EndTime.HasValue)
  73. throw UserFriendlyException.SameMessage("请选择时间!");
  74. dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
  75. return _trCallRecordRepository.Queryable()
  76. .Includes(p => p.Order)
  77. .Where(p => p.CreatedTime >= dto.StartTime && p.CreatedTime <= dto.EndTime && p.CallDirection == ECallDirection.In)
  78. .WhereIF(dto.TypeCode == "2", p => p.OnState == EOnState.On && p.AnsweredTime != null)
  79. // .Where(p => p.Gateway != "82826886" && SqlFunc.Length(p.Gateway) != 4)
  80. .WhereIF(!string.IsNullOrEmpty(dto.Keyword), p => p.Gateway == dto.Keyword)
  81. .OrderByDescending(p => p.CreatedTime)
  82. .MergeTable();
  83. }
  84. }
  85. }