MdpSourceConfigService.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Admin.NET.Plugin.AiDOP.Entity.DataPlatform;
  2. namespace Admin.NET.Plugin.AiDOP.DataPlatform;
  3. /// <summary>数据源配置只读 API(供配置中心 sources 页)。</summary>
  4. [ApiDescriptionSettings(Order = 324, Description = "数据中台数据源")]
  5. [Route("api/DataPlatform")]
  6. [AllowAnonymous]
  7. [NonUnify]
  8. public class MdpSourceConfigService : IDynamicApiController, ITransient
  9. {
  10. private readonly ISqlSugarClient _db;
  11. public MdpSourceConfigService(ISqlSugarClient db) => _db = db;
  12. [DisplayName("数据源列表")]
  13. [HttpGet("sources")]
  14. public async Task<object> GetList([FromQuery] string? keyword, [FromQuery] string? type)
  15. {
  16. var q = _db.Queryable<MdpSource>().Where(x => x.Status == 1);
  17. if (!string.IsNullOrWhiteSpace(keyword))
  18. {
  19. var kw = keyword.Trim();
  20. q = q.Where(x => x.SourceCode.Contains(kw) || x.SourceName.Contains(kw));
  21. }
  22. if (!string.IsNullOrWhiteSpace(type))
  23. q = q.Where(x => x.SourceType == type.Trim());
  24. var list = await q.OrderBy(x => x.SourceCode).ToListAsync();
  25. return new
  26. {
  27. list = list.Select(x => new
  28. {
  29. id = x.Id,
  30. sourceCode = x.SourceCode,
  31. sourceName = x.SourceName,
  32. sourceType = x.SourceType,
  33. direction = string.Equals(x.SourceType, "API", StringComparison.OrdinalIgnoreCase) ? "拉取" : "入站",
  34. dbType = x.DbType ?? "-",
  35. host = string.Equals(x.SourceType, "API", StringComparison.OrdinalIgnoreCase)
  36. ? (x.ApiBaseUrl ?? "-")
  37. : $"{x.DbHost}/{x.DbName}",
  38. health = x.HealthStatus switch
  39. {
  40. 1 => "正常",
  41. 0 => "异常",
  42. _ => "未知"
  43. },
  44. healthType = x.HealthStatus switch
  45. {
  46. 1 => "success",
  47. 0 => "danger",
  48. _ => "info"
  49. },
  50. lastCheck = x.LastHealthCheck?.ToString("yyyy-MM-dd HH:mm:ss") ?? "-",
  51. healthMsg = x.HealthMsg
  52. })
  53. };
  54. }
  55. }