From 0cd3bea6bd89c7f0ef59d25baec853e5f38d3e01 Mon Sep 17 00:00:00 2001 From: chenchun <454313500@qq.com> Date: Sun, 11 Sep 2022 12:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Config/SwaggerDoc.xml | 12 +++ .../Controllers/AccountController.cs | 2 +- .../Controllers/UserController.cs | 21 +++++ .../yi-sqlsugar-dev.db | Bin 126976 -> 126976 bytes .../Yi.Framework.DTOModel/UserInfoDto.cs | 17 ++++ .../Yi.Framework.Interface/IUserService.cs | 22 +++-- .../Yi.Framework.Model/UserEntity.cs | 16 ++++ .../Yi.Framework.Service/UserService.cs | 35 +++++--- Yi.Vue3.X.RuoYi/src/api/system/user.js | 13 ++- .../src/views/system/user/index.vue | 75 ++++++++++-------- 10 files changed, 158 insertions(+), 55 deletions(-) create mode 100644 Yi.Framework.Net6/Yi.Framework.DTOModel/UserInfoDto.cs 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 6cc32675ecb8e0163f65fe25cb9a94078ce2f0bd..a260cd1e663c607b3e80b9d8151ed52585bf87a5 100644 GIT binary patch delta 1361 zcmaizOH30{7=`atIvt?X3xS4!JPk`*XYM@OsUccQc@~C3kp?B$7Fs|{fmWd13=fG3 zaZyq?8W%1M3s+)e+_<17n7D9jqQOMt!X+EG7;m3eDw^D6au(nH|8wq{^)H(BFPivy zVsf|9MojMC+=rS3wM}i8-$=Gq%}`2Z4|q!g04jTk2kEa301DJ?NFAW21^|5O^oP4E zTboq?F$ftL$-uI$EV6K%1qnt;6nTy}v4~^QaI`1ZFNZu6&VU#S`-2YenAgWJwrOrL zuow`!?1HOrZlaG5a;~7+Iv@?$qq0x2^?DXvj)n2L=$hx2)no9E*nQ%f)pTvBf7}ro zUR~|Kvt$|!4@%R#7<8Mjx#rxCVfSiB2cF3zmPI^1h{ZNOq}S(wjRGy1^|7kQM}HVk z?W;=GXDkeZ9Vx|@7z;8RS%er#5D|+l;k&un*oZg~3P+cGJ<;1t@5FM*;2c?r$lR>c zAM113hL@f8Tka``-{X~+BO{D^$rCZz{hd>@a%i-B;kL^@Gc-5rl?C6FA+{hajL%2q zV4&aU7rN)ix?0@+-av5LHR@c94FsLo7MGdIqD-cIvc4guB3>urO|^;R#;3ZCNp&4r zPhg)`3e+baHC?=r@lj-h;Vc3&;!Kdq6qyM}cp-V*)UHzR!9DmeS$*{`Ogz3s*EQtd zRfB_~^C^*ugG*h_G+hngA>4s7tkr$g?difgGkrq8q3_WSx;oj`daP9>x`HH0a2eMH zq_29mSw-k;zJ9jitn*iwRz^(cD``tmpeL`NJn#HJTA4$Y%-HzP3Kbq(VB;sL(x$Q& zgp7h@mMV(JW>D~ZhX;YtNBHu5Lh^71 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 @@