using System.Collections.Generic; namespace Oms.Application.Services.Approval.Contracts; /// /// 审批提交请求(业务侧组装后交给 Gate)。 /// public class ApprovalSubmitRequest { /// 操作编码。 public string OperationCode { get; set; } = string.Empty; /// 业务幂等键(同操作下 Pending 中不可重复)。 public string BizKey { get; set; } = string.Empty; /// 摘要标题。 public string Title { get; set; } = string.Empty; /// 冻结业务载荷 JSON。 public string? PayloadJson { get; set; } /// 展示摘要对象(序列化进 SummaryJson)。 public object? Summary { get; set; } /// 条件求值上下文字典(中文标签 → 值);无条件时可空。 public IReadOnlyDictionary? ConditionContext { get; set; } } /// /// Gate 判定结果。 /// public enum ApprovalGateDecision { /// 无需审批,业务可立即执行。 Bypass = 0, /// 已创建待审批实例。 PendingApproval = 1 } /// /// Gate 返回。 /// public class ApprovalGateResult { /// 判定。 public ApprovalGateDecision Decision { get; set; } /// 实例 Id(PendingApproval 时有值)。 public int? InstanceId { get; set; } /// 实例单号。 public string? InstanceNo { get; set; } /// 说明。 public string? Message { get; set; } } /// /// 审批门面:业务入口调用,判断 Bypass 或建单。 /// public interface IApprovalGate { /// /// 检查是否需审;需审则创建实例与任务,否则 Bypass。 /// Task CheckAndSubmitOrBypassAsync( ApprovalSubmitRequest request, CancellationToken cancellationToken = default); } /// /// 终审通过后的业务执行器(按 OperationCode 注册)。 /// public interface IApprovalOperationHandler { /// 支持的操作编码。 string OperationCode { get; } /// /// 执行业务。成功无异常;失败抛 BusinessException 或普通 Exception,引擎记 ExecuteFailed。 /// Task ExecuteAsync(ApprovalExecutionContext context, CancellationToken cancellationToken = default); } /// /// 执行上下文。 /// public class ApprovalExecutionContext { public int InstanceId { get; set; } public string InstanceNo { get; set; } = string.Empty; public string OperationCode { get; set; } = string.Empty; public string BizKey { get; set; } = string.Empty; public string? PayloadJson { get; set; } public int ApplicantUserId { get; set; } public string ApplicantUserGuid { get; set; } = string.Empty; public int ApproverUserId { get; set; } public string ApproverUserGuid { get; set; } = string.Empty; } /// /// 条件上下文工厂(按操作提供公式字段;未注册则仅允许空条件)。 /// public interface IApprovalConditionContextFactory { string OperationCode { get; } /// 将业务上下文字典转为公式求值用标签字典。 IReadOnlyDictionary Build(IReadOnlyDictionary? raw); }