namespace Admin.NET.Plugin.AiDOP.Const.S8;
///
/// S8-NOTIFY-RECIPIENT-1:通知事件码。
///
/// 每一条都对应一个真实存在的派发点(见 TriggerHint)。
/// 刻意不造没有业务入口的事件 —— 配了却永远不触发的通知,比没有通知更难排查。
///
public static class S8NotifyEventCode
{
/// 规则命中建单 / 人工提报建单。
public const string ExceptionCreated = "EXCEPTION_CREATED";
/// 被认领。
public const string ExceptionClaimed = "EXCEPTION_CLAIMED";
/// 被转派。
public const string ExceptionTransferred = "EXCEPTION_TRANSFERRED";
/// 提交复核(等待审核)。
public const string VerificationSubmitted = "VERIFICATION_SUBMITTED";
/// 超时自动升级。
public const string EscalationTriggered = "ESCALATION_TRIGGERED";
/// 检测到恢复。
public const string ExceptionRecovered = "EXCEPTION_RECOVERED";
/// 超时关闭(闭环及时性回顾)。
public const string ExceptionOverdueClosed = "EXCEPTION_OVERDUE_CLOSED";
}
///
/// 收件人类型。第一版只有四类,全部能真实解析出 SysUserId。
///
/// Supervisor 刻意缺席:系统里不存在组织主管关系
/// (SysOrg.DirectorId 与 SysUser.ManagerUserId 实测填充率均为 0)。
/// 给一个永远解析为空的选项,等于让管理员配一条永远发不出去的通知。
///
public static class S8RecipientType
{
/// 该规则的处理账号池(复用 P1-C 的 Rule Handler Pool,不复制第二份人员配置)。
public const string HandlerPool = "HANDLER_POOL";
/// 当前处理人(assignee_user_id)。
public const string Assignee = "ASSIGNEE";
///
/// 当前实际审核人。
/// 不是新建的 Reviewer Pool —— 它解析的是当前事实:
/// 优先取单据上的 verifier_user_id(提交复核时手选、真正能点通过/退回的人);
/// 尚未提交复核时回落到审批流节点解析出的审批人。
///
public const string Reviewer = "REVIEWER";
/// 指定账号(多选 SysUser)。
public const string SpecificUser = "SPECIFIC_USER";
}
/// 事件元信息。
public sealed record S8NotifyEventDefinition(string Code, string DisplayName, string TriggerHint, int OrderNo);
///
/// 事件与收件人类型目录。后端派发、配置校验、前端 UI 三方共用同一份,
/// 避免出现「页面能配、后端根本不派发」或反之。
///
public static class S8NotificationCatalog
{
public static readonly IReadOnlyList Events = new List
{
new(S8NotifyEventCode.ExceptionCreated, "异常产生", "规则命中建单 / 人工提报", 10),
new(S8NotifyEventCode.ExceptionClaimed, "认领成功", "POST {id}/claim", 20),
new(S8NotifyEventCode.ExceptionTransferred, "转派", "POST {id}/transfer", 30),
new(S8NotifyEventCode.VerificationSubmitted, "提交复核", "POST {id}/submit-verification", 40),
new(S8NotifyEventCode.EscalationTriggered, "超时升级", "超时自动升级作业", 50),
new(S8NotifyEventCode.ExceptionRecovered, "异常恢复", "调度器检测到恢复", 60),
new(S8NotifyEventCode.ExceptionOverdueClosed, "超时关闭", "检验通过后闭环及时性回顾", 70),
};
public static readonly IReadOnlyList RecipientTypes = new[]
{
S8RecipientType.HandlerPool,
S8RecipientType.Assignee,
S8RecipientType.Reviewer,
S8RecipientType.SpecificUser,
};
///
/// 租户级默认配置的 rule_code 哨兵值。
/// 人工提报的异常没有来源规则,它的通知只能落在租户级默认上。
/// 用显式常量而不是 NULL:NULL 在唯一索引里的比较语义容易让人配出两条"默认"。
///
public const string TenantDefaultRuleCode = "*";
private static readonly HashSet EventSet =
Events.Select(e => e.Code).ToHashSet(StringComparer.OrdinalIgnoreCase);
private static readonly HashSet TypeSet =
RecipientTypes.ToHashSet(StringComparer.OrdinalIgnoreCase);
public static bool IsKnownEvent(string? code) => !string.IsNullOrWhiteSpace(code) && EventSet.Contains(code!);
public static bool IsKnownRecipientType(string? t) => !string.IsNullOrWhiteSpace(t) && TypeSet.Contains(t!);
}