| 12345678910111213141516171819202122232425262728293031323334353637 |
- namespace Admin.NET.Plugin.AiDOP.DataPlatform;
- public sealed class MdpTenantStdSource
- {
- public string SourceSystem { get; init; } = "";
- public string SourceScope { get; init; } = "";
- }
- /// <summary>未登记或来源不一致时返回 null。不回退任何默认来源。</summary>
- public sealed class MdpTenantStdSourceResolver : ITransient
- {
- private readonly ISqlSugarClient _db;
- public MdpTenantStdSourceResolver(ISqlSugarClient db) => _db = db;
- public Task<MdpTenantStdSource?> GetSourceAsync(long tenantId, string stdObject, CancellationToken cancellationToken = default)
- => ReadAsync(tenantId, stdObject, false, cancellationToken);
- internal Task<MdpTenantStdSource?> GetSourceForShareAsync(long tenantId, string stdObject)
- => ReadAsync(tenantId, stdObject, true, default);
- private async Task<MdpTenantStdSource?> ReadAsync(long tenantId, string stdObject, bool forShare, CancellationToken cancellationToken)
- {
- if (tenantId <= 0 || string.IsNullOrWhiteSpace(stdObject))
- return null;
- var rows = await _db.Ado.SqlQueryAsync<MdpTenantStdSource>(
- """
- SELECT source_system AS SourceSystem, IFNULL(source_scope,'') AS SourceScope
- FROM mdp_tenant_std_source
- WHERE tenant_id=@tenant AND std_object=@obj
- LIMIT 1
- """ + (forShare ? " FOR SHARE" : string.Empty),
- new { tenant = tenantId, obj = stdObject.Trim() });
- cancellationToken.ThrowIfCancellationRequested();
- return rows.FirstOrDefault();
- }
- }
|