namespace Admin.NET.Plugin.AiDOP.Entity.S8; [SugarTable("ado_s8_watch_rule", "S8 监视规则")] [SugarIndex("idx_s8_watch_rule_type", nameof(TenantId), OrderByType.Asc, nameof(FactoryId), OrderByType.Asc, nameof(RuleType), OrderByType.Asc)] [SugarIndex("idx_s8_watch_rule_source_object", nameof(TenantId), OrderByType.Asc, nameof(FactoryId), OrderByType.Asc, nameof(SourceObjectType), OrderByType.Asc)] [SugarIndex("idx_s8_watch_rule_dispatch", nameof(Enabled), OrderByType.Asc, nameof(PausedUntil), OrderByType.Asc, nameof(NextRunAt), OrderByType.Asc)] [SugarIndex("idx_s8_watch_rule_lock_until", nameof(LockUntil), OrderByType.Asc)] [SugarIndex("idx_s8_watch_rule_rule_code", nameof(RuleCode), OrderByType.Asc)] public class AdoS8WatchRule { [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true, ColumnDataType = "bigint")] public long Id { get; set; } [SugarColumn(ColumnName = "tenant_id", ColumnDataType = "bigint")] public long TenantId { get; set; } [SugarColumn(ColumnName = "factory_id", ColumnDataType = "bigint")] public long FactoryId { get; set; } [SugarColumn(ColumnName = "rule_code", Length = 64)] public string RuleCode { get; set; } = string.Empty; [SugarColumn(ColumnName = "scene_code", Length = 64)] public string SceneCode { get; set; } = string.Empty; [SugarColumn(ColumnName = "data_source_id", ColumnDataType = "bigint")] public long DataSourceId { get; set; } [SugarColumn(ColumnName = "watch_object_type", Length = 64)] public string WatchObjectType { get; set; } = string.Empty; [SugarColumn(ColumnName = "expression", Length = 2000, IsNullable = true)] public string? Expression { get; set; } /// S8 业务枚举 FOLLOW(关注)/ SERIOUS(严重)。 [SugarColumn(ColumnName = "severity", Length = 32)] public string Severity { get; set; } = "FOLLOW"; [SugarColumn(ColumnName = "poll_interval_seconds")] public int PollIntervalSeconds { get; set; } = 300; [SugarColumn(ColumnName = "enabled", ColumnDataType = "boolean")] public bool Enabled { get; set; } [SugarColumn(ColumnName = "created_at")] public DateTime CreatedAt { get; set; } = DateTime.Now; [SugarColumn(ColumnName = "updated_at", IsNullable = true)] public DateTime? UpdatedAt { get; set; } /// 规则类型:TIMEOUT / SHORTAGE / OUT_OF_RANGE。R1 仅落列,evaluator 不分派。 [SugarColumn(ColumnName = "rule_type", Length = 32, IsNullable = true)] public string? RuleType { get; set; } /// 源对象类型(DEVICE / ORDER / MATERIAL / QUALITY_CHECK 等)。R1 与 watch_object_type 可保持一致。 [SugarColumn(ColumnName = "source_object_type", Length = 64, IsNullable = true)] public string? SourceObjectType { get; set; } /// 规则类型相关结构化参数 JSON。R1 仅预留,service 不解析。 [SugarColumn(ColumnName = "params_json", ColumnDataType = "mediumtext", IsNullable = true)] public string? ParamsJson { get; set; } // ============================================================ // S8-SCHED-SCHEMA-1:调度运行态字段(仅落列,本轮不接调度逻辑) // ============================================================ /// 下次到期执行时间。NULL 视为可立即执行。 [SugarColumn(ColumnName = "next_run_at", IsNullable = true)] public DateTime? NextRunAt { get; set; } /// 上次执行时间。 [SugarColumn(ColumnName = "last_run_at", IsNullable = true)] public DateTime? LastRunAt { get; set; } /// 上次执行状态:SUCCESS / FAILED / SKIPPED。 [SugarColumn(ColumnName = "last_status", Length = 20, IsNullable = true)] public string? LastStatus { get; set; } /// 上次执行错误摘要。 [SugarColumn(ColumnName = "last_error", Length = 500, IsNullable = true)] public string? LastError { get; set; } /// 上次执行耗时(毫秒)。 [SugarColumn(ColumnName = "last_duration_ms", IsNullable = true)] public int? LastDurationMs { get; set; } /// 上次执行 RunId(关联 detection_log)。 [SugarColumn(ColumnName = "last_run_id", Length = 64, IsNullable = true)] public string? LastRunId { get; set; } /// 调度抢占租约 token(多实例并发安全)。 [SugarColumn(ColumnName = "lock_token", Length = 64, IsNullable = true)] public string? LockToken { get; set; } /// 持有租约的实例标识。 [SugarColumn(ColumnName = "locked_by", Length = 128, IsNullable = true)] public string? LockedBy { get; set; } /// 租约失效时间;超过此时间视为可被其他实例抢占(僵尸自愈)。 [SugarColumn(ColumnName = "lock_until", IsNullable = true)] public DateTime? LockUntil { get; set; } /// 本次运行开始时间(与 LockUntil 配合用于僵尸判定)。 [SugarColumn(ColumnName = "running_started_at", IsNullable = true)] public DateTime? RunningStartedAt { get; set; } /// 连续失败计数;用于到达阈值后写 PausedUntil 自动暂停。 [SugarColumn(ColumnName = "consecutive_failure_count")] public int ConsecutiveFailureCount { get; set; } = 0; /// 暂停至何时;NULL 表示未暂停;远未来值表示手工暂停。 [SugarColumn(ColumnName = "paused_until", IsNullable = true)] public DateTime? PausedUntil { get; set; } /// 暂停原因(auto_failure / manual / ...)。 [SugarColumn(ColumnName = "pause_reason", Length = 64, IsNullable = true)] public string? PauseReason { get; set; } /// 持续命中 N 次才建单(抗抖触发);默认 1 = 立即建单。 [SugarColumn(ColumnName = "trigger_count_required")] public int TriggerCountRequired { get; set; } = 1; /// 持续未命中 N 次才标 recovered(抗抖恢复);默认 1 = 立即恢复。 [SugarColumn(ColumnName = "recover_count_required")] public int RecoverCountRequired { get; set; } = 1; }