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; /// /// EXCEPTION_CLOSURE 流程的 Biz 回调(双线合一后已退化为复检审批载体)。 /// 启动点:S8 提交复检;终态由 S8 业务侧(ApproveVerification/RejectVerification)决定。 /// 该 handler 只负责维护 ActiveFlowInstanceId 字段,不再改写 e.Status。 /// 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.ActiveFlowBizType = BizType; e.UpdatedAt = DateTime.Now; await _rep.UpdateAsync(e); await InsertTimelineAsync(e.Id, "VERIFY_FLOW_START", "复检审批流启动", instanceId, null); } public async Task OnFlowCompleted(long bizId, long instanceId, FlowInstanceStatusEnum finalStatus, long? lastApproverId) { var e = await _rep.GetByIdAsync(bizId) ?? throw new S8BizException("异常不存在"); e.ActiveFlowInstanceId = null; e.ActiveFlowBizType = null; e.UpdatedAt = DateTime.Now; await _rep.UpdateAsync(e); // 状态由 S8 服务层管控(VERIFY_APPROVED/VERIFY_REJECTED 时间线已写)。 // 这里只补一条流程级审计标记,便于追溯审批实例终态。 var label = finalStatus switch { FlowInstanceStatusEnum.Approved => "复检审批流通过", FlowInstanceStatusEnum.Rejected => "复检审批流拒绝", FlowInstanceStatusEnum.Cancelled => "复检审批流撤回", _ => "复检审批流结束", }; await InsertTimelineAsync(e.Id, "VERIFY_FLOW_END", label, instanceId, lastApproverId); } public async Task> GetBizData(long bizId) { var e = await _rep.GetByIdAsync(bizId); if (e == null) return new Dictionary(); return new Dictionary { ["sceneCode"] = e.SceneCode ?? string.Empty, ["factoryCode"] = e.FactoryId.ToString(), }; } private async Task InsertTimelineAsync(long exceptionId, string code, string label, long? instanceId, long? approverId) { string? remark = null; if (instanceId.HasValue && approverId.HasValue) remark = $"审批实例ID: {instanceId},审批人: {approverId}"; else if (instanceId.HasValue) remark = $"审批实例ID: {instanceId}"; else if (approverId.HasValue) remark = $"审批人: {approverId}"; await _timelineRep.InsertAsync(new AdoS8ExceptionTimeline { ExceptionId = exceptionId, ActionCode = code, ActionLabel = label, FromStatus = null, ToStatus = null, OperatorId = approverId, ActionRemark = remark, CreatedAt = DateTime.Now }); } }