feat: initialize Evergreen Health backend
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
namespace Admin.NET.Core.Service;
|
||||
|
||||
/// <summary>
|
||||
/// 接口/动态API输出
|
||||
/// </summary>
|
||||
public class ApiOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 组名称
|
||||
/// </summary>
|
||||
public string GroupName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 接口名称
|
||||
/// </summary>
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 路由名称
|
||||
/// </summary>
|
||||
public string RouteName { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
using Magicodes.ExporterAndImporter.Core.Filters;
|
||||
using Magicodes.ExporterAndImporter.Core.Models;
|
||||
|
||||
namespace Admin.NET.Core.Service;
|
||||
|
||||
/// <summary>
|
||||
/// 基础存储过程输入类
|
||||
/// </summary>
|
||||
public class BaseProcInput
|
||||
{
|
||||
/// <summary>
|
||||
/// ProcId
|
||||
/// </summary>
|
||||
public string ProcId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据库配置Id
|
||||
/// </summary>
|
||||
public string ConfigId { get; set; } = SqlSugarConst.MainConfigId;
|
||||
|
||||
/// <summary>
|
||||
/// 存储过程输入参数
|
||||
/// </summary>
|
||||
/// <example>{"id":"351060822794565"}</example>
|
||||
public Dictionary<string, object> ProcParams { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 带表头名称存储过程输入类
|
||||
/// </summary>
|
||||
public class ExportProcByTMPInput : BaseProcInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 模板名称
|
||||
/// </summary>
|
||||
public string Template { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 带表头名称存储过程输入类
|
||||
/// </summary>
|
||||
public class ExportProcInput : BaseProcInput
|
||||
{
|
||||
public Dictionary<string, string> EHeader { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 指定导出类名(有排序)存储过程输入类
|
||||
/// </summary>
|
||||
public class ExportProcInput2 : BaseProcInput
|
||||
{
|
||||
public List<string> EHeader { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 前端指定列
|
||||
/// </summary>
|
||||
public class ProcExporterHeaderFilter : IExporterHeaderFilter
|
||||
{
|
||||
private Dictionary<string, Tuple<string, int>> _includeHeader;
|
||||
|
||||
public ProcExporterHeaderFilter(Dictionary<string, Tuple<string, int>> includeHeader)
|
||||
{
|
||||
_includeHeader = includeHeader;
|
||||
}
|
||||
|
||||
public ExporterHeaderInfo Filter(ExporterHeaderInfo exporterHeaderInfo)
|
||||
{
|
||||
if (_includeHeader != null && _includeHeader.Count > 0)
|
||||
{
|
||||
var key = exporterHeaderInfo.PropertyName.ToUpper();
|
||||
if (_includeHeader.ContainsKey(key))
|
||||
{
|
||||
exporterHeaderInfo.DisplayName = _includeHeader[key].Item1;
|
||||
return exporterHeaderInfo;
|
||||
}
|
||||
else
|
||||
{
|
||||
exporterHeaderInfo.ExporterHeaderAttribute.Hidden = true;
|
||||
}
|
||||
}
|
||||
return exporterHeaderInfo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
namespace Admin.NET.Core.Service;
|
||||
|
||||
/// <summary>
|
||||
/// 国密公钥私钥对输出
|
||||
/// </summary>
|
||||
public class SmKeyPairOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 私匙
|
||||
/// </summary>
|
||||
public string PrivateKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 公匙
|
||||
/// </summary>
|
||||
public string PublicKey { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
namespace Admin.NET.Core.Service;
|
||||
|
||||
/// <summary>
|
||||
/// 接口压测输入参数
|
||||
/// </summary>
|
||||
public class StressTestInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 接口请求地址
|
||||
/// </summary>
|
||||
/// <example>https://gitee.com/zuohuaijun/Admin.NET</example>
|
||||
[Required(ErrorMessage = "接口请求地址不能为空")]
|
||||
public string RequestUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求方式
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "请求方式不能为空")]
|
||||
public string RequestMethod { get; set; } = nameof(HttpMethod.Get);
|
||||
|
||||
/// <summary>
|
||||
/// 每轮请求量
|
||||
/// </summary>
|
||||
/// <example>100</example>
|
||||
[Required(ErrorMessage = "每轮请求量不能为空")]
|
||||
[Range(1, 100000, ErrorMessage = "每轮请求量必须为1-100000")]
|
||||
public int? NumberOfRequests { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 压测轮数
|
||||
/// </summary>
|
||||
/// <example>5</example>
|
||||
[Required(ErrorMessage = "压测轮数不能为空")]
|
||||
[Range(1, 10000, ErrorMessage = "压测轮数必须为1-10000")]
|
||||
public int? NumberOfRounds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大并行量(默认为当前主机逻辑处理器的数量)
|
||||
/// </summary>
|
||||
/// <example>500</example>
|
||||
[Range(0, 10000, ErrorMessage = "最大并行量必须为0-10000")]
|
||||
public int? MaxDegreeOfParallelism { get; set; } = Environment.ProcessorCount;
|
||||
|
||||
/// <summary>
|
||||
/// 请求参数
|
||||
/// </summary>
|
||||
public List<KeyValuePair<string, string>> RequestParameters { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 请求头参数
|
||||
/// </summary>
|
||||
public Dictionary<string, string> Headers { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 路径参数
|
||||
/// </summary>
|
||||
public Dictionary<string, string> PathParameters { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Query参数
|
||||
/// </summary>
|
||||
public Dictionary<string, string> QueryParameters { get; set; } = new();
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
namespace Admin.NET.Core.Service;
|
||||
|
||||
/// <summary>
|
||||
/// 接口压测输出参数
|
||||
/// </summary>
|
||||
public class StressTestOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 总请求次数
|
||||
/// </summary>
|
||||
public long TotalRequests { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总用时(秒)
|
||||
/// </summary>
|
||||
public double TotalTimeInSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 成功请求次数
|
||||
/// </summary>
|
||||
public long SuccessfulRequests { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 失败请求次数
|
||||
/// </summary>
|
||||
public long FailedRequests { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 每秒查询率(QPS)
|
||||
/// </summary>
|
||||
public double QueriesPerSecond { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最小响应时间(毫秒)
|
||||
/// </summary>
|
||||
public double MinResponseTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大响应时间(毫秒)
|
||||
/// </summary>
|
||||
public double MaxResponseTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 平均响应时间(毫秒)
|
||||
/// </summary>
|
||||
public double AverageResponseTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// P10 响应时间(毫秒)
|
||||
/// </summary>
|
||||
public double Percentile10ResponseTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// P25 响应时间(毫秒)
|
||||
/// </summary>
|
||||
public double Percentile25ResponseTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// P50 响应时间(毫秒)
|
||||
/// </summary>
|
||||
public double Percentile50ResponseTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// P75 响应时间(毫秒)
|
||||
/// </summary>
|
||||
public double Percentile75ResponseTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// P90 响应时间(毫秒)
|
||||
/// </summary>
|
||||
public double Percentile90ResponseTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// P99 响应时间(毫秒)
|
||||
/// </summary>
|
||||
public double Percentile99ResponseTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// P999 响应时间(毫秒)
|
||||
/// </summary>
|
||||
public double Percentile999ResponseTime { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
using Org.BouncyCastle.Utilities.Encoders;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace Admin.NET.Core.Service;
|
||||
|
||||
/// <summary>
|
||||
/// 系统通用服务 🧩
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Order = 101)]
|
||||
[AllowAnonymous]
|
||||
public class SysCommonService : IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IApiDescriptionGroupCollectionProvider _apiProvider;
|
||||
private readonly SqlSugarRepository<SysUser> _sysUserRep;
|
||||
private readonly CDConfigOptions _cdConfigOptions;
|
||||
private readonly UserManager _userManager;
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public SysCommonService(IApiDescriptionGroupCollectionProvider apiProvider,
|
||||
SqlSugarRepository<SysUser> sysUserRep,
|
||||
IOptions<CDConfigOptions> giteeOptions,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
UserManager userManager)
|
||||
{
|
||||
_sysUserRep = sysUserRep;
|
||||
_apiProvider = apiProvider;
|
||||
_userManager = userManager;
|
||||
_cdConfigOptions = giteeOptions.Value;
|
||||
_httpClient = httpClientFactory.CreateClient();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取国密公钥私钥对 🏆
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[DisplayName("获取国密公钥私钥对")]
|
||||
public SmKeyPairOutput GetSmKeyPair()
|
||||
{
|
||||
var kp = GM.GenerateKeyPair();
|
||||
var privateKey = Hex.ToHexString(((ECPrivateKeyParameters)kp.Private).D.ToByteArray()).ToUpper();
|
||||
var publicKey = Hex.ToHexString(((ECPublicKeyParameters)kp.Public).Q.GetEncoded()).ToUpper();
|
||||
|
||||
return new SmKeyPairOutput
|
||||
{
|
||||
PrivateKey = privateKey,
|
||||
PublicKey = publicKey,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有接口/动态API 🔖
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[DisplayName("获取所有接口/动态API")]
|
||||
public List<ApiOutput> GetApiList()
|
||||
{
|
||||
var apiList = new List<ApiOutput>();
|
||||
foreach (var item in _apiProvider.ApiDescriptionGroups.Items)
|
||||
{
|
||||
foreach (var apiDescription in item.Items)
|
||||
{
|
||||
var displayName = apiDescription.TryGetMethodInfo(out MethodInfo apiMethodInfo) ? apiMethodInfo.GetCustomAttribute<DisplayNameAttribute>(true)?.DisplayName : "";
|
||||
|
||||
apiList.Add(new ApiOutput
|
||||
{
|
||||
GroupName = item.GroupName,
|
||||
DisplayName = displayName,
|
||||
RouteName = apiDescription.RelativePath
|
||||
});
|
||||
}
|
||||
}
|
||||
return apiList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载标记错误的临时Excel(全局)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[DisplayName("下载标记错误的临时Excel(全局)")]
|
||||
public async Task<IActionResult> DownloadErrorExcelTemp([FromQuery] string fileName = null)
|
||||
{
|
||||
var userId = App.User?.FindFirst(ClaimConst.UserId)?.Value;
|
||||
var resultStream = App.GetRequiredService<SysCacheService>().Get<MemoryStream>(CacheConst.KeyExcelTemp + userId);
|
||||
|
||||
if (resultStream == null) throw Oops.Oh("错误标记文件已过期。");
|
||||
|
||||
return await Task.FromResult(new FileStreamResult(resultStream, "application/octet-stream")
|
||||
{
|
||||
FileDownloadName = $"{(string.IsNullOrEmpty(fileName) ? "错误标记_" + DateTime.Now.ToString("yyyyMMddhhmmss") : fileName)}.xlsx"
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加密字符串 🔖
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[SuppressMonitor]
|
||||
[DisplayName("加密字符串")]
|
||||
public dynamic EncryptPlainText([Required] string plainText)
|
||||
{
|
||||
return CryptogramUtil.Encrypt(plainText);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接口压测 🔖
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[DisplayName("接口压测")]
|
||||
public async Task<StressTestOutput> StressTest(StressTestInput input)
|
||||
{
|
||||
// 限制仅超管用户才能使用此功能
|
||||
if (!_userManager.SuperAdmin) throw Oops.Oh(ErrorCodeEnum.SA001);
|
||||
|
||||
var stopwatch = new Stopwatch();
|
||||
var responseTimes = new List<double>(); //响应时间集合
|
||||
input.RequestMethod = input.RequestMethod.ToUpper();
|
||||
long totalRequests = 0, successfulRequests = 0, failedRequests = 0;
|
||||
|
||||
stopwatch.Start();
|
||||
var semaphore = new SemaphoreSlim(input.MaxDegreeOfParallelism!.Value > 0 ? input.MaxDegreeOfParallelism.Value : Environment.ProcessorCount);
|
||||
|
||||
#region 参数构建
|
||||
|
||||
// 构建基础URI(不包括路径和查询参数)
|
||||
var baseUriBuilder = new UriBuilder(input.RequestUri);
|
||||
var queryString = HttpUtility.ParseQueryString(baseUriBuilder.Query);
|
||||
|
||||
// 替换路径参数到baseUriBuilder.Path
|
||||
foreach (var param in input.PathParameters)
|
||||
{
|
||||
baseUriBuilder.Path = baseUriBuilder.Path.Replace($"{{{param.Key}}}", param.Value, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
// 构建Query参数
|
||||
foreach (var param in input.QueryParameters)
|
||||
{
|
||||
queryString[param.Key] = param.Value;
|
||||
}
|
||||
|
||||
baseUriBuilder.Query = queryString.ToString() ?? string.Empty;
|
||||
var fullUri = baseUriBuilder.Uri;
|
||||
|
||||
// 创建一次性的HttpRequestMessage模板
|
||||
HttpRequestMessage requestTemplate = CreateRequestMessage(input, fullUri);
|
||||
|
||||
#endregion 参数构建
|
||||
|
||||
var tasks = Enumerable.Range(0, input.NumberOfRounds!.Value * input.NumberOfRequests!.Value).Select(async _ =>
|
||||
{
|
||||
await semaphore.WaitAsync();
|
||||
try
|
||||
{
|
||||
var requestStopwatch = new Stopwatch();
|
||||
requestStopwatch.Start();
|
||||
|
||||
using (var request = requestTemplate.DeepCopy())
|
||||
{
|
||||
if (!string.Equals(input.RequestMethod, "GET", StringComparison.OrdinalIgnoreCase) && input.RequestParameters.Any())
|
||||
{
|
||||
var content = new FormUrlEncodedContent(input.RequestParameters);
|
||||
request.Content = content;
|
||||
}
|
||||
|
||||
using (var response = await _httpClient.SendAsync(request))
|
||||
{
|
||||
response.EnsureSuccessStatusCode(); // 抛出错误状态码异常
|
||||
|
||||
requestStopwatch.Stop();
|
||||
responseTimes.Add(requestStopwatch.Elapsed.TotalMilliseconds);
|
||||
Interlocked.Increment(ref successfulRequests);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Interlocked.Increment(ref failedRequests);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Interlocked.Increment(ref totalRequests);
|
||||
semaphore.Release();
|
||||
}
|
||||
});
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
stopwatch.Stop();
|
||||
|
||||
var totalTimeInSeconds = stopwatch.Elapsed.TotalSeconds;
|
||||
var qps = totalTimeInSeconds > 0 ? totalRequests / totalTimeInSeconds : 0;
|
||||
var orderResponseTimes = responseTimes.OrderBy(t => t).ToList();
|
||||
var averageResponseTime = responseTimes.Any() ? responseTimes.Average() : 0;
|
||||
var minResponseTime = responseTimes.Any() ? responseTimes.Min() : 0;
|
||||
var maxResponseTime = responseTimes.Any() ? responseTimes.Max() : 0;
|
||||
|
||||
return new StressTestOutput
|
||||
{
|
||||
TotalRequests = totalRequests,
|
||||
TotalTimeInSeconds = totalTimeInSeconds,
|
||||
SuccessfulRequests = successfulRequests,
|
||||
FailedRequests = failedRequests,
|
||||
QueriesPerSecond = qps,
|
||||
MinResponseTime = minResponseTime,
|
||||
MaxResponseTime = maxResponseTime,
|
||||
AverageResponseTime = averageResponseTime,
|
||||
Percentile10ResponseTime = CalculatePercentile(orderResponseTimes, 0.1),
|
||||
Percentile25ResponseTime = CalculatePercentile(orderResponseTimes, 0.25),
|
||||
Percentile50ResponseTime = CalculatePercentile(orderResponseTimes, 0.5),
|
||||
Percentile75ResponseTime = CalculatePercentile(orderResponseTimes, 0.75),
|
||||
Percentile90ResponseTime = CalculatePercentile(orderResponseTimes, 0.9),
|
||||
Percentile99ResponseTime = CalculatePercentile(orderResponseTimes, 0.99),
|
||||
Percentile999ResponseTime = CalculatePercentile(orderResponseTimes, 0.999)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建请求消息
|
||||
/// </summary>
|
||||
/// <param name="input">输入参数</param>
|
||||
/// <param name="fullUri">url</param>
|
||||
/// <returns></returns>
|
||||
private HttpRequestMessage CreateRequestMessage(StressTestInput input, Uri fullUri)
|
||||
{
|
||||
HttpRequestMessage request = input.RequestMethod switch
|
||||
{
|
||||
"GET" => new HttpRequestMessage(HttpMethod.Get, fullUri),
|
||||
"PUT" => new HttpRequestMessage(HttpMethod.Put, fullUri),
|
||||
"POST" => new HttpRequestMessage(HttpMethod.Post, fullUri),
|
||||
"DELETE" => new HttpRequestMessage(HttpMethod.Delete, fullUri),
|
||||
_ => throw Oops.Bah("请求方式异常")
|
||||
};
|
||||
|
||||
// 设置请求头
|
||||
foreach (var header in input.Headers)
|
||||
{
|
||||
request.Headers.Add(header.Key, header.Value);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算百分位请求耗时
|
||||
/// </summary>
|
||||
/// <param name="times">请求耗时列表</param>
|
||||
/// <param name="percentile">百分位</param>
|
||||
/// <returns></returns>
|
||||
private double CalculatePercentile(List<double> times, double percentile)
|
||||
{
|
||||
if (!times.Any()) return 0;
|
||||
var index = (int)Math.Ceiling(percentile * times.Count) - 1;
|
||||
return times[index < times.Count ? index : times.Count - 1];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||||
//
|
||||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||||
//
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
namespace Admin.NET.Core.Service;
|
||||
|
||||
/// <summary>
|
||||
/// 系统存储过程服务 🧩
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Order = 102)]
|
||||
public class SysProcService : IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
|
||||
public SysProcService(ISqlSugarClient db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出存储过程数据-指定列,没有指定的字段会被隐藏 🔖
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<IActionResult> PocExport2(ExportProcInput input)
|
||||
{
|
||||
var db = _db.AsTenant().GetConnectionScope(input.ConfigId);
|
||||
var dt = await db.Ado.UseStoredProcedure().GetDataTableAsync(input.ProcId, input.ProcParams);
|
||||
|
||||
var headers = new Dictionary<string, Tuple<string, int>>();
|
||||
var index = 1;
|
||||
foreach (var val in input.EHeader)
|
||||
{
|
||||
headers.Add(val.Key.ToUpper(), new Tuple<string, int>(val.Value, index));
|
||||
index++;
|
||||
}
|
||||
var excelExporter = new ExcelExporter();
|
||||
var da = await excelExporter.ExportAsByteArray(dt, new ProcExporterHeaderFilter(headers));
|
||||
return new FileContentResult(da, "application/octet-stream") { FileDownloadName = input.ProcId + ".xlsx" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据模板导出存储过程数据 🔖
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IActionResult> PocExport(ExportProcByTMPInput input)
|
||||
{
|
||||
var db = _db.AsTenant().GetConnectionScope(input.ConfigId);
|
||||
var dt = await db.Ado.UseStoredProcedure().GetDataTableAsync(input.ProcId, input.ProcParams);
|
||||
|
||||
var excelExporter = new ExcelExporter();
|
||||
string template = AppDomain.CurrentDomain.BaseDirectory + "/wwwroot/template/" + input.Template + ".xlsx";
|
||||
var bs = await excelExporter.ExportBytesByTemplate(dt, template);
|
||||
return new FileContentResult(bs, "application/octet-stream") { FileDownloadName = input.ProcId + ".xlsx" };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取存储过程返回表-Oracle、达梦参数顺序不能错 🔖
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<DataTable> ProcTable(BaseProcInput input)
|
||||
{
|
||||
var db = _db.AsTenant().GetConnectionScope(input.ConfigId);
|
||||
return await db.Ado.UseStoredProcedure().GetDataTableAsync(input.ProcId, input.ProcParams);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取存储过程返回数据集-Oracle、达梦参数顺序不能错
|
||||
/// Oracle 返回table、table1,其他返回table1、table2。适用于报表、复杂详细页面等 🔖
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<DataSet> CommonDataSet(BaseProcInput input)
|
||||
{
|
||||
var db = _db.AsTenant().GetConnectionScope(input.ConfigId);
|
||||
return await db.Ado.UseStoredProcedure().GetDataSetAllAsync(input.ProcId, input.ProcParams);
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 根据配置表获取对映存储过程
|
||||
///// </summary>
|
||||
///// <param name="input"></param>
|
||||
///// <returns></returns>
|
||||
//public async Task<DataTable> ProcEnitybyConfig(BaseProcInput input)
|
||||
//{
|
||||
// var key = "ProcConfig";
|
||||
// var ds = _sysCacheService.Get<Dictionary<string, string>>(key);
|
||||
// if (ds == null || ds.Count == 0 || !ds.ContainsKey(input.ProcId))
|
||||
// {
|
||||
// var datas = await _db.Queryable<ProcConfig>().ToListAsync();
|
||||
// ds = datas.ToDictionary(m => m.ProcId, m => m.ProcName);
|
||||
// _sysCacheService.Set(key, ds);
|
||||
// }
|
||||
// var procName = ds[input.ProcId];
|
||||
// return await _db.Ado.UseStoredProcedure().GetDataTableAsync(procName, input.ProcParams);
|
||||
//}
|
||||
}
|
||||
Reference in New Issue
Block a user