AdoS8WatchRule.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. /// <summary>S8 业务枚举 FOLLOW(关注)/ SERIOUS(严重)。</summary>
  27. [SugarColumn(ColumnName = "severity", Length = 32)]
  28. public string Severity { get; set; } = "FOLLOW";
  29. [SugarColumn(ColumnName = "poll_interval_seconds")]
  30. public int PollIntervalSeconds { get; set; } = 300;
  31. [SugarColumn(ColumnName = "enabled", ColumnDataType = "boolean")]
  32. public bool Enabled { get; set; }
  33. [SugarColumn(ColumnName = "created_at")]
  34. public DateTime CreatedAt { get; set; } = DateTime.Now;
  35. [SugarColumn(ColumnName = "updated_at", IsNullable = true)]
  36. public DateTime? UpdatedAt { get; set; }
  37. /// <summary>规则类型:TIMEOUT / SHORTAGE / OUT_OF_RANGE。R1 仅落列,evaluator 不分派。</summary>
  38. [SugarColumn(ColumnName = "rule_type", Length = 32, IsNullable = true)]
  39. public string? RuleType { get; set; }
  40. /// <summary>源对象类型(DEVICE / ORDER / MATERIAL / QUALITY_CHECK 等)。R1 与 watch_object_type 可保持一致。</summary>
  41. [SugarColumn(ColumnName = "source_object_type", Length = 64, IsNullable = true)]
  42. public string? SourceObjectType { get; set; }
  43. /// <summary>规则类型相关结构化参数 JSON。R1 仅预留,service 不解析。</summary>
  44. [SugarColumn(ColumnName = "params_json", ColumnDataType = "mediumtext", IsNullable = true)]
  45. public string? ParamsJson { get; set; }
  46. // ============================================================
  47. // S8-SCHED-SCHEMA-1:调度运行态字段(仅落列,本轮不接调度逻辑)
  48. // ============================================================
  49. /// <summary>下次到期执行时间。NULL 视为可立即执行。</summary>
  50. [SugarColumn(ColumnName = "next_run_at", IsNullable = true)]
  51. public DateTime? NextRunAt { get; set; }
  52. /// <summary>上次执行时间。</summary>
  53. [SugarColumn(ColumnName = "last_run_at", IsNullable = true)]
  54. public DateTime? LastRunAt { get; set; }
  55. /// <summary>上次执行状态:SUCCESS / FAILED / SKIPPED。</summary>
  56. [SugarColumn(ColumnName = "last_status", Length = 20, IsNullable = true)]
  57. public string? LastStatus { get; set; }
  58. /// <summary>上次执行错误摘要。</summary>
  59. [SugarColumn(ColumnName = "last_error", Length = 500, IsNullable = true)]
  60. public string? LastError { get; set; }
  61. /// <summary>上次执行耗时(毫秒)。</summary>
  62. [SugarColumn(ColumnName = "last_duration_ms", IsNullable = true)]
  63. public int? LastDurationMs { get; set; }
  64. /// <summary>上次执行 RunId(关联 detection_log)。</summary>
  65. [SugarColumn(ColumnName = "last_run_id", Length = 64, IsNullable = true)]
  66. public string? LastRunId { get; set; }
  67. /// <summary>调度抢占租约 token(多实例并发安全)。</summary>
  68. [SugarColumn(ColumnName = "lock_token", Length = 64, IsNullable = true)]
  69. public string? LockToken { get; set; }
  70. /// <summary>持有租约的实例标识。</summary>
  71. [SugarColumn(ColumnName = "locked_by", Length = 128, IsNullable = true)]
  72. public string? LockedBy { get; set; }
  73. /// <summary>租约失效时间;超过此时间视为可被其他实例抢占(僵尸自愈)。</summary>
  74. [SugarColumn(ColumnName = "lock_until", IsNullable = true)]
  75. public DateTime? LockUntil { get; set; }
  76. /// <summary>本次运行开始时间(与 LockUntil 配合用于僵尸判定)。</summary>
  77. [SugarColumn(ColumnName = "running_started_at", IsNullable = true)]
  78. public DateTime? RunningStartedAt { get; set; }
  79. /// <summary>连续失败计数;用于到达阈值后写 PausedUntil 自动暂停。</summary>
  80. [SugarColumn(ColumnName = "consecutive_failure_count")]
  81. public int ConsecutiveFailureCount { get; set; } = 0;
  82. /// <summary>暂停至何时;NULL 表示未暂停;远未来值表示手工暂停。</summary>
  83. [SugarColumn(ColumnName = "paused_until", IsNullable = true)]
  84. public DateTime? PausedUntil { get; set; }
  85. /// <summary>暂停原因(auto_failure / manual / ...)。</summary>
  86. [SugarColumn(ColumnName = "pause_reason", Length = 64, IsNullable = true)]
  87. public string? PauseReason { get; set; }
  88. /// <summary>持续命中 N 次才建单(抗抖触发);默认 1 = 立即建单。</summary>
  89. [SugarColumn(ColumnName = "trigger_count_required")]
  90. public int TriggerCountRequired { get; set; } = 1;
  91. /// <summary>持续未命中 N 次才标 recovered(抗抖恢复);默认 1 = 立即恢复。</summary>
  92. [SugarColumn(ColumnName = "recover_count_required")]
  93. public int RecoverCountRequired { get; set; } = 1;
  94. }