MdpTenantStdSourceResolver.cs 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. namespace Admin.NET.Plugin.AiDOP.DataPlatform;
  2. public sealed class MdpTenantStdSource
  3. {
  4. public string SourceSystem { get; init; } = "";
  5. public string SourceScope { get; init; } = "";
  6. }
  7. /// <summary>未登记或来源不一致时返回 null。不回退任何默认来源。</summary>
  8. public sealed class MdpTenantStdSourceResolver : ITransient
  9. {
  10. private readonly ISqlSugarClient _db;
  11. public MdpTenantStdSourceResolver(ISqlSugarClient db) => _db = db;
  12. public async Task<MdpTenantStdSource?> GetSourceAsync(long tenantId, string stdObject, CancellationToken cancellationToken = default)
  13. {
  14. if (tenantId <= 0 || string.IsNullOrWhiteSpace(stdObject))
  15. return null;
  16. var rows = await _db.Ado.SqlQueryAsync<MdpTenantStdSource>(
  17. """
  18. SELECT source_system AS SourceSystem, IFNULL(source_scope,'') AS SourceScope
  19. FROM mdp_tenant_std_source
  20. WHERE tenant_id=@tenant AND std_object=@obj
  21. LIMIT 1
  22. """,
  23. new { tenant = tenantId, obj = stdObject.Trim() });
  24. cancellationToken.ThrowIfCancellationRequested();
  25. return rows.FirstOrDefault();
  26. }
  27. }