using DS.Module.Core; using DS.Module.Core.Data; using DS.WMS.Core.Op.Dtos.TaskInteraction; using DS.WMS.Core.Op.Entity.TaskInteraction; using DS.WMS.Core.Op.Interface.TaskInteraction; using DS.WMS.Core.TaskPlat; namespace DS.WMS.Core.Op.Method.TaskInteraction { /// /// 动作执行管理 /// public class ActionManagerService : ServiceBase, IActionManagerService { Dictionary ExecutorMappings; /// /// 初始化 /// public ActionManagerService(IServiceProvider serviceProvider) : base(serviceProvider) { ExecutorMappings = new Dictionary(); ExecutorMappings[TaskActionType.Mail] = new MailActionExecutor(); } /// /// 触发任务执行动作 /// /// 任务信息 /// public async Task TriggerAction(BusinessTask businessTask) { ArgumentNullException.ThrowIfNull(businessTask, nameof(businessTask)); //目前只限制任务完成才触发 if (businessTask.TaskStatus != TaskStatusEnum.Complete) return; // 执行自动化操作 TaskFlowDataContext dataContext = new( (TaskFlowDataNameConst.BusinessTask, businessTask) ); TaskFlowRuner taskFlow = new(TenantDb, ServiceProvider); await taskFlow.RunWithBsno(businessTask.TaskType, businessTask.BusinessId, dataContext); } public async Task ExecuteAsync(TaskFlowDataContext dataContext) { ArgumentNullException.ThrowIfNull(dataContext, nameof(dataContext)); TaskActionType actionType = (TaskActionType)dataContext.Get("ActionType"); if (ExecutorMappings.TryGetValue(actionType, out IActionExecutor executor)) { var context = new ActionExecutionContext { TaskInfo = dataContext.Get(TaskFlowDataNameConst.BusinessTask), ServiceProvider = ServiceProvider }; foreach (var key in dataContext.Keys) { context.AdditionalData[key] = dataContext[key]; } await executor.ExecuteAsync(context); } } } /// /// 任务执行类型 /// public enum TaskActionType { /// /// 后台任务 /// BackgroundWorker, /// /// 邮件 /// Mail, } }