You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.3 KiB
85 lines
2.3 KiB
|
3 months ago
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Api;
|
||
|
|
using ATS.NonCustodial.Application.Contracts.Interfaces.Admins.Api.Output;
|
||
|
|
using ATS.NonCustodial.Shared.Common.Attributes;
|
||
|
|
using ATS.NonCustodial.Shared.Common.UnifiedResults;
|
||
|
|
using ATS.NonCustodial.Shared.Extensions;
|
||
|
|
|
||
|
|
namespace ATS.NonCustodial.AdminUi.Helpers.Logs
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// Api帮助类
|
||
|
|
/// </summary>
|
||
|
|
/// Author:mxg
|
||
|
|
/// CreatedTimed:2022-05-18 09:46 AM
|
||
|
|
[SingleInstance]
|
||
|
|
public class ApiHelper
|
||
|
|
{
|
||
|
|
#region Identity
|
||
|
|
|
||
|
|
private List<ApiHelperDto> _apis;
|
||
|
|
private static readonly object LockObject = new();
|
||
|
|
private readonly IApiService _apiService;
|
||
|
|
|
||
|
|
public ApiHelper(IApiService apiService)
|
||
|
|
{
|
||
|
|
_apiService = apiService;
|
||
|
|
}
|
||
|
|
|
||
|
|
#endregion Identity
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 主要是在Action 操作的时候添加操作日志时候用
|
||
|
|
/// </summary>
|
||
|
|
/// <returns></returns>
|
||
|
|
public List<ApiHelperDto> GetApis()
|
||
|
|
{
|
||
|
|
if (_apis != null && _apis.Any()) return _apis;
|
||
|
|
|
||
|
|
lock (LockObject)
|
||
|
|
{
|
||
|
|
if (_apis != null && _apis.Any()) return _apis;
|
||
|
|
|
||
|
|
_apis = new List<ApiHelperDto>();
|
||
|
|
|
||
|
|
var apis = ((ResultOutput<List<ApiListOutput>>)_apiService.GetListAsync("").Result)
|
||
|
|
.Data
|
||
|
|
.Select(a => new
|
||
|
|
{
|
||
|
|
a.Id,
|
||
|
|
a.ParentId,
|
||
|
|
a.Label,
|
||
|
|
a.Path
|
||
|
|
});
|
||
|
|
|
||
|
|
foreach (var api in apis)
|
||
|
|
{
|
||
|
|
var parentLabel = apis.FirstOrDefault(a => a.Id == api.ParentId)?.Label;
|
||
|
|
|
||
|
|
_apis.Add(new ApiHelperDto
|
||
|
|
{
|
||
|
|
Label = parentLabel.NotNull() ? $"{parentLabel} / {api.Label}" : api.Label,
|
||
|
|
Path = api.Path?.ToLower().Trim('/')
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
return _apis;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
///
|
||
|
|
/// </summary>
|
||
|
|
public class ApiHelperDto
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 接口名称
|
||
|
|
/// </summary>
|
||
|
|
public string Label { get; set; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 接口地址
|
||
|
|
/// </summary>
|
||
|
|
public string Path { get; set; }
|
||
|
|
}
|
||
|
|
}
|