S1MdpRunScope.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. namespace Admin.NET.Plugin.AiDOP.DataPlatform.S1Refresh;
  2. /// <summary>S1 全量重算不可为空的租户/工厂作用域。</summary>
  3. public sealed record S1MdpRunScope(long TenantId, long FactoryId)
  4. {
  5. public static S1MdpRunScope Create(long tenantId, long factoryId)
  6. {
  7. if (tenantId <= 0)
  8. throw new InvalidOperationException("S1 全量重算必须指定有效 tenantId,禁止 tenantId=0");
  9. if (factoryId <= 0)
  10. throw new InvalidOperationException("S1 全量重算必须指定有效 factoryId");
  11. if (factoryId == tenantId)
  12. throw new InvalidOperationException("S1 全量重算的 factoryId 不能等于 tenantId");
  13. return new S1MdpRunScope(tenantId, factoryId);
  14. }
  15. public string LockName => $"S1_MDP_FULL:{TenantId}:{FactoryId}";
  16. public string ScopeKey => $"{TenantId}:{FactoryId}";
  17. }
  18. public static class S1MdpRebuildStage
  19. {
  20. public const string Queued = "QUEUED";
  21. public const string AcquiringLock = "ACQUIRING_LOCK";
  22. public const string Preparing = "PREPARING";
  23. public const string Staging = "STAGING";
  24. public const string Standard = "STANDARD";
  25. public const string Dwd = "DWD";
  26. public const string Kpi = "KPI";
  27. public const string Atomic = "ATOMIC";
  28. public const string Finalizing = "FINALIZING";
  29. public const string Success = "SUCCESS";
  30. public const string Failed = "FAILED";
  31. public const string Cancelled = "CANCELLED";
  32. public const int StageTotal = 5;
  33. public static int ToStageIndex(string stage) => stage switch
  34. {
  35. Staging => 1,
  36. Standard => 2,
  37. Dwd => 3,
  38. Kpi => 4,
  39. Atomic or Finalizing or Success => 5,
  40. _ => 0
  41. };
  42. public static string ToChinese(string? stage) => stage switch
  43. {
  44. Queued => "排队中",
  45. AcquiringLock => "等待资源",
  46. Preparing => "准备运行环境",
  47. Staging => "拉取源数据",
  48. Standard => "标准化数据",
  49. Dwd => "生成 DWD 明细",
  50. Kpi => "重算 KPI",
  51. Atomic => "重建原子数据",
  52. Finalizing => "收尾",
  53. Success => "已完成",
  54. Failed => "失败",
  55. Cancelled => "已取消",
  56. _ => stage ?? ""
  57. };
  58. }
  59. public sealed record S1MdpProgressUpdate(
  60. string Stage,
  61. int StageIndex,
  62. int ProgressPercent,
  63. string Message,
  64. int? Rows = null,
  65. string? CompletedStage = null);
  66. public sealed class S1MdpScopeRow
  67. {
  68. public long TenantId { get; set; }
  69. public long FactoryId { get; set; }
  70. }