using Admin.NET.Plugin.ApprovalFlow;
using Admin.NET.Plugin.ApprovalFlow.Service;
namespace Admin.NET.Plugin.AiDOP.Order;
///
/// 订单评审审批业务回调
/// 注册 BizType = "ORDER_REVIEW"
///
public class OrderReviewBizHandler : IFlowBizHandler, ITransient
{
public string BizType => "ORDER_REVIEW";
private readonly SqlSugarRepository _seOrderRep;
public OrderReviewBizHandler(SqlSugarRepository seOrderRep)
{
_seOrderRep = seOrderRep;
}
public async Task OnFlowStarted(long bizId, long instanceId)
{
try
{
await _seOrderRep.AsUpdateable()
.SetColumns(o => o.FlowState == "审批中")
.Where(o => o.Id == bizId)
.ExecuteCommandAsync();
}
catch (Exception) { /* 表不存在时静默跳过 */ }
}
public async Task OnFlowCompleted(long bizId, long instanceId, FlowInstanceStatusEnum finalStatus, long? lastApproverId)
{
var state = finalStatus switch
{
FlowInstanceStatusEnum.Approved => "已通过",
FlowInstanceStatusEnum.Rejected => "已拒绝",
FlowInstanceStatusEnum.Cancelled => "已撤销",
_ => "已终止",
};
try
{
await _seOrderRep.AsUpdateable()
.SetColumns(o => o.FlowState == state)
.Where(o => o.Id == bizId)
.ExecuteCommandAsync();
}
catch (Exception) { /* 表不存在时静默跳过 */ }
}
public Task OnNodeCompleted(long bizId, long instanceId, string nodeId, string nodeName, long? approverUserId)
{
return Task.CompletedTask;
}
public async Task> GetBizData(long bizId)
{
try
{
var order = await _seOrderRep.GetByIdAsync(bizId);
if (order == null) return new Dictionary();
return new Dictionary
{
["urgent"] = order.Urgent ?? 0,
["customLevel"] = order.CustomLevel ?? 0,
["orderType"] = order.OrderType ?? 0,
};
}
catch (Exception) { return new Dictionary(); }
}
}