using Admin.NET.Plugin.ApprovalFlow; using Admin.NET.Plugin.ApprovalFlow.Service; using Admin.NET.Plugin.AiDOP.Entity.S8; namespace Admin.NET.Plugin.AiDOP.Service.S8; /// /// 异常关闭确认审批业务回调 /// BizType = "EXCEPTION_CLOSURE" /// public class ExceptionClosureBizHandler : IFlowBizHandler, ITransient { public string BizType => "EXCEPTION_CLOSURE"; private readonly SqlSugarRepository _rep; private readonly SqlSugarRepository _timelineRep; public ExceptionClosureBizHandler( SqlSugarRepository rep, SqlSugarRepository timelineRep) { _rep = rep; _timelineRep = timelineRep; } public async Task OnFlowStarted(long bizId, long instanceId) { var e = await _rep.GetByIdAsync(bizId) ?? throw new S8BizException("异常不存在"); e.ActiveFlowInstanceId = instanceId; e.UpdatedAt = DateTime.Now; await _rep.UpdateAsync(e); await InsertTimelineAsync(e.Id, "CLOSURE_START", "发起关闭确认", null, null, instanceId); } public async Task OnFlowCompleted(long bizId, FlowInstanceStatusEnum finalStatus) { var e = await _rep.GetByIdAsync(bizId) ?? throw new S8BizException("异常不存在"); e.ActiveFlowInstanceId = null; e.UpdatedAt = DateTime.Now; if (finalStatus == FlowInstanceStatusEnum.Approved) { e.Status = "CLOSED"; e.ClosedAt = DateTime.Now; await _rep.UpdateAsync(e); await InsertTimelineAsync(e.Id, "CLOSURE_APPROVED", "关闭已确认", "RESOLVED", "CLOSED", null); } else { e.Status = "IN_PROGRESS"; await _rep.UpdateAsync(e); await InsertTimelineAsync(e.Id, "CLOSURE_REJECTED", "关闭被驳回", "RESOLVED", "IN_PROGRESS", null); } } public async Task> GetBizData(long bizId) { var e = await _rep.GetByIdAsync(bizId); if (e == null) return new Dictionary(); return new Dictionary { ["sceneCode"] = e.SceneCode, }; } private async Task InsertTimelineAsync(long exceptionId, string code, string label, string? from, string? to, long? instanceId) { await _timelineRep.InsertAsync(new AdoS8ExceptionTimeline { ExceptionId = exceptionId, ActionCode = code, ActionLabel = label, FromStatus = from, ToStatus = to, ActionRemark = instanceId.HasValue ? $"审批实例ID: {instanceId}" : null, CreatedAt = DateTime.Now }); } }