| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using Admin.NET.Plugin.AiDOP.Entity.DataPlatform;
- namespace Admin.NET.Plugin.AiDOP.DataPlatform;
- /// <summary>数据源配置只读 API(供配置中心 sources 页)。</summary>
- [ApiDescriptionSettings(Order = 324, Description = "数据中台数据源")]
- [Route("api/DataPlatform")]
- [AllowAnonymous]
- [NonUnify]
- public class MdpSourceConfigService : IDynamicApiController, ITransient
- {
- private readonly ISqlSugarClient _db;
- public MdpSourceConfigService(ISqlSugarClient db) => _db = db;
- [DisplayName("数据源列表")]
- [HttpGet("sources")]
- public async Task<object> GetList([FromQuery] string? keyword, [FromQuery] string? type)
- {
- var q = _db.Queryable<MdpSource>().Where(x => x.Status == 1);
- if (!string.IsNullOrWhiteSpace(keyword))
- {
- var kw = keyword.Trim();
- q = q.Where(x => x.SourceCode.Contains(kw) || x.SourceName.Contains(kw));
- }
- if (!string.IsNullOrWhiteSpace(type))
- q = q.Where(x => x.SourceType == type.Trim());
- var list = await q.OrderBy(x => x.SourceCode).ToListAsync();
- return new
- {
- list = list.Select(x => new
- {
- id = x.Id,
- sourceCode = x.SourceCode,
- sourceName = x.SourceName,
- sourceType = x.SourceType,
- direction = string.Equals(x.SourceType, "API", StringComparison.OrdinalIgnoreCase) ? "拉取" : "入站",
- dbType = x.DbType ?? "-",
- host = string.Equals(x.SourceType, "API", StringComparison.OrdinalIgnoreCase)
- ? (x.ApiBaseUrl ?? "-")
- : $"{x.DbHost}/{x.DbName}",
- health = x.HealthStatus switch
- {
- 1 => "正常",
- 0 => "异常",
- _ => "未知"
- },
- healthType = x.HealthStatus switch
- {
- 1 => "success",
- 0 => "danger",
- _ => "info"
- },
- lastCheck = x.LastHealthCheck?.ToString("yyyy-MM-dd HH:mm:ss") ?? "-",
- healthMsg = x.HealthMsg
- })
- };
- }
- }
|