Explorar o código

新增设为重点接口

qinchaoyue hai 1 mes
pai
achega
2c98ac2422

+ 2 - 2
src/Hotline.Api/Controllers/ExportData/ExportDataController.cs

@@ -54,10 +54,10 @@ public class ExportDataController : BaseController
             .Where(endpoint => endpoint.RoutePattern.RawText == originalPath)
             .ToList()
             ?? throw UserFriendlyException.SameMessage($"根据URL查询路由失败: {originalPath}");
-        var matchingEndpoint = matchingEndpoints.First();
+        var matchingEndpoint = matchingEndpoints.FirstOrDefault();
         if (matchingEndpoints.Count > 1)
         {
-            matchingEndpoint = matchingEndpoints.First(m => m.DisplayName.Contains("Get"));
+            matchingEndpoint = matchingEndpoints.FirstOrDefault(m => m.DisplayName.Contains("Get"));
         }
         if (matchingEndpoint == null)
             throw UserFriendlyException.SameMessage($"根据URL查询路由失败: {originalPath}");

+ 19 - 0
src/Hotline.Api/Controllers/Snapshot/BiSnapshotController.cs

@@ -258,6 +258,25 @@ public class BiSnapshotController : BaseController
         return items;
     }
 
+    /// <summary>
+    /// 行业统计
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpGet("industry-statistics")]
+    public async Task<IndustryStatisticsOutDto> IndustryStatisticsAsync([FromQuery] IndustryStatisticsInDto dto)
+    {
+        return new IndustryStatisticsOutDto
+        {
+            Headers = await _industryRepository.Queryable().Where(m => m.IsEnable == true).Select(m => new SystemDicDataOutDto { 
+                Id = m.Id,
+                DicDataName = m.Name,
+                DicDataValue = m.Name,
+            }).ToListAsync(),
+            Data = _biSnapshotApplication.GetIndustryStatistics(dto)
+        };
+    }
+
     /// <summary>
     /// 检查合规统计-详情
     /// </summary>

+ 9 - 0
src/Hotline.Api/Controllers/Snapshot/SnapshotOrderController.cs

@@ -75,6 +75,15 @@ public class SnapshotOrderController : BaseController
     public async Task<PagedDto<OrderSnapshotItemsOutDto>> GetOrderSnapshotItems([FromQuery] OrderSnapshotItemsInDto dto)
         => (await _orderSnapshotApplication.GetOrderSnapshotItems(dto).ToPagedListAsync(dto)).ToPaged();
 
+    /// <summary>
+    /// 设为重点
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpPut("isemphasis")]
+    public async Task UpdateIsEmphasisAsync([FromBody] UpdateIsEmphasisInDto dto)
+        => await _orderSnapshotApplication.UpdateIsEmphasisAsync(dto);
+
     /// <summary>
     /// 电气焊作业申报工单集合
     /// </summary>

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

@@ -850,4 +850,20 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
 #endif
         return query;
     }
+
+    public List<Dictionary<string, object>> GetIndustryStatistics(IndustryStatisticsInDto dto)
+    {
+        var query = _industryRepository.Queryable(includeDeleted: true)
+            .LeftJoin<OrderSnapshot>((industry, snapshot) => snapshot.IndustryId == industry.Id && snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime)
+            .LeftJoin<Order>((industry, snapshot, order) => order.Id == snapshot.Id)
+            .Where((industry) => industry.IsEnable == true)
+            .Select((industry, snapshot, order) => new
+            {
+                OrderCount = SqlFunc.AggregateSum(snapshot.Id),
+                order.AllDuration,
+                IsEmphasis = SqlFunc.AggregateSum(SqlFunc.IIF(snapshot.IsEmphasis == true, 1, 0)),
+            });
+        var outDto = new List<Dictionary<string, object>>();
+        return outDto;
+    }
 }

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

@@ -97,4 +97,11 @@ public interface IBiSnapshotApplication
     ISugarQueryable<CompliantStatisticsDetailsOutDto> GetCompliantStatisticsDetails(CompliantStatisticsDetailsInDto dto);
     List<Dictionary<string, object>> GetReTransactStatistics(ReTransactStatisticsInDto dto);
     ISugarQueryable<ReTransactStatisticsDetailsOutDto> GetReTransactStatisticsDetail(ReTransactStatisticsDetailsInDto dto);
+
+    /// <summary>
+    /// 行业统计
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    List<Dictionary<string, object>> GetIndustryStatistics(IndustryStatisticsInDto dto);
 }

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

@@ -143,4 +143,5 @@ public interface IOrderSnapshotApplication
     /// <param name="orderId"></param>
     /// <param name="firstErrorId"></param>
     Task UpdateSpecialReasonAsync(string orderId, string errorId, string errorName);
+    Task UpdateIsEmphasisAsync(UpdateIsEmphasisInDto dto);
 }

+ 8 - 0
src/Hotline.Application/Snapshot/SnapshotOrderApplication.cs

@@ -589,4 +589,12 @@ public class SnapshotOrderApplication : IOrderSnapshotApplication, IScopeDepende
             .Where(m => m.Id == orderId)
             .ExecuteCommandAsync();
     }
+
+    public async Task UpdateIsEmphasisAsync(UpdateIsEmphasisInDto dto)
+    {
+        await _orderSnapshotRepository.Updateable()
+            .SetColumns(m => m.IsEmphasis == true)
+            .Where(m => dto.Ids.Contains(m.Id))
+            .ExecuteCommandAsync();
+    }
 }

+ 8 - 0
src/Hotline.Share/Dtos/Snapshot/OrderDto.cs

@@ -1960,6 +1960,14 @@ public record OrderSnapshotItemsInDto : PagedRequest
     public string? IndustryId { get; set; }
 }
 
+public class UpdateIsEmphasisInDto
+{
+    /// <summary>
+    /// Id集合
+    /// </summary>
+    public IList<string> Ids { get; set; }
+}
+
 public class OrderSnapshotItemsOutDto
 {
     /// <summary>

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

@@ -2882,3 +2882,25 @@ public record ReTransactStatisticsDetailsInDto : PagedRequest
     [Required]
     public string OrgCode { get; set; }
 }
+
+public class IndustryStatisticsOutDto
+{
+    /// <summary>
+    /// 表头
+    /// </summary>
+    public IList<SystemDicDataOutDto> Headers { get; set; }
+
+    /// <summary>
+    /// 数据
+    /// </summary>
+    public List<Dictionary<string, object>> Data { get; set; }
+
+}
+
+public class IndustryStatisticsInDto
+{
+    [Required]
+    public DateTime StartTime { get; set; }
+    [Required]
+    public DateTime EndTime { get; set; }
+}

+ 6 - 0
src/Hotline/Snapshot/OrderSnapshot.cs

@@ -101,6 +101,12 @@ public class OrderSnapshot : CreationSoftDeleteEntity
     [SugarColumn(ColumnDescription = "作业时间")]
     public DateTime? EndWorkTime { get; set; }
 
+    /// <summary>
+    /// 是否重点
+    /// </summary>
+    [SugarColumn(ColumnDescription = "是否重点")]
+    public bool? IsEmphasis { get; set; }
+
     #region 标记工单是否安全生产字段
 
     /// <summary>

+ 2 - 0
test/Hotline.Tests/Application/OrderSnapshotApplicationTest.cs

@@ -142,8 +142,10 @@ public class OrderSnapshotApplicationTest : TestBase
             {
                 var log = _snapshotLabelLogRepository.Queryable().Where(m => m.OrderId == order.Id).First();
                 log.ShouldNotBeNull();
+                await _orderSnapshotApplication.UpdateIsEmphasisAsync(new UpdateIsEmphasisInDto { Ids = [order.Id]});
                 var snapshot = _orderSnapshotRepository.Get(order.Id);
                 snapshot.LabelName.ShouldBe(string.Join(',', inputLable.Select(m => m.DicDataName)), "label异常");
+                snapshot.IsEmphasis.ShouldBe(true);
             })
             .部门审核网格员红包(Set政法委)
             .部门审核网格员红包(Set应急管理局)