MdpSourceIdentity.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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;旧数据为空时才按原始表名查全局登记表。
  18. /// 全局登记表无法表达同一逻辑表在不同租户下的不同第三方来源,不能覆盖行级来源。
  19. /// </summary>
  20. public static string Resolve(string tableExpr, string systemExpr) =>
  21. $"COALESCE(NULLIF({systemExpr},''), (SELECT r.source_system FROM mdp_source_table_registry r WHERE r.source_table = {tableExpr} LIMIT 1), '')";
  22. /// <summary>QAD 驼峰表名 → 165;T8 拼音前缀 → T8。对不上的返回 null,调用方不得猜测。</summary>
  23. public static string? ClassifySourceTable(string? name)
  24. {
  25. if (string.IsNullOrWhiteSpace(name)) return null;
  26. var table = name.Trim();
  27. if (table.StartsWith("ic_", StringComparison.Ordinal)
  28. || table.StartsWith("kc_", StringComparison.Ordinal)
  29. || table.StartsWith("cj_", StringComparison.Ordinal)
  30. || table.StartsWith("sys_pe", StringComparison.Ordinal))
  31. return "T8";
  32. if (char.IsUpper(table[0]) && table.Skip(1).Any(char.IsUpper) && !table.Contains('_'))
  33. return "DOPDEMORQ_SQLSERVER";
  34. return null;
  35. }
  36. }