/// <summary>
        /// 获取用户角色列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <returns>主键数组</returns>
        public string[] GetUserRoleIds(UserInfo userInfo, string userId)
        {
            string[] returnValue = null;
            var      parameter   = ParameterUtil.CreateWithLog(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                var userRoleManager = new PiUserRoleManager(dbProvider, userInfo);
                returnValue         = userRoleManager.GetAllRoleIds(userId);
                // returnValue = userRoleManager.GetRoleIds(userId);
            });
            return(returnValue);
        }
        /// <summary>
        /// 获取用户的条件约束表达式
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="permissionCode">权限代码</param>
        /// <returns>主键</returns>
        public string GetUserConstraint(string tableName, string permissionCode = "Resource.AccessPermission")
        {
            string returnValue = string.Empty;
            // 这里是获取用户的条件表达式
            // 1: 首先用户在哪些角色里是有效的?
            // 2: 这些角色都有哪些哪些条件约束?
            // 3: 组合约束条件?
            // 4:用户本身的约束条件?
            string permissionId = string.Empty;
            PiPermissionItemManager permissionItemManager = new PiPermissionItemManager(this.UserInfo);

            permissionId = permissionItemManager.GetIdByAdd(permissionCode);

            PiUserRoleManager manager = new PiUserRoleManager(this.DBProvider, this.UserInfo);

            string[] roleIds = manager.GetAllRoleIds(UserInfo.Id);
            if (roleIds == null || roleIds.Length == 0)
            {
                return(returnValue);
            }
            PiPermissionScopeManager scopeManager = new PiPermissionScopeManager(this.DBProvider, this.UserInfo);

            string[] names =
            {
                PiPermissionScopeTable.FieldResourceCategory
                , PiPermissionScopeTable.FieldResourceId
                , PiPermissionScopeTable.FieldTargetCategory
                , PiPermissionScopeTable.FieldTargetId
                , PiPermissionScopeTable.FieldPermissionId
                , PiPermissionScopeTable.FieldEnabled
                , PiPermissionScopeTable.FieldDeleteMark
            };
            Object[] values =
            {
                PiRoleTable.TableName
                , roleIds
                , "Table"
                , tableName
                , permissionId
                , 1
                , 0
            };

            DataTable dtPermissionScope    = scopeManager.GetDT(names, values);
            string    permissionConstraint = string.Empty;

            foreach (DataRow dataRow in dtPermissionScope.Rows)
            {
                permissionConstraint = dataRow[PiPermissionScopeTable.FieldPermissionConstraint].ToString();
                permissionConstraint = permissionConstraint.Trim();
                if (!string.IsNullOrEmpty(permissionConstraint))
                {
                    returnValue += " AND " + permissionConstraint;
                }
            }

            //得到当前用户的约束条件
            string userConstraint = this.GetConstraint(PiUserTable.TableName, this.UserInfo.Id, tableName) ?? "";

            if (!string.IsNullOrEmpty(userConstraint))
            {
                returnValue += " AND " + userConstraint;
            }

            if (!string.IsNullOrEmpty(returnValue))
            {
                returnValue = returnValue.Substring(5);
                // 解析替换约束表达式标准函数
                returnValue = ConstraintUtil.PrepareParameter(this.UserInfo, returnValue);
            }

            return(returnValue);
        }