namespace Admin.NET.Plugin.AiDOP.DataPlatform; /// /// source_system 只表示真实来源系统。写入通道记在 written_by,不再把 AIDOP 同时当成来源和写入方。 /// 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"; /// /// 先按原始表名查登记表,再用贴源行自带的 source_system。两处都没有时留空,不写成 AIDOP。 /// public static string Resolve(string tableExpr, string systemExpr) => $"COALESCE((SELECT r.source_system FROM mdp_source_table_registry r WHERE r.source_table = {tableExpr} LIMIT 1), NULLIF({systemExpr},''), '')"; /// QAD 驼峰表名 → 165;T8 拼音前缀 → T8。对不上的返回 null,调用方不得猜测。 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; } }