Parcourir la source

增加话务统计分析导出

tangjiang il y a 10 mois
Parent
commit
863a11f7ba
1 fichiers modifiés avec 80 ajouts et 54 suppressions
  1. 80 54
      src/Hotline.Api/Controllers/Bi/BiCallController.cs

+ 80 - 54
src/Hotline.Api/Controllers/Bi/BiCallController.cs

@@ -7,9 +7,11 @@ using Hotline.Repository.SqlSugar.Extensions;
 using Hotline.Settings;
 using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.CallCenter;
+using Hotline.Share.Dtos.Order;
 using Hotline.Share.Enums.CallCenter;
 using Hotline.Share.Enums.User;
 using Hotline.Share.Requests;
+using Hotline.Tools;
 using Hotline.Users;
 using MapsterMapper;
 using Microsoft.AspNetCore.Authorization;
@@ -38,7 +40,7 @@ public class BiCallController : BaseController
 
 
 
-	public BiCallController(
+    public BiCallController(
         IRepository<TrCallRecord> trCallRecordRepository,
         IRepository<User> userRepository,
         IRepository<TelRest> telRestRepository,
@@ -46,7 +48,7 @@ public class BiCallController : BaseController
         ITrCallRecordRepository trCallRecordRepositoryEx,
         ISystemSettingCacheManager systemSettingCacheManager,
         ISystemDicDataCacheManager sysDicDataCacheManager,
-		IRepository<Work> workRepository)
+        IRepository<Work> workRepository)
     {
         _trCallRecordRepository = trCallRecordRepository;
         _userRepository = userRepository;
@@ -57,7 +59,7 @@ public class BiCallController : BaseController
         _workRepository = workRepository;
         _sysDicDataCacheManager = sysDicDataCacheManager;
 
-	}
+    }
 
     [HttpGet("calls")]
     [AllowAnonymous]
@@ -110,9 +112,32 @@ public class BiCallController : BaseController
         #endregion
         dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
 
-         return await _trCallRecordRepositoryEx.GetQueryCalls(dto.StartTime.Value, dto.EndTime.Value);
+        return await _trCallRecordRepositoryEx.GetQueryCalls(dto.StartTime.Value, dto.EndTime.Value);
 
     }
+
+    [HttpGet("calls_export")]
+    [AllowAnonymous]
+    public async Task<FileStreamResult> ExportQueryCallsAsync([FromQuery] ExportExcelDto<BiQueryCallsDto> dto)
+    {
+        if (!dto.QueryDto.StartTime.HasValue || !dto.QueryDto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
+
+        dto.QueryDto.EndTime = dto.QueryDto.EndTime.Value.AddDays(1).AddSeconds(-1);
+
+        var list = await _trCallRecordRepositoryEx.GetQueryCalls(dto.QueryDto.StartTime.Value, dto.QueryDto.EndTime.Value);
+        dynamic? dynamicClass = DynamicClassHelper.CreateDynamicClass(dto.ColumnInfos);
+
+        var dtos = list
+            .Select(stu => _mapper.Map(stu, typeof(BiCallDto), dynamicClass))
+            .Cast<object>()
+            .ToList();
+
+        var stream = ExcelHelper.CreateStream(dtos);
+
+        return ExcelStreamResult(stream, "话务统计分析");
+    }
+
+
     /// <summary>
     /// 坐席话务统计分析
     /// </summary>
@@ -155,17 +180,17 @@ public class BiCallController : BaseController
               .ToListAsync(HttpContext.RequestAborted);
 
 
-        list.ForEach(d=>
+        list.ForEach(d =>
         {
             d.LoginDuration = _workRepository.Queryable().Where(q => q.UserId == d.UserId && q.CreationTime >= dto.StartTime && q.CreationTime <= dto.EndTime).Sum(q => q.WorkingDuration);
-            if (d.LoginDuration!=null)
+            if (d.LoginDuration != null)
             {
-                d.LoginDuration = Math.Round(d.LoginDuration.Value, digits:2);
+                d.LoginDuration = Math.Round(d.LoginDuration.Value, digits: 2);
             }
             d.RestDuration = _telRestRepository.Queryable().Where(q => q.UserId == d.UserId && q.CreationTime >= dto.StartTime && q.CreationTime <= dto.EndTime).Sum(q => q.RestDuration);
-            d.RestDuration = Math.Round(d.RestDuration, digits:2);
+            d.RestDuration = Math.Round(d.RestDuration, digits: 2);
         });
-              
+
 
         return list;
     }
@@ -177,7 +202,7 @@ public class BiCallController : BaseController
     /// <returns></returns>
     [HttpGet("rests")]
     [AllowAnonymous]
-    public async Task<IReadOnlyList<BiSeatRestDto>> QuerySeatRest([FromQuery]QuerySeatRestRequest dto)
+    public async Task<IReadOnlyList<BiSeatRestDto>> QuerySeatRest([FromQuery] QuerySeatRestRequest dto)
     {
         if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
         dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
@@ -196,8 +221,8 @@ public class BiCallController : BaseController
                 RestCount = SqlFunc.AggregateCount(x.Id),
                 RestDuration = SqlFunc.AggregateSum(x.RestDuration / 60) / SqlFunc.AggregateCount(x.Id)
             })
-            .OrderByIF(dto.SortRule is 0,a=> a.RestDuration,OrderByType.Asc)
-            .OrderByIF(dto.SortRule is 1,a=> a.RestDuration,OrderByType.Desc)
+            .OrderByIF(dto.SortRule is 0, a => a.RestDuration, OrderByType.Asc)
+            .OrderByIF(dto.SortRule is 1, a => a.RestDuration, OrderByType.Desc)
             .MergeTable()
             .ToListAsync(HttpContext.RequestAborted);
     }
@@ -209,19 +234,20 @@ public class BiCallController : BaseController
     /// <returns></returns>
     [HttpGet("seatswitch")]
     [AllowAnonymous]
-    public async Task<PagedDto<BiSeatSwitchDto>> QuerySeatSwitch([FromQuery]QuerySeatSwitchRequest dto)
+    public async Task<PagedDto<BiSeatSwitchDto>> QuerySeatSwitch([FromQuery] QuerySeatSwitchRequest dto)
     {
         if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
 
         dto.EndTime = dto.EndTime.Value.AddDays(1).AddSeconds(-1);
 
-        var (total,items) = await _trCallRecordRepository.Queryable()
+        var (total, items) = await _trCallRecordRepository.Queryable()
             .Where(x => !string.IsNullOrEmpty(x.AgentTransferNumber))
             .WhereIF(!string.IsNullOrEmpty(dto.UserName), x => x.UserName.Contains(dto.UserName))
             .WhereIF(!string.IsNullOrEmpty(dto.CDPN), x => x.CDPN.Contains(dto.CDPN))
-            .WhereIF(dto.StartTime.HasValue,x=>x.CreatedTime >= dto.StartTime.Value)
-            .WhereIF(dto.EndTime.HasValue,x=>x.CreatedTime <= dto.EndTime.Value)
-            .Select(x=> new BiSeatSwitchDto { 
+            .WhereIF(dto.StartTime.HasValue, x => x.CreatedTime >= dto.StartTime.Value)
+            .WhereIF(dto.EndTime.HasValue, x => x.CreatedTime <= dto.EndTime.Value)
+            .Select(x => new BiSeatSwitchDto
+            {
                 UserId = x.UserId,
                 CPN = x.CPN,
                 CDPN = x.CDPN,
@@ -241,56 +267,56 @@ public class BiCallController : BaseController
     /// <returns></returns>
     [HttpGet("hourcall")]
     [AllowAnonymous]
-    public async Task<List<TrCallHourDto>> QueryHourCall([FromQuery]DateTime beginDate,DateTime? endDate, string source)
+    public async Task<List<TrCallHourDto>> QueryHourCall([FromQuery] DateTime beginDate, DateTime? endDate, string source)
     {
         //获取配置
         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 list = await _trCallRecordRepositoryEx.GetCallHourList(beginDate,endDate,noConnectByeTimes,effectiveTimes,connectByeTimes,source);
+        var list = await _trCallRecordRepositoryEx.GetCallHourList(beginDate, endDate, noConnectByeTimes, effectiveTimes, connectByeTimes, source);
         return list;
     }
 
-	/// <summary>
-	/// 通话时段统计明细
-	/// </summary>
-	/// <returns></returns>
-	[HttpGet("hourcall_list")]
-	public async Task<object> QueryCallList([FromQuery] DateTime beginDate, DateTime? endDate, string type, string source, TimeSpan? startHourTo , int pageIndex, int pageSize)
-	{
-		//获取配置
-		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 list = await _trCallRecordRepositoryEx.GetCallList(beginDate, endDate, noConnectByeTimes, effectiveTimes, connectByeTimes, type, source, startHourTo,pageIndex, pageSize);
-		return list;
-	}
-
-	/// <summary>
-	/// 通话时段统计明细获取基本信息
-	/// </summary>
-	/// <param name="id"></param>
-	/// <returns></returns>
-	[HttpGet("hourcall_list_base")]
+    /// <summary>
+    /// 通话时段统计明细
+    /// </summary>
+    /// <returns></returns>
+    [HttpGet("hourcall_list")]
+    public async Task<object> QueryCallList([FromQuery] DateTime beginDate, DateTime? endDate, string type, string source, TimeSpan? startHourTo, int pageIndex, int pageSize)
+    {
+        //获取配置
+        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 list = await _trCallRecordRepositoryEx.GetCallList(beginDate, endDate, noConnectByeTimes, effectiveTimes, connectByeTimes, type, source, startHourTo, pageIndex, pageSize);
+        return list;
+    }
+
+    /// <summary>
+    /// 通话时段统计明细获取基本信息
+    /// </summary>
+    /// <param name="id"></param>
+    /// <returns></returns>
+    [HttpGet("hourcall_list_base")]
     public async Task<object> ReTransactBaseData()
     {
-	    var rsp = new
-	    {
-		    CallForwardingSource = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.CallForwardingSource),
-		    CallForwardingType = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.CallForwardingType),
-		};
-	    return rsp;
+        var rsp = new
+        {
+            CallForwardingSource = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.CallForwardingSource),
+            CallForwardingType = _sysDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.CallForwardingType),
+        };
+        return rsp;
     }
 
-	/// <summary>
-	/// 热线号码统计
-	/// </summary>
-	/// <param name="StartDate"></param>
-	/// <param name="EndDate"></param>
-	/// <returns></returns>
-	[AllowAnonymous]
+    /// <summary>
+    /// 热线号码统计
+    /// </summary>
+    /// <param name="StartDate"></param>
+    /// <param name="EndDate"></param>
+    /// <returns></returns>
+    [AllowAnonymous]
     [HttpGet("gateway-query")]
-    public async Task<List<CallHotLineDto>> QueryGateWay(DateTime beginDate, DateTime endDate,string gateway)
+    public async Task<List<CallHotLineDto>> QueryGateWay(DateTime beginDate, DateTime endDate, string gateway)
     {
         //获取配置
         int noConnectByeTimes = int.Parse(_systemSettingCacheManager.GetSetting(SettingConstants.NoConnectByeTimes)?.SettingValue[0]);