using Admin.NET.Plugin.AiDOP.Entity;
using Admin.NET.Plugin.ApprovalFlow;
using Admin.NET.Plugin.ApprovalFlow.Service;
namespace Admin.NET.Plugin.AiDOP.Service;
///
/// 智慧运营改善计划审批回调。
///
public class SmartOpsImprovementBizHandler : IFlowBizHandler, ITransient
{
public const string BizTypeCode = "SMART_OPS_IMPROVEMENT";
public string BizType => BizTypeCode;
private readonly SqlSugarRepository _rep;
public SmartOpsImprovementBizHandler(SqlSugarRepository rep)
{
_rep = rep;
}
public async Task OnFlowStarted(long bizId, long instanceId)
{
await _rep.AsUpdateable()
.SetColumns(x => x.Status == "approving")
.SetColumns(x => x.FlowInstanceId == instanceId)
.SetColumns(x => x.UpdateTime == DateTime.Now)
.Where(x => x.Id == bizId)
.ExecuteCommandAsync();
}
public async Task OnFlowCompleted(long bizId, long instanceId, FlowInstanceStatusEnum finalStatus, long? lastApproverId)
{
var status = finalStatus == FlowInstanceStatusEnum.Approved ? "executing" : "rejected";
await _rep.AsUpdateable()
.SetColumns(x => x.Status == status)
.SetColumns(x => x.UpdateTime == DateTime.Now)
.Where(x => x.Id == bizId)
.ExecuteCommandAsync();
}
public async Task> GetBizData(long bizId)
{
var plan = await _rep.GetByIdAsync(bizId);
if (plan == null) return new Dictionary();
return new Dictionary
{
["moduleCode"] = plan.ModuleCode,
["metricCode"] = plan.MetricCode ?? "",
["problemLevel"] = plan.ProblemLevel,
["problemName"] = plan.ProblemName,
["problemDept"] = plan.ProblemDept ?? "",
["status"] = plan.Status,
};
}
}