Dun.Jason 1 年之前
父節點
當前提交
a88c2c5ccf

+ 13 - 2
src/Hotline.Api/Controllers/HotSpotController.cs

@@ -10,6 +10,7 @@ using Hotline.Share.Enums.Order;
 using Hotline.Share.Enums.Settings;
 using MapsterMapper;
 using Microsoft.AspNetCore.Mvc;
+using SqlSugar;
 using StackExchange.Redis;
 using XF.Domain.Exceptions;
 using XF.Domain.Repository;
@@ -45,10 +46,20 @@ namespace Hotline.Api.Controllers
         [HttpGet("children")]
         public async Task<IReadOnlyList<Hotspot>> GetChildren([FromQuery] string? id)
         {
-            return await _hotspotTypeRepository.Queryable()
+             var list = await  _hotspotTypeRepository.Queryable()
                 .Where(x => x.ParentId == id)
                 .OrderBy(d => d.HotSpotName)
-                .ToListAsync();
+                .Select(x=> new Hotspot
+                {
+                    Id = x.Id,
+                    HotSpotName = x.HotSpotName,
+                    ParentId = x.ParentId,
+                    HotSpotFullName = x.HotSpotFullName,
+                    ProvinceCode = x.ProvinceCode,
+                    HasChild = SqlFunc.Subqueryable<Hotspot>().Where(d=>d.ParentId == x.Id).Any()
+                }).ToListAsync();
+
+            return list;
         }
 
         /// <summary>

+ 4 - 0
src/Hotline/Settings/Hotspots/Hotspot.cs

@@ -25,5 +25,9 @@ namespace Hotline.Settings.Hotspots
 
         [SugarColumn(IsIgnore = true)]
         public List<Hotspot> Children { get; set; }
+
+        [SugarColumn(IsIgnore = true)]
+        public bool HasChild { get; set; }
+
     }
 }

+ 1 - 0
src/XF.Domain.Repository/IRepositoryWithTKey.cs

@@ -31,6 +31,7 @@ namespace XF.Domain.Repository
             params (bool isWhere, Expression<Func<TEntity, bool>> expression)[] whereIfs);
         Task<bool> AnyAsync(CancellationToken cancellationToken = default);
         Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
+
         Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
     }
 }