AdoS8RuleDetectionState.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. namespace Admin.NET.Plugin.AiDOP.Entity.S8;
  2. /// <summary>
  3. /// S8 规则检测抗抖累计状态(建单前阶段)。
  4. /// 用途:在"持续 N 次命中才建单 / 持续 N 次未命中才标 recovered"路径上,
  5. /// 承载每条 (rule_code, dedup_key) 在还未建单时的累计计数。
  6. /// 本表无软删字段;唯一记录由 (tenant_id, factory_id, rule_code, dedup_key) 决定。
  7. /// 已建单后的抗抖累计落在 ado_s8_exception.consecutive_hit_count / consecutive_miss_count。
  8. /// </summary>
  9. [SugarTable("ado_s8_rule_detection_state", "S8 规则检测抗抖状态")]
  10. [SugarIndex("uk_s8_rule_detection_state_dedup",
  11. nameof(TenantId), OrderByType.Asc,
  12. nameof(FactoryId), OrderByType.Asc,
  13. nameof(RuleCode), OrderByType.Asc,
  14. nameof(DedupKey), OrderByType.Asc,
  15. IsUnique = true)]
  16. [SugarIndex("idx_s8_rule_detection_state_rule",
  17. nameof(TenantId), OrderByType.Asc,
  18. nameof(FactoryId), OrderByType.Asc,
  19. nameof(RuleCode), OrderByType.Asc)]
  20. [SugarIndex("idx_s8_rule_detection_state_active_exception",
  21. nameof(ActiveExceptionId), OrderByType.Asc)]
  22. public class AdoS8RuleDetectionState
  23. {
  24. [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true, ColumnDataType = "bigint")]
  25. public long Id { get; set; }
  26. [SugarColumn(ColumnName = "tenant_id", ColumnDataType = "bigint")]
  27. public long TenantId { get; set; }
  28. [SugarColumn(ColumnName = "factory_id", ColumnDataType = "bigint")]
  29. public long FactoryId { get; set; }
  30. /// <summary>规则人读编码(关联 ado_s8_watch_rule.rule_code)。</summary>
  31. [SugarColumn(ColumnName = "rule_code", Length = 64)]
  32. public string RuleCode { get; set; } = string.Empty;
  33. /// <summary>命中去重键,与 ado_s8_exception.dedup_key 同模型。</summary>
  34. [SugarColumn(ColumnName = "dedup_key", Length = 128)]
  35. public string DedupKey { get; set; } = string.Empty;
  36. /// <summary>源对象类型(DEVICE / ORDER / MATERIAL / QUALITY_CHECK 等)。</summary>
  37. [SugarColumn(ColumnName = "source_object_type", Length = 64, IsNullable = true)]
  38. public string? SourceObjectType { get; set; }
  39. /// <summary>源对象主键或业务 ID(字符串以适配跨表/跨域)。</summary>
  40. [SugarColumn(ColumnName = "source_object_id", Length = 64, IsNullable = true)]
  41. public string? SourceObjectId { get; set; }
  42. /// <summary>建单前的连续命中次数;累计到 trigger_count_required 才建单。</summary>
  43. [SugarColumn(ColumnName = "consecutive_hit_count")]
  44. public int ConsecutiveHitCount { get; set; } = 0;
  45. /// <summary>建单前的连续未命中次数;用于尚未建单但抖动归零的场景。</summary>
  46. [SugarColumn(ColumnName = "consecutive_miss_count")]
  47. public int ConsecutiveMissCount { get; set; } = 0;
  48. /// <summary>当前活跃的异常 Id(建单后写入;建单前为 NULL)。</summary>
  49. [SugarColumn(ColumnName = "active_exception_id", ColumnDataType = "bigint", IsNullable = true)]
  50. public long? ActiveExceptionId { get; set; }
  51. /// <summary>最近一次评估时间(命中或未命中均刷新)。</summary>
  52. [SugarColumn(ColumnName = "last_seen_at", IsNullable = true)]
  53. public DateTime? LastSeenAt { get; set; }
  54. /// <summary>最近一次命中时间。</summary>
  55. [SugarColumn(ColumnName = "last_hit_at", IsNullable = true)]
  56. public DateTime? LastHitAt { get; set; }
  57. /// <summary>最近一次未命中时间。</summary>
  58. [SugarColumn(ColumnName = "last_miss_at", IsNullable = true)]
  59. public DateTime? LastMissAt { get; set; }
  60. [SugarColumn(ColumnName = "created_at")]
  61. public DateTime CreatedAt { get; set; } = DateTime.Now;
  62. [SugarColumn(ColumnName = "updated_at", IsNullable = true)]
  63. public DateTime? UpdatedAt { get; set; }
  64. }