AdoS8WatchRule.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. namespace Admin.NET.Plugin.AiDOP.Entity.S8;
  2. [SugarTable("ado_s8_watch_rule", "S8 监视规则")]
  3. [SugarIndex("idx_s8_watch_rule_type", nameof(TenantId), OrderByType.Asc, nameof(FactoryId), OrderByType.Asc, nameof(RuleType), OrderByType.Asc)]
  4. [SugarIndex("idx_s8_watch_rule_source_object", nameof(TenantId), OrderByType.Asc, nameof(FactoryId), OrderByType.Asc, nameof(SourceObjectType), OrderByType.Asc)]
  5. [SugarIndex("idx_s8_watch_rule_dispatch", nameof(Enabled), OrderByType.Asc, nameof(PausedUntil), OrderByType.Asc, nameof(NextRunAt), OrderByType.Asc)]
  6. [SugarIndex("idx_s8_watch_rule_lock_until", nameof(LockUntil), OrderByType.Asc)]
  7. [SugarIndex("idx_s8_watch_rule_rule_code", nameof(RuleCode), OrderByType.Asc)]
  8. public class AdoS8WatchRule
  9. {
  10. [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true, ColumnDataType = "bigint")]
  11. public long Id { get; set; }
  12. [SugarColumn(ColumnName = "tenant_id", ColumnDataType = "bigint")]
  13. public long TenantId { get; set; }
  14. [SugarColumn(ColumnName = "factory_id", ColumnDataType = "bigint")]
  15. public long FactoryId { get; set; }
  16. [SugarColumn(ColumnName = "rule_code", Length = 64)]
  17. public string RuleCode { get; set; } = string.Empty;
  18. [SugarColumn(ColumnName = "scene_code", Length = 64)]
  19. public string SceneCode { get; set; } = string.Empty;
  20. [SugarColumn(ColumnName = "data_source_id", ColumnDataType = "bigint")]
  21. public long DataSourceId { get; set; }
  22. [SugarColumn(ColumnName = "watch_object_type", Length = 64)]
  23. public string WatchObjectType { get; set; } = string.Empty;
  24. [SugarColumn(ColumnName = "expression", Length = 2000, IsNullable = true)]
  25. public string? Expression { get; set; }
  26. [SugarColumn(ColumnName = "severity", Length = 32)]
  27. public string Severity { get; set; } = "MEDIUM";
  28. [SugarColumn(ColumnName = "poll_interval_seconds")]
  29. public int PollIntervalSeconds { get; set; } = 300;
  30. [SugarColumn(ColumnName = "enabled", ColumnDataType = "boolean")]
  31. public bool Enabled { get; set; }
  32. [SugarColumn(ColumnName = "created_at")]
  33. public DateTime CreatedAt { get; set; } = DateTime.Now;
  34. [SugarColumn(ColumnName = "updated_at", IsNullable = true)]
  35. public DateTime? UpdatedAt { get; set; }
  36. /// <summary>规则类型:TIMEOUT / SHORTAGE / OUT_OF_RANGE。R1 仅落列,evaluator 不分派。</summary>
  37. [SugarColumn(ColumnName = "rule_type", Length = 32, IsNullable = true)]
  38. public string? RuleType { get; set; }
  39. /// <summary>源对象类型(DEVICE / ORDER / MATERIAL / QUALITY_CHECK 等)。R1 与 watch_object_type 可保持一致。</summary>
  40. [SugarColumn(ColumnName = "source_object_type", Length = 64, IsNullable = true)]
  41. public string? SourceObjectType { get; set; }
  42. /// <summary>规则类型相关结构化参数 JSON。R1 仅预留,service 不解析。</summary>
  43. [SugarColumn(ColumnName = "params_json", ColumnDataType = "mediumtext", IsNullable = true)]
  44. public string? ParamsJson { get; set; }
  45. // ============================================================
  46. // S8-SCHED-SCHEMA-1:调度运行态字段(仅落列,本轮不接调度逻辑)
  47. // ============================================================
  48. /// <summary>下次到期执行时间。NULL 视为可立即执行。</summary>
  49. [SugarColumn(ColumnName = "next_run_at", IsNullable = true)]
  50. public DateTime? NextRunAt { get; set; }
  51. /// <summary>上次执行时间。</summary>
  52. [SugarColumn(ColumnName = "last_run_at", IsNullable = true)]
  53. public DateTime? LastRunAt { get; set; }
  54. /// <summary>上次执行状态:SUCCESS / FAILED / SKIPPED。</summary>
  55. [SugarColumn(ColumnName = "last_status", Length = 20, IsNullable = true)]
  56. public string? LastStatus { get; set; }
  57. /// <summary>上次执行错误摘要。</summary>
  58. [SugarColumn(ColumnName = "last_error", Length = 500, IsNullable = true)]
  59. public string? LastError { get; set; }
  60. /// <summary>上次执行耗时(毫秒)。</summary>
  61. [SugarColumn(ColumnName = "last_duration_ms", IsNullable = true)]
  62. public int? LastDurationMs { get; set; }
  63. /// <summary>上次执行 RunId(关联 detection_log)。</summary>
  64. [SugarColumn(ColumnName = "last_run_id", Length = 64, IsNullable = true)]
  65. public string? LastRunId { get; set; }
  66. /// <summary>调度抢占租约 token(多实例并发安全)。</summary>
  67. [SugarColumn(ColumnName = "lock_token", Length = 64, IsNullable = true)]
  68. public string? LockToken { get; set; }
  69. /// <summary>持有租约的实例标识。</summary>
  70. [SugarColumn(ColumnName = "locked_by", Length = 128, IsNullable = true)]
  71. public string? LockedBy { get; set; }
  72. /// <summary>租约失效时间;超过此时间视为可被其他实例抢占(僵尸自愈)。</summary>
  73. [SugarColumn(ColumnName = "lock_until", IsNullable = true)]
  74. public DateTime? LockUntil { get; set; }
  75. /// <summary>本次运行开始时间(与 LockUntil 配合用于僵尸判定)。</summary>
  76. [SugarColumn(ColumnName = "running_started_at", IsNullable = true)]
  77. public DateTime? RunningStartedAt { get; set; }
  78. /// <summary>连续失败计数;用于到达阈值后写 PausedUntil 自动暂停。</summary>
  79. [SugarColumn(ColumnName = "consecutive_failure_count")]
  80. public int ConsecutiveFailureCount { get; set; } = 0;
  81. /// <summary>暂停至何时;NULL 表示未暂停;远未来值表示手工暂停。</summary>
  82. [SugarColumn(ColumnName = "paused_until", IsNullable = true)]
  83. public DateTime? PausedUntil { get; set; }
  84. /// <summary>暂停原因(auto_failure / manual / ...)。</summary>
  85. [SugarColumn(ColumnName = "pause_reason", Length = 64, IsNullable = true)]
  86. public string? PauseReason { get; set; }
  87. /// <summary>持续命中 N 次才建单(抗抖触发);默认 1 = 立即建单。</summary>
  88. [SugarColumn(ColumnName = "trigger_count_required")]
  89. public int TriggerCountRequired { get; set; } = 1;
  90. /// <summary>持续未命中 N 次才标 recovered(抗抖恢复);默认 1 = 立即恢复。</summary>
  91. [SugarColumn(ColumnName = "recover_count_required")]
  92. public int RecoverCountRequired { get; set; } = 1;
  93. }