/// <summary> /// 修改用户信息 /// </summary> /// <param name="userEntity">实体对象</param> public void UpdateEntity(UserEntity userEntity) { Base_User moudle = Base_User.SingleOrDefault("where UserId=@0", userEntity.UserId); moudle = EntityConvertTools.CopyToModel <UserEntity, Base_User>(userEntity, moudle); moudle.Update(); }
/// <summary> /// 修改用户状态 /// </summary> /// <param name="keyValue">主键值</param> /// <param name="State">状态:1-启动;0-禁用</param> public void UpdateState(string keyValue, int State) { UserEntity userEntity = new UserEntity(); userEntity.Modify(keyValue); userEntity.EnabledMark = State; Base_User user = Base_User.SingleOrDefault("where UserId=@0", keyValue); user = EntityConvertTools.CopyToModel <UserEntity, Base_User>(userEntity, user); user.UserId = keyValue; user.Update(); }
/// <summary> /// 修改用户登录密码 /// </summary> /// <param name="keyValue">主键值</param> /// <param name="Password">新密码(MD5 小写)</param> public void RevisePassword(string keyValue, string Password) { UserEntity userEntity = new UserEntity(); userEntity.UserId = keyValue; userEntity.Secretkey = Md5Helper.MD5(CommonHelper.CreateNo(), 16).ToLower(); userEntity.Password = Md5Helper.MD5(DESEncrypt.Encrypt(Password, userEntity.Secretkey).ToLower(), 32).ToLower(); Base_User user = Base_User.SingleOrDefault("where UserId=@0", keyValue); user = EntityConvertTools.CopyToModel <UserEntity, Base_User>(userEntity, user); user.UserId = keyValue; user.Update(); }
/// <summary> /// 保存用户表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="userEntity">用户实体</param> /// <returns></returns> public string SaveForm(string keyValue, UserEntity userEntity) { try { using (var tran = QSDMS_SQLDB.GetInstance().GetTransaction()) { #region 基本信息 if (!string.IsNullOrEmpty(keyValue)) { userEntity.Modify(keyValue); userEntity.Password = null; Base_User model = Base_User.SingleOrDefault("where UserId=@0", keyValue); model = EntityConvertTools.CopyToModel <UserEntity, Base_User>(userEntity, model); model.UserId = keyValue; model.Update(); } else { userEntity.Create(); keyValue = userEntity.UserId; userEntity.Secretkey = Md5Helper.MD5(CommonHelper.CreateNo(), 16).ToLower(); userEntity.Password = Md5Helper.MD5(DESEncrypt.Encrypt(userEntity.Password, userEntity.Secretkey).ToLower(), 32).ToLower(); userEntity.EnabledMark = 1; userEntity.DeleteMark = 0; Base_User model = EntityConvertTools.CopyToModel <UserEntity, Base_User>(userEntity, null); model.Insert(); } #endregion #region 默认添加 角色、岗位、职位 Base_UserRelation.Delete("where UserId=@0 and IsDefault=1", userEntity.UserId); List <UserRelationEntity> userRelationEntitys = new List <UserRelationEntity>(); //角色 这里多个角色逻辑处理 //if (!string.IsNullOrEmpty(userEntity.RoleId)) //{ // userRelationEntitys.Add(new UserRelationEntity // { // Category = (int)QSDMS.Model.Enums.UserCategoryEnum.角色, // UserRelationId = Guid.NewGuid().ToString(), // UserId = userEntity.UserId, // ObjectId = userEntity.RoleId, // CreateDate = DateTime.Now, // CreateUserId = OperatorProvider.Provider.Current().UserId, // CreateUserName = OperatorProvider.Provider.Current().UserName, // IsDefault = 1, // }); //} //一个用户多个角色 if (!string.IsNullOrEmpty(userEntity.RoleId)) { Base_UserRole.Delete("where UserId=@0", userEntity.UserId); string[] roles = userEntity.RoleId.Split(','); for (int i = 0; i < roles.Length; i++) { //用户角色表 string roleid = roles[i]; var userrole = new UserRoleEntity(); userrole.UserRoleId = Util.Util.NewUpperGuid(); userrole.UserId = userEntity.UserId; userrole.RoleId = roleid.Split('|')[0]; userrole.RoleName = roleid.Split('|')[1]; Base_UserRole model = EntityConvertTools.CopyToModel <UserRoleEntity, Base_UserRole>(userrole, null); model.Insert(); //用户关系表 userRelationEntitys.Add(new UserRelationEntity { Category = (int)QSDMS.Model.Enums.UserCategoryEnum.角色, UserRelationId = Guid.NewGuid().ToString(), UserId = userEntity.UserId, ObjectId = userrole.RoleId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = 1, }); } } //岗位 if (!string.IsNullOrEmpty(userEntity.DutyId)) { userRelationEntitys.Add(new UserRelationEntity { Category = (int)QSDMS.Model.Enums.UserCategoryEnum.岗位, UserRelationId = Guid.NewGuid().ToString(), UserId = userEntity.UserId, ObjectId = userEntity.DutyId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = 1, }); } //职位 if (!string.IsNullOrEmpty(userEntity.PostId)) { userRelationEntitys.Add(new UserRelationEntity { Category = (int)QSDMS.Model.Enums.UserCategoryEnum.职位, UserRelationId = Guid.NewGuid().ToString(), UserId = userEntity.UserId, ObjectId = userEntity.PostId, CreateDate = DateTime.Now, CreateUserId = OperatorProvider.Provider.Current().UserId, CreateUserName = OperatorProvider.Provider.Current().UserName, IsDefault = 1, }); } //插入用户关系表 foreach (UserRelationEntity userRelationItem in userRelationEntitys) { Base_UserRelation model = EntityConvertTools.CopyToModel <UserRelationEntity, Base_UserRelation>(userRelationItem, null); model.Insert(); } #endregion Base_UserAuthorize.Delete("where UserId=@0", userEntity.UserId); //插入用户对应数据权限 if (!string.IsNullOrEmpty(userEntity.AuthorizeDataId)) { string[] uthorizeDatas = userEntity.AuthorizeDataId.Split(','); for (int i = 0; i < uthorizeDatas.Length; i++) { string objectid = uthorizeDatas[i]; var userAuthorize = new UserAuthorizeEntity(); userAuthorize.UserAuthorizeId = Util.Util.NewUpperGuid(); userAuthorize.UserId = userEntity.UserId; userAuthorize.ObjectId = objectid.Split('|')[0]; userAuthorize.ObjectName = objectid.Split('|')[1]; Base_UserAuthorize model = EntityConvertTools.CopyToModel <UserAuthorizeEntity, Base_UserAuthorize>(userAuthorize, null); model.Insert(); } } tran.Complete(); } return(keyValue); } catch (Exception ex) { throw ex; } }
/// <summary> /// 登录验证 /// </summary> /// <param name="username">用户名</param> /// <returns></returns> public UserEntity CheckLogin(string username) { var user = Base_User.SingleOrDefault("where (Account=@0 or Mobile=@0 or Email=@0)", username); return(EntityConvertTools.CopyToModel <Base_User, UserEntity>(user, null)); }
/// <summary> /// 用户实体 /// </summary> /// <param name="keyValue">主键值</param> /// <returns></returns> public UserEntity GetEntity(string keyValue) { var user = Base_User.SingleOrDefault("where UserId=@0", keyValue); return(EntityConvertTools.CopyToModel <Base_User, UserEntity>(user, null)); }