| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using Admin.NET.Plugin.ApprovalFlow;
- using Admin.NET.Plugin.ApprovalFlow.Service;
- namespace Admin.NET.Plugin.AiDOP.Order;
- /// <summary>
- /// 订单评审审批业务回调
- /// 注册 BizType = "ORDER_REVIEW"
- /// </summary>
- public class OrderReviewBizHandler : IFlowBizHandler, ITransient
- {
- public string BizType => "ORDER_REVIEW";
- private readonly SqlSugarRepository<SeOrder> _seOrderRep;
- public OrderReviewBizHandler(SqlSugarRepository<SeOrder> 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, FlowInstanceStatusEnum finalStatus)
- {
- 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, string nodeId, string nodeName)
- {
- return Task.CompletedTask;
- }
- public async Task<Dictionary<string, object>> GetBizData(long bizId)
- {
- try
- {
- var order = await _seOrderRep.GetByIdAsync(bizId);
- if (order == null) return new Dictionary<string, object>();
- return new Dictionary<string, object>
- {
- ["urgent"] = order.Urgent ?? 0,
- ["customLevel"] = order.CustomLevel ?? 0,
- ["orderType"] = order.OrderType ?? 0,
- };
- }
- catch (Exception) { return new Dictionary<string, object>(); }
- }
- }
|