All checks were successful
Build and Deploy / deploy (push) Successful in 1m18s
一期落地定义、实例、任务、事件及模拟提交通路,业务接入后续再挂 Operation Adapter。 Co-authored-by: Cursor <cursoragent@cursor.com>
120 lines
3.5 KiB
C#
120 lines
3.5 KiB
C#
using System.Collections.Generic;
|
||
|
||
namespace Oms.Application.Services.Approval.Contracts;
|
||
|
||
/// <summary>
|
||
/// 审批提交请求(业务侧组装后交给 Gate)。
|
||
/// </summary>
|
||
public class ApprovalSubmitRequest
|
||
{
|
||
/// <summary>操作编码。</summary>
|
||
public string OperationCode { get; set; } = string.Empty;
|
||
|
||
/// <summary>业务幂等键(同操作下 Pending 中不可重复)。</summary>
|
||
public string BizKey { get; set; } = string.Empty;
|
||
|
||
/// <summary>摘要标题。</summary>
|
||
public string Title { get; set; } = string.Empty;
|
||
|
||
/// <summary>冻结业务载荷 JSON。</summary>
|
||
public string? PayloadJson { get; set; }
|
||
|
||
/// <summary>展示摘要对象(序列化进 SummaryJson)。</summary>
|
||
public object? Summary { get; set; }
|
||
|
||
/// <summary>条件求值上下文字典(中文标签 → 值);无条件时可空。</summary>
|
||
public IReadOnlyDictionary<string, object?>? ConditionContext { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// Gate 判定结果。
|
||
/// </summary>
|
||
public enum ApprovalGateDecision
|
||
{
|
||
/// <summary>无需审批,业务可立即执行。</summary>
|
||
Bypass = 0,
|
||
|
||
/// <summary>已创建待审批实例。</summary>
|
||
PendingApproval = 1
|
||
}
|
||
|
||
/// <summary>
|
||
/// Gate 返回。
|
||
/// </summary>
|
||
public class ApprovalGateResult
|
||
{
|
||
/// <summary>判定。</summary>
|
||
public ApprovalGateDecision Decision { get; set; }
|
||
|
||
/// <summary>实例 Id(PendingApproval 时有值)。</summary>
|
||
public int? InstanceId { get; set; }
|
||
|
||
/// <summary>实例单号。</summary>
|
||
public string? InstanceNo { get; set; }
|
||
|
||
/// <summary>说明。</summary>
|
||
public string? Message { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 审批门面:业务入口调用,判断 Bypass 或建单。
|
||
/// </summary>
|
||
public interface IApprovalGate
|
||
{
|
||
/// <summary>
|
||
/// 检查是否需审;需审则创建实例与任务,否则 Bypass。
|
||
/// </summary>
|
||
Task<ApprovalGateResult> CheckAndSubmitOrBypassAsync(
|
||
ApprovalSubmitRequest request,
|
||
CancellationToken cancellationToken = default);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 终审通过后的业务执行器(按 OperationCode 注册)。
|
||
/// </summary>
|
||
public interface IApprovalOperationHandler
|
||
{
|
||
/// <summary>支持的操作编码。</summary>
|
||
string OperationCode { get; }
|
||
|
||
/// <summary>
|
||
/// 执行业务。成功无异常;失败抛 BusinessException 或普通 Exception,引擎记 ExecuteFailed。
|
||
/// </summary>
|
||
Task ExecuteAsync(ApprovalExecutionContext context, CancellationToken cancellationToken = default);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 执行上下文。
|
||
/// </summary>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 条件上下文工厂(按操作提供公式字段;未注册则仅允许空条件)。
|
||
/// </summary>
|
||
public interface IApprovalConditionContextFactory
|
||
{
|
||
string OperationCode { get; }
|
||
|
||
/// <summary>将业务上下文字典转为公式求值用标签字典。</summary>
|
||
IReadOnlyDictionary<string, object?> Build(IReadOnlyDictionary<string, object?>? raw);
|
||
}
|