YiBinSeatStateDataService.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using DocumentFormat.OpenXml.Drawing;
  2. using Hotline.CallCenter.Calls;
  3. using Hotline.DI;
  4. using SqlSugar;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using XF.Domain.Dependency;
  11. using XF.Domain.Repository;
  12. namespace Hotline.Application.Bigscreen;
  13. [Injection(AppScopes = EAppScope.YiBin)]
  14. public class YiBinSeatStateDataService : SeatStateDataServiceBase, ISeatStateDataService, IScopeDependency
  15. {
  16. private readonly IRepository<TrCallRecord> _callRepository;
  17. public YiBinSeatStateDataService(IRepository<TrCallRecord> callRepository, IRepository<CallNative> repository) : base(repository)
  18. {
  19. _callRepository = callRepository;
  20. }
  21. public override async Task<object> GetCall24(CancellationToken stoppingToken)
  22. {
  23. List<string> timeList = new List<string>();
  24. for (int i = 0;i < 24;i++)
  25. {
  26. var time = i < 10 ? $"0{i}" : i.ToString();
  27. timeList.Add(time);
  28. }
  29. var now = DateTime.Now.Date;
  30. var call24 = await _callRepository.Queryable()
  31. .Where(x => x.CreatedTime.Date == now
  32. && x.CallOrderType == Share.Enums.CallCenter.ECallOrderType.Order && x.CallDirection == Share.Enums.CallCenter.ECallDirection.In
  33. )
  34. .Select(x => new { time = x.CreatedTime.ToString("hh"), x.CallDirection }).MergeTable()
  35. .GroupBy(x => x.time)
  36. .Select(x => new
  37. {
  38. Time = x.time.ToString(),
  39. In = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.In, 1, 0)),
  40. //Out = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.Out, 1, 0)),
  41. }).MergeTable().ToListAsync(stoppingToken);
  42. var callOut24 = await _callRepository.Queryable()
  43. .Where(x => x.CreatedTime.Date == now && x.CallDirection == Share.Enums.CallCenter.ECallDirection.Out)
  44. .Select(x => new { time = x.CreatedTime.ToString("hh"), x.CallDirection }).MergeTable()
  45. .GroupBy(x => x.time)
  46. .Select(x => new
  47. {
  48. Time = x.time.ToString(),
  49. Out = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.Out, 1, 0)),
  50. }).MergeTable().ToListAsync(stoppingToken);
  51. var call24List = (from t1 in timeList
  52. join t2 in call24 on t1 equals t2.Time into t1_t2
  53. join t3 in callOut24 on t1 equals t3.Time into t1_t3
  54. from item in t1_t3.DefaultIfEmpty()
  55. select new
  56. {
  57. Time = t1 + ":00",
  58. In = t1_t2.Select(x => x.In).FirstOrDefault(),
  59. Out = t1_t3.Select(x => x.Out).FirstOrDefault()
  60. }).ToList();
  61. return call24List;
  62. }
  63. public override async Task<object> GetCallTop10(CancellationToken stoppingToken)
  64. {
  65. var callTop10 = await _callRepository.Queryable()
  66. .Where(x => x.CreatedTime.Date == DateTime.Now.Date
  67. && x.CallOrderType == Share.Enums.CallCenter.ECallOrderType.Order
  68. )
  69. .GroupBy(x => x.UserName)
  70. .Select(x => new
  71. {
  72. UserName = x.UserName,
  73. In = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.In, 1, 0))
  74. }).MergeTable().OrderByDescending(x => x.In).Take(10).ToListAsync(stoppingToken);
  75. return callTop10;
  76. }
  77. public override async Task<object> GetCallList(CancellationToken stoppingToken)
  78. {
  79. var callList = await _callRepository.Queryable()
  80. .Where(x => x.CreatedTime.Date == DateTime.Now.Date
  81. && x.CallOrderType == Share.Enums.CallCenter.ECallOrderType.Order
  82. )
  83. .Select(x => new
  84. {
  85. InOn = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.In && x.OnState == Share.Enums.CallCenter.EOnState.On, 1, 0)),
  86. ValidOn = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.In && x.OnState == Share.Enums.CallCenter.EOnState.On && x.Duration > 5, 1, 0)),
  87. InNoOn = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.In && x.OnState == Share.Enums.CallCenter.EOnState.NoOn, 1, 0)),
  88. OutOn = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.Out && x.OnState == Share.Enums.CallCenter.EOnState.On, 1, 0)),
  89. InQueueNoOn = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.In && x.OnState == Share.Enums.CallCenter.EOnState.NoOn && x.QueueTims > 0, 1, 0)),
  90. }).MergeTable().ToListAsync(stoppingToken);
  91. return callList;
  92. }
  93. public override async Task<object> GetCallAverage(CancellationToken stoppingToken)
  94. {
  95. List<string> timeList = new List<string>();
  96. for (int i = 0;i < 24;i++)
  97. {
  98. var time = i < 10 ? $"0{i}" : i.ToString();
  99. timeList.Add(time);
  100. }
  101. var callAverage = await _callRepository.Queryable()
  102. .Where(x => x.CreatedTime.Date == DateTime.Now.Date
  103. && x.CallOrderType == Share.Enums.CallCenter.ECallOrderType.Order
  104. )
  105. .Select(x => new { time = x.CreatedTime.ToString("hh"), x.CallDirection }).MergeTable()
  106. .GroupBy(x => x.time)
  107. .Select(x => new
  108. {
  109. Time = x.time.ToString(),
  110. In = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.In, 1, 0)),
  111. InAverag = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.In, 1, 0)) / 60,
  112. Out = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.Out, 1, 0)),
  113. OutAverag = SqlFunc.AggregateSum(SqlFunc.IIF(x.CallDirection == Share.Enums.CallCenter.ECallDirection.Out, 1, 0)) / 60,
  114. }).MergeTable().ToListAsync(stoppingToken);
  115. var callAverageList = (from t1 in timeList
  116. join t2 in callAverage on t1 equals t2.Time into t1_t2
  117. from item in t1_t2.DefaultIfEmpty()
  118. select new
  119. {
  120. Time = t1 + ":00",
  121. In = t1_t2.Select(x => x.In).FirstOrDefault(),
  122. InAverag = t1_t2.Select(x => x.InAverag).FirstOrDefault(),
  123. Out = t1_t2.Select(x => x.Out).FirstOrDefault(),
  124. OutAverag = t1_t2.Select(x => x.OutAverag).FirstOrDefault()
  125. }).ToList();
  126. return callAverageList;
  127. }
  128. }