| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- namespace Admin.NET.Plugin.AiDOP.DataPlatform;
- /// <summary>
- /// source_system 只表示真实来源系统。写入通道记在 written_by,不再把 AIDOP 同时当成来源和写入方。
- /// </summary>
- public static class MdpSourceIdentity
- {
- public const string DbSync = "DB_SYNC";
- public const string ApiInbound = "API_INBOUND";
- public const string PlatformForm = "PLATFORM_FORM";
- public const string Seed = "SEED";
- public const string LegacyUnverified = "LEGACY_UNVERIFIED";
- public const string Native = "AIDOP_NATIVE";
- /// <summary>贴源 source_system 取系统码;系统码为空时退回通道 source_code。</summary>
- public static string NeutralCode(string? systemCode, string sourceCode) =>
- string.IsNullOrWhiteSpace(systemCode) ? sourceCode : systemCode.Trim();
- /// <summary>
- /// 优先使用贴源行自带的 source_system;旧数据为空时才按原始表名查全局登记表。
- /// 全局登记表无法表达同一逻辑表在不同租户下的不同第三方来源,不能覆盖行级来源。
- /// </summary>
- public static string Resolve(string tableExpr, string systemExpr) =>
- $"COALESCE(NULLIF({systemExpr},''), (SELECT r.source_system FROM mdp_source_table_registry r WHERE r.source_table = {tableExpr} LIMIT 1), '')";
- /// <summary>QAD 驼峰表名 → 165;T8 拼音前缀 → T8。对不上的返回 null,调用方不得猜测。</summary>
- public static string? ClassifySourceTable(string? name)
- {
- if (string.IsNullOrWhiteSpace(name)) return null;
- var table = name.Trim();
- if (table.StartsWith("ic_", StringComparison.Ordinal)
- || table.StartsWith("kc_", StringComparison.Ordinal)
- || table.StartsWith("cj_", StringComparison.Ordinal)
- || table.StartsWith("sys_pe", StringComparison.Ordinal))
- return "T8";
- if (char.IsUpper(table[0]) && table.Skip(1).Any(char.IsUpper) && !table.Contains('_'))
- return "DOPDEMORQ_SQLSERVER";
- return null;
- }
- }
|