Dun.Jason hai 1 ano
pai
achega
dffeedfc28

+ 3 - 2
src/Hotline.Api/Controllers/Bi/BiCallController.cs

@@ -114,8 +114,8 @@ public class BiCallController : BaseController
         return await _userRepository.Queryable()
               .LeftJoin<TrCallRecord>((u, c) => u.Id == c.UserId)
               .Where(u => !u.IsDeleted && u.UserType == EUserType.Seat)
-              .WhereIF(dto.StartTime.HasValue, (_, c) => c.CreatedTime >= dto.StartTime.Value)
-              .WhereIF(dto.EndTime.HasValue, (_, c) => c.CreatedTime <= dto.EndTime.Value)
+              .WhereIF(dto.StartTime.HasValue, (u, c) => c.CreatedTime >= dto.StartTime.Value)
+              .WhereIF(dto.EndTime.HasValue, (u, c) => c.CreatedTime <= dto.EndTime.Value)
               .GroupBy((u, c) => new { c.UserName, c.TelNo })
               .Select((u, c) => new BiSeatCallsDto
               {
@@ -142,6 +142,7 @@ public class BiCallController : BaseController
     /// <param name="dto"></param>
     /// <returns></returns>
     [HttpGet("rests")]
+    [AllowAnonymous]
     public async Task<IReadOnlyList<BiSeatRestDto>> QuerySeatRest([FromQuery]QuerySeatRestRequest dto)
     {
         return await _telRestRepository.Queryable()

+ 16 - 1
src/Hotline.Api/Controllers/Bi/BiOrderController.cs

@@ -14,6 +14,7 @@ using Hotline.FlowEngine.Workflows;
 using Hotline.Share.Dtos.CallCenter;
 using MapsterMapper;
 using XF.Domain.Exceptions;
+using Microsoft.AspNetCore.Authorization;
 
 namespace Hotline.Api.Controllers.Bi
 {
@@ -193,6 +194,7 @@ namespace Hotline.Api.Controllers.Bi
         /// <param name="dto"></param>
         /// <returns></returns>
         [HttpGet("visit-nosatisfied")]
+        [AllowAnonymous]
         public async Task<object> QueryVisitNoSatisfied([FromQuery] QueryVisitNoSatiisfiedRequest dto)
         {
 	        if (!dto.StartTime.HasValue || !dto.EndTime.HasValue) throw UserFriendlyException.SameMessage("请选择时间!");
@@ -413,5 +415,18 @@ namespace Hotline.Api.Controllers.Bi
 	        var (total, items) = await query.ToPagedListAsync(dto, HttpContext.RequestAborted);
 	        return new PagedDto<AcceptTypeTop10Vo>(total, items);
 		}
-	}
+
+        /// <summary>
+        /// 热点类型部门统计
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpGet("hotport-org-statistics")]
+        public async Task<object> HotPortJoinOrgStatistics([FromQuery]HotPortJoinOrgStatisticsRequest dto)
+        {
+            return await _orderRepository.HotPortJoinOrgStatistics(dto.StartTime, dto.EndTime);
+        }
+
+
+    }
 }

+ 37 - 21
src/Hotline.Repository.SqlSugar/CallCenter/TrCallRecordRepository.cs

@@ -1,5 +1,6 @@
 using Hotline.Caching.Interfaces;
 using Hotline.CallCenter.Calls;
+using Hotline.Orders;
 using Hotline.Repository.SqlSugar.DataPermissions;
 using Hotline.Share.Dtos.CallCenter;
 using Hotline.Share.Enums.CallCenter;
@@ -46,38 +47,53 @@ namespace Hotline.Repository.SqlSugar.CallCenter
             //        IvrByeCount = SqlFunc.AggregateSum(SqlFunc.IIF(o.CallDirection == ECallDirection.In && o.BeginIvrTime.HasValue && !o.BeginQueueTime.HasValue && !o.BeginRingTime.HasValue && o.OnState == EOnState.NoOn, 1, 0)), //IVR挂断
             //    }).ToListAsync();
             //计算小时差
-            if (!endDate.HasValue)
-            {
-                endDate = beginDate.Date.AddDays(1).AddMilliseconds(-1);
-            }
-            TimeSpan timeDifference = endDate.Value.Subtract(beginDate).Duration();
+            //if (!endDate.HasValue)
+            //{
+            //    endDate = beginDate.Date.AddDays(1).AddMilliseconds(-1);
+            //}
+            //TimeSpan timeDifference = endDate.Value.Subtract(beginDate).Duration();
 
-            int hourDiff = (int)(timeDifference.TotalHours);
-            if (!endDate.HasValue)
-            {
-                endDate = beginDate.Date.AddDays(1).AddMilliseconds(-1);
-            }
-            //计算时间差
-            int hour = Convert.ToInt32((endDate - beginDate).Value.TotalHours);
+            //int hourDiff = (int)(timeDifference.TotalHours);
+            //if (!endDate.HasValue)
+            //{
+            //    endDate = beginDate.Date.AddDays(1).AddMilliseconds(-1);
+            //}
+            ////计算时间差
+            //int hour = Convert.ToInt32((endDate - beginDate).Value.TotalHours);
+
+            //List<DateTime> dts = new List<DateTime>() { beginDate };
+            //for (int i = 0; i < hour - 1; i++)
+            //{
+            //    dts.Add(dts.Last().AddHours(1));
+            //}
+
+            //var list = await Db.Reportable(dts).ToQueryable<DateTime>()
+            //    .LeftJoin<TrCallRecord>((it, o) => o.CreatedTime >= it.ColumnName && o.CreatedTime < it.ColumnName.AddHours(1))
+            //    .GroupBy(it => it.ColumnName)
+            //    .OrderBy(it => it.ColumnName)
+            //    .Select((it, o) => new TrCallHourDto()
+            //    {
+            //        Dates = it.ColumnName,
+            //        //Hour = it.ColumnName.Hour,
+            //        Count = SqlFunc.AggregateSum(SqlFunc.IIF(o.CallDirection == ECallDirection.In, 1, 0)), //呼入总量
+            //    })
+            //    .ToListAsync();
 
-            List<DateTime> dts = new List<DateTime>() { beginDate };
-            for (int i = 0; i < hour - 1; i++)
+            List<DateTime> dts = new List<DateTime>() { beginDate.Date.AddDays(1) };
+            for (int i = 0; i < 24; i++)//搞出所有时间断
             {
-                dts.Add(dts.Last().AddHours(1));
+                dts.Add(dts.Last().AddHours(-1));
             }
 
-            var list = await Db.Reportable(dts).ToQueryable<DateTime>()
+            var list = Db.Reportable(dts).ToQueryable<DateTime>()
                 .LeftJoin<TrCallRecord>((it, o) => o.CreatedTime >= it.ColumnName && o.CreatedTime <= it.ColumnName.AddHours(1))
                 .GroupBy(it => it.ColumnName)
                 .OrderBy(it => it.ColumnName)
                 .Select((it, o) => new TrCallHourDto()
                 {
                     Dates = it.ColumnName,
-                    Hour = it.ColumnName.Hour,
-                    Count = SqlFunc.AggregateSum(SqlFunc.IIF(o.CallDirection == ECallDirection.In, 1, 0))
-                }).ToListAsync();
-
-            //Db.Queryable<TrCallRecord>().LeftJoin<>
+                    Count = SqlFunc.AggregateSum(SqlFunc.IIF(o.CallDirection == ECallDirection.In,1,0))
+                }).ToList();
 
 
             return list;

+ 58 - 1
src/Hotline.Repository.SqlSugar/Orders/OrderRepository.cs

@@ -4,6 +4,8 @@ using Hotline.Orders;
 using Hotline.Repository.SqlSugar.DataPermissions;
 using Hotline.Repository.SqlSugar.Extensions;
 using Hotline.Repository.SqlSugar.Ts;
+using Hotline.Settings;
+using Hotline.Settings.Hotspots;
 using Hotline.Settings.TimeLimits;
 using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.FlowEngine.Workflow;
@@ -83,5 +85,60 @@ namespace Hotline.Repository.SqlSugar.Orders
         {
 			await Db.Updateable<Order>().SetColumns(x=>x.FileJson == order.FileJson).Where(x=>x.Id == order.Id).ExecuteCommandAsync(cancellationToken);
 		}
-	}
+
+
+        public async Task<object> HotPortJoinOrgStatistics(DateTime StartTime, DateTime EndTime)
+        {
+            //查询一级热点
+            var hotSpotList = await Db.Queryable<Hotspot>().Where(x => string.IsNullOrEmpty(x.ParentId)).ToListAsync();
+            List<dynamic>? listReturn = new List<dynamic>();
+            foreach (var item in hotSpotList)
+            {
+                var table = await Db.Queryable<Order>()
+                    .LeftJoin<SystemOrganize>((it,o)=> it.CurrentHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == o.Id)
+                    .GroupBy((it,o) => new {
+                        CurrentHandleOrgCode =(it.CurrentHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))),
+                        o.Name
+                    })
+                    .Select((it,o) => new
+                    {
+                        OrgCode = it.CurrentHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
+                        Count = SqlFunc.AggregateSum(SqlFunc.IIF(it.HotspotId.Substring(0,2)==item.Id,1,0)),
+                        Key = item.Id,
+                        OrgName = o.Name,
+                        HotSorpName = item.HotSpotName
+                    }).ToPivotListAsync(x=>x.Key,x=>new { x.OrgCode,x.OrgName,x.HotSorpName },x=> x.Sum(x=>x.Count));
+                listReturn.AddRange(table);
+            }
+
+            return new { HotSpot = hotSpotList, Data = listReturn };
+
+
+
+            //var list = await Db.Queryable<Order>()
+            //    .GroupBy(x => x.CurrentHandleOrgCode)
+            //    .Select(x => new
+            //    {
+            //        OrgCode = x.CurrentHandleOrgCode.Substring(0, 6),
+            //        Count = SqlFunc.AggregateCount(x.Id)
+            //    })
+            //    .ToListAsync();
+
+            //var listGroup = await Db.Reportable(listReturn).ToQueryable().GroupBy(x => x.OrgCode)
+            //    .Select(x => new
+            //    {
+            //        OrgCode = x. //x.OrgCode,
+            //        Count = SqlFunc.AggregateSum(x.Count)
+            //    }).ToListAsync();
+
+            //var listGroupHsOrg = await Db.Reportable(listGroup).ToQueryable()
+            //    .LeftJoin<SystemOrganize>((it,o)=> it.OrgCode == o.Id)
+            //    .Select((it,o) => new { 
+            //        OrgCode = it.OrgCode,
+            //        OrgName = o.Name,
+            //        Count = it.Count
+            //    })
+            //    .ToListAsync();
+        }
+    }
 }

+ 8 - 0
src/Hotline.Share/Requests/PagedKeywordRequest.cs

@@ -30,6 +30,14 @@ public record ReportPagedRequest : PagedKeywordRequest
 
 }
 
+public record HotPortJoinOrgStatisticsRequest
+{
+	public DateTime StartTime { get; set; }
+
+	public DateTime EndTime { get; set; }
+}
+
+
 public record HotspotReportPagedRequest : ReportPagedRequest { 
 
 	public string Id { get; set; }

+ 4 - 1
src/Hotline/Orders/IOrderRepository.cs

@@ -18,5 +18,8 @@ namespace Hotline.Orders
         Task RemoveOrderFinalityBatchAsync(List<string> ids, CancellationToken cancellationToken);
         Task OrderScreenRevisionVisit(string VisitId, bool canHandle, CancellationToken cancellationToken);
         Task FileAsync(Order order, CancellationToken cancellationToken);
-	}
+
+        Task<object> HotPortJoinOrgStatistics(DateTime StartTime, DateTime EndTime);
+
+    }
 }