MdpSourceIdentity.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. namespace Admin.NET.Plugin.AiDOP.DataPlatform;
  2. /// <summary>
  3. /// source_system 只表示真实来源系统。写入通道记在 written_by,不再把 AIDOP 同时当成来源和写入方。
  4. /// </summary>
  5. public static class MdpSourceIdentity
  6. {
  7. public const string DbSync = "DB_SYNC";
  8. public const string ApiInbound = "API_INBOUND";
  9. public const string PlatformForm = "PLATFORM_FORM";
  10. public const string Seed = "SEED";
  11. public const string LegacyUnverified = "LEGACY_UNVERIFIED";
  12. public const string Native = "AIDOP_NATIVE";
  13. /// <summary>贴源 source_system 取系统码;系统码为空时退回通道 source_code。</summary>
  14. public static string NeutralCode(string? systemCode, string sourceCode) =>
  15. string.IsNullOrWhiteSpace(systemCode) ? sourceCode : systemCode.Trim();
  16. /// <summary>
  17. /// 先按原始表名查登记表,再用贴源行自带的 source_system。两处都没有时留空,不写成 AIDOP。
  18. /// </summary>
  19. public static string Resolve(string tableExpr, string systemExpr) =>
  20. $"COALESCE((SELECT r.source_system FROM mdp_source_table_registry r WHERE r.source_table = {tableExpr} LIMIT 1), NULLIF({systemExpr},''), '')";
  21. /// <summary>QAD 驼峰表名 → 165;T8 拼音前缀 → T8。对不上的返回 null,调用方不得猜测。</summary>
  22. public static string? ClassifySourceTable(string? name)
  23. {
  24. if (string.IsNullOrWhiteSpace(name)) return null;
  25. var table = name.Trim();
  26. if (table.StartsWith("ic_", StringComparison.Ordinal)
  27. || table.StartsWith("kc_", StringComparison.Ordinal)
  28. || table.StartsWith("cj_", StringComparison.Ordinal)
  29. || table.StartsWith("sys_pe", StringComparison.Ordinal))
  30. return "T8";
  31. if (char.IsUpper(table[0]) && table.Skip(1).Any(char.IsUpper) && !table.Contains('_'))
  32. return "DOPDEMORQ_SQLSERVER";
  33. return null;
  34. }
  35. }