ExceptionClosureBizHandler.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Admin.NET.Plugin.ApprovalFlow;
  2. using Admin.NET.Plugin.ApprovalFlow.Service;
  3. using Admin.NET.Plugin.AiDOP.Entity.S8;
  4. namespace Admin.NET.Plugin.AiDOP.Service.S8;
  5. /// <summary>
  6. /// 异常关闭确认审批业务回调
  7. /// BizType = "EXCEPTION_CLOSURE"
  8. /// </summary>
  9. public class ExceptionClosureBizHandler : IFlowBizHandler, ITransient
  10. {
  11. public string BizType => "EXCEPTION_CLOSURE";
  12. private readonly SqlSugarRepository<AdoS8Exception> _rep;
  13. private readonly SqlSugarRepository<AdoS8ExceptionTimeline> _timelineRep;
  14. public ExceptionClosureBizHandler(
  15. SqlSugarRepository<AdoS8Exception> rep,
  16. SqlSugarRepository<AdoS8ExceptionTimeline> timelineRep)
  17. {
  18. _rep = rep;
  19. _timelineRep = timelineRep;
  20. }
  21. public async Task OnFlowStarted(long bizId, long instanceId)
  22. {
  23. var e = await _rep.GetByIdAsync(bizId) ?? throw new S8BizException("异常不存在");
  24. e.ActiveFlowInstanceId = instanceId;
  25. e.UpdatedAt = DateTime.Now;
  26. await _rep.UpdateAsync(e);
  27. await InsertTimelineAsync(e.Id, "CLOSURE_START", "发起关闭确认", null, null, instanceId);
  28. }
  29. public async Task OnFlowCompleted(long bizId, FlowInstanceStatusEnum finalStatus)
  30. {
  31. var e = await _rep.GetByIdAsync(bizId) ?? throw new S8BizException("异常不存在");
  32. e.ActiveFlowInstanceId = null;
  33. e.UpdatedAt = DateTime.Now;
  34. if (finalStatus == FlowInstanceStatusEnum.Approved)
  35. {
  36. e.Status = "CLOSED";
  37. e.ClosedAt = DateTime.Now;
  38. await _rep.UpdateAsync(e);
  39. await InsertTimelineAsync(e.Id, "CLOSURE_APPROVED", "关闭已确认", "RESOLVED", "CLOSED", null);
  40. }
  41. else
  42. {
  43. e.Status = "IN_PROGRESS";
  44. await _rep.UpdateAsync(e);
  45. await InsertTimelineAsync(e.Id, "CLOSURE_REJECTED", "关闭被驳回", "RESOLVED", "IN_PROGRESS", null);
  46. }
  47. }
  48. public async Task<Dictionary<string, object>> GetBizData(long bizId)
  49. {
  50. var e = await _rep.GetByIdAsync(bizId);
  51. if (e == null) return new Dictionary<string, object>();
  52. return new Dictionary<string, object>
  53. {
  54. ["sceneCode"] = e.SceneCode,
  55. };
  56. }
  57. private async Task InsertTimelineAsync(long exceptionId, string code, string label, string? from, string? to, long? instanceId)
  58. {
  59. await _timelineRep.InsertAsync(new AdoS8ExceptionTimeline
  60. {
  61. ExceptionId = exceptionId,
  62. ActionCode = code,
  63. ActionLabel = label,
  64. FromStatus = from,
  65. ToStatus = to,
  66. ActionRemark = instanceId.HasValue ? $"审批实例ID: {instanceId}" : null,
  67. CreatedAt = DateTime.Now
  68. });
  69. }
  70. }