Browse Source

重办统计详情

qinchaoyue 1 month ago
parent
commit
c1a34f13d4

+ 12 - 13
src/Hotline.Api/Controllers/Snapshot/BiSnapshotController.cs

@@ -139,7 +139,7 @@ public class BiSnapshotController : BaseController
     /// <param name="dto"></param>
     /// <returns></returns>
     [HttpGet("processing-statistics-detail")]
-    public async Task<PagedDto<SnapshotProcessingStatisticsDetailsOutDto>> GetSnapshotProcessingStatisticsDetails([FromQuery]SnapshotProcessingStatisticsDetailsInDto dto)
+    public async Task<PagedDto<SnapshotProcessingStatisticsDetailsOutDto>> GetSnapshotProcessingStatisticsDetails([FromQuery] SnapshotProcessingStatisticsDetailsInDto dto)
         => (await _biSnapshotApplication.GetSnapshotProcessingStatisticsDetails(dto).ToPagedListAsync(dto)).ToPaged();
 
     /// <summary>
@@ -224,7 +224,7 @@ public class BiSnapshotController : BaseController
     /// <param name="dto"></param>
     /// <returns></returns>
     [HttpGet("department-statistics")]
-    public async Task<IList<SnapshotDepartmentStatisticsOutDto>> GetSnapshotDepartmentStatisticsAsync([FromQuery]SnapshotDepartmentStatisticsInDto dto)
+    public async Task<IList<SnapshotDepartmentStatisticsOutDto>> GetSnapshotDepartmentStatisticsAsync([FromQuery] SnapshotDepartmentStatisticsInDto dto)
         => await _biSnapshotApplication.GetSnapshotDepartmentStatistics(dto).ToListAsync();
 
     /// <summary>
@@ -242,7 +242,7 @@ public class BiSnapshotController : BaseController
     /// <param name="dto"></param>
     /// <returns></returns>
     [HttpGet("department-avetime-statistics-detail")]
-    public async Task<PagedDto<SnapshotDepartmentAveTimeStatisticsDetailsOutDto>> GetSnapshotDepartmentAveTimeStatisticsDtailsAsync([FromQuery]SnapshotDepartmentAveTimeStatisticsDetailsInDto dto)
+    public async Task<PagedDto<SnapshotDepartmentAveTimeStatisticsDetailsOutDto>> GetSnapshotDepartmentAveTimeStatisticsDtailsAsync([FromQuery] SnapshotDepartmentAveTimeStatisticsDetailsInDto dto)
         => (await _biSnapshotApplication.GetSnapshotDepartmentAveTimeStatisticsDtails(dto).ToPagedListAsync(dto)).ToPaged();
 
     /// <summary>
@@ -276,20 +276,19 @@ public class BiSnapshotController : BaseController
     public async Task<ReTransactStatisticsOutDto> GetReTransactStatisticsAsync([FromQuery] ReTransactStatisticsInDto dto)
     {
         var headers = _systemDicDataCacheManager.GetSysDicDataCache(SysDicTypeConsts.InstaShotSpecialReason).Adapt<IList<SystemDicDataOutDto>>();
-        headers.Add(new SystemDicDataOutDto 
-        {
-            DicDataName = "OrgName",
-            DicDataValue = "OrgName",
-        });
-        headers.Add(new SystemDicDataOutDto
-        { 
-            DicDataValue = "OrgCode",
-            DicDataName = "OrgCode"
-        });
         return new ReTransactStatisticsOutDto
         {
             Headers = headers,
             Data = _biSnapshotApplication.GetReTransactStatistics(dto)
         };
     }
+
+    /// <summary>
+    /// 重办统计详情-随手拍
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpGet("re_transact-statistics-detail")]
+    public async Task<PagedDto<ReTransactStatisticsDetailsOutDto>> GetReTransactStatisticsDetailAsync([FromQuery] ReTransactStatisticsDetailsInDto dto)
+        => (await _biSnapshotApplication.GetReTransactStatisticsDetail(dto).ToPagedListAsync(dto)).ToPaged();
 }

+ 25 - 8
src/Hotline.Application/Snapshot/BiSnapshotApplication.cs

@@ -790,19 +790,15 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
                 SpecialReasonName = it.SpecialReasonName
             }).ToList();
 
-        // 2. 处理 Pivot 逻辑
         var pivotResult = new List<Dictionary<string, object>>();
 
-        // 先获取所有 OrgCode 和 OrgName
         var orgGroups = rawData.GroupBy(x => new { x.OrgCode, x.OrgName });
 
-        // 先获取所有可能的 SpecialReasonId(动态列)
         var specialReasons = rawData
             .Select(x => x.SpecialReasonId)
             .Distinct()
             .ToList();
 
-        // 3. 遍历 OrgCode 进行聚合转换
         foreach (var orgGroup in orgGroups)
         {
             var row = new Dictionary<string, object>
@@ -811,13 +807,11 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
                 ["OrgCode"] = orgGroup.Key.OrgCode
             };
 
-            // 初始化 SpecialReasonId 列
             foreach (var reason in specialReasons)
             {
-                row[reason] = 0; // 先默认 0
+                row[reason] = 0; 
             }
 
-            // 填充对应的 OrderCountNum
             foreach (var item in orgGroup)
             {
                 if (item.SpecialReasonId != null)
@@ -828,7 +822,30 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
 
             pivotResult.Add(row);
         }
-
+        pivotResult.AddSumLine("OrgName");
         return pivotResult;
     }
+
+    public ISugarQueryable<ReTransactStatisticsDetailsOutDto> GetReTransactStatisticsDetail(ReTransactStatisticsDetailsInDto dto)
+    {
+        var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
+            .LeftJoin<Order>((snapshot, order) => order.Id == snapshot.Id)
+            .LeftJoin<OrderSpecial>((snapshot, order, special) => special.OrderId == order.Id)
+            .LeftJoin<SystemOrganize>((snapshot, order, special, org) => org.Id == special.OrgId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")))
+            .Where((snapshot, order, special) => order.CreationTime >= dto.StartTime && order.CreationTime <= dto.EndTime && order.ActualHandleOrgCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == dto.OrgCode && special.Id != null && snapshot.SpecialReasonId != null && special.SpecialType == ESpecialType.ReTransact)
+            .WhereIF(dto.FieldName.NotNullOrEmpty(), (snapshot, order) => dto.FieldName == snapshot.SpecialReasonId)
+            .OrderByDescending((snapshot, order) => order.CreationTime)
+            .Select((snapshot, order, special, org) => new ReTransactStatisticsDetailsOutDto 
+            {
+                ReTransactOrgName = special.OrgName, // 被重办部门
+                ReTransactOneOrgName = org.Name, // 被重办一级部门
+                ReTransactTime = special.CreationTime, // 重办时间
+                ReTransactHandlerName = special.CreatorName, // 重办操作人
+                ReTransactContent = special.Opinion // 重办理由
+            }, true);
+#if DEBUG
+        var sql = query.ToSqlString();
+#endif
+        return query;
+    }
 }

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

@@ -96,4 +96,5 @@ public interface IBiSnapshotApplication
 
     ISugarQueryable<CompliantStatisticsDetailsOutDto> GetCompliantStatisticsDetails(CompliantStatisticsDetailsInDto dto);
     List<Dictionary<string, object>> GetReTransactStatistics(ReTransactStatisticsInDto dto);
+    ISugarQueryable<ReTransactStatisticsDetailsOutDto> GetReTransactStatisticsDetail(ReTransactStatisticsDetailsInDto dto);
 }

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

@@ -2706,3 +2706,179 @@ public class ReTransactStatisticsOutDto
     /// </summary>
     public List<Dictionary<string, object>> Data {get; set; }
 }
+
+public class ReTransactStatisticsDetailsOutDto
+{ 
+    /// <summary>
+    /// Id
+    /// </summary>
+    public string Id { get; set; }
+
+    /// <summary>
+    /// No
+    /// </summary>
+    public string? No { 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 EOrderStatus Status { get; set; }
+
+    /// <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 string? ReTransactOrgName { get; set; }
+
+    /// <summary>
+    /// 被重办一级部门
+    /// </summary>
+    public string? ReTransactOneOrgName { get; set; }
+
+    /// <summary>
+    /// 重办时间
+    /// </summary>
+    public DateTime? ReTransactTime { get; set; }
+
+    /// <summary>
+    /// 重办操作人
+    /// </summary>
+    public string? ReTransactHandlerName { get; set; }
+
+    /// <summary>
+    /// 重办理由
+    /// </summary>
+    public string ReTransactContent { get; set; }
+
+    /// <summary>
+    /// 受理时间开始
+    /// </summary>
+    public DateTime? BeginCreationTime { get; set; }
+
+    /// <summary>
+    /// 受理时间结束
+    /// </summary>
+    public DateTime? EndCreationTime { get; set; }
+
+    /// <summary>
+    /// 行业
+    /// </summary>
+    public string IndustryName { get; set; }
+
+    /// <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 AcceptorName { get; set; }
+
+}
+
+public record ReTransactStatisticsDetailsInDto : PagedRequest
+{
+    [Required]
+    public DateTime StartTime { get; set; }
+    [Required]
+    public DateTime EndTime { get; set; }
+
+    /// <summary>
+    /// 字段名称
+    /// </summary>
+    public string? FieldName { get; set; }
+
+    /// <summary>
+    /// 部门Code
+    /// </summary>
+    [Required]
+    public string OrgCode { get; set; }
+}

+ 36 - 0
src/Hotline.Share/Tools/ListExtensions.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Runtime.CompilerServices;
 using System.Text;
 using System.Threading.Tasks;
 
@@ -32,9 +33,44 @@ public static class ListExtensions
         return value != null && value.Count != 0;
     }
 
+    private static void AddSumLineForDictionaryList(IList<Dictionary<string, object>> list, string fieldName)
+    {
+        var sumRow = new Dictionary<string, object>();
+
+        foreach (var key in list.First().Keys)
+        {
+            sumRow[key] = key == fieldName ? "合计" : 0;
+        }
+
+        foreach (var item in list)
+        {
+            foreach (var key in item.Keys)
+            {
+                if (key != fieldName && item[key] is IConvertible) 
+                {
+                    try
+                    {
+                        sumRow[key] = Convert.ToDecimal(sumRow[key]) + Convert.ToDecimal(item[key]);
+                    }
+                    catch
+                    {
+                        sumRow[key] = item[key]; 
+                    }
+                }
+            }
+        }
+
+        list.Add(sumRow);
+    }
+
     public static void AddSumLine<T>(this IList<T> list, string fieldName)
     {
         var type = typeof(T);
+        if (typeof(T) == typeof(Dictionary<string, object>))
+        {
+            AddSumLineForDictionaryList(list as IList<Dictionary<string, object>>, fieldName);
+            return;
+        }
         var properties = type.GetProperties();
         var sumLine = Activator.CreateInstance<T>();
         foreach (var property in properties)

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

@@ -99,5 +99,10 @@ public class BiSnapshotApplicationTest : TestBase
         var b = _biSnapshotApplication.GetReTransactStatistics(inDto.Adapt<ReTransactStatisticsInDto>());
         b.ShouldNotBeNull();
         var c = b.ToJson();
+
+        var bInDto = inDto.Adapt<ReTransactStatisticsDetailsInDto>();
+        bInDto.OrgCode = "001";
+        var d = await _biSnapshotApplication.GetReTransactStatisticsDetail(bInDto).ToListAsync();
+        d.ShouldNotBeNull();
     }
 }