diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index 371d9ddd..889d2c7d 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -360,5 +360,17 @@ + + + 更新用户信息 + + + + + + 添加用户 + + + diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs index 5a3a3591..4ea014ce 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/AccountController.cs @@ -130,7 +130,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers var userEntiy = await _iUserService._repository.GetByIdAsync(userId); //判断输入的老密码是否和原密码相同 - if (_iUserService.JudgePassword(userEntiy, updatePasswordDto.OldPassword)) + if (userEntiy.JudgePassword(updatePasswordDto.OldPassword)) { userEntiy.Password = updatePasswordDto.NewPassword; userEntiy.BuildPassword(); diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs index 302fc6d9..2814149c 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/UserController.cs @@ -94,5 +94,26 @@ namespace Yi.Framework.ApiMicroservice.Controllers { return Result.Success().SetData(await _iUserService.GetInfoById(id)); } + + + /// + /// 更新用户信息 + /// + /// + [HttpPut] + public async Task UpdateInfo(UserInfoDto userDto) + { + return Result.Success().SetStatus(await _iUserService.UpdateInfo(userDto)); + } + + /// + /// 添加用户 + /// + /// + [HttpPost] + public async Task AddInfo(UserInfoDto userDto) + { + return Result.Success().SetStatus(await _iUserService.AddInfo(userDto)); + } } } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db index 6cc32675..a260cd1e 100644 Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ diff --git a/Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs b/Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs new file mode 100644 index 00000000..51616402 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Model.Models; + +namespace Yi.Framework.DTOModel +{ + public class UserInfoDto + { + public UserEntity User { get; set; } + public List RoleIds { get; set; } + public List PostId { get; set; } + public long? DeptId { get; set; } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs index 37776e4f..abf0b509 100644 --- a/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IUserService.cs @@ -68,13 +68,7 @@ namespace Yi.Framework.Interface /// Task GetUserAllInfo(long userId); - /// - /// 判断用户密码是否和原密码相同 - /// - /// - /// - /// - bool JudgePassword(UserEntity user, string password); + /// /// 动态条件分页查询 @@ -90,5 +84,19 @@ namespace Yi.Framework.Interface /// /// List RouterBuild(List menus); + + /// + /// 更新用户信息 + /// + /// + /// + Task UpdateInfo(UserInfoDto userDto); + + /// + /// 添加用户信息 + /// + /// + /// + Task AddInfo(UserInfoDto userDto); } } diff --git a/Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs index 3fbc442e..ebdb3f40 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/UserEntity.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using SqlSugar; +using Yi.Framework.Common.Helper; + namespace Yi.Framework.Model.Models { public partial class UserEntity @@ -26,5 +28,19 @@ namespace Yi.Framework.Model.Models this.Salt = Common.Helper.MD5Helper.GenerateSalt(); this.Password = Common.Helper.MD5Helper.SHA2Encode(password, this.Salt); } + + /// + /// 判断密码和加密后的密码是否相同 + /// + /// + /// + public bool JudgePassword(string password) + { + if (this.Password == MD5Helper.SHA2Encode(password, this.Salt)) + { + return true; + } + return false; + } } } diff --git a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs index 1be9b474..c33e6ff7 100644 --- a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs @@ -81,13 +81,12 @@ namespace Yi.Framework.Service //多次操作,需要事务确保原子性 return await _repositoryUserRole.UseTranAsync(async () => { + //删除用户之前所有的用户角色关系(物理删除,没有恢复的必要) + await _repositoryUserRole.DeleteAsync(u => userIds.Contains((long)u.UserId)); //遍历用户 foreach (var userId in userIds) { - //删除用户之前所有的用户角色关系(物理删除,没有恢复的必要) - await _repositoryUserRole.DeleteAsync(u => u.UserId == userId); - //添加新的关系 List userRoleEntities = new(); foreach (var roleId in roleIds) @@ -154,14 +153,7 @@ namespace Yi.Framework.Service return userRoleMenu; } - public bool JudgePassword(UserEntity user, string password) - { - if (user.Password == MD5Helper.SHA2Encode(password, user.Salt)) - { - return true; - } - return false; - } + public async Task>> SelctPageList(UserEntity user, PageParModel page) @@ -222,5 +214,26 @@ namespace Yi.Framework.Service } return routers; } + + public async Task UpdateInfo(UserInfoDto userDto) + { + //未填写密码,可不更新 + userDto.User.Salt = null; + if (userDto.User.Password.IsNotNull()) + { + userDto.User.BuildPassword(); + } + var res1 = await _repository.UpdateIgnoreNullAsync(userDto.User); + var res2 = await GiveUserSetRole(new List { userDto.User.Id }, userDto.RoleIds); + return res1 && res2; + } + + public async Task AddInfo(UserInfoDto userDto) + { + userDto.User.BuildPassword(); + var res1 = await _repository.InsertReturnSnowflakeIdAsync(userDto.User); + var res2 = await GiveUserSetRole(new List { res1 }, userDto.RoleIds); + return !0.Equals(res1) && res2; + } } } diff --git a/Yi.Vue3.X.RuoYi/src/api/system/user.js b/Yi.Vue3.X.RuoYi/src/api/system/user.js index c94146bd..3f7077d0 100644 --- a/Yi.Vue3.X.RuoYi/src/api/system/user.js +++ b/Yi.Vue3.X.RuoYi/src/api/system/user.js @@ -21,7 +21,7 @@ export function getUser(userId) { // 新增用户 export function addUser(data) { return request({ - url: '/system/user', + url: '/user/addInfo', method: 'post', data: data }) @@ -30,7 +30,7 @@ export function addUser(data) { // 修改用户 export function updateUser(data) { return request({ - url: '/system/user', + url: '/user/updateInfo', method: 'put', data: data }) @@ -38,9 +38,14 @@ export function updateUser(data) { // 删除用户 export function delUser(userId) { + if("string"==typeof(userId)) + { + userId=[userId]; + } return request({ - url: '/system/user/' + userId, - method: 'delete' + url: '/user/delList', + method: 'delete', + data:userId }) } diff --git a/Yi.Vue3.X.RuoYi/src/views/system/user/index.vue b/Yi.Vue3.X.RuoYi/src/views/system/user/index.vue index c4b1a5a5..19a2e451 100644 --- a/Yi.Vue3.X.RuoYi/src/views/system/user/index.vue +++ b/Yi.Vue3.X.RuoYi/src/views/system/user/index.vue @@ -88,19 +88,19 @@