浏览代码

部门平均办理时间-随手拍

qinchaoyue 1 月之前
父节点
当前提交
c6ed8878a9

+ 18 - 1
src/Hotline.Api/Controllers/Snapshot/BiSnapshotController.cs

@@ -215,8 +215,25 @@ public class BiSnapshotController : BaseController
     /// </summary>
     /// <param name="dto"></param>
     /// <returns></returns>
-    /// <exception cref="NotImplementedException"></exception>
     [HttpGet("department-statistics")]
     public async Task<IList<SnapshotDepartmentStatisticsOutDto>> GetSnapshotDepartmentStatisticsAsync([FromQuery]SnapshotDepartmentStatisticsInDto dto)
         => await _biSnapshotApplication.GetSnapshotDepartmentStatistics(dto).ToListAsync();
+
+    /// <summary>
+    /// 部门平均办理时间-随手拍
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpGet("department-avetime-statistics")]
+    public async Task<IList<SnapshotDepartmentAveTimeStatisticsOutDto>> GetSnapshotDepartmentAveTimeStatisticsAsync([FromQuery] SnapshotDepartmentAveTimeStatisticsInDto dto)
+        => await _biSnapshotApplication.GetSnapshotDepartmentAveTimeStatistics(dto).ToListAsync();
+
+    /// <summary>
+    /// 部门平均办理时间-随手拍-详情
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    public async Task<PagedDto<SnapshotDepartmentAveTimeStatisticsDetailsOutDto>> GetSnapshotDepartmentAveTimeStatisticsDtailsAsync([FromQuery]SnapshotDepartmentAveTimeStatisticsDetailsInDto dto)
+        => (await _biSnapshotApplication.GetSnapshotDepartmentAveTimeStatisticsDtails(dto).ToPagedListAsync(dto)).ToPaged();
+
 }

+ 43 - 0
src/Hotline.Application/Snapshot/BiSnapshotApplication.cs

@@ -652,4 +652,47 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
         return query;
     }
 
+    public ISugarQueryable<SnapshotDepartmentAveTimeStatisticsOutDto> GetSnapshotDepartmentAveTimeStatistics(SnapshotDepartmentAveTimeStatisticsInDto dto)
+    {
+        bool IsCenter = _sessionContext.OrgIsCenter;
+        var orgLevel = _sessionContext.OrgLevel;
+        string orgLevelStr = (_sessionContext.RequiredOrgId.Length + 3).ToString();
+
+        var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
+            .LeftJoin<Order>((snapshot, order) => snapshot.Id == order.Id)
+            .LeftJoin<OrderSendBackAudit>((snapshot, order, back) => snapshot.Id == back.OrderId && back.State == ESendBackAuditState.End)
+            .LeftJoin<OrderVisit>((snapshot, order, back, visit) => snapshot.Id == visit.OrderId && visit.VisitState == EVisitState.Visited)
+            .LeftJoin<OrderSecondaryHandling>((snapshot, order, back, visit, second) => snapshot.Id == second.OrderId && second.State == ESecondaryHandlingState.End)
+            .Where((snapshot, order) => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime && order.ActualHandleOrgCode != null)
+            .GroupBy((snapshot, order) => new
+            {
+                OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6"))
+            })
+            .Select((snapshot, order, back, visit, second) => new SnapshotDepartmentAveTimeStatisticsOutDto()
+            {
+                OrgCode = order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")),
+                OrderCountNum = SqlFunc.AggregateCount(snapshot.Id),
+                TotalSeconds = SqlFunc.AggregateSum(order.AllDuration),
+            })
+            .MergeTable()
+            .LeftJoin<SystemOrganize>((it, o) => it.OrgCode == o.Id)
+            .Select((it, o) => new SnapshotDepartmentAveTimeStatisticsOutDto()
+            {
+                OrgName = o.Name,
+                OrgCode = it.OrgCode,
+                TotalSeconds = it.TotalSeconds,
+                OrderCountNum = it.OrderCountNum
+            });
+
+        return query;
+    }
+
+    public ISugarQueryable<SnapshotDepartmentAveTimeStatisticsDetailsOutDto> GetSnapshotDepartmentAveTimeStatisticsDtails(SnapshotDepartmentAveTimeStatisticsDetailsInDto dto)
+    {
+        var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
+            .LeftJoin<Order>((snapshot, order) => snapshot.Id == order.Id)
+            .Where((snapshot, order) => order.CreationTime >= dto.StartTime && order.CreationTime <= dto.EndTime && order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == dto.OrgCode)
+            .Select((snapshot, order) => new SnapshotDepartmentAveTimeStatisticsDetailsOutDto(), true) ;
+        return query;
+    }
 }

+ 9 - 0
src/Hotline.Application/Snapshot/IBiSnapshotApplication.cs

@@ -77,4 +77,13 @@ public interface IBiSnapshotApplication
     /// <returns></returns>
     /// <exception cref="NotImplementedException"></exception>
     ISugarQueryable<SnapshotDepartmentStatisticsOutDto> GetSnapshotDepartmentStatistics(SnapshotDepartmentStatisticsInDto dto);
+
+    /// <summary>
+    /// 部门平均办理时间-随手拍
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    ISugarQueryable<SnapshotDepartmentAveTimeStatisticsOutDto> GetSnapshotDepartmentAveTimeStatistics(SnapshotDepartmentAveTimeStatisticsInDto dto);
+
+    ISugarQueryable<SnapshotDepartmentAveTimeStatisticsDetailsOutDto> GetSnapshotDepartmentAveTimeStatisticsDtails(SnapshotDepartmentAveTimeStatisticsDetailsInDto dto);
 }

+ 192 - 0
src/Hotline.Share/Dtos/Snapshot/StatisticsDto.cs

@@ -2305,3 +2305,195 @@ public class SnapshotDepartmentStatisticsInDto
     [Required]
     public DateTime EndTime { get; set; }
 }
+
+public class SnapshotDepartmentAveTimeStatisticsOutDto
+{
+    public string OrgCode { get; set; }
+    public object OrgName { get; set; }
+
+    /// <summary>
+    /// 工单数
+    /// </summary>
+    public int OrderCountNum { get; set; }
+
+    /// <summary>
+    /// 总秒数
+    /// </summary>
+    public double? TotalSeconds { get; set; }
+
+    /// <summary>
+    /// 总分钟数
+    /// </summary>
+    public string TotalMinutes => TotalSeconds == null ? "0" : ((double)TotalSeconds / 60).ToString("f0");
+
+    /// <summary>
+    /// 平均分钟数
+    /// </summary>
+    public string AvgMinutes => OrderCountNum == 0 ? "0" : (double.Parse(TotalMinutes) / OrderCountNum).ToString("f2");
+
+    /// <summary>
+    /// 平均小时数
+    /// </summary>
+    public string AvgHours => OrderCountNum == 0 ? "0": (double.Parse(TotalMinutes) / 60 / OrderCountNum).ToString("f2");
+}
+
+public class SnapshotDepartmentAveTimeStatisticsInDto
+{
+    [Required]
+    public DateTime StartTime { get; set; }
+    [Required]
+    public DateTime EndTime { get; set; }
+
+}
+
+public record SnapshotDepartmentAveTimeStatisticsDetailsInDto : PagedRequest
+{
+    [Required]
+    public DateTime StartTime { get; set; }
+    [Required]
+    public DateTime EndTime { get; set; }
+
+    /// <summary>
+    /// 部门编号
+    /// </summary>
+    [Required]
+    public string OrgCode { get; set; }
+}
+
+public class SnapshotDepartmentAveTimeStatisticsDetailsOutDto
+{
+
+    /// <summary>
+    /// Id
+    /// </summary>
+    public string Id { get; set; }
+
+    /// <summary>
+    /// 过期状态
+    /// </summary>
+    public EExpiredStatus? ExpiredStatus => FiledTime.CalculateExpiredState(Status, this.ExpiredTime, this.NearlyExpiredTime, this.NearlyExpiredTimeOne);
+
+    /// <summary>
+    /// 过期状态
+    /// </summary>
+    public string ExpiredStatusText => ExpiredStatus.GetDescription();
+
+    /// <summary>
+    /// 受理编号
+    /// </summary>
+    public string No { get; set; }
+
+    /// <summary>
+    /// 信件状态
+    /// </summary>
+    public EOrderStatus Status { get; set; }
+
+    /// <summary>
+    /// 信件状态
+    /// </summary>
+    public string StatusTxt => Status.GetDescription();
+
+    /// <summary>
+    /// 来源
+    /// </summary>
+    public string SourceChannel { get; set; }
+
+    /// <summary>
+    /// 当前节点
+    /// </summary>
+    public string CurrentStepName { get; set; }
+
+    /// <summary>
+    /// 重办次数
+    /// </summary>
+    public int ReTransactNum { get; set; }
+
+    /// <summary>
+    /// 是否紧急
+    /// </summary>
+    public bool IsUrgent { get; set; }
+
+    /// <summary>
+    /// 是否紧急
+    /// </summary>
+    public string IsUrgentText => IsUrgent ? "紧急" : "-";
+
+    /// <summary>
+    /// 期满时间
+    /// </summary>
+    public DateTime? ExpiredTime { get; set; }
+
+    /// <summary>
+    /// 即将超期时间
+    /// </summary>
+    public DateTime? NearlyExpiredTime { get; set; }
+
+    /// <summary>
+    /// 即将超期时间第一级
+    /// </summary>
+    public DateTime? NearlyExpiredTimeOne { get; set; }
+
+    /// <summary>
+    /// 是否超期
+    /// </summary>
+    public bool IsExpired
+    {
+        get
+        {
+            if (ExpiredTime.HasValue)
+                return DateTime.Now > ExpiredTime.Value;
+            return false;
+        }
+    }
+
+    /// <summary>
+    /// 受理时间
+    /// </summary>
+    public DateTime CreationTime { get; set; }
+
+    /// <summary>
+    /// 标题
+    /// </summary>
+    public string Title { get; set; }
+
+    /// <summary>
+    /// 办理时长(秒)
+    /// </summary>
+    public int? AllDuration { get; set; }
+
+    /// <summary>
+    /// 办理时长(分)
+    /// </summary>
+    public string TotalMinutes => AllDuration == null ? "0" : ((double)AllDuration / 60).ToString("f0");
+
+    /// <summary>
+    /// 办理时长(时)
+    /// </summary>
+    public string TotalHours => AllDuration == null ? "0" : ((double)AllDuration / 60 / 60).ToString("f2");
+
+    /// <summary>
+    /// 接办部门
+    /// </summary>
+    public string ActualHandleOrgName { get; set; }
+
+    /// <summary>
+    /// 接办时间
+    /// </summary>
+    public DateTime? ActualHandleTime { get; set; }
+
+    /// <summary>
+    /// 办结时间
+    /// </summary>
+    public DateTime? FiledTime { get; set; }
+
+    /// <summary>
+    /// 受理类型
+    /// </summary>
+    public string AcceptType { get; set; }
+
+    /// <summary>
+    /// 热点类型
+    /// </summary>
+    public string HotspotName { get; set; }
+
+}

+ 3 - 0
test/Hotline.Tests/Application/BiSnapshotApplicationTest.cs

@@ -91,5 +91,8 @@ public class BiSnapshotApplicationTest : TestBase
         };
         var items = await _biSnapshotApplication.GetSnapshotDepartmentStatistics(inDto).ToListAsync();
         items.ShouldNotBeNull();
+
+        var a = await _biSnapshotApplication.GetSnapshotDepartmentAveTimeStatistics(inDto.Adapt<SnapshotDepartmentAveTimeStatisticsInDto>()).ToListAsync();
+        a.ShouldNotBeNull();
     }
 }