/// <summary> /// 解锁指定用户 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userName">登录名(用户名)</param> /// <returns>大于0解锁成功</returns> public int UnLockUser(UserInfo userInfo, string userName) { var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.LogOnService_UnLockUser); int result = 0; ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider => { var manager = new PiUserManager(userInfo); var parameters = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(PiUserTable.FieldUserName, userName), new KeyValuePair <string, object>(PiUserTable.FieldEnabled, 1), new KeyValuePair <string, object>(PiUserTable.FieldDeleteMark, 0) }; var entity = BaseEntity.Create <PiUserEntity>(manager.GetDT(parameters, 0, null)); if ((entity != null) && !string.IsNullOrEmpty(entity.Id)) { var longOnmanager = new PiUserLogOnManager(); PiUserLogOnEntity lonOnentity = longOnmanager.GetEntity(entity.Id); lonOnentity.LockStartDate = null; lonOnentity.LockEndDate = null; result = longOnmanager.Update(lonOnentity); } }); return(result); }
/// <summary> /// 用户离职 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userName">离职人员用户名</param> /// <param name="dimissionCause">离职原因</param> /// <param name="dimissionDate">离职日期</param> /// <param name="dimissionWhither">离职去向</param> /// <returns>大于0操作成功</returns> public int UserDimission(UserInfo userInfo, string userName, string dimissionCause, DateTime?dimissionDate, string dimissionWhither = null) { var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.LogOnService_UserDimission); int result = 0; ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider => { var manager = new PiUserManager(userInfo); var parameters = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(PiUserTable.FieldUserName, userName), new KeyValuePair <string, object>(PiUserTable.FieldEnabled, 1), new KeyValuePair <string, object>(PiUserTable.FieldDeleteMark, 0) }; var entity = BaseEntity.Create <PiUserEntity>(manager.GetDT(parameters, 0, null)); if ((entity != null) && !string.IsNullOrEmpty(entity.Id)) { entity.Enabled = 0; entity.IsDimission = 1; entity.DimissionCause = dimissionCause; entity.DimissionWhither = dimissionWhither; entity.DimissionDate = dimissionDate ?? DateTime.Now; result = manager.Update(entity); //离职的员工就不能登录系统了,应该锁定了 var longOnmanager = new PiUserLogOnManager(); PiUserLogOnEntity lonOnentity = longOnmanager.GetEntity(entity.Id); lonOnentity.LockStartDate = DateTime.Now; result += longOnmanager.Update(lonOnentity); } }); return(result); }
/// <summary> /// 按主键获取用户列表 /// </summary> /// <param name="userInfo">用户</param> /// <param name="ids">主键数组</param> /// <returns>数据表</returns> public DataTable GetDTByIds(UserInfo userInfo, string[] ids) { var dataTable = new DataTable(PiUserTable.TableName); var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.UserService_GetDTByIds); ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider => { var userManager = new PiUserManager(dbProvider, userInfo); dataTable = userManager.GetDT(PiUserTable.FieldId, ids, PiUserTable.FieldSortCode); dataTable.TableName = PiUserTable.TableName; }); return(dataTable); }
/// <summary> /// 获得内部员工列表 /// </summary> /// <param name="userInfo">用户</param> /// <returns>数据表</returns> public DataTable GetStaffUserDT(UserInfo userInfo) { var dataTable = new DataTable(PiStaffTable.TableName); var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.LogOnService_GetStaffUserDT); ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider => { // 检查用户在线状态(服务器专用) var userManager = new PiUserManager(dbProvider); userLogOnManager.CheckOnLine(); // 获取允许登录列表 string[] names = { PiUserTable.FieldEnabled, PiUserTable.FieldDeleteMark, PiUserTable.FieldIsStaff }; Object[] values = { 1, 0, 1 }; dataTable = userManager.GetDT(names, values, PiStaffTable.FieldSortCode); dataTable.TableName = PiUserTable.TableName; }); return(dataTable); }
/// <summary> /// 按组织机构获取角色列表 /// </summary> /// <param name="userInfo">用户</param> /// <param name="organizeId">组织机构主键</param> /// <param name="showUser">显示用户</param> /// <returns>角色列表</returns> public DataTable GetDTByOrganize(UserInfo userInfo, string organizeId, bool showUser = true) { var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.RoleService_GetDTByOrganize); var dtRole = new DataTable(PiRoleTable.TableName); ServiceUtil.ProcessRDIReadDb(userInfo, parameter, (dbProvider) => { // 获得角色列表 var manager = new PiRoleManager(dbProvider, userInfo); dtRole = manager.GetDTByOrganize(organizeId); PiUserManager userManager = new PiUserManager(dbProvider, userInfo); if (showUser) { DataTable dataTableUser = userManager.GetDT(); if (!dtRole.Columns.Contains("Users")) { dtRole.Columns.Add("Users"); } // 友善的显示属于多个角色的功能 string userName = string.Empty; foreach (DataRow dr in dtRole.Rows) { userName = string.Empty; // 获取所在用户 string[] userIds = userManager.GetUserIdsInRole(dr[PiRoleTable.FieldId].ToString()); if (userIds != null) { userName = userIds.Aggregate(userName, (current, t) => current + BusinessLogic.GetProperty(dataTableUser, t, PiRoleTable.FieldRealName) + ", "); } if (!string.IsNullOrEmpty(userName)) { userName = userName.Substring(0, userName.Length - 2); // 设置用户的名称 dr["Users"] = userName; } } dtRole.AcceptChanges(); } dtRole.TableName = PiRoleTable.TableName; }); return(dtRole); }
/// <summary> /// 按部门获取用户列表 /// </summary> /// <param name="userInfo">用户</param> /// <param name="departmentId">部门主键</param> /// <param name="containChildren">含子部门</param> /// <returns>数据表</returns> public DataTable GetDTByDepartment(UserInfo userInfo, string departmentId, bool containChildren) { var dataTable = new DataTable(PiUserTable.TableName); var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.UserService_GetDTByDepartment); ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider => { var userManager = new PiUserManager(dbProvider, userInfo); if (string.IsNullOrEmpty(departmentId)) { dataTable = userManager.GetDT(PiUserTable.FieldDeleteMark, 0, PiUserTable.FieldSortCode); } else { dataTable = containChildren? userManager.GetChildrenUsers(departmentId) : userManager.GetDTByDepartment(departmentId); } dataTable.TableName = PiUserTable.TableName; }); return(dataTable); }
/// <summary> /// 激活帐户 /// </summary> /// <param name="openId">唯一识别码</param> /// <param name="statusCode">返回状态码</param> /// <returns>用户实体</returns> public UserInfo AccountActivation(string openId, out string statusCode) { // 1.用户是否存在? UserInfo userInfo = null; // 用户没有找到状态 statusCode = StatusCode.UserNotFound.ToString(); // 检查是否有效的合法的参数 if (!String.IsNullOrEmpty(openId)) { PiUserManager userManager = new PiUserManager(DBProvider); // DataTable dataTable = userManager.GetDT(PiUserTable.FieldOpenId, openId, PiUserTable.FieldDeleteMark, 0); DataTable dataTable = userManager.GetDT(PiUserTable.FieldDeleteMark, 0); if (dataTable.Rows.Count == 1) { //PiUserEntity userEntity = new PiUserEntity(dataTable); PiUserEntity userEntity = BaseEntity.Create <PiUserEntity>(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(PiUserTable.FieldId, userEntity.Id, PiUserTable.FieldEnabled, 1); return(userInfo); } } } return(userInfo); }
/// <summary> /// 得到指定部门包含的用户列表 /// </summary> /// <param name="userInfo">当前用户</param> /// <param name="departmentId">部门主键</param> /// <param name="containChildren">是否包含子部门</param> /// <returns>数据表</returns> public DataTable GetDepartmentUser(UserInfo userInfo, string departmentId, bool containChildren) { var result = new DataTable(PiUserTable.TableName); var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.UserService_GetDepartmentUser); ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider => { var manager = new PiUserManager(dbProvider, userInfo); if (string.IsNullOrEmpty(departmentId)) { result = manager.GetDT(new KeyValuePair <string, object>(PiUserTable.FieldDeleteMark, 0), 200, PiUserTable.FieldSortCode); } else if (containChildren) { result = manager.GetChildrenUsers(departmentId); } else { result = manager.GetDataTableByDepartment(departmentId); } }); return(result); }