public async Task DirectGo(CommonSignConfigurationNode node, string entityKey, string executeUseKey, string executeUserEntensionInfo, List <WorkflowUserInfo> userInfos) { var configuration = node.Configuration; //获取工作流资源 var workflowResource = await _workflowResourceRepository.QueryByKey(configuration.WorkflowResourceType, entityKey); if (workflowResource == null) { var fragment = new TextFragment() { Code = TextCodes.NotFoundWorkflowResourceByKey, DefaultFormatting = "找不到Type为{0},Key为{1}的工作流资源", ReplaceParameters = new List <object>() { configuration.WorkflowResourceType, entityKey } }; throw new UtilityException((int)Errors.NotFoundWorkflowResourceByKey, fragment); } await _commonSignConfigurationNodeStore.Lock(string.Format(ApplicationLockBaseNames.CommonSignConfiguration, configuration.EntityType, entityKey), async() => { await using (DBTransactionScope scope = new DBTransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted, Timeout = new TimeSpan(0, 5, 0) })) { if (!string.IsNullOrEmpty(node.DirectGoExecuteServiceName)) { var directGoExecuteService = _commonSignConfigurationNodeDirectGoExecuteServiceSelector.Choose(node.DirectGoExecuteServiceName); await directGoExecuteService.Execute(node, node.DirectGoExecuteServiceConfiguration, null, workflowResource.Status, entityKey, executeUseKey, executeUserEntensionInfo, userInfos); } //获取当前状态下所有步骤 await workflowResource.GetStepByCurrentStatus(async(step) => { //为每个状态执行关闭动作 await workflowResource.UpdateStepCompleteStatus(step.ActionName, step.Status, true, async(userAction) => { await Task.FromResult(0); }); }); //创建流程处理 await CreateFlowExecute(node, entityKey, null, workflowResource.Status, executeUseKey, executeUserEntensionInfo, userInfos); scope.Complete(); }; },
public async Task CreateFlowExecute(CommonSignConfigurationNode node, string entityKey, string sourceActionName, int sourceStatus, string executeUseKey, string executeUserEntensionInfo, List <WorkflowUserInfo> userInfos) { var configuration = node.Configuration; //获取工作流资源 var workflowResource = await _workflowResourceRepository.QueryByKey(configuration.WorkflowResourceType, entityKey); if (workflowResource == null) { var fragment = new TextFragment() { Code = TextCodes.NotFoundWorkflowResourceByKey, DefaultFormatting = "找不到Type为{0},Key为{1}的工作流资源", ReplaceParameters = new List <object>() { configuration.WorkflowResourceType, entityKey } }; throw new UtilityException((int)Errors.NotFoundWorkflowResourceByKey, fragment); } //更新工作流资源状态为当前节点状态 await workflowResource.UpdateStatus(node.WorkflowStatus); //针对该节点下的所有动作做处理 await _commonSignConfigurationNodeActionStore.QueryByNode(node.ID, async (action) => { List <WorkflowUserInfo> stepUserInfos = new List <WorkflowUserInfo>(); //判断处理用户是否由外部手动输入 if (action.ExecuteUserIsManual) { if ((userInfos == null || userInfos.Count == 0) && string.IsNullOrEmpty(action.ExecuteUserGetServiceName)) { var fragment = new TextFragment() { Code = TextCodes.CommonSignConfigurationNodeActionManualUserEmpty, DefaultFormatting = "工作流资源类型为{0}的通用审批配置下名称为{1}的节点下的动作名称为{2}的节点动作需要外部传入用户,但没有传入", ReplaceParameters = new List <object>() { configuration.WorkflowResourceType, node.Name, action.ActionName } }; throw new UtilityException((int)Errors.CommonSignConfigurationNodeActionManualUserEmpty, fragment); } if (userInfos != null) { foreach (var userInfoItem in userInfos) { //手动输入直接使用参数中的用户类型和用户关键字 WorkflowStep workflowStep = new WorkflowStep() { ResourceID = workflowResource.ID, ActionName = action.ActionName, UserType = userInfoItem.UserType, UserKey = userInfoItem.UserKey, UserCount = 1, Complete = false }; //创建工作流步骤 await workflowResource.AddStep(workflowStep); stepUserInfos.Add(userInfoItem); } } } if (!string.IsNullOrEmpty(action.ExecuteUserGetServiceName)) { //需要通过获取待处理用户接口获取所有用户信息 var getExecuteUserService = _commonSignConfigurationNodeGetExecuteUserServiceSelector.Choose(action.ExecuteUserGetServiceName); await getExecuteUserService.Execute(action, configuration.EntityType, entityKey, action.ExecuteUserGetServiceConfiguration, async(result) => { var existsItem = (from item in stepUserInfos where item.UserType == result.UserType && item.UserKey == result.UserKey select item).FirstOrDefault(); if (existsItem == null) { //新建步骤 WorkflowStep workflowStep = new WorkflowStep() { ResourceID = workflowResource.ID, ActionName = action.ActionName, UserType = result.UserType, UserKey = result.UserKey, UserCount = 1, Complete = false }; //创建工作流步骤 await workflowResource.AddStep(workflowStep); stepUserInfos.Add(new WorkflowUserInfo(result.UserType, result.UserKey)); } }); } //执行扩展动作 if (!string.IsNullOrEmpty(action.CreateFlowExecuteServiceName)) { var executeService = _commonSignConfigurationNodeCreateFlowExecuteServiceSelector.Choose(action.CreateFlowExecuteServiceName); await executeService.Execute(action, action.CreateFlowExecuteServiceConfiguration, sourceActionName, sourceStatus, entityKey, executeUseKey, executeUserEntensionInfo, stepUserInfos); } }); }