IS8RuleEvaluator.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Admin.NET.Plugin.AiDOP.Entity.S8;
  2. namespace Admin.NET.Plugin.AiDOP.Service.S8.Rules;
  3. /// <summary>
  4. /// R2 规则 evaluator 抽象。每个 rule_type 对应一个实现,由 S8WatchSchedulerService 按 rule_type 分派。
  5. /// 首版仅 TIMEOUT;OUT_OF_RANGE 走 S8WatchSchedulerService 内既有兼容分支,不接入此抽象。
  6. /// 不做事件触发、不做 SLA 升级、不做严重度阶梯。
  7. /// </summary>
  8. public interface IS8RuleEvaluator
  9. {
  10. /// <summary>支持的 rule_type 字符串(TIMEOUT / SHORTAGE / OUT_OF_RANGE)。</summary>
  11. string RuleType { get; }
  12. /// <summary>评估一条 WatchRule,产出 0..N 条命中。不做去重、不建单。</summary>
  13. Task<List<S8RuleHit>> EvaluateAsync(
  14. long tenantId,
  15. long factoryId,
  16. AdoS8WatchRule rule,
  17. IReadOnlyList<AdoS8AlertRule> alertRules,
  18. CancellationToken cancellationToken = default);
  19. }
  20. /// <summary>
  21. /// 内部命中模型。供 R2 evaluator 与 S8WatchSchedulerService 的 dedup/建单消费。
  22. /// 字段全部 nullable 以兼容 TIMEOUT / SHORTAGE / OUT_OF_RANGE 三类。R2 仅 TIMEOUT 路径写入。
  23. /// </summary>
  24. public sealed class S8RuleHit
  25. {
  26. public long SourceRuleId { get; set; }
  27. public string SourceRuleCode { get; set; } = string.Empty;
  28. public string SourceObjectType { get; set; } = string.Empty;
  29. public string SourceObjectId { get; set; } = string.Empty;
  30. public string RelatedObjectCode { get; set; } = string.Empty;
  31. public string ExceptionTypeCode { get; set; } = string.Empty;
  32. public string SceneCode { get; set; } = string.Empty;
  33. public string Severity { get; set; } = "FOLLOW";
  34. public string DedupKey { get; set; } = string.Empty;
  35. public string SourcePayload { get; set; } = "{}";
  36. public DateTime DetectedAt { get; set; } = DateTime.Now;
  37. public string Title { get; set; } = string.Empty;
  38. public long DataSourceId { get; set; }
  39. public long? OccurrenceDeptId { get; set; }
  40. public long? ResponsibleDeptId { get; set; }
  41. /// <summary>
  42. /// 命中归属模块码(S1-S7)。evaluator 可显式提供以覆盖 scene 默认派生;
  43. /// 留 null 时建单方按严格 S1-S7 派生:hit.SceneCode(仅 S1-S7)→ exception_type.scene_code。
  44. /// 不接受 legacy 复合 scene(S8-EXCEPTION-CREATION-MODULE-CODE-FIX-1)。
  45. /// </summary>
  46. public string? ModuleCode { get; set; }
  47. }