OrderReviewBizHandler.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Admin.NET.Plugin.ApprovalFlow;
  2. using Admin.NET.Plugin.ApprovalFlow.Service;
  3. namespace Admin.NET.Plugin.AiDOP.Order;
  4. /// <summary>
  5. /// 订单评审审批业务回调
  6. /// 注册 BizType = "ORDER_REVIEW"
  7. /// </summary>
  8. public class OrderReviewBizHandler : IFlowBizHandler, ITransient
  9. {
  10. public string BizType => "ORDER_REVIEW";
  11. private readonly SqlSugarRepository<SeOrder> _seOrderRep;
  12. public OrderReviewBizHandler(SqlSugarRepository<SeOrder> seOrderRep)
  13. {
  14. _seOrderRep = seOrderRep;
  15. }
  16. public async Task OnFlowStarted(long bizId, long instanceId)
  17. {
  18. try
  19. {
  20. await _seOrderRep.AsUpdateable()
  21. .SetColumns(o => o.FlowState == "审批中")
  22. .Where(o => o.Id == bizId)
  23. .ExecuteCommandAsync();
  24. }
  25. catch (Exception) { /* 表不存在时静默跳过 */ }
  26. }
  27. public async Task OnFlowCompleted(long bizId, FlowInstanceStatusEnum finalStatus)
  28. {
  29. var state = finalStatus switch
  30. {
  31. FlowInstanceStatusEnum.Approved => "已通过",
  32. FlowInstanceStatusEnum.Rejected => "已拒绝",
  33. FlowInstanceStatusEnum.Cancelled => "已撤销",
  34. _ => "已终止",
  35. };
  36. try
  37. {
  38. await _seOrderRep.AsUpdateable()
  39. .SetColumns(o => o.FlowState == state)
  40. .Where(o => o.Id == bizId)
  41. .ExecuteCommandAsync();
  42. }
  43. catch (Exception) { /* 表不存在时静默跳过 */ }
  44. }
  45. public Task OnNodeCompleted(long bizId, string nodeId, string nodeName)
  46. {
  47. return Task.CompletedTask;
  48. }
  49. public async Task<Dictionary<string, object>> GetBizData(long bizId)
  50. {
  51. try
  52. {
  53. var order = await _seOrderRep.GetByIdAsync(bizId);
  54. if (order == null) return new Dictionary<string, object>();
  55. return new Dictionary<string, object>
  56. {
  57. ["urgent"] = order.Urgent ?? 0,
  58. ["customLevel"] = order.CustomLevel ?? 0,
  59. ["orderType"] = order.OrderType ?? 0,
  60. };
  61. }
  62. catch (Exception) { return new Dictionary<string, object>(); }
  63. }
  64. }