/// <summary> /// 将用户从某些角色中移除 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userId">用户主键</param> /// <param name="removeRoleIds">角色主键数组</param> /// <returns>影响行数</returns> public int RemoveUserFromRole(BaseUserInfo userInfo, string userId, string[] removeRoleIds) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); if (removeRoleIds != null) { returnValue += userManager.RemoveFormRole(userId, removeRoleIds); } 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(returnValue); }
/// <summary> /// 撤销用户权限 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userName">用户名</param> /// <param name="permissionCode">权限编号</param> /// <returns>主键</returns> public int RevokeUserPermission(BaseUserInfo userInfo, string userName, string permissionCode) { int result = 0; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { var userManager = new BaseUserManager(dbHelper, userInfo); string userId = userManager.GetId(new KeyValuePair <string, object>(BaseUserEntity.FieldUserName, userName)); if (!String.IsNullOrEmpty(userId)) { var userPermissionManager = new BaseUserPermissionManager(dbHelper, userInfo); result = userPermissionManager.RevokeByPermissionCode(userInfo.SystemCode, userId, permissionCode); } }); return(result); }
/// <summary> /// 用户退出 /// </summary> /// <param name="openId">信令</param> /// <param name="systemCode">系统编码</param> /// <param name="ipAddress">IP地址</param> /// <param name="macAddress">MAC地址</param> /// <returns>影响行数</returns> public bool SignOut(string openId, string systemCode = "Base", string ipAddress = null, string macAddress = null) { var result = 0; // 应该进行一次日志记录 // 从缓存读取、效率高 if (!string.IsNullOrWhiteSpace(openId)) { var userEntity = BaseUserManager.GetEntityByOpenIdByCache(openId); if (userEntity != null && userEntity.Id > 0) { var ipAddressName = string.Empty; if (!string.IsNullOrEmpty(ipAddress)) { ipAddressName = IpUtil.GetInstance().FindName(ipAddress); } BaseLogonLogManager.AddLog(systemCode, userEntity, ipAddress, ipAddressName, macAddress, Status.SignOut.ToDescription(), 0, 1); // 是否更新访问日期信息 if (!BaseSystemInfo.UpdateVisit) { return(result > 0); } // 最后一次登录时间 var sql = "UPDATE " + BaseUserLogonEntity.CurrentTableName + " SET " + BaseUserLogonEntity.FieldPreviousVisitTime + " = " + BaseUserLogonEntity.FieldLastVisitTime; //Troy.Cui 2020-02-29用户退出时也强制OpenId重新生成,和登录时一样强制生成OpenId sql += " , " + BaseUserLogonEntity.FieldOpenId + " = '" + Guid.NewGuid().ToString("N") + "'"; sql += ", " + BaseUserLogonEntity.FieldOpenIdTimeoutTime + " = " + DbHelper.GetDbNow(); sql += " , " + BaseUserLogonEntity.FieldUserOnline + " = 0 " + " , " + BaseUserLogonEntity.FieldLastVisitTime + " = " + DbHelper.GetDbNow(); sql += " WHERE " + BaseUserLogonEntity.FieldUserId + " = " + DbHelper.GetParameter(BaseUserEntity.FieldId); var dbParameters = new List <IDbDataParameter> { DbHelper.MakeParameter(BaseUserEntity.FieldId, userEntity.Id) }; result = ExecuteNonQuery(sql, dbParameters.ToArray()); } } return(result > 0); }
public string GetAllRolesId() { string[] roleIds = new BaseUserManager().GetAllRoleIds(this.UserInfo.Id); string roleIdsString = null; if (roleIds.Length > 0) { foreach (var roleId in roleIds) { roleIdsString += roleId + ","; } if (!string.IsNullOrEmpty(roleIdsString)) { // 去掉末尾的"," roleIdsString = roleIdsString.TrimEnd(','); } } return(roleIdsString); }
/// <summary> /// 批量删除 /// </summary> /// <param name="userInfo">用户</param> /// <param name="ids">主键数组</param> /// <returns>影响行数</returns> public int BatchDelete(BaseUserInfo userInfo, string[] ids) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); returnValue = userManager.Delete(ids); // 用户已经被删除的员工的UserId设置为Null,说白了,是需要整理数据 userManager.CheckUserStaff(); 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(returnValue); }
/// <summary> /// 更新用户 /// </summary> /// <param name="userInfo">用户信息</param> /// <param name="userEntity">用户实体</param> /// <param name="statusCode">状态码</param> /// <param name="statusMessage">状态信息</param> /// <returns>影响行数</returns> public int UpdateUser(BaseUserInfo userInfo, BaseUserEntity userEntity, out string statusCode, out string statusMessage) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); // 调用方法,并且返回运行结果 returnValue = userManager.Update(userEntity, out statusCode); statusMessage = userManager.GetStateMessage(statusCode); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.UserService_UpdateUser, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(returnValue); }
/// <summary> /// 添加用户 /// </summary> /// <param name="dbHelper">数据库连接</param> /// <param name="userInfo">用户信息</param> /// <param name="userEntity">用户实体</param> /// <param name="statusCode">状态码</param> /// <param name="statusMessage">状态信息</param> /// <returns>主键</returns> public string AddUser(IDbHelper dbHelper, BaseUserInfo userInfo, BaseUserEntity userEntity, out string statusCode, out string statusMessage) { // 加强安全验证防止未授权匿名调用 #if (!DEBUG) BaseSystemInfo.IsAuthorized(userInfo); #endif string returnValue = string.Empty; BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); // 若是系统需要用加密的密码,这里需要加密密码。 if (BaseSystemInfo.ServerEncryptPassword) { userEntity.UserPassword = userManager.EncryptUserPassword(userEntity.UserPassword); // 安全通讯密码、交易密码也生成好 userEntity.CommunicationPassword = userManager.EncryptUserPassword(userEntity.CommunicationPassword); } returnValue = userManager.Add(userEntity, out statusCode); statusMessage = userManager.GetStateMessage(statusCode); // 自己不用给自己发提示信息,这个提示信息是为了提高工作效率的,还是需要审核通过的,否则垃圾信息太多了 if (userEntity.Enabled == 0 && statusCode.Equals(StatusCode.OKAdd.ToString())) { // 不是系统管理员添加 if (!userInfo.IsAdministrator) { // 给超级管理员群组发信息 BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo); string[] roleIds = roleManager.GetIds(new KeyValuePair <string, object>(BaseRoleEntity.FieldCode, "Administrators")); string[] userIds = userManager.GetIds(new KeyValuePair <string, object>(BaseUserEntity.FieldCode, "Administrator")); // 发送请求审核的信息 BaseMessageEntity messageEntity = new BaseMessageEntity(); messageEntity.FunctionCode = MessageFunction.WaitForAudit.ToString(); // Pcsky 2012.05.04 显示申请的用户名 messageEntity.Contents = userInfo.RealName + "(" + userInfo.IPAddress + ")" + AppMessage.UserService_Application + userEntity.UserName + AppMessage.UserService_Check; //messageEntity.Contents = userInfo.RealName + "(" + userInfo.IPAddress + ")" + AppMessage.UserService_Application + userEntity.RealName + AppMessage.UserService_Check; BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo); messageManager.BatchSend(userIds, null, roleIds, messageEntity, false); } } return(returnValue); }
/// <summary> /// 按角色获取用户列表 /// </summary> /// <param name="userInfo">用户</param> /// <param name="roleId">角色主键</param> /// <returns>数据表</returns> public string[] GetUserByRole(BaseUserInfo userInfo, string roleId) { string[] result = null; var dt = new DataTable(BaseUserEntity.TableName); var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { var userManager = new BaseUserManager(dbHelper, userInfo); string sqlQuery = "SELECT " + BaseUserEntity.FieldId + "," + BaseUserEntity.FieldRealName + " FROM " + BaseUserEntity.TableName; sqlQuery += " WHERE (" + BaseUserEntity.TableName + "." + BaseUserEntity.FieldDeletionStateCode + " = 0 " + " AND " + BaseUserEntity.TableName + "." + BaseUserEntity.FieldEnabled + " = 1 " + " AND " + BaseUserEntity.TableName + "." + BaseUserEntity.FieldIsVisible + " = 1 ) "; if (!String.IsNullOrEmpty(roleId)) { // 从用户读取用户 sqlQuery += " AND " + BaseUserEntity.FieldId + " IN (" + "SELECT " + BaseUserRoleEntity.FieldUserId + " FROM " + BaseUserRoleEntity.TableName + " WHERE " + BaseUserRoleEntity.TableName + "." + BaseUserRoleEntity.FieldDeletionStateCode + " = 0 " + " AND " + BaseUserRoleEntity.TableName + "." + BaseUserRoleEntity.FieldEnabled + " = 1 " + " AND " + BaseUserRoleEntity.TableName + "." + BaseUserRoleEntity.FieldRoleId + " = '" + roleId + "') "; } sqlQuery += " ORDER BY " + BaseUserEntity.TableName + "." + BaseUserEntity.FieldSortCode; dt = userManager.Fill(sqlQuery); dt.TableName = BaseUserEntity.TableName; List <string> list = new List <string>(); foreach (DataRow dr in dt.Rows) { list.Add(dr[BaseUserEntity.FieldId].ToString() + "=" + dr[BaseUserEntity.FieldRealName].ToString()); } result = list.ToArray(); }); return(result); }
/// <summary> /// 按角色获取用户列表 /// </summary> /// <param name="userInfo">用户</param> /// <returns>数据权限</returns> public DataTable GetDataTableByRole(BaseUserInfo userInfo, string roleId) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif DataTable dataTable = new DataTable(BaseStaffEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); // 获取允许登录列表 dataTable = userManager.GetDataTableByRole(roleId); dataTable.TableName = BaseUserEntity.TableName; BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.UserService_GetDataTableByRole, 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="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); }
/// <summary> /// 给用户权限 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userName">用户名</param> /// <param name="permissionCode">权限编号</param> /// <returns>主键</returns> public string GrantUserPermission(BaseUserInfo userInfo, string userName, string permissionCode) { var result = string.Empty; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (ServiceUtil.ProcessFun)((dbHelper) => { var userManager = new BaseUserManager(dbHelper, userInfo); var userId = userManager.GetId(new KeyValuePair <string, object>(BaseUserEntity.FieldUserName, userName)); if (ValidateUtil.IsInt(userId)) { var userPermissionManager = new BasePermissionManager((IDbHelper)dbHelper, (BaseUserInfo)userInfo); result = userPermissionManager.GrantByPermissionCode(userInfo.SystemCode, userId, permissionCode); } })); return(result); }
/// <summary> /// 登录 /// </summary> /// <param name="taskId">任务标识</param> /// <param name="userInfo">用户</param> /// <param name="nickName">昵称</param> /// <param name="password">密码</param> /// <param name="openId">单点登录标识</param> /// <returns>登录实体类</returns> public UserLogonResult LogonByNickName(string taskId, BaseUserInfo userInfo, string nickName, string password, string openId) { var result = new UserLogonResult(); var parameter = ServiceInfo.Create(taskId, userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { // 先侦测是否在线 // userLogonManager.CheckOnline(); // 再进行登录 var userManager = new BaseUserManager(userInfo) { CheckIsAdministrator = true }; result = userManager.LogonByNickName(nickName, password, openId, userInfo.SystemCode); }); return(result); }
/// <summary> /// 清除角色权限 /// /// 1.清除角色的用户归属。 /// 2.清除角色的模块权限。 /// 3.清除角色的操作权限。 /// </summary> /// <param name="userInfo">用户</param> /// <param name="id">主键</param> /// <returns>数据表</returns> public int ClearRolePermission(BaseUserInfo userInfo, string id) { var result = 0; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { var userManager = new BaseUserManager(dbHelper, userInfo); result += userManager.ClearUser(userInfo.SystemCode, id); var rolePermissionManager = new BasePermissionManager(dbHelper, userInfo); result += rolePermissionManager.RevokeRoleAll(userInfo.SystemCode, id); var roleScopeManager = new BaseRoleScopeManager(dbHelper, userInfo); result += roleScopeManager.RevokeAll(userInfo.SystemCode, id); }); return(result); }
/// <summary> /// 缓存预热,强制重新缓存 /// </summary> /// <returns>影响行数</returns> public static int CachePreheating() { int result = 0; // 把所有的数据都缓存起来的代码 BaseUserManager manager = new BaseUserManager(); using (IDataReader dataReader = manager.ExecuteReader(0, BaseUserEntity.FieldId)) { while (dataReader.Read()) { BaseUserEntity entity = BaseEntity.Create <BaseUserEntity>(dataReader, false); BaseUserManager.SetCache(entity); result++; } dataReader.Close(); } return(result); }
/// <summary> /// 激活帐户 /// </summary> /// <param name="openId">唯一识别码</param> /// <param name="statusCode">返回状态码</param> /// <returns>用户实体</returns> public BaseUserInfo AccountActivation(string openId, out string statusCode) { // 1.用户是否存在? BaseUserInfo userInfo = null; // 用户没有找到状态 statusCode = StatusCode.UserNotFound.ToString(); // 检查是否有效的合法的参数 if (!String.IsNullOrEmpty(openId)) { BaseUserManager userManager = new BaseUserManager(DbHelper); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldOpenId, openId)); parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0)); DataTable dataTable = userManager.GetDataTable(parameters); if (dataTable.Rows.Count == 1) { BaseUserEntity userEntity = new BaseUserEntity(dataTable); // 3.用户是否被锁定? if (userEntity.Enabled == 0) { statusCode = StatusCode.UserLocked.ToString(); return(userInfo); } if (userEntity.Enabled == 1) { // 2.用户是否已经被激活? statusCode = StatusCode.UserIsActivate.ToString(); return(userInfo); } if (userEntity.Enabled == -1) { // 4.成功激活用户 statusCode = StatusCode.OK.ToString(); userManager.SetProperty(new KeyValuePair <string, object>(BaseUserEntity.FieldId, userEntity.Id), new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1)); return(userInfo); } } } return(userInfo); }
/// <summary> /// 验证用户数字签名密码 /// </summary> /// <param name="userInfo">用户</param> /// <param name="signedPassword">验证数字签名密码</param> /// <param name="ipAddress">IP地址</param> /// <param name="statusCode">返回状态码</param> /// <param name="statusMessage">返回状消息</param> /// <returns>是否正确</returns> public bool SignedPassword(BaseUserInfo userInfo, string signedPassword) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif bool returnValue = false; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); returnValue = userManager.SignedPassword(signedPassword); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.LogOnService_SignedPassword, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(returnValue); }
/// <summary> /// 激活帐户 /// </summary> /// <param name="openId">唯一识别码</param> /// <returns>用户实体</returns> public BaseUserInfo AccountActivation(string openId) { // 1.用户是否存在? BaseUserInfo userInfo = null; // 用户没有找到状态 this.StatusCode = Status.UserNotFound.ToString(); // 检查是否有效的合法的参数 if (!String.IsNullOrEmpty(openId)) { BaseUserManager manager = new BaseUserManager(DbHelper); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); // parameters.Add(new KeyValuePair<string, object>(BaseUserEntity.FieldOpenId, openId)); parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0)); var dt = manager.GetDataTable(parameters); if (dt.Rows.Count == 1) { BaseUserEntity entity = BaseEntity.Create <BaseUserEntity>(dt); // 3.用户是否被锁定? if (entity.Enabled == 0) { this.StatusCode = Status.UserLocked.ToString(); return(userInfo); } if (entity.Enabled == 1) { // 2.用户是否已经被激活? this.StatusCode = Status.UserIsActivate.ToString(); return(userInfo); } if (entity.Enabled == -1) { // 4.成功激活用户 this.StatusCode = Status.OK.ToString(); manager.SetProperty(new KeyValuePair <string, object>(BaseUserEntity.FieldId, entity.Id), new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1)); return(userInfo); } } } return(userInfo); }
/// <summary> /// 检查在线状态 /// </summary> /// <param name="userInfo">用户</param> /// <param name="onLineState">用户在线状态</param> /// <returns>离线人数</returns> public int CheckOnLine(BaseUserInfo userInfo, int onLineState) { // 写入调试信息 #if (DEBUG) // int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper); // 设置为在线状态 userManager.OnLine(userInfo.Id, onLineState); returnValue = userManager.CheckOnLine(); } catch (Exception ex) { LogUtil.WriteException(ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) // BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(returnValue); }
/// <summary> /// 批量设置默认角色 /// </summary> /// <param name="userInfo"></param> /// <param name="userIds"></param> /// <param name="roleId"></param> /// <returns>影响行数</returns> public int BatchSetDefaultRole(BaseUserInfo userInfo, string[] userIds, string roleId) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); returnValue = userManager.SetProperty(userIds, new KeyValuePair <string, object>(BaseUserEntity.FieldRoleId, roleId)); 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(returnValue); }
////////////////////////////////////////////////////////////////////////////////////////////////////// /// 用户权限判断相关(需要实现对外调用) ////////////////////////////////////////////////////////////////////////////////////////////////////// #region public bool IsInRole(BaseUserInfo userInfo, string userId, string roleName) /// <summary> /// 用户是否在指定的角色里 /// </summary> /// <param name="userInfo">用户</param> /// <param name="UserId">用户主键</param> /// <param name="roleName">角色名称</param> /// <returns>在角色里</returns> public bool IsInRole(BaseUserInfo userInfo, string userId, string roleName) { bool result = false; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { // 先获得角色主键 string tableName = userInfo.SystemCode + "Role"; var roleManager = new BaseRoleManager(dbHelper, userInfo, tableName); string roleCode = roleManager.GetProperty(new KeyValuePair <string, object>(BaseRoleEntity.FieldRealName, roleName), BaseRoleEntity.FieldCode); // 判断用户的默认角色 if (!string.IsNullOrEmpty(roleCode)) { var userManager = new BaseUserManager(dbHelper, userInfo); result = userManager.IsInRoleByCode(userId, roleCode); } }); return(result); }
public static BaseUserEntity GetObjectByNickNameByCache(BaseUserInfo userInfo, string nickName) { BaseUserEntity result = null; if (string.IsNullOrEmpty(nickName)) { return(result); } string key = "User:ByNickName:" + nickName.ToLower(); result = BaseUserManager.GetObjectByNickNameByCache(key); // 远程通过接口获取数据 if (result == null) { result = GetObjectByNickName(userInfo, nickName); } return(result); }
/// <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); }
/// <summary> /// 获取参数列表 /// </summary> /// <param name="userInfo">用户</param> /// <param name="categoryCode">分类编号</param> /// <param name="parameterId">参数主键</param> /// <returns>数据表</returns> public DataTable GetDataTableByParameter(BaseUserInfo userInfo, string categoryCode, string parameterId) { var result = new DataTable(BaseParameterEntity.CurrentTableName); var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { var manager = new BaseParameterManager(dbHelper, userInfo); result = manager.GetDataTableByParameter(categoryCode, parameterId); result.TableName = BaseParameterEntity.CurrentTableName; // 2015-12-21 吉日嘎拉,这里重新设置mac缓存,删除掉缓存。 if (categoryCode.Equals("MacAddress")) { BaseUserManager.ResetMacAddressByCache(parameterId); } }); return(result); }
/// <summary> /// 获取用户实体 /// </summary> /// <param name="userInfo">用户</param> /// <param name="id">主键</param> /// <returns>实体</returns> public BaseUserEntity GetEntity(BaseUserInfo userInfo, string id) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif BaseUserEntity userEntity = null; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); userEntity = userManager.GetEntity(id); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.UserService_GetEntity, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(userEntity); }
/// <summary> /// 获得用户列表 /// </summary> /// <param name="taskId">任务标识</param> /// <param name="userInfo">用户</param> /// <returns>数据表</returns> public DataTable GetUserDT(string taskId, BaseUserInfo userInfo) { var result = new DataTable(BaseUserEntity.TableName); var parameter = ServiceInfo.Create(taskId, userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { // 检查用户在线状态(服务器专用) BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(); userLogOnManager.CheckOnLine(); var userManager = new BaseUserManager(dbHelper, userInfo); // 获取允许登录列表 List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDeletionStateCode, 0)); result = userManager.GetDataTable(parameters, BaseUserEntity.FieldSortCode); result.TableName = BaseUserEntity.TableName; }); return(result); }
/// <summary> /// 用户名是否重复 /// </summary> /// <param name="userInfo">用户</param> /// <param name="parameters">字段名,字段值</param> /// <returns>已存在</returns> public bool Exists(BaseUserInfo userInfo, List <KeyValuePair <string, object> > parameters) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif bool returnValue = false; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper); returnValue = userManager.Exists(parameters); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(returnValue); }
/// <summary> /// 清除用户权限 /// /// 1.清除用户的角色归属。 /// 2.清除用户的模块权限。 /// 3.清除用户的操作权限。 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userId">用户主键</param> /// <returns>数据表</returns> public int ClearUserPermission(BaseUserInfo userInfo, string userId) { var result = 0; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (ServiceUtil.ProcessFun)((dbHelper) => { var systemCode = userInfo.SystemCode; var userManager = new BaseUserManager(dbHelper, userInfo); result += userManager.ClearRole(systemCode, userId); var userPermissionManager = new BasePermissionManager((IDbHelper)dbHelper, (BaseUserInfo)userInfo); result += userPermissionManager.RevokeUserAll(systemCode, userId); var userPermissionScopeManager = new BaseUserScopeManager(dbHelper, userInfo); result += userPermissionScopeManager.RevokeAll(systemCode, userId); })); return(result); }
/// <summary> /// 缓存预热,强制重新缓存 /// </summary> /// <returns>影响行数</returns> public static int CachePreheating() { var result = 0; // 把所有的数据都缓存起来的代码 var manager = new BaseUserManager(); var dataReader = manager.ExecuteReader(0, BaseUserEntity.FieldId); if (dataReader != null && !dataReader.IsClosed) { while (dataReader.Read()) { var entity = BaseEntity.Create <BaseUserEntity>(dataReader, false); SetCache(entity); result++; } dataReader.Close(); } return(result); }
/// <summary> /// 为了提高授权的运行速度 /// </summary> /// <param name="systemCode">系统编号</param> /// <param name="userId">用户主键</param> /// <param name="roleId">角色主键</param> /// <param name="enabled">有效状态</param> /// <returns>主键</returns> public string AddToRoleById(string systemCode, string userId, string roleId, bool enabled = true) { string result = string.Empty; if (string.IsNullOrEmpty(systemCode)) { systemCode = "Base"; } string tableName = string.Empty; if (!string.IsNullOrEmpty(userId) && !string.IsNullOrEmpty(roleId)) { BaseUserRoleEntity entity = new BaseUserRoleEntity(); entity.UserId = userId; entity.RoleId = roleId; entity.Enabled = enabled ? 1 : 0; entity.DeletionStateCode = 0; // 2016-03-02 吉日嘎拉 增加按公司可以区别数据的功能。 if (this.DbHelper.CurrentDbType == CurrentDbType.MySql) { entity.CompanyId = BaseUserManager.GetCompanyIdByCache(userId); } // 2015-12-05 吉日嘎拉 把修改人记录起来,若是新增加的 if (this.UserInfo != null) { entity.CreateUserId = this.UserInfo.Id; entity.CreateBy = this.UserInfo.RealName; entity.CreateOn = System.DateTime.Now; entity.ModifiedUserId = this.UserInfo.Id; entity.ModifiedBy = this.UserInfo.RealName; entity.ModifiedOn = System.DateTime.Now; } tableName = systemCode + "UserRole"; BaseUserRoleManager manager = new BaseUserRoleManager(this.DbHelper, this.UserInfo, tableName); result = manager.Add(entity); } return(result); }
public string[] GetUserIds(string[] organizeIds, string[] roleIds) { // 要注意不能重复发信息,只能发一次。 string[] companyUsers = null; // 按公司查找用户 string[] departmentUsers = null; // 按部门查找用户 string[] workgroupUsers = null; // 按工作组查找用户 if (organizeIds != null) { // 这里获得的是用户主键,不是员工主键 companyUsers = this.GetProperties(BaseUserEntity.FieldCompanyId, organizeIds, BaseUserEntity.FieldId); departmentUsers = this.GetProperties(BaseUserEntity.FieldDepartmentId, organizeIds, BaseUserEntity.FieldId); workgroupUsers = this.GetProperties(BaseUserEntity.FieldWorkgroupId, organizeIds, BaseUserEntity.FieldId); } string[] roleUsers = null; if (roleIds != null) { BaseUserManager userManager = new BaseUserManager(DbHelper); roleUsers = userManager.GetUserIds(roleIds); } string[] userIds = StringUtil.Concat(companyUsers, departmentUsers, workgroupUsers, roleUsers); return(userIds); }