/// <summary>
        /// 流程任务处理
        /// </summary>
        /// <param name="stepId">流程步骤Id</param>
        /// <returns>返回操作结果</returns>
        public OperationResult ActionTask(Guid stepId)
        {
            OperationResult or  = new OperationResult(OperationResultType.Error);
            String          msg = String.Empty;

            if (this.NowUser.IsNullOrEmpty())
            {
                msg = "流程启动者未空.";
                return(new OperationResult(OperationResultType.QueryNull, msg));
            }

            if (this.MainId.IsNullOrEmpty())
            {
                msg = "流程无主题依赖.";
                return(new OperationResult(OperationResultType.QueryNull, msg));
            }
            // 获取当前流程运行实例
            List <WFRunInstance> instances   = WFRunInstanceService.Entities.Where(c => c.MainId == MainId).ToList();
            WFRunInstance        runInstance = instances.FirstOrDefault();

            if (runInstance.IsNullOrEmpty())
            {
                msg = "该流程不存在!";
                return(new OperationResult(OperationResultType.QueryNull, msg));
            }

            // 当前流程实例对应步骤信息
            List <WFRunStep> rSteps = WFRunStepService.Entities.Where(c => c.InstanceId == runInstance.Id).OrderByDescending(c => c.Sort).ToList();

            // 上去步骤
            WFRunStep rStep = rSteps.FirstOrDefault(c => c.Id == stepId && c.Status == 0);

            if (rStep.IsNullOrEmpty())
            {
                msg = "该步骤已过期或无效!";
                return(new OperationResult(OperationResultType.QueryNull, msg));
            }
            // 获取当前实例
            WFInfo      wfInfo = this.GetWFInstall(runInstance.DesignJSON);
            List <Line> lines  = wfInfo.Lines.Where(c => c.FromID == rStep.SId).ToList();

            // 声明下一步骤默认处理者Id和名称
            String rId = String.Empty;

            foreach (Line line in lines)
            {
                Step   toStep = wfInfo.Steps.Where(c => c.Id == line.ToID).FirstOrDefault();
                String id     = toStep.DefaultUser;
                rId = rId.IsNullOrEmpty() ? id : rId + ";" + id;

                WFRunStep item = new WFRunStep
                {
                    Id          = Guid.NewGuid(),
                    ParentId    = rStep.Id,
                    SId         = toStep.Id,
                    Name        = toStep.Name,
                    FormUrl     = toStep.FormUrl,
                    FormId      = toStep.FormId.GetGuid(),
                    InstanceId  = runInstance.Id,
                    SenderId    = NowUser.Id,
                    SenderTime  = DateTime.Now,
                    ReceiveTime = DateTime.Now,
                    ReceiveId   = id,
                    Status      = 0,
                    Sort        = (rSteps.Count == 0 ? 1 : rSteps.Count) + 1
                };
                rSteps.Add(item);
                if (!CreateStep.IsNullOrEmpty())
                {
                    WFTaskArgs args = new WFTaskArgs(item, wfInfo, runInstance, NowUser);
                    CreateStep(args);
                }
                //tasks.Add(this.CreateTask(item, user, mainId, wfInfo.Name));
            }
            // 标记当前步骤完成
            rStep.Status = 2;
            rSteps.Add(rStep);

            if (!CreateStep.IsNullOrEmpty())
            {
                WFTaskArgs args = new WFTaskArgs(rStep, wfInfo, runInstance, NowUser);
                CreateStep(args);
            }
            or = WFRunStepService.AddOrUpdate(c => new { c.Id }, rSteps);
            if (or.ResultType == OperationResultType.Success)
            {
                or = new OperationResult(OperationResultType.Success, "任务处理完成", true);
                if (!WFComplete.IsNullOrEmpty())
                {
                    WFTaskArgs args = new WFTaskArgs(rStep, wfInfo, runInstance, NowUser);
                    WFComplete(args);
                }
            }
            else
            {
                or = new OperationResult(OperationResultType.QueryNull, "任务处理失败", false);
            }
            return(or);
        }
        /// <summary>
        /// 根据指定参数启动流程
        /// 根据指定步骤Id查询数据为空,则创建一个新流程
        /// </summary>
        /// <returns>返回操作结果</returns>
        public OperationResult Execute()
        {
            OperationResult or  = new OperationResult(OperationResultType.Error);
            String          msg = String.Empty;

            if (this.DesignId.IsNullOrEmpty())
            {
                msg = "流程设计Id为空.";
                return(new OperationResult(OperationResultType.QueryNull, msg));
            }
            if (this.MainId.IsNullOrEmpty())
            {
                msg = "流程无主题依赖.";
                return(new OperationResult(OperationResultType.QueryNull, msg));
            }
            if (this.NowUser.IsNullOrEmpty())
            {
                msg = "流程启动者不能为空.";
                return(new OperationResult(OperationResultType.QueryNull, msg));
            }
            // 声明流程实例
            WFInfo wfInfo = new WFInfo();
            // 获取当前流程运行实例
            List <WFRunInstance> instances   = WFRunInstanceService.Entities.Where(c => c.MainId == this.MainId).ToList();
            WFRunInstance        runInstance = instances.FirstOrDefault();

            // 如果流程实例不存在,这创建流程实例
            if (runInstance.IsNullOrEmpty())
            {
                or = WFModelService.GetByKey(this.DesignId);
                WFModel design = or.AppendData as WFModel;
                if (!or.IsNullOrEmpty())
                {
                    // 实例当前流程设计
                    wfInfo      = this.GetWFInstall(design.DesignJSON);
                    runInstance = this.CreateInstance(design.DesignJSON, this.MainId, this.NowUser.Id);
                }
                else
                {
                    msg = "流程模型未找到!";
                    return(new OperationResult(OperationResultType.QueryNull, msg));
                }
            }
            else
            {
                // 实例当前流程设计
                wfInfo = this.GetWFInstall(runInstance.DesignJSON);
            }

            // 获取指定实体对应运行步骤信息
            List <WFRunStep> rSteps = WFRunStepService.Entities.Where(c => c.InstanceId == runInstance.Id).OrderByDescending(c => c.Sort).ToList();
            // 获得当前运行步骤
            WFRunStep rStep   = rSteps.FirstOrDefault();
            Boolean   isFirst = false;

            // 判断步骤是否为空,如果为空则为第一次启动流程,并创建一个新步骤信息
            if (rStep.IsNullOrEmpty())
            {
                // 流程当前步骤
                Step step = wfInfo.Steps.Where(c => c.Id == wfInfo.FirstStepID).FirstOrDefault();
                rStep = new WFRunStep
                {
                    ParentId   = Guid.Empty,
                    SId        = step.Id,
                    FormId     = step.FormId.GetGuid(),
                    Name       = step.Name,
                    FormUrl    = step.FormUrl,
                    InstanceId = runInstance.Id,
                    SenderId   = this.NowUser.Id,
                    SenderTime = DateTime.Now,
                    Status     = 2,
                    Sort       = 1
                };
                isFirst = true;
            }

            // 获取当前步骤下一步路线
            List <Line> lines = wfInfo.Lines.Where(c => c.FromID == rStep.SId).ToList();

            // 判断当前步骤是否为空
            if (lines.IsNullOrEmpty() || lines.Count == 0)
            {
                msg = "流程设计中连线存在问题.";
                return(new OperationResult(OperationResultType.QueryNull, msg));
            }

            // 声明下一步骤默认处理者Id和名称
            String rId = String.Empty;

            foreach (Line line in lines)
            {
                Boolean isTrue = false;
                // 判断连线是否满足规则
                if (!line.Expression.IsNullOrEmpty())
                {
                    isTrue = LineWhere(line.Expression, wfInfo.DBTableName);
                }

                if (!line.TSql.IsNullOrEmpty())
                {
                    //or = WFModelService.Context.
                    SqlParameter s = new SqlParameter("@mainId", SqlDbType.UniqueIdentifier)
                    {
                        Value = "00000000-0000-0000-0000-000000000001".GetGuid()
                    };
                    Int32 result = WFModelService.DB.SqlQuery <Int32>(line.TSql, s).FirstOrDefault();
                    isTrue = result > 0 ? true : false;

                    //if (or.ResultType == OperationResultType.Success)
                    //{
                    //    or.AppendData
                    //    isTrue = true;
                    //}
                }
                //Boolean isTrue = true;
                if (isTrue)
                {
                    // 连线下一步骤
                    Step toStep = wfInfo.Steps.Where(c => c.Id == line.ToID).FirstOrDefault();

                    String id = toStep.DefaultUser;
                    rId = rId.IsNullOrEmpty() ? id : rId + ";" + id;

                    WFRunStep item = new WFRunStep
                    {
                        Id         = Guid.NewGuid(),
                        ParentId   = rStep.SId,
                        SId        = toStep.Id,
                        Name       = toStep.Name,
                        FormUrl    = toStep.FormUrl,
                        InstanceId = runInstance.Id,
                        FormId     = toStep.FormId.GetGuid(),
                        SenderId   = NowUser.Id,
                        SenderTime = DateTime.Now,
                        ReceiveId  = id,
                        Status     = 0,
                        Sort       = (rSteps.Count == 0 ? 1 : rSteps.Count) + 1
                    };
                    rSteps.Add(item);
                    //or = this.Insert(item);

                    if (!CreateStep.IsNullOrEmpty())
                    {
                        WFTaskArgs args = new WFTaskArgs(item, wfInfo, runInstance, NowUser);
                        CreateStep(args);
                    }
                }
            }

            // 第一次创建流程
            if (isFirst)
            {
                rStep.ReceiveId = rId;
                rSteps.Add(rStep);

                if (!CreateStep.IsNullOrEmpty())
                {
                    WFTaskArgs args = new WFTaskArgs(rStep, wfInfo, runInstance, NowUser);
                    CreateStep(args);
                }
            }
            or = WFRunStepService.AddOrUpdate(c => new { c.Id }, rSteps);
            if (or.ResultType == OperationResultType.Success)
            {
                or = new OperationResult(OperationResultType.Success, "流程启动成功", true);
                if (!WFComplete.IsNullOrEmpty())
                {
                    WFTaskArgs args = new WFTaskArgs(rStep, wfInfo, runInstance, NowUser);
                    WFComplete(args);
                }
            }
            else
            {
                or = new OperationResult(OperationResultType.QueryNull, "流程启动失败", false);
            }

            return(or);
        }