예제 #1
0
        /// <summary>
        /// 侦听接收通知处理
        /// </summary>
        /// <param name="execution"></param>
        public void Notify(IExecutionEntity execution)
        {
            if (execution.CurrentFlowElement is UserTask userTask && userTask.HasMultiInstanceLoopCharacteristics())
            {
                var varName = userTask.LoopCharacteristics.GetCollectionVarName();

                if (execution.GetVariable(varName) == null)
                {
                    List <IUserInfo> users         = new List <IUserInfo>();
                    string           getUserPolicy = userTask.GetUsersPolicy();
                    if (string.IsNullOrWhiteSpace(getUserPolicy) == false)
                    {
                        QueryBookmark[] actors = JsonConvert.DeserializeObject <QueryBookmark[]>(getUserPolicy);

                        IGetBookmarkRuleProvider ruleProvider = ProcessEngineServiceProvider.Resolve <IGetBookmarkRuleProvider>();

                        foreach (QueryBookmark query in actors)
                        {
                            IGetBookmarkRule rule = ruleProvider.CreateBookmarkRule(query.RuleType.ToString());
                            rule.Execution = execution;
                            rule.Condition = query;
                            users.AddRange(Context.ProcessEngineConfiguration.CommandExecutor.Execute(rule));
                        }
                    }

                    //if (users.Count == 0)
                    //{
                    //    throw new NoneCountersignUsersException(execution.CurrentFlowElement.Name);
                    //}

                    execution.SetVariable(varName, users.Count == 0 ? new string[] { "" } : users.Select(x => x.Id).Distinct().ToArray());
                }
            }
        }
        /// <summary>
        /// 侦听接收通知处理
        /// </summary>
        /// <param name="execution"></param>
        public void Notify(IExecutionEntity execution)
        {
            if (execution.CurrentFlowElement is UserTask userTask && userTask.HasMultiInstanceLoopCharacteristics())
            {
                var varName = userTask.LoopCharacteristics.GetCollectionVarName();

                if (execution.GetVariable(varName) == null)
                {
                    List <IUserInfo> users         = new List <IUserInfo>();
                    string           getUserPolicy = userTask.GetUsersPolicy();
                    if (string.IsNullOrWhiteSpace(getUserPolicy) == false)
                    {
                        if (EXPR_PATTERN.IsMatch(getUserPolicy))
                        {
                            getUserPolicy = EXPR_PATTERN.Replace(getUserPolicy, (m) =>
                            {
                                var value     = m.Groups[1].Value;
                                var variables = execution.Variables;
                                object roles  = ExpressionManager.GetValue(variables, value, variables);
                                return(roles.ToString());
                            });
                        }

                        QueryBookmark[] actors = JsonConvert.DeserializeObject <QueryBookmark[]>(getUserPolicy);

                        IGetBookmarkRuleProvider ruleProvider = ProcessEngineServiceProvider.Resolve <IGetBookmarkRuleProvider>();

                        foreach (QueryBookmark query in actors)
                        {
                            IGetBookmarkRule rule = ruleProvider.CreateBookmarkRule(query.RuleType.ToString());
                            rule.Execution = execution;
                            rule.Condition = query;
                            var us = Context.ProcessEngineConfiguration.CommandExecutor.Execute(rule);
                            users.AddRange(us);
                        }
                    }

                    if (users.Count == 0)
                    {
                        users.Add(Authentication.AuthenticatedUser);
                        logger.LogWarning($"调用查询人员服务失败,分组没有人,重新指到当前提交人,Duty={getUserPolicy}");
                        //throw new NoneCountersignUsersException(execution.CurrentFlowElement.Name);
                    }

                    execution.SetVariable(varName, users.Count == 0 ? new string[] { "" } : users.Select(x => x.Id).Distinct().ToArray());
                }
            }
        }