예제 #1
0
        public async Task <ValidateResult> ValidateUser(WorkflowStep step, string userKey)
        {
            ValidateResult result = new ValidateResult()
            {
                Result = true
            };

            //如果该步骤已经是完成状态,则直接返回false
            if (step.Complete)
            {
                result.Result      = false;
                result.Description = string.Format(StringLanguageTranslate.Translate(TextCodes.WorkflowStepHasCompleted, "ID为{0},资源ID为{1},动作名称{2},状态为{3},用户类型为{4},用户关键字为{5}的工作流步骤已经是完成状态"), step.ID, step.ResourceID, step.ActionName, step.Status, step.UserType, step.UserKey);
                return(result);
            }

            //需要检查步骤下面是否已经存在相同用户的动作
            var userAction = await _workflowStepUserActionStore.QueryByStepAndUser(step.Resource.Type, step.Resource.Key, step.ID, userKey);

            if (userAction != null)
            {
                //如果存在,表示该用户已经做过动作,返回false
                result.Result      = false;
                result.Description = string.Format(StringLanguageTranslate.Translate(TextCodes.WorkflowStepUserHasAction, "ID为{0},资源ID为{1},动作名称{2},状态为{3},用户类型为{4},用户关键字为{5}的工作流步骤中用户信息为{6}的用户已经处理过"), step.ID, step.ResourceID, step.ActionName, step.Status, step.UserType, step.UserKey, userKey);
                return(result);
            }

            //需要调用服务检查
            if (!_validateUserKeyServiceFactories.TryGetValue(step.UserType, out IFactory <IValidateUserKeyService> serviceFactory))
            {
                var fragment = new TextFragment()
                {
                    Code = TextCodes.NotFoundWorkflowValidateUserKeyServiceFactoryByType,
                    DefaultFormatting = "在工作流步骤的实现中,找不到类型为{0}的Factory<IValidateUserKeyService>",
                    ReplaceParameters = new List <object>()
                    {
                        step.UserType
                    }
                };

                throw new UtilityException((int)Errors.NotFoundWorkflowValidateUserKeyServiceFactoryByType, fragment);
            }

            var service = serviceFactory.Create();

            result = await service.Execute(step.UserKey, userKey);

            return(result);
        }
예제 #2
0
 public async Task GetUserInfos(WorkflowStep step, Func <string, Task> callback)
 {
     await _getUserInfoFromWorkflowStepService.Execute(step.UserType, step.UserKey, callback);
 }
예제 #3
0
        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);
                }
            });
        }
예제 #4
0
 /// <summary>
 /// 为资源增加步骤
 /// </summary>
 /// <param name="step"></param>
 /// <returns></returns>
 public async Task AddStep(WorkflowStep step)
 {
     await _imp.AddStep(this, step);
 }