重构接口列表tree-list
This commit is contained in:
parent
317dc30b17
commit
4f3b7733e0
@ -1,6 +1,8 @@
|
|||||||
using InterfaceForward.Repositories;
|
using InterfaceForward.Repositories;
|
||||||
using InterfaceForward.Repositories.Interface.Entitys;
|
using InterfaceForward.Repositories.Interface.Entitys;
|
||||||
|
using InterfaceForward.Repositories.Interface.ValueObjects;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
namespace InterfaceForward.Application.Services.Interface;
|
namespace InterfaceForward.Application.Services.Interface;
|
||||||
|
|
||||||
@ -10,6 +12,40 @@ namespace InterfaceForward.Application.Services.Interface;
|
|||||||
[ApiExplorerSettings(GroupName = "接口服务")]
|
[ApiExplorerSettings(GroupName = "接口服务")]
|
||||||
public class InterfaceCategoryService(IBasicRepository<InterfaceCategoryEntity> categoryRepository) : ApplicationService
|
public class InterfaceCategoryService(IBasicRepository<InterfaceCategoryEntity> categoryRepository) : ApplicationService
|
||||||
{
|
{
|
||||||
|
public const int CategoryRootId = 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取分组树
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="isUpstream"></param>
|
||||||
|
/// <param name="datas"></param>
|
||||||
|
internal async Task<List<CategoryTreeNode<T>>> GetCategoryTree<T>(bool isUpstream, List<T> datas)
|
||||||
|
where T : HasCategoryId
|
||||||
|
{
|
||||||
|
var categories = await categoryRepository.GetListAsync(x => x.IsUpStream == isUpstream);
|
||||||
|
|
||||||
|
return GetCategoryTree(categories, CategoryRootId, datas);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<CategoryTreeNode<T>> GetCategoryTree<T>(List<InterfaceCategoryEntity> categories, int pId,
|
||||||
|
List<T> datas) where T : HasCategoryId
|
||||||
|
{
|
||||||
|
var res = new List<CategoryTreeNode<T>>();
|
||||||
|
foreach (var category in categories.Where(x => x.PId == pId))
|
||||||
|
{
|
||||||
|
res.Add(new CategoryTreeNode<T>
|
||||||
|
{
|
||||||
|
Id = category.Id,
|
||||||
|
Name = category.Name,
|
||||||
|
Data = datas.Where(x => x.CategoryId == category.Id).ToList(),
|
||||||
|
Children = GetCategoryTree(categories, category.Id, datas)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 添加接口分类
|
/// 添加接口分类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -29,7 +65,7 @@ public class InterfaceCategoryService(IBasicRepository<InterfaceCategoryEntity>
|
|||||||
Name = name
|
Name = name
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新接口分类
|
/// 更新接口分类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -47,7 +83,7 @@ public class InterfaceCategoryService(IBasicRepository<InterfaceCategoryEntity>
|
|||||||
category.Name = name;
|
category.Name = name;
|
||||||
await categoryRepository.UpdateAsync(category);
|
await categoryRepository.UpdateAsync(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 删除接口分类
|
/// 删除接口分类
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -60,6 +96,27 @@ public class InterfaceCategoryService(IBasicRepository<InterfaceCategoryEntity>
|
|||||||
{
|
{
|
||||||
throw new BusinessException("分类不存在");
|
throw new BusinessException("分类不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
await categoryRepository.SoftDeleteAsync(x => x.Id == id);
|
await categoryRepository.SoftDeleteAsync(x => x.Id == id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CategoryTreeNode<T> where T : HasCategoryId
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 分组名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据
|
||||||
|
/// </summary>
|
||||||
|
public List<T> Data { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 子分组
|
||||||
|
/// </summary>
|
||||||
|
public List<CategoryTreeNode<T>> Children { get; set; }
|
||||||
}
|
}
|
||||||
@ -33,6 +33,9 @@ public class ServiceProviderInterfaceService : ApplicationService
|
|||||||
|
|
||||||
private IBasicRepository<InterfaceMapEntity> InterfaceMapRepository =>
|
private IBasicRepository<InterfaceMapEntity> InterfaceMapRepository =>
|
||||||
LazyServiceProvider.GetRequiredService<IBasicRepository<InterfaceMapEntity>>();
|
LazyServiceProvider.GetRequiredService<IBasicRepository<InterfaceMapEntity>>();
|
||||||
|
|
||||||
|
private InterfaceCategoryService InterfaceCategoryService =>
|
||||||
|
LazyServiceProvider.GetRequiredService<InterfaceCategoryService>();
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -41,10 +44,14 @@ public class ServiceProviderInterfaceService : ApplicationService
|
|||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("Interface/ServiceProviderInterfacePaginatedList")]
|
[HttpPost("Interface/ServiceProviderInterfacePaginatedList")]
|
||||||
public async Task<PagedResult<ServiceProviderInterfacePaginatedOutputValueObject>>
|
public async Task<List<CategoryTreeNode<ServiceProviderInterfaceTreeListOutputValueObject>>>
|
||||||
ServiceProviderInterfacePaginatedListAsync(ServiceProviderInterfacePaginatedInputObjectValue input)
|
ServiceProviderInterfacePaginatedListAsync(ServiceProviderInterfaceTreeListInputObjectValue input)
|
||||||
{
|
{
|
||||||
return await InterfaceRepository.GetServiceProviderInterfacePaginatedListAsync(input);
|
var res = await InterfaceRepository.GetServiceProviderInterfaceListAsync(input);
|
||||||
|
|
||||||
|
var tree = await InterfaceCategoryService.GetCategoryTree(false, res);
|
||||||
|
|
||||||
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -24,6 +24,7 @@ public class SystemInterfaceService : ApplicationService
|
|||||||
private readonly ParameterService _parameterService;
|
private readonly ParameterService _parameterService;
|
||||||
private readonly IInterfaceRepository _interfaceRepository;
|
private readonly IInterfaceRepository _interfaceRepository;
|
||||||
private readonly IBasicRepository<InterfaceMapEntity> _interfaceMapRepository;
|
private readonly IBasicRepository<InterfaceMapEntity> _interfaceMapRepository;
|
||||||
|
private readonly InterfaceCategoryService _interfaceCategoryService;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 系统接口下拉列表缓存key
|
/// 系统接口下拉列表缓存key
|
||||||
@ -34,25 +35,31 @@ public class SystemInterfaceService : ApplicationService
|
|||||||
public SystemInterfaceService(
|
public SystemInterfaceService(
|
||||||
IInterfaceRepository interfaceRepository
|
IInterfaceRepository interfaceRepository
|
||||||
, ParameterService parameterService
|
, ParameterService parameterService
|
||||||
, IBasicRepository<InterfaceMapEntity> interfaceMapRepository)
|
, IBasicRepository<InterfaceMapEntity> interfaceMapRepository
|
||||||
|
, InterfaceCategoryService interfaceCategoryService)
|
||||||
{
|
{
|
||||||
_parameterService = parameterService;
|
_parameterService = parameterService;
|
||||||
_interfaceMapRepository = interfaceMapRepository;
|
_interfaceMapRepository = interfaceMapRepository;
|
||||||
|
_interfaceCategoryService = interfaceCategoryService;
|
||||||
_interfaceRepository = interfaceRepository;
|
_interfaceRepository = interfaceRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 系统接口分页列表
|
/// 系统接口树形列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("Interface/SystemInterfacePaginatedList")]
|
[HttpPost("Interface/GetSystemInterfaceTreeListAsync")]
|
||||||
public async Task<PagedResult<SystemInterfacePaginatedOutputValueObject>>
|
public async Task<List<CategoryTreeNode<SystemInterfaceTreeListValueObject>>>
|
||||||
SystemInterfacePaginatedListAsync(SystemInterfacePaginatedInputObjectValue input)
|
GetSystemInterfaceTreeListAsync(SystemInterfaceTreeListInputObjectValue input)
|
||||||
{
|
{
|
||||||
return await _interfaceRepository.GetSystemInterfacePaginatedListAsync(input);
|
var res = await _interfaceRepository.GetSystemInterfaceListAsync(input);
|
||||||
|
|
||||||
|
var tree = await _interfaceCategoryService.GetCategoryTree(true, res);
|
||||||
|
|
||||||
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -17,5 +17,11 @@
|
|||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "Name")]
|
[SugarColumn(ColumnName = "Name")]
|
||||||
public string Name { get; set; } = null!;
|
public string Name { get; set; } = null!;
|
||||||
|
|
||||||
|
///<summary>
|
||||||
|
/// 0:服务商接口;1:系统接口
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnName = "IsUpStream")]
|
||||||
|
public bool IsUpStream { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -13,18 +13,18 @@ namespace InterfaceForward.Repositories.Interface.Services
|
|||||||
public interface IInterfaceRepository:IBasicRepository<InterfaceEntity>
|
public interface IInterfaceRepository:IBasicRepository<InterfaceEntity>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取系统接口分页列表
|
/// 获取系统接口列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<PagedResult<SystemInterfacePaginatedOutputValueObject>> GetSystemInterfacePaginatedListAsync(SystemInterfacePaginatedInputObjectValue input);
|
Task<List<SystemInterfaceTreeListValueObject>> GetSystemInterfaceListAsync(SystemInterfaceTreeListInputObjectValue input);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取服务商接口分页
|
/// 获取服务商接口列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<PagedResult<ServiceProviderInterfacePaginatedOutputValueObject>> GetServiceProviderInterfacePaginatedListAsync(ServiceProviderInterfacePaginatedInputObjectValue input);
|
Task<List<ServiceProviderInterfaceTreeListOutputValueObject>> GetServiceProviderInterfaceListAsync(ServiceProviderInterfaceTreeListInputObjectValue input);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取参数列表
|
/// 获取参数列表
|
||||||
|
|||||||
@ -16,39 +16,40 @@ public class InterfaceRepository : BasicRepository<InterfaceEntity>, IInterfaceR
|
|||||||
public string InterfaceGroup => "InterfaceGroup";
|
public string InterfaceGroup => "InterfaceGroup";
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<PagedResult<SystemInterfacePaginatedOutputValueObject>>
|
public async Task<List<SystemInterfaceTreeListValueObject>>
|
||||||
GetSystemInterfacePaginatedListAsync(SystemInterfacePaginatedInputObjectValue input)
|
GetSystemInterfaceListAsync(SystemInterfaceTreeListInputObjectValue input)
|
||||||
{
|
{
|
||||||
// t_interface驱动t_interface_map,数据量上来可以在t_interface_map UpStreamId字段建立索引
|
// t_interface驱动t_interface_map,数据量上来可以在t_interface_map UpStreamId字段建立索引
|
||||||
var query = AsQueryable()
|
var query = AsQueryable()
|
||||||
.LeftJoin<DictionaryEntity>((a, c) => a.Category == c.Id)
|
.LeftJoin<DictionaryEntity>((a, d) => (int)a.RequestProtocol == d.Id)
|
||||||
.LeftJoin<DictionaryEntity>((a, c, d) => (int)a.RequestProtocol == d.Id)
|
.LeftJoin<DictionaryEntity>((a, d, e) => a.RequestMethod == e.Id)
|
||||||
.LeftJoin<DictionaryEntity>((a, c, d, e) => a.RequestMethod == e.Id)
|
|
||||||
.Where(a => a.IsUpStream)
|
.Where(a => a.IsUpStream)
|
||||||
;
|
;
|
||||||
|
|
||||||
query.WhereIF(input.Category != 0, a => a.Category == input.Category) // 默认“请选择”对应0,数据源在数据库字典中配置
|
query
|
||||||
.WhereIF(!string.IsNullOrEmpty(input.Name), a => a.Name.Contains(input.Name!)) // 默认为空,支持模糊搜索
|
.WhereIF(!string.IsNullOrEmpty(input.Name), a => a.Name.Contains(input.Name!)) // 默认为空,支持模糊搜索
|
||||||
.WhereIF(!string.IsNullOrEmpty(input.Code), a => a.Code.Contains(input.Code!)) // 默认为空,支持模糊搜索
|
.WhereIF(!string.IsNullOrEmpty(input.Code), a => a.Code.Contains(input.Code!)) // 默认为空,支持模糊搜索
|
||||||
;
|
;
|
||||||
|
|
||||||
return await query.Select((a, c, d, e) => new SystemInterfacePaginatedOutputValueObject
|
return await query
|
||||||
{
|
.OrderBy(a => a.CreateTime)
|
||||||
Id = a.Id,
|
.Select((a, d, e) => new SystemInterfaceTreeListValueObject
|
||||||
Category = c.Name,
|
{
|
||||||
Name = a.Name,
|
Id = a.Id,
|
||||||
Code = a.Code,
|
CategoryId = a.Category,
|
||||||
RequestProtocol = d.Name,
|
Name = a.Name,
|
||||||
Description = a.Description,
|
Code = a.Code,
|
||||||
MapCount = SqlFunc.Subqueryable<InterfaceMapEntity>().Where(x => x.UpStreamId == a.Id && !x.IsDeleted)
|
RequestProtocol = d.Name,
|
||||||
.DistinctCount(x => x.ServiceProviderId),
|
Description = a.Description,
|
||||||
UpdateTime = a.UpdateTime,
|
MapCount = SqlFunc.Subqueryable<InterfaceMapEntity>().Where(x => x.UpStreamId == a.Id && !x.IsDeleted)
|
||||||
}).OrderByDescending(a => a.UpdateTime).ToPagedListAsync(input.PageIndex, input.PageSize);
|
.DistinctCount(x => x.ServiceProviderId),
|
||||||
|
UpdateTime = a.UpdateTime,
|
||||||
|
}).ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<PagedResult<ServiceProviderInterfacePaginatedOutputValueObject>>
|
public async Task<List<ServiceProviderInterfaceTreeListOutputValueObject>>
|
||||||
GetServiceProviderInterfacePaginatedListAsync(ServiceProviderInterfacePaginatedInputObjectValue input)
|
GetServiceProviderInterfaceListAsync(ServiceProviderInterfaceTreeListInputObjectValue input)
|
||||||
{
|
{
|
||||||
var query = AsQueryable()
|
var query = AsQueryable()
|
||||||
.LeftJoin<DictionaryEntity>((a, b) => (int)a.RequestProtocol == b.Id)
|
.LeftJoin<DictionaryEntity>((a, b) => (int)a.RequestProtocol == b.Id)
|
||||||
@ -60,9 +61,12 @@ public class InterfaceRepository : BasicRepository<InterfaceEntity>, IInterfaceR
|
|||||||
.WhereIF(!string.IsNullOrEmpty(input.Name), a => a.Name.Contains(input.Name!)) // 默认为空,支持模糊搜索
|
.WhereIF(!string.IsNullOrEmpty(input.Name), a => a.Name.Contains(input.Name!)) // 默认为空,支持模糊搜索
|
||||||
.WhereIF(!string.IsNullOrEmpty(input.Code), a => a.Code.Contains(input.Code!)) // 默认为空,支持模糊搜索
|
.WhereIF(!string.IsNullOrEmpty(input.Code), a => a.Code.Contains(input.Code!)) // 默认为空,支持模糊搜索
|
||||||
;
|
;
|
||||||
return await query.Select((a, b, c) => new ServiceProviderInterfacePaginatedOutputValueObject
|
return await query
|
||||||
|
.OrderBy(a => a.CreateTime)
|
||||||
|
.Select((a, b, c) => new ServiceProviderInterfaceTreeListOutputValueObject
|
||||||
{
|
{
|
||||||
Id = a.Id,
|
Id = a.Id,
|
||||||
|
CategoryId = a.Category,
|
||||||
Name = a.Name,
|
Name = a.Name,
|
||||||
Code = a.Code,
|
Code = a.Code,
|
||||||
RequestProtocol = b.Name,
|
RequestProtocol = b.Name,
|
||||||
@ -71,8 +75,7 @@ public class InterfaceRepository : BasicRepository<InterfaceEntity>, IInterfaceR
|
|||||||
Description = a.Description,
|
Description = a.Description,
|
||||||
UpdateTime = a.UpdateTime,
|
UpdateTime = a.UpdateTime,
|
||||||
})
|
})
|
||||||
.OrderByDescending(a => a.UpdateTime)
|
.ToListAsync();
|
||||||
.ToPagedListAsync(input.PageIndex, input.PageSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -5,7 +5,7 @@ namespace InterfaceForward.Repositories.Interface.ValueObjects;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 服务商接口分页
|
/// 服务商接口分页
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ServiceProviderInterfacePaginatedInputObjectValue : PagedQueryInput
|
public class ServiceProviderInterfaceTreeListInputObjectValue
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 服务商Id
|
/// 服务商Id
|
||||||
@ -3,7 +3,7 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ServiceProviderInterfacePaginatedOutputValueObject
|
public class ServiceProviderInterfaceTreeListOutputValueObject: HasCategoryId
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 接口Id
|
/// 接口Id
|
||||||
@ -5,13 +5,8 @@ namespace InterfaceForward.Repositories.Interface.ValueObjects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 分页查询系统接口
|
/// 分页查询系统接口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SystemInterfacePaginatedInputObjectValue : PagedQueryInput
|
public class SystemInterfaceTreeListInputObjectValue
|
||||||
{
|
{
|
||||||
///<summary>
|
|
||||||
/// 接口分组,默认请选择对应0值
|
|
||||||
///</summary>
|
|
||||||
public int Category { get; set; }
|
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
/// 接口名
|
/// 接口名
|
||||||
///</summary>
|
///</summary>
|
||||||
@ -1,20 +1,23 @@
|
|||||||
namespace InterfaceForward.Repositories.Interface.ValueObjects
|
namespace InterfaceForward.Repositories.Interface.ValueObjects
|
||||||
{
|
{
|
||||||
|
public class HasCategoryId
|
||||||
|
{
|
||||||
|
///<summary>
|
||||||
|
/// 接口分组id
|
||||||
|
///</summary>
|
||||||
|
public int CategoryId { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SystemInterfacePaginatedOutputValueObject
|
public class SystemInterfaceTreeListValueObject: HasCategoryId
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 接口Id
|
/// 接口Id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
///<summary>
|
|
||||||
/// 接口分组
|
|
||||||
///</summary>
|
|
||||||
public string Category { get; set; }
|
|
||||||
|
|
||||||
///<summary>
|
///<summary>
|
||||||
/// 接口名
|
/// 接口名
|
||||||
///</summary>
|
///</summary>
|
||||||
Loading…
Reference in New Issue
Block a user