public List <UserInfo> GetFlowToRoleUserInfos(int tempId)
        {
            var             allUserInfos    = UserInfoService.GetEntities(u => u.DelFlag == delflagNormal).ToList();
            List <UserInfo> flowToUserInfos = new List <UserInfo>();

            //当前用户每个角色
            foreach (RoleInfo loginUserRoleInfo in LoginUser.RoleInfo)
            {
                string flowToRoleKeyWord = GetRoleHelper.GetFlowToRoleKeyWord(loginUserRoleInfo, tempId);
                foreach (UserInfo onUserInfo in allUserInfos)
                {
//所有用户中一个用户的每个角色
                    foreach (RoleInfo oneRoleOfoneUser in onUserInfo.RoleInfo)
                    {
                        if (flowToRoleKeyWord == null)
                        {
                            continue;
                        }
                        if (oneRoleOfoneUser.RoleName.Contains(flowToRoleKeyWord))
                        {
                            flowToUserInfos.Add(onUserInfo);
                        }
                    }
                }
            }
            return(flowToUserInfos);
        }
        public ActionResult Add(WF_Instance instance, int id, int flowTo)
        {
            var currentUserId = LoginUser.ID;

            //在工作流实例表添加一条数据:
            instance.DelFlag   = delflagNormal;
            instance.StartTime = DateTime.Now;
            instance.FilePath  = string.Empty;

            instance.StartBy      = currentUserId;
            instance.Level        = 0;
            instance.Status       = (short)Heima8.OA.Model.Enum.WF_InstanceEnum.Processing;
            instance.WFInstanceId = Guid.Empty;
            instance.WF_TempID    = id;
            WF_InstanceService.Add(instance);
            //第二点:启动工作流
            //1、获得工作流类型
            var temp     = GetWfTemp(instance);
            var activity = WorkflowFactory.GetActivity(temp.ActityType);
            WorkflowApplication wfApp = null;

            //2、家具产品对应的逻辑
            if (activity is ProductFlow)
            {
                //家具逻辑中,设计之后数控和小锯是二选一
                var designRole =
                    RoleInfoService.GetEntities(r => r.DelFlag == delflagNormal && r.RoleName.Contains("设计"))
                    .FirstOrDefault();
                string flowToKeyWord = GetRoleHelper.GetFlowToRoleKeyWord(designRole, id);
                wfApp = WorkflowApplicationHelper.CreateWorkflowApp(activity,
                                                                    new Dictionary <string, object>()
                {
                    { "AfterDesignFlowTo", flowToKeyWord }
                });
            }//else if{ 其他工作流的逻辑}
            else
            {//没有对应的工作流提前结束
                return(RedirectToAction("ShowMyCheck"));
            }

            instance.WFInstanceId = wfApp.Id;
            WF_InstanceService.Update(instance);

            //第三点:在步骤表里面添加两条步骤。一个当前已经处理的完成步骤。
            WF_Step startStep = new WF_Step();

            startStep.WF_InstanceID  = instance.ID;
            startStep.SubTime        = DateTime.Now;
            startStep.StepName       = "提交审批表单";
            startStep.IsEndStep      = false;
            startStep.IsStartStep    = true;
            startStep.ProcessBy      = currentUserId;
            startStep.PorcessComment = "提交申请";
            startStep.ProcessResult  = "通过";
            startStep.ProcessTime    = DateTime.Now;
//            startStep.StepName = "提交审批表单";
            startStep.StepStatus = (short)Heima8.OA.Model.Enum.WFStepEnum.Processed;


            WF_StepService.Add(startStep);

            //二个步骤:下一步谁审批的步骤。  项目经理审批
            WF_Step nextStep = new WF_Step();

            nextStep.WF_InstanceID  = instance.ID;
            nextStep.SubTime        = DateTime.Now;
            nextStep.ProcessTime    = DateTime.Now;
            nextStep.PorcessComment = string.Empty;

            nextStep.IsEndStep   = false;
            nextStep.IsStartStep = false;
            nextStep.ProcessBy   = flowTo;

            nextStep.ProcessResult = "";

            nextStep.StepName   = "";
            nextStep.StepStatus = (short)Heima8.OA.Model.Enum.WFStepEnum.UnProecess;
            WF_StepService.Add(nextStep);
            return(RedirectToAction("ShowMyCheck"));
        }