Пример #1
0
        /// <summary>
        /// 从缓存中获取角色编号
        /// </summary>
        /// <param name="systemCode">系统编码</param>
        /// <param name="userId"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        public static string[] GetRoleIdsByCache(string systemCode, string userId, string companyId = null)
        {
            // 返回值
            string[] result = null;

            if (!string.IsNullOrEmpty(userId))
            {
                //2017.12.20增加默认的HttpRuntime.Cache缓存
                var cacheKey = "Array" + systemCode + userId + companyId + "RoleIds";
                //var cacheTime = default(TimeSpan);
                var cacheTime = TimeSpan.FromMilliseconds(86400000);
                result = CacheUtil.Cache <string[]>(cacheKey, () =>
                {
                    //进行数据库查询
                    var userManager = new BaseUserManager();
                    return(userManager.GetRoleIds(systemCode, userId, companyId));
                }, true, false, cacheTime);

                //// 进行数据库查询
                //BaseUserManager userManager = new BaseUserManager();
                //result = userManager.GetRoleIds(systemCode, userId, companyId);
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// 获取用户列表
        /// 当用户非常多时,不需要显示角色
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="showRole">显示角色</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTable(BaseUserInfo userInfo, bool showRole = true)
        {
            var result = new DataTable(BaseUserEntity.CurrentTableName);

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                // 这里是获取用户列表
                var userManager = new BaseUserManager(dbHelper, userInfo);
                // 获取允许登录列表
                var parameters = new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(BaseUserEntity.FieldDeleted, 0),
                    new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1),
                    new KeyValuePair <string, object>(BaseUserEntity.FieldIsVisible, 1)
                };
                result = userManager.GetDataTable(parameters, BaseUserEntity.FieldSortCode);
                // 是否显示角色信息
                if (showRole)
                {
                    // 这里是获取角色列表
                    var tableName     = userInfo.SystemCode + "Role";
                    var roleManager   = new BaseRoleManager(dbHelper, userInfo, tableName);
                    var dataTableRole = roleManager.GetDataTable();
                    if (!result.Columns.Contains("RoleName"))
                    {
                        result.Columns.Add("RoleName");
                    }
                    // 友善的显示属于多个角色的功能
                    var roleName = string.Empty;
                    foreach (DataRow dr in result.Rows)
                    {
                        roleName = string.Empty;
                        // 获取所在角色
                        var roleIds = userManager.GetRoleIds(dr[BaseUserEntity.FieldId].ToString());
                        if (roleIds != null)
                        {
                            for (var i = 0; i < roleIds.Length; i++)
                            {
                                roleName = roleName + BaseUtil.GetProperty(dataTableRole, roleIds[i], BaseRoleEntity.FieldName) + " ";
                            }
                        }
                        // 设置角色的名称
                        if (!string.IsNullOrEmpty(roleName))
                        {
                            dr["RoleName"] = roleName;
                        }
                    }
                    result.AcceptChanges();
                }
                result.TableName = BaseUserEntity.CurrentTableName;
            });

            return(result);
        }
        /// <summary>
        /// 获取用户的件约束表达式
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="tableName">表名</param>
        /// <returns>主键</returns>
        public string GetUserConstraint(string tableName, string permissionCode = "Resource.AccessPermission")
        {
            string result = string.Empty;
            // 这里是获取用户的条件表达式
            // 1: 首先用户在哪些角色里是有效的?
            // 2: 这些角色都有哪些哪些条件约束?
            // 3: 组合约束条件?
            // 4:用户本身的约束条件?
            string permissionId = string.Empty;

            permissionId = BaseModuleManager.GetIdByCodeByCache(this.UserInfo.SystemCode, permissionCode);

            BaseUserManager manager = new BaseUserManager(this.DbHelper, this.UserInfo);

            string[] roleIds = manager.GetRoleIds(UserInfo.Id);
            if (roleIds == null || roleIds.Length == 0)
            {
                return(result);
            }
            BasePermissionScopeManager scopeManager = new BasePermissionScopeManager(this.DbHelper, this.UserInfo);

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldResourceCategory, BaseRoleEntity.TableName));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldResourceId, roleIds));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldTargetCategory, "Table"));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldTargetId, tableName));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldPermissionId, permissionId));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldEnabled, 1));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldDeletionStateCode, 0));

            DataTable dtPermissionScope    = scopeManager.GetDataTable(parameters);
            string    permissionConstraint = string.Empty;

            foreach (DataRow dr in dtPermissionScope.Rows)
            {
                permissionConstraint = dr[BasePermissionScopeEntity.FieldPermissionConstraint].ToString();
                permissionConstraint = permissionConstraint.Trim();
                if (!string.IsNullOrEmpty(permissionConstraint))
                {
                    result += " AND " + permissionConstraint;
                }
            }
            if (!string.IsNullOrEmpty(result))
            {
                result = result.Substring(5);
                // 解析替换约束表达式标准函数
                result = ConstraintUtil.PrepareParameter(this.UserInfo, result);
            }

            return(result);
        }
        /// <summary>
        /// 获取用户的角色主键数组
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <returns>主键数组</returns>
        public string[] GetUserRoleIds(BaseUserInfo userInfo, string userId)
        {
            string[] result = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var userManager = new BaseUserManager(dbHelper, userInfo);
                result          = userManager.GetRoleIds(userInfo.SystemCode, userId);
                // result = userRoleManager.GetRoleIds(userId);
            });

            return(result);
        }
Пример #5
0
        public static string[] GetRoleIdsByCache(string systemCode, string userId, string companyId = null)
        {
            // 返回值
            string[] result = null;

            if (!string.IsNullOrEmpty(userId))
            {
                string key = "User:"******":" + systemCode + ":Role";

                using (var readOnlyRedisClient = PooledRedisHelper.GetPermissionReadOnlyClient())
                {
                    HashSet <string> setItems = readOnlyRedisClient.GetAllItemsFromSet(key);
                    if (setItems.Count == 0)
                    {
                        // 找不到数据进行数据库查询
                        BaseUserManager userManager = new BaseUserManager();
                        string[]        roleIds     = userManager.GetRoleIds(systemCode, userId, companyId);

                        List <string> items = null;
                        if (roleIds.Length > 0)
                        {
                            items = new List <string>(roleIds);
                        }
                        else
                        {
                            // 2016-02-26 吉日嘎拉 这里是为了防止重复读取,数据库被拖、效率低
                            items = new List <string>(new string[] { string.Empty });
                        }
#if ReadOnlyRedis
                        using (var redisClient = PooledRedisHelper.GetPermissionClient())
                        {
                            redisClient.AddRangeToSet(key, items);
                            redisClient.ExpireEntryAt(key, DateTime.Now.AddMinutes(20));
                        }
#else
                        readOnlyRedisClient.AddRangeToSet(key, items);
                        readOnlyRedisClient.ExpireEntryAt(key, DateTime.Now.AddMinutes(20));
#endif
                    }
                    else
                    {
                        result = setItems.ToArray();
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// 获取用户角色数据列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="targetUserId">目标角色</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTableByUser(BaseUserInfo userInfo, string targetUserId)
        {
            DataTable result = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var tableName = userInfo.SystemCode + "UserRole";
                var manager   = new BaseUserManager(dbHelper, userInfo, tableName);
                var roleIds   = manager.GetRoleIds(userInfo.SystemCode, targetUserId);

                tableName        = userInfo.SystemCode + "Role";
                var roleManager  = new BaseRoleManager(dbHelper, userInfo, tableName);
                result           = roleManager.GetDataTable(BaseRoleEntity.FieldId, roleIds, BaseRoleEntity.FieldSortCode);
                result.TableName = BaseRoleEntity.CurrentTableName;
            });

            return(result);
        }
Пример #7
0
        /// <summary>
        /// 获取待审批
        /// </summary>
        /// <param name="userInfo">用户信息</param>
        /// <param name="userId">用户主键</param>
        /// <param name="categoryCode">分类代码</param>
        /// <param name="categorybillFullName">单据分类名称</param>
        /// <param name="searchValue">查询字符串</param>
        /// <returns></returns>
        public DataTable GetWaitForAudit(BaseUserInfo userInfo, string userId = null, string categoryCode = null, string categorybillFullName = null, string searchValue = null)
        {
            DataTable dt = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                //BaseUserManager userManager = new BaseUserManager(dbHelper);
                var userManager  = new BaseUserManager(dbHelper, userInfo);
                string[] roleIds = userManager.GetRoleIds(userInfo.Id);
                dbHelper.Close();
                // 这里是获取待审核信息
                dbHelper.Open(WorkFlowDbConnection);
                var workFlowCurrentManager = new BaseWorkFlowCurrentManager(dbHelper, userInfo);
                dt           = workFlowCurrentManager.GetWaitForAudit(userId, categoryCode, categorybillFullName, searchValue);
                dt.TableName = BaseWorkFlowCurrentEntity.TableName;
            });

            return(dt);
        }
Пример #8
0
        private void GetUserRoles(BaseUserInfo userInfo, IDbHelper dbHelper, DataTable dt)
        {
            string[] roleIds = null;
            // 这里是获取角色列表
            string          tableName   = userInfo.SystemCode + "Role";
            BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo, tableName);

            if (!dt.Columns.Contains("RoleName"))
            {
                dt.Columns.Add("RoleName");
            }
            // 友善的显示属于多个角色的功能
            string roleName = string.Empty;

            foreach (DataRow dr in dt.Rows)
            {
                roleName = string.Empty;
                // 获取所在角色
                var userManager = new BaseUserManager(dbHelper, userInfo);
                roleIds = userManager.GetRoleIds(dr[BaseUserEntity.FieldId].ToString());
                if (roleIds != null && roleIds.Length > 0)
                {
                    for (int i = 0; i < roleIds.Length; i++)
                    {
                        roleName = roleName + BaseRoleManager.GetRealNameByCache(userInfo.SystemCode, roleIds[i]) + ", ";
                    }
                }
                // 设置角色的名称
                if (!string.IsNullOrEmpty(roleName))
                {
                    roleName       = roleName.Substring(0, roleName.Length - 2);
                    dr["RoleName"] = roleName;
                }
            }
            dt.AcceptChanges();
        }
Пример #9
0
        /// <summary>
        /// 获取等审核信息
        /// </summary>
        /// <param name="userId">用户主键</param>
        /// <param name="categoryCode">分类代码</param>
        /// <param name="categorybillFullName"></param>
        /// <param name="searchValue">查询字符串</param>
        /// <param name="containsTheRejectedDocuments">显示退回的</param>
        /// <returns>数据表</returns>
        public DataTable GetWaitForAudit(string userId = null, string categoryCode = null, string categorybillFullName = null, string searchValue = null, bool containsTheRejectedDocuments = true)
        {
            if (string.IsNullOrEmpty(userId))
            {
                userId = this.UserInfo.Id;
            }
            string sqlQuery = "SELECT * "
                              + "   FROM " + BaseWorkFlowCurrentEntity.TableName
                              // 未被删除的,有效的数据,还没能审核结束的
                              + "  WHERE (" + BaseWorkFlowCurrentEntity.FieldDeletionStateCode + " = 0) "
                              // Enabled 0 表示,审核还没结束
                              // Enabled 1 表示,审核已经完成了
                              + "    AND (" + BaseWorkFlowCurrentEntity.FieldEnabled + " = 0) ";

            if (!containsTheRejectedDocuments)
            {
                sqlQuery += "    AND (" + BaseWorkFlowCurrentEntity.FieldAuditStatus + " != 'AuditReject') ";
            }
            if (!string.IsNullOrEmpty(userId))
            {
                // 待审核的工作流(指向用户的)
                sqlQuery += "    AND (" + BaseWorkFlowCurrentEntity.FieldToUserId + "='" + userId + "' ";
                sqlQuery += "           OR " + BaseWorkFlowCurrentEntity.FieldToUserId + " LIKE '%" + userId + "%'";
                //(指向角色的)
                BaseUserManager userManager = new BaseUserManager(this.UserInfo);
                string[]        roleIds     = userManager.GetRoleIds(userId);
                if (roleIds != null && roleIds.Length > 0)
                {
                    sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldToRoleId + " IN (" + StringUtil.ArrayToList(roleIds) + ")";
                }
                //(指向部门的)
                string[] organizeIds = userManager.GetAllOrganizeIds(userId);
                if (organizeIds != null && organizeIds.Length > 0)
                {
                    sqlQuery += " OR (" + BaseWorkFlowCurrentEntity.FieldToUserId + " IS NULL AND " + BaseWorkFlowCurrentEntity.FieldToDepartmentId + " IN (" + StringUtil.ArrayToList(organizeIds) + "))";
                }
                sqlQuery += " ) ";
            }
            if (!string.IsNullOrEmpty(categoryCode))
            {
                sqlQuery += " AND ProcessId IN (SELECT Id FROM BaseWorkFlowProcess WHERE (CategoryCode = '" + categoryCode + "')) ";
                // BaseWorkFlowBillTemplateManager templateManager = new BaseWorkFlowBillTemplateManager(this.DbHelper, this.UserInfo);
                // var result = templateManager.Search(string.Empty, categoryCode, string.Empty, null, false);
                // string categoryCodes = BaseBusinessLogic.FieldToList(result, BaseWorkFlowBillTemplateEntity.FieldCode);
                // if (!string.IsNullOrEmpty(categoryCodes))
                // {
                //    sqlQuery += " AND (BaseWorkFlowCurrent.CategoryCode IN (" + categoryCodes + ")) ";
                // }
            }
            if (!string.IsNullOrEmpty(categorybillFullName))
            {
                sqlQuery += " AND (" + BaseWorkFlowCurrentEntity.TableName + "." + BaseWorkFlowCurrentEntity.FieldCategoryFullName + " ='" + categorybillFullName + "') ";
            }

            List <IDbDataParameter> dbParameters = new List <IDbDataParameter>();

            if (!String.IsNullOrEmpty(searchValue))
            {
                searchValue = searchValue.Trim();
                sqlQuery   += " AND (" + BaseWorkFlowCurrentEntity.FieldObjectFullName + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldObjectFullName);
                sqlQuery   += " OR " + BaseWorkFlowCurrentEntity.FieldAuditUserRealName + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldAuditUserRealName);
                sqlQuery   += " OR " + BaseWorkFlowCurrentEntity.FieldAuditIdea + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldAuditIdea);
                sqlQuery   += " OR " + BaseWorkFlowCurrentEntity.FieldAuditStatusName + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldAuditStatusName);
                sqlQuery   += " OR " + BaseWorkFlowCurrentEntity.FieldToDepartmentName + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldToDepartmentName);
                sqlQuery   += " OR " + BaseWorkFlowCurrentEntity.FieldToUserRealName + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldToUserRealName) + ")";
                if (searchValue.IndexOf("%") < 0)
                {
                    searchValue = "%" + searchValue + "%";
                }
                dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldObjectFullName, searchValue));
                dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldAuditUserRealName, searchValue));
                dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldAuditIdea, searchValue));
                dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldAuditStatusName, searchValue));
                dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldToDepartmentName, searchValue));
                dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldToUserRealName, searchValue));
            }
            // 排序字段
            sqlQuery += " ORDER BY " + BaseWorkFlowCurrentEntity.FieldSendDate;
            return(DbHelper.Fill(sqlQuery, dbParameters.ToArray()));
        }
Пример #10
0
        /// <summary>
        /// 获取等审核信息
        /// </summary>
        /// <param name="userId">用户主键</param>
        /// <param name="categoryCode">分类代码</param>
        /// <param name="categorybillFullName"></param>
        /// <param name="searchValue">查询字符串</param>
        /// <param name="containsTheRejectedDocuments">显示退回的</param>
        /// <returns>数据表</returns>
        public DataTable GetWaitForAuditByPage(out int recordCount, int pageIndex = 0, int pageSize = 100, string sort = null, string direction = "ASC", string userId = null, string categoryCode = null, string categorybillFullName = null, string searchValue = null, bool containsTheRejectedDocuments = true)
        {
            if (string.IsNullOrEmpty(userId))
            {
                userId = this.UserInfo.Id;
            }
            string sqlQuery = "SELECT * "
                              + "   FROM " + BaseWorkFlowCurrentEntity.TableName
                              // 未被删除的,有效的数据,还没能审核结束的
                              + "  WHERE (" + BaseWorkFlowCurrentEntity.FieldDeletionStateCode + " = 0) "
                              // Enabled 0 表示,审核还没结束
                              // Enabled 1 表示,审核已经完成了
                              + "    AND (" + BaseWorkFlowCurrentEntity.FieldEnabled + " = 0) ";

            if (!containsTheRejectedDocuments)
            {
                sqlQuery += "    AND (" + BaseWorkFlowCurrentEntity.FieldAuditStatus + " != 'AuditReject') ";
            }
            if (!string.IsNullOrEmpty(userId))
            {
                // 待审核的工作流(指向用户的)
                sqlQuery += "    AND (" + BaseWorkFlowCurrentEntity.FieldToUserId + "='" + userId + "' ";
                sqlQuery += "           OR " + BaseWorkFlowCurrentEntity.FieldToUserId + " LIKE '%" + userId + "%'";
                //(指向角色的)
                BaseUserManager userManager = new BaseUserManager(this.UserInfo);
                string[]        roleIds     = userManager.GetRoleIds(userId);
                if (roleIds != null && roleIds.Length > 0)
                {
                    sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldToRoleId + " IN (" + StringUtil.ArrayToList(roleIds) + ")";
                }
                //(指向部门的)
                string[] organizeIds = userManager.GetAllOrganizeIds(userId);
                if (organizeIds != null && organizeIds.Length > 0)
                {
                    sqlQuery += " OR (" + BaseWorkFlowCurrentEntity.FieldToUserId + " IS NULL AND " + BaseWorkFlowCurrentEntity.FieldToDepartmentId + " IN (" + StringUtil.ArrayToList(organizeIds) + "))";
                }
                sqlQuery += " ) ";
            }
            if (!string.IsNullOrEmpty(categoryCode))
            {
                sqlQuery += " AND ProcessId IN (SELECT Id FROM BaseWorkFlowProcess WHERE (CategoryCode = '" + categoryCode + "')) ";
            }
            if (!string.IsNullOrEmpty(categorybillFullName))
            {
                sqlQuery += " AND (" + BaseWorkFlowCurrentEntity.TableName + "." + BaseWorkFlowCurrentEntity.FieldCategoryFullName + " ='" + categorybillFullName + "') ";
            }

            List <IDbDataParameter> dbParameters = new List <IDbDataParameter>();

            if (!String.IsNullOrEmpty(searchValue))
            {
                if (searchValue.IndexOf("%") < 0)
                {
                    searchValue = "%" + searchValue + "%";
                }
                sqlQuery += " AND (" + BaseWorkFlowCurrentEntity.FieldObjectFullName + " LIKE '" + searchValue + "'";
                sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldAuditUserRealName + " LIKE '" + searchValue + "'";
                sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldAuditIdea + " LIKE '" + searchValue + "'";
                sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldAuditStatusName + " LIKE '" + searchValue + "'";
                sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldToDepartmentName + " LIKE '" + searchValue + "'";
                sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldToUserRealName + " LIKE '" + searchValue + "'" + ")";
            }
            sqlQuery = string.Format("({0})", sqlQuery);
            var dt = DbLogic.GetDataTableByPage(this.dbHelper, out recordCount, sqlQuery, "*",
                                                pageIndex, pageSize, null, null, "");

            return(dt);
        }