MdpSourceConfigService.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. && x.SourceType != "FILE_EXCEL");
  18. if (!string.IsNullOrWhiteSpace(keyword))
  19. {
  20. var kw = keyword.Trim();
  21. q = q.Where(x => x.SourceCode.Contains(kw) || x.SourceName.Contains(kw));
  22. }
  23. if (!string.IsNullOrWhiteSpace(type))
  24. q = q.Where(x => x.SourceType == type.Trim());
  25. var list = await q.OrderBy(x => x.SourceCode).ToListAsync();
  26. return new
  27. {
  28. list = list.Select(x => new
  29. {
  30. id = x.Id,
  31. sourceCode = x.SourceCode,
  32. sourceName = x.SourceName,
  33. sourceType = x.SourceType,
  34. direction = string.Equals(x.SourceType, "API", StringComparison.OrdinalIgnoreCase) ? "拉取"
  35. : string.Equals(x.SourceType, "FILE_EXCEL", StringComparison.OrdinalIgnoreCase) ? "文件入站" : "入站",
  36. dbType = x.DbType ?? "-",
  37. host = string.Equals(x.SourceType, "API", StringComparison.OrdinalIgnoreCase)
  38. ? (x.ApiBaseUrl ?? "-")
  39. : string.Equals(x.SourceType, "FILE_EXCEL", StringComparison.OrdinalIgnoreCase)
  40. ? "-"
  41. : $"{x.DbHost}/{x.DbName}",
  42. health = string.Equals(x.SourceType, "FILE_EXCEL", StringComparison.OrdinalIgnoreCase)
  43. ? (string.IsNullOrWhiteSpace(x.SourceCode) ? "配置异常" : "可用")
  44. : x.HealthStatus switch
  45. {
  46. 1 => "正常",
  47. 0 => "异常",
  48. _ => "未知"
  49. },
  50. healthType = x.HealthStatus switch
  51. {
  52. 1 => "success",
  53. 0 => "danger",
  54. _ => "info"
  55. },
  56. lastCheck = x.LastHealthCheck?.ToString("yyyy-MM-dd HH:mm:ss") ?? "-",
  57. healthMsg = x.HealthMsg
  58. })
  59. };
  60. }
  61. }