/// <summary>
        /// 获得加签处理人
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="workflowId">流程模版id</param>
        /// <param name="worktaskId">任务模版id<</param>
        /// <param name="workflowInsId">流程实例id</param>
        /// <param name="worktaskInsId">任务实例id</param>
        /// <returns></returns>
        public DataTable GetTaskInsNextOperTable(UserInfo userInfo, string workflowId, string worktaskId, string workflowInsId, string worktaskInsId)
        {
            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.WorkFlowInstanceService_GetTaskInsNextOperTable);
            var dataTable = new DataTable(WorkTaskInstanceTable.TableName);

            ServiceUtil.ProcessWorkFlowDb(userInfo, parameter, dbProvider =>
            {
                var manager = new WorkTaskInstanceManager(dbProvider, userInfo);
                dataTable   = manager.GetTaskInsNextOperTable(workflowId, worktaskId, workflowInsId, worktaskInsId);
            });
            return(dataTable);
        }
        /// <summary>
        /// 设定任务实例正常结束
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="operatedDes">处理说明</param>
        /// <param name="worktaskInsId">任务实例id</param>
        /// <returns></returns>
        public int SetWorkTaskInstanceOver(UserInfo userInfo, string operatedDes, string worktaskInsId)
        {
            int returnValue = -1;
            var parameter   = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.WorkFlowInstanceService_SetWorkTaskInstanceOver);

            ServiceUtil.ProcessWorkFlowDbWithTransaction(userInfo, parameter, dbProvider =>
            {
                var manager = new WorkTaskInstanceManager(dbProvider, userInfo);
                // 调用方法,并且返回运行结果
                returnValue = manager.SetWorkTaskInstanceOver(operatedDes, worktaskInsId);
            });
            return(returnValue);
        }
        /// <summary>
        /// 是否存在指定任务实例
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="worktaskInsId">任务实例id</param>
        /// <returns></returns>
        public bool WorkTaskInstanceExist(UserInfo userInfo, string worktaskInsId)
        {
            bool returnValue = false;
            var  parameter   = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.WorkFlowInstanceService_WorkTaskInstanceExist);

            ServiceUtil.ProcessWorkFlowDb(userInfo, parameter, dbProvider =>
            {
                var manager = new WorkTaskInstanceManager(dbProvider, userInfo);
                // 调用方法,并且返回运行结果
                returnValue = manager.Exists(worktaskInsId);
            });
            return(returnValue);
        }
        /// <summary>
        /// 任务撤回
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户Id</param>
        /// <param name="workTaskInsId">任务实例id</param>
        /// <returns></returns>
        public string WorkTaskRevoke(UserInfo userInfo, string userId, string workTaskInsId)
        {
            string returnValue = string.Empty;
            var    parameter   = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.WorkFlowInstanceService_WorkTaskRevoke);

            ServiceUtil.ProcessWorkFlowDbWithTransaction(userInfo, parameter, dbProvider =>
            {
                var manager = new WorkTaskInstanceManager(dbProvider, userInfo);
                // 调用方法,并且返回运行结果
                returnValue = manager.WorkTaskRevoke(userId, workTaskInsId);
            });
            return(returnValue);
        }
        /// <summary>
        /// 任务任意退回
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <param name="operatorInsId">退回的处理实例Id</param>
        /// <param name="backyy">退回原因</param>
        /// <param name="workflowInsId">上级</param>
        /// <returns></returns>
        public string WorkTaskBackry(string userId, string operatorInsId, string backyy, string workflowInsId)
        {
            try
            {
                //1、存储过程方法

                /*
                 * int i = this.DBProvider.ExecuteProcedure("WorkTaskSubmitBackProry", new IDbDataParameter[]
                 * {
                 *  DBProvider.MakeParameter("OPERATORINSTANCEID", operatorInsId),
                 *  DBProvider.MakeParameter("BACKYY", backyy),
                 *  DBProvider.MakeParameter("WORKFLOWINSID", workflowInsId),
                 *  DBProvider.MakeParameter("USERID", userId)
                 * });
                 * return (i > 0) ? WorkFlowConst.SuccessCode : WorkFlowConst.TaskAssignErrorCode;
                 */
                //2、直接语句法
                int returnValue = 0;

                //2.1、取得处理的任务实例
                string workTaskInsId = new OperatorInstanceManager(DBProvider).GetProperty(OperatorInstanceTable.FieldOperatorInsId, operatorInsId, OperatorInstanceTable.FieldWorkTaskInsId);
                //2.2、获取前一任务实例
                string workFlow = new WorkTaskInstanceManager(DBProvider).GetProperty(WorkTaskInstanceTable.FieldWorkTaskInsId, workTaskInsId, WorkTaskInstanceTable.FieldWorkFlowInsId);

                //2.3、设定当前任务结束
                //SetWorkTaskInstanceOver(userId, workTaskInsId);
                SetWorkTaskInstanceOver(GetUserRealNameById(userId), workTaskInsId);

                //2.4、设置当前处理者实例结束
                returnValue += new OperatorInstanceManager(DBProvider).SetOperatorInstanceOver(userId, operatorInsId);
                //2.5、
                string strSql = string.Format(@"
                                        INSERT  INTO WORKFLOWBACK(ID, USERID ,OPERATORINSID ,BACKYY , BACKTIME)
                                        VALUES  ( {0} ,{1} ,{2} ,{3},{4} )",
                                              DBProvider.GetParameter("ID"),
                                              DBProvider.GetParameter("USERID"),
                                              DBProvider.GetParameter("OPERATORINSID"),
                                              DBProvider.GetParameter("BACKYY"),
                                              DBProvider.GetDBNow());
                returnValue += DBProvider.ExecuteNonQuery(strSql, new[] {
                    DBProvider.MakeParameter("ID", BusinessLogic.NewGuid()),
                    DBProvider.MakeParameter("USERID", GetUserRealNameById(userId)),
                    DBProvider.MakeParameter("OPERATORINSID", workFlow),
                    DBProvider.MakeParameter("BACKYY", backyy)
                });
                //2.6、
                strSql = string.Format(@"
                                        INSERT  INTO AUDITMESSAGE
                                                ( AUDITID,WORKFLOWINSID ,MESSAGE ,AUDITUSERID ,AUDITUSERNAME ,AUDITRESULT ,AUDITTIME ,AUDITXYB)
                                        VALUES  ( {0} ,{1} ,{2} ,{3} ,{4} ,{5} ,{6},{7})",
                                       DBProvider.GetParameter("AUDITID"),
                                       DBProvider.GetParameter("WORKFLOWINSID"),
                                       DBProvider.GetParameter("MESSAGE"),
                                       DBProvider.GetParameter("AUDITUSERID"),
                                       DBProvider.GetParameter("USERID"),
                                       "'任意退回'",
                                       DBProvider.GetDBNow(),
                                       0);
                returnValue += DBProvider.ExecuteNonQuery(strSql, new[] {
                    DBProvider.MakeParameter("AUDITID", BusinessLogic.NewGuid()),
                    DBProvider.MakeParameter("WORKFLOWINSID", workFlow),
                    DBProvider.MakeParameter("MESSAGE", backyy),
                    DBProvider.MakeParameter("AUDITUSERID", userId),
                    DBProvider.MakeParameter("USERID", GetUserRealNameById(userId))
                });
                //2.7、退回至提交人 此处与WORKFLOWCONST.TASKBACKMSG对应
                //UPDATE  WORKTASKINSTANCE  SET  SUCCESSMSG = '任意退回至提交人!'   WHERE   WORKTASKINSID = @WORKTASKINSID
                returnValue += SetProperty(WorkTaskInstanceTable.FieldWorkTaskInsId, workTaskInsId, WorkTaskInstanceTable.FieldSuccessMsg, "任意退回至提交人!");

                //2.8、任务状态重置
                switch (DBProvider.CurrentDbType)
                {
                case CurrentDbType.Access:
                case CurrentDbType.SqlServer:
                    strSql = string.Format(@"
                                        UPDATE  WORKTASKINSTANCE
                                        SET     ENDTIME = {0} ,STATUS = '2' ,REMINDED = '0' ,OPERATEDDES = ISNULL(OPERATEDDES, '') + ',但被[' + {1} + ']任意退回,'
                                        WHERE   WORKTASKINSID = {2}  AND STATUS = 3",
                                           DBProvider.GetDBNow(),
                                           DBProvider.GetParameter("USERID"),
                                           DBProvider.GetParameter("WORKTASKINSID"));
                    break;

                case CurrentDbType.Oracle:
                    strSql = string.Format(@"
                                        UPDATE  WORKTASKINSTANCE
                                        SET     ENDTIME = {0} ,STATUS = '2' ,REMINDED = '0' ,OPERATEDDES = NVL(OPERATEDDES, '') + ',但被[' + {1} + ']任意退回,'
                                        WHERE   WORKTASKINSID = {2}  AND STATUS = 3",
                                           DBProvider.GetDBNow(),
                                           DBProvider.GetParameter("USERID"),
                                           DBProvider.GetParameter("WORKTASKINSID"));
                    break;

                case CurrentDbType.MySql:
                    strSql = string.Format(@"
                                        UPDATE  WORKTASKINSTANCE
                                        SET     ENDTIME = {0} ,STATUS = '2' ,REMINDED = '0' ,OPERATEDDES = CONCAT(IFNULL(OPERATEDDES, '') ,',但被[',{1},']任意退回,')
                                        WHERE   WORKTASKINSID = {2}  AND STATUS = 3",
                                           DBProvider.GetDBNow(),
                                           DBProvider.GetParameter("USERID"),
                                           DBProvider.GetParameter("WORKTASKINSID"));
                    break;
                }
                returnValue += DBProvider.ExecuteNonQuery(strSql, new[] {
                    DBProvider.MakeParameter("USERID", GetUserRealNameById(userId)),
                    DBProvider.MakeParameter("WORKTASKINSID", workflowInsId)
                });
                return((returnValue > 0) ? WorkFlowConst.SuccessCode : WorkFlowConst.TaskAssignErrorCode);
            }
            catch (Exception ex)
            {
                //LogHelper.WriteLog(ex);
                throw new Exception("BizLogicError:任务退回失败,请与管理员联系!Error:" + ex.Message);
            }
        }
        /// <summary>
        /// 创建处理者实例
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="oldWorktaskInsId"></param>
        /// <param name="oldworktaskId"></param>
        /// <param name="workFlowId"></param>
        /// <param name="workTaskId"></param>
        /// <param name="workFlowInstanceId"></param>
        /// <param name="WorkTaskInstanceId"></param>
        /// <param name="operParam"></param>
        /// <returns></returns>
        private string CreateOperInstance(string userId, string oldWorktaskInsId, string oldworktaskId, string workFlowId, string workTaskId, string workFlowInstanceId, string WorkTaskInstanceId, OperParameter operParam)
        {
            int    operType;             //处理类型
            string operContent;          //处理者id
            int    OperRelation;         //处理者关系
            var    OperContentText = ""; //处理者的名称

            //动态指定下一任务处理人
            DataTable tmpDyDt = new WorkTaskInstanceManager(this.DBProvider, this.UserInfo).GetTaskInsNextOperTable(workFlowId, oldworktaskId, workFlowInstanceId, oldWorktaskInsId);

            foreach (DataRow dr in tmpDyDt.Rows)
            {
                operContent = dr[WorkTaskInsNextOperTable.FieldUserId].ToString();
                if (string.IsNullOrEmpty(operContent))
                {
                    continue;
                }
                var userName = new PiUserManager(DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType, SystemInfo.RDIFrameworkDbConectionString), this.UserInfo).GetEntity(operContent).RealName;
                operParam.OperContent    = operContent;
                operParam.OperContenText = userName;
                operParam.OperRelation   = 0;
                operParam.OperType       = 3;
                new InstanceTypeManager(this.DBProvider, this.UserInfo).AssignUser(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
            }

            DataTable tmpTeDt = new WorkTaskManager(this.DBProvider, this.UserInfo).GetTaskOperator(workFlowId, workTaskId);

            //如果没有处理者
            if ((tmpTeDt == null || tmpTeDt.Rows.Count <= 0) && (tmpDyDt.Rows.Count <= 0))
            {
                return(WorkFlowConst.NoFoundOperatorCode);
            }

            foreach (DataRow dr in tmpTeDt.Rows)
            {
                operType                 = System.Convert.ToInt16(dr[OperatorTable.FieldOperType].ToString());
                operContent              = dr[OperatorTable.FieldOperContent].ToString();
                OperRelation             = Convert.ToInt16(dr[OperatorTable.FieldRelation]);
                OperContentText          = dr[OperatorTable.FieldOperDisplay].ToString();
                operParam.OperType       = operType;
                operParam.OperContent    = operContent;
                operParam.OperRelation   = OperRelation;
                operParam.OperContenText = OperContentText;
                switch (operType)
                {       //在此函数中加入处理者策略
                case 1: //流程启动者
                    var startflowUser     = new InstanceTypeManager(this.DBProvider, this.UserInfo).GetStartWorkflowUser(workFlowInstanceId);
                    var startflowUserName = new PiUserManager(DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType, SystemInfo.RDIFrameworkDbConectionString), this.UserInfo).GetEntity(startflowUser).UserName;
                    operParam.OperContent    = startflowUser;
                    operParam.OperContenText = startflowUserName;
                    if (OperRelation == 0)    //无处理这关系
                    {
                        new InstanceTypeManager(this.DBProvider, this.UserInfo).AssignUser(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                    }
                    else
                    {
                        new InstanceTypeManager(this.DBProvider, this.UserInfo).UserRelation(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                    }
                    break;

                case 2:    //某一任务实际处理者
                    var dtTaskUser = new InstanceTypeManager(this.DBProvider, this.UserInfo).GetTaskInstanceUser(workFlowInstanceId, operContent);
                    foreach (DataRow drUser in dtTaskUser.Rows)
                    {
                        var rlUserId   = drUser["USERID"].ToString();
                        var rlUserName = new PiUserManager(DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType, SystemInfo.RDIFrameworkDbConectionString), this.UserInfo).GetEntity(rlUserId).RealName;
                        operParam.OperContent    = rlUserId;
                        operParam.OperContenText = rlUserName;
                        if (OperRelation == 0)    //无处理这关系
                        {
                            new InstanceTypeManager(this.DBProvider, this.UserInfo).AssignUser(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                        }
                        else
                        {
                            new InstanceTypeManager(this.DBProvider, this.UserInfo).UserRelation(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                        }
                    }
                    break;

                case 3:    //指定人员
                    if (OperRelation == 0)
                    {
                        new InstanceTypeManager(this.DBProvider, this.UserInfo).AssignUser(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                    }
                    else
                    {
                        new InstanceTypeManager(this.DBProvider, this.UserInfo).UserRelation(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                    }
                    break;

                case 4:    //部门
                    if (OperRelation == 0)
                    {
                        new InstanceTypeManager(this.DBProvider, this.UserInfo).AssignArchitecture(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                    }
                    else
                    {
                        new InstanceTypeManager(this.DBProvider, this.UserInfo).ArchRelation(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                    }
                    break;

                case 5:    //角色
                    new InstanceTypeManager(this.DBProvider, this.UserInfo).AssignGroup(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                    break;

                case 6:    //岗位
                    new InstanceTypeManager(this.DBProvider, this.UserInfo).AssignArchitecture(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                    break;

                case 7:    //从变量中获取
                    var varUser = GetWorkTaskVarValue(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, OperContentText);
                    if (varUser.Length > 2)
                    {
                        varUser = varUser.Substring(1, varUser.Length - 2);

                        var varUserName = new PiUserManager(DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType, SystemInfo.RDIFrameworkDbConectionString), this.UserInfo).GetEntity(varUser).UserName;
                        if (string.IsNullOrEmpty(varUserName) || varUserName == "'")
                        {
                            return(WorkFlowConst.IsNullUserIdCode);   //如果用户取不到就报错
                        }
                        operParam.OperContent    = varUser;
                        operParam.OperContenText = varUserName;
                    }
                    else
                    {
                        return(WorkFlowConst.IsNullUserIdCode); //如果用户取不到就报错
                    }
                    if (OperRelation == 0)                      //无处理者关系
                    {
                        new InstanceTypeManager(this.DBProvider, this.UserInfo).AssignUser(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                    }
                    else
                    {
                        new InstanceTypeManager(this.DBProvider, this.UserInfo).UserRelation(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                    }

                    break;

                case 8:    //某一任务选择的处理者
                    throw new Exception("无此类型");
                    break;

                case 9:    //所有人
                    new InstanceTypeManager(this.DBProvider, this.UserInfo).AssignAll(userId, workFlowId, workTaskId, workFlowInstanceId, WorkTaskInstanceId, operParam);
                    break;

                case 10:    //指派
                    throw new Exception("无此类型");
                    break;

                case 11:    //授权
                    throw new Exception("无此类型");
                    break;

                default:
                    Console.WriteLine("Default case");
                    break;
                }
            }
            return(WorkFlowConst.SuccessCode);
        }