/// <summary> /// 获取用户的新信息 /// </summary> /// <param name="userInfo">用户</param> /// <param name="openId">单点登录标识</param> /// <returns>数据表</returns> public DataTable GetDataTableNew(BaseUserInfo userInfo, out string openId) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif openId = userInfo.OpenId; DataTable dataTable = new DataTable(BaseMessageEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); if (!BaseSystemInfo.CheckOnLine) { BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); openId = userManager.GetProperty(userInfo.Id, BaseUserEntity.FieldOpenId); } if (userInfo.OpenId.Equals(openId)) { BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); dataTable = messageManager.GetDataTableNew(); dataTable.TableName = BaseMessageEntity.TableName; } // BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, "获取用户的新信息", MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return dataTable; }
/// <summary> /// 获得用户的某个权限范围资源主键数组 /// </summary> /// <param name="userId">用户</param> /// <param name="targetCategory">资源分类</param> /// <param name="permissionItemCode">权限编号</param> /// <returns>主键数组</returns> public string[] GetResourceScopeIds(string userId, string targetCategory, string permissionItemCode) { string tableName = BasePermissionItemEntity.TableName; if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode)) { tableName = BaseSystemInfo.SystemCode + "PermissionItem"; } BasePermissionItemManager permissionItemManager = new BasePermissionItemManager(DbHelper, UserInfo, tableName); string permissionItemId = permissionItemManager.GetId(new KeyValuePair<string, object>(BasePermissionItemEntity.FieldCode, permissionItemCode)); BaseUserManager userManager = new BaseUserManager(DbHelper, UserInfo); string defaultRoleId = userManager.GetProperty(userId, BaseUserEntity.FieldRoleId); tableName = BaseUserRoleEntity.TableName; if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode)) { tableName = BaseSystemInfo.SystemCode + "UserRole"; } this.CurrentTableName = "BasePermissionScope"; if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode)) { this.CurrentTableName = BaseSystemInfo.SystemCode + "PermissionScope"; } string sqlQuery = string.Empty; sqlQuery = // 用户的权限 " SELECT TargetId " + " FROM " + this.CurrentTableName + " WHERE (" + this.CurrentTableName + ".ResourceCategory = '" + BaseUserEntity.TableName + "') " + " AND (ResourceId = '" + userId + "') " + " AND (TargetCategory = '" + targetCategory + "') " + " AND (PermissionId = '" + permissionItemId + "') " + " AND (Enabled = 1) " + " AND (DeletionStateCode = 0)" + " UNION " // 用户归属的角色的权限 + " SELECT TargetId " + " FROM " + this.CurrentTableName + " WHERE (ResourceCategory = '" + BaseRoleEntity.TableName + "') " + " AND (TargetCategory = '" + targetCategory + "') " + " AND (PermissionId = '" + permissionItemId + "') " + " AND (DeletionStateCode = 0)" + " AND (Enabled = 1) " + " AND ((ResourceId IN ( " + " SELECT RoleId " + " FROM " + tableName + " WHERE (UserId = '" + userId + "') " + " AND (Enabled = 1) " + " AND (DeletionStateCode = 0) ) "; if (!string.IsNullOrEmpty(defaultRoleId)) { // 用户的默认角色 sqlQuery += " OR (ResourceId = '" + defaultRoleId + "')"; } sqlQuery += " ) " + " ) "; DataTable dataTable = DbHelper.Fill(sqlQuery); string[] resourceIds = BaseBusinessLogic.FieldToArray(dataTable, BasePermissionScopeEntity.FieldTargetId); // 按部门获取权限 if (BaseSystemInfo.UseOrganizePermission) { sqlQuery = string.Empty; BaseUserEntity userEntity = new BaseUserManager(this.DbHelper).GetEntity(userId); sqlQuery = " SELECT TargetId " + " FROM " + this.CurrentTableName + " WHERE (" + this.CurrentTableName + ".ResourceCategory = '" + BaseOrganizeEntity.TableName + "') " + " AND (ResourceId = '" + userEntity.CompanyId + "' OR " + " ResourceId = '" + userEntity.DepartmentId + "' OR " + " ResourceId = '" + userEntity.SubCompanyId + "' OR" + " ResourceId = '" + userEntity.WorkgroupId + "') " + " AND (TargetCategory = '" + targetCategory + "') " + " AND (PermissionId = '" + permissionItemId + "') " + " AND (Enabled = 1) " + " AND (DeletionStateCode = 0)"; dataTable = DbHelper.Fill(sqlQuery); string[] resourceIdsByOrganize = BaseBusinessLogic.FieldToArray(dataTable, BasePermissionScopeEntity.FieldTargetId); resourceIds = StringUtil.Concat(resourceIds, resourceIdsByOrganize); } if (targetCategory.Equals(BaseOrganizeEntity.TableName)) { TransformPermissionScope(userId, ref resourceIds, userManager); } return resourceIds; }