|
@@ -92,16 +92,20 @@ namespace GxPress.Repository.Implement.Navigation
|
|
|
if (terminal > 0)
|
|
|
query.Where(nameof(Entity.Navigations.Navigation.Terminal), terminal);
|
|
|
query.Where(nameof(Entity.Navigations.Navigation.IsDisable), false);
|
|
|
- query.Where(nameof(Entity.Navigations.Navigation.ParentId), 0);
|
|
|
query.OrderByDesc(nameof(Entity.Navigations.Navigation.Sort));
|
|
|
- var result = await _repository.GetAllAsync(query);
|
|
|
- var navigationResult = result.Select(n => _mapper.Map<NavigationResult>(n));
|
|
|
- foreach (var item in navigationResult)
|
|
|
+ var queryResult = await _repository.GetAllAsync(query);
|
|
|
+ var navigationResult = queryResult.Select(n => _mapper.Map<NavigationResult>(n)).ToList();
|
|
|
+ var result = navigationResult.Where(n => n.ParentId == 0);
|
|
|
+ foreach (var item in result)
|
|
|
{
|
|
|
- item.IsChildren = await IsExistsAsync(item.Id);
|
|
|
- item.Children = await GetTreeAsync(item.Id, navigationResult.ToList());
|
|
|
+ item.IsChildren = navigationResult.Any(n => n.ParentId == item.Id);
|
|
|
+ if (item.IsChildren)
|
|
|
+ {
|
|
|
+ var navigationResultChildren = navigationResult.Where(n => n.ParentId == item.Id).ToList();
|
|
|
+ item.Children = await GetTreeAsync(item.Id, navigationResult.ToList(), navigationResultChildren);
|
|
|
+ }
|
|
|
}
|
|
|
- return navigationResult;
|
|
|
+ return result;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 递归获取子集
|
|
@@ -110,27 +114,23 @@ namespace GxPress.Repository.Implement.Navigation
|
|
|
/// <param name="id"></param>
|
|
|
/// <param name="items"></param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<List<NavigationResult>> GetTreeAsync(int id, List<NavigationResult> items)
|
|
|
+ public async Task<List<NavigationResult>> GetTreeAsync(int id, List<NavigationResult> navigationResults, List<NavigationResult> items)
|
|
|
{
|
|
|
foreach (var item in items)
|
|
|
{
|
|
|
- item.IsChildren = await IsExistsAsync(item.Id);
|
|
|
+ item.IsChildren = navigationResults.Any(n => n.ParentId == item.Id);
|
|
|
if (item.IsChildren)
|
|
|
{
|
|
|
- var navigations = await _repository.GetAllAsync(Q.Where(nameof(Entity.Navigations.Navigation.ParentId), item.Id));
|
|
|
- item.Children = _mapper.Map<List<NavigationResult>>(navigations);
|
|
|
+ var navigationResultsParent = navigationResults.Where(n => n.ParentId == item.Id);
|
|
|
+ item.Children = _mapper.Map<List<NavigationResult>>(navigationResultsParent);
|
|
|
foreach (var childrenItem in item.Children)
|
|
|
{
|
|
|
- await GetTreeAsync(childrenItem.Id, item.Children);
|
|
|
+ await GetTreeAsync(childrenItem.Id, navigationResults, item.Children);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return items;
|
|
|
}
|
|
|
- public async Task<bool> IsExistsAsync(int parentId)
|
|
|
- {
|
|
|
- return await _repository.ExistsAsync(Q.Where(nameof(Entity.Navigations.Navigation.ParentId), parentId));
|
|
|
- }
|
|
|
/// <summary>
|
|
|
/// 获取导航栏数据
|
|
|
/// </summary>
|
|
@@ -149,7 +149,7 @@ namespace GxPress.Repository.Implement.Navigation
|
|
|
var systemLabels = await _systemLabelRepository.GetAllAsync(Q.WhereIn(nameof(Entity.SystemLabel.SystemLabel.Id), StringUtils.StringCollectionToIntList(middleLable.LabelId)));
|
|
|
foreach (var item in systemLabels)
|
|
|
{
|
|
|
- var navigationResult = new NavigationResult()
|
|
|
+ var navigationMediaResult = new NavigationMediaResult()
|
|
|
{
|
|
|
Sort = item.Sort,
|
|
|
StyleType = item.StyleType,
|