qinchaoyue пре 1 месец
родитељ
комит
6e96b4520d

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

@@ -182,4 +182,9 @@ public class BiSnapshotController : BaseController
     [HttpGet("duplicate")]
     public async Task<PagedDto<DuplicateItemsOutDto>> GetDuplicateItemsAsync([FromQuery] DuplicateItemsInDto dto)
     => (await _biSnapshotApplication.GetDuplicateItems(dto).ToPagedListAsync(dto)).ToPaged();
+
+    
+    [HttpGet("county-statistics")]
+    public async Task<IList<CountyStatisticsOutDto>> GetCountyStatisticsAsync([FromQuery] CountyStatisticsInDto dto)
+        => await _biSnapshotApplication.GetCountyStatistics(dto).ToListAsync();
 }

+ 41 - 4
src/Hotline.Application/Snapshot/BiSnapshotApplication.cs

@@ -45,8 +45,9 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
     private readonly IRepository<Hotspot> _hotspotTypeRepository;
     private readonly ISessionContext _sessionContext;
     private readonly IOrderRepository _orderRepository;
+    private readonly ICommunityInfoRepository _communityInfoRepository;
 
-    public BiSnapshotApplication(IOrderSnapshotRepository orderSnapshotRepository, IRedPackRecordRepository redPackRecordRepository, IIndustryRepository industryRepository, IIndustryCaseRepository industryCaseRepository, IRedPackAuditRepository redPackAuditRepository, IRepository<Hotspot> hotspotTypeRepository, ISessionContext sessionContext, IOrderRepository orderRepository)
+    public BiSnapshotApplication(IOrderSnapshotRepository orderSnapshotRepository, IRedPackRecordRepository redPackRecordRepository, IIndustryRepository industryRepository, IIndustryCaseRepository industryCaseRepository, IRedPackAuditRepository redPackAuditRepository, IRepository<Hotspot> hotspotTypeRepository, ISessionContext sessionContext, IOrderRepository orderRepository, ICommunityInfoRepository communityInfoRepository)
     {
         _orderSnapshotRepository = orderSnapshotRepository;
         _redPackRecordRepository = redPackRecordRepository;
@@ -56,6 +57,7 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
         _hotspotTypeRepository = hotspotTypeRepository;
         _sessionContext = sessionContext;
         _orderRepository = orderRepository;
+        _communityInfoRepository = communityInfoRepository;
     }
 
     public ISugarQueryable<HotspotStatisticsOutDto> GetHotspotStatistics(HotspotStatisticsInDto dto)
@@ -434,7 +436,7 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
     public ISugarQueryable<GuiderWorkStatisticsOutDto> GetGuiderWorkStatisticsAsync(GuiderWorkStatisticsInDto dto)
     {
         var query = _orderSnapshotRepository.Queryable(includeDeleted: true)
-            .Where(snapshot => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime && snapshot.MemberName != null )
+            .Where(snapshot => snapshot.CreationTime >= dto.StartTime && snapshot.CreationTime <= dto.EndTime && snapshot.MemberName != null)
             .GroupBy(snapshot => new { snapshot.MemberName, snapshot.MemberMobile })
             .Select(snapshot => new GuiderWorkStatisticsOutDto
             {
@@ -463,7 +465,7 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
             _ => throw new UserFriendlyException($"入参: {dto.FieldName} 异常")
         };
         return query.Select((snapshot, order) => new GuiderWorkStatisticsDetailsOutDto
-        { 
+        {
         }, true);
     }
 
@@ -490,7 +492,7 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
             .Where((snapshot, order) => snapshot.IsGuidSystemCallBack == true)
             .WhereIF(dto.MemberMobile.NotNullOrEmpty(), snapshot => snapshot.MemberMobile.Contains(dto.MemberMobile))
             .WhereIF(dto.BeginCreationTime != null && dto.EndCreationTime != null, snapshot => snapshot.CreationTime >= dto.BeginCreationTime && snapshot.CreationTime <= dto.EndCreationTime)
-            .WhereIF(dto.MemberName.NotNullOrEmpty(), snapshot => snapshot.MemberName.Contains( dto.MemberName))
+            .WhereIF(dto.MemberName.NotNullOrEmpty(), snapshot => snapshot.MemberName.Contains(dto.MemberName))
             .WhereIF(dto.No.NotNullOrEmpty(), (snapshot, order) => order.No.Contains(dto.No))
             .WhereIF(dto.Title.NotNullOrEmpty(), (snapshot, order) => order.Title.Contains(dto.Title))
             .WhereIF(dto.NetworkENumber.NotNullOrEmpty(), (snapshot, order) => snapshot.NetworkENumber.Contains(dto.NetworkENumber))
@@ -518,4 +520,39 @@ public class BiSnapshotApplication : IBiSnapshotApplication, IScopeDependency
             .Select((snapshot, order) => new DuplicateItemsOutDto(), true);
         return query;
     }
+
+    public ISugarQueryable<CountyStatisticsOutDto> GetCountyStatistics(CountyStatisticsInDto dto)
+    {
+        var IsCenter = _sessionContext.OrgIsCenter;
+        string count = "2";
+        string countx = string.Empty;
+        if (dto.CountyCode.NotNullOrEmpty())
+        {
+            count = (dto.CountyCode.Length + 2).ToString();
+            countx = dto.CountyCode.Length.ToString();
+        }
+        return _communityInfoRepository.Queryable()
+        .LeftJoin<Order>((it, o) => it.Id == o.HotspotId)
+        .LeftJoin<OrderSnapshot>((it, o, s) => o.Id == s.Id)
+        .Where((it, o, s) => o.CreationTime >= dto.StartTime && o.CreationTime <= dto.EndTime && s.Id != null)
+        .WhereIF(dto.CountyCode.IsNullOrEmpty(), (it, o) => o.Id != null)
+        .WhereIF(dto.CountyCode.NotNullOrEmpty(), (it, o) => it.ParentCode.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(countx)) == dto.CountyCode)
+        .WhereIF(IsCenter == false, (it, o) => o.ActualHandleOrgCode.StartsWith(_sessionContext.RequiredOrgId))
+        .GroupBy((it, o) => new { Id = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)) })
+        .Select((it, o) => new
+        {
+            CommunityCode = it.Id.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>(count)),
+            SumCount = SqlFunc.AggregateCount(it.FullName)
+        })
+        .MergeTable()
+        .LeftJoin<CommunityInfo>((x, q) => x.CommunityCode == q.Id)
+        .Select((x, q) => new CountyStatisticsOutDto
+        {
+            CountyCode = x.CommunityCode,
+            SumCount = x.SumCount,
+            CountyName = q.Name,
+            HasChild = SqlFunc.Subqueryable<Hotspot>().Where(d => d.ParentId == x.CommunityCode).Any()
+        });
+
+    }
 }

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

@@ -54,4 +54,5 @@ public interface IBiSnapshotApplication
     /// <returns></returns>
     ISugarQueryable<GuiderWorkLogsOutDto> GetGuiderWorkLogs(GuiderWorkLogsInDto dto);
     ISugarQueryable<DuplicateItemsOutDto> GetDuplicateItems(DuplicateItemsInDto dto);
+    ISugarQueryable<CountyStatisticsOutDto> GetCountyStatistics(CountyStatisticsInDto dto);
 }

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

@@ -1899,3 +1899,27 @@ public class DuplicateItemsOutDto
     /// </summary>
     public string AcceptorName { get; set; }
 }
+
+public class CountyStatisticsInDto
+{
+    [Required]
+    public DateTime StartTime { get; set; }
+    [Required]
+    public DateTime EndTime { get; set; }
+
+    /// <summary>
+    /// 行业Id
+    /// </summary>
+    public string? IndustryId { get; set; }
+
+    public string? CountyCode { get; set; }
+}
+
+public class CountyStatisticsOutDto
+{
+    public string CountyCode { get; set; }
+    public int SumCount { get; set; }
+    public string CountyName { get; set; }
+    public bool HasChild { get; set; }
+
+}