namespace Admin.NET.Plugin.AiDOP.Entity.S8; /// /// S8 规则检测抗抖累计状态(建单前阶段)。 /// 用途:在"持续 N 次命中才建单 / 持续 N 次未命中才标 recovered"路径上, /// 承载每条 (rule_code, dedup_key) 在还未建单时的累计计数。 /// 本表无软删字段;唯一记录由 (tenant_id, factory_id, rule_code, dedup_key) 决定。 /// 已建单后的抗抖累计落在 ado_s8_exception.consecutive_hit_count / consecutive_miss_count。 /// [SugarTable("ado_s8_rule_detection_state", "S8 规则检测抗抖状态")] [SugarIndex("uk_s8_rule_detection_state_dedup", nameof(TenantId), OrderByType.Asc, nameof(FactoryId), OrderByType.Asc, nameof(RuleCode), OrderByType.Asc, nameof(DedupKey), OrderByType.Asc, IsUnique = true)] [SugarIndex("idx_s8_rule_detection_state_rule", nameof(TenantId), OrderByType.Asc, nameof(FactoryId), OrderByType.Asc, nameof(RuleCode), OrderByType.Asc)] [SugarIndex("idx_s8_rule_detection_state_active_exception", nameof(ActiveExceptionId), OrderByType.Asc)] public class AdoS8RuleDetectionState { [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; } /// 规则人读编码(关联 ado_s8_watch_rule.rule_code)。 [SugarColumn(ColumnName = "rule_code", Length = 64)] public string RuleCode { get; set; } = string.Empty; /// 命中去重键,与 ado_s8_exception.dedup_key 同模型。 [SugarColumn(ColumnName = "dedup_key", Length = 128)] public string DedupKey { get; set; } = string.Empty; /// 源对象类型(DEVICE / ORDER / MATERIAL / QUALITY_CHECK 等)。 [SugarColumn(ColumnName = "source_object_type", Length = 64, IsNullable = true)] public string? SourceObjectType { get; set; } /// 源对象主键或业务 ID(字符串以适配跨表/跨域)。 [SugarColumn(ColumnName = "source_object_id", Length = 64, IsNullable = true)] public string? SourceObjectId { get; set; } /// 建单前的连续命中次数;累计到 trigger_count_required 才建单。 [SugarColumn(ColumnName = "consecutive_hit_count")] public int ConsecutiveHitCount { get; set; } = 0; /// 建单前的连续未命中次数;用于尚未建单但抖动归零的场景。 [SugarColumn(ColumnName = "consecutive_miss_count")] public int ConsecutiveMissCount { get; set; } = 0; /// 当前活跃的异常 Id(建单后写入;建单前为 NULL)。 [SugarColumn(ColumnName = "active_exception_id", ColumnDataType = "bigint", IsNullable = true)] public long? ActiveExceptionId { get; set; } /// 最近一次评估时间(命中或未命中均刷新)。 [SugarColumn(ColumnName = "last_seen_at", IsNullable = true)] public DateTime? LastSeenAt { get; set; } /// 最近一次命中时间。 [SugarColumn(ColumnName = "last_hit_at", IsNullable = true)] public DateTime? LastHitAt { get; set; } /// 最近一次未命中时间。 [SugarColumn(ColumnName = "last_miss_at", IsNullable = true)] public DateTime? LastMissAt { get; set; } [SugarColumn(ColumnName = "created_at")] public DateTime CreatedAt { get; set; } = DateTime.Now; [SugarColumn(ColumnName = "updated_at", IsNullable = true)] public DateTime? UpdatedAt { get; set; } }