From 0e6113f0a61bcac6539d8f9ac8cde385928f77e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B7=B3?= Date: Fri, 16 Sep 2022 18:57:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Config/SwaggerDoc.xml | 6 + .../Controllers/RoleController.cs | 11 +- .../yi-sqlsugar-dev.db | Bin 151552 -> 151552 bytes .../Yi.Framework.Interface/IRoleService.cs | 15 + .../Yi.Framework.Service/RoleService.cs | 38 +- Yi.Vue3.X.RuoYi/src/api/system/role.js | 2 +- .../src/views/system/role/index.vue | 654 ++++++++++++------ 7 files changed, 507 insertions(+), 219 deletions(-) diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index b1d379e1..704bf226 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -351,6 +351,12 @@ + + + 更改角色数据权限 + + + 测试控制器 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs index 738acd95..de57f7a6 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs @@ -85,9 +85,16 @@ namespace Yi.Framework.ApiMicroservice.Controllers public async Task UpdateStatus(long roleId, bool isDel) { return Result.Success().SetData(await _iRoleService._repository.UpdateIgnoreNullAsync(new RoleEntity() { Id = roleId, IsDeleted = isDel })); - } - + /// + ///更改角色数据权限 + /// + /// + [HttpPut] + public async Task UpdateDataScpoce(RoleInfoDto roleDto) + { + return Result.Success().SetStatus(await _iRoleService.UpdateDataScpoce(roleDto)); + } } } 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 6010d8eb458d1aa4e7ada590e64a95d9987c3deb..9861e3b1b5ad8636772619ab75602312ff8f2098 100644 GIT binary patch delta 1041 zcmaiyO=uHA6oB7sHj`a-XI9FZN|e@di{fg1MBcP^2Ju7xW^YMJNOWC;O9Tqma2h9^bt0{Vc7jORMUm9BMy4 zQckzQJp1x>?df^42{Ms^W{FInlWJ4H@LQvEl7>g1Tvh;vP*(Ln&u1InnB|OG#ZrNl z@}B8Btl%=2Cr?LPB3<$1Pi-)mPk+7+~K{g6U*pj-4lJwp}pi7b;TqHAB8$3|OP;~fS# z1;N9{&h*-vq)P^#{j)B5OR95Lvbo7^&)B}xx_noMaYe%kdSFED-G;fz1+jal? zmY_2oy3tcSz+nKceS6z{Q3DvqeZ{BeRwjjdw3a^ga3PM>RZmBBquY50M+5Q5UED&V z^Po5kpu6f~xiKy3cg8+-qT@dF{p*DE&)9=?yM;Y>an&)tN27ssq>d8w$*4FCz+?B7 zO*AagWpO*VXybT%FzSI6M#fIKf2AjYOc;dA!94*=_XHqEK`@6@Pk^NTDXhkln%Gu` RTm<@_KA`6|NM8Ci@)x%k>pcJf delta 232 zcmZozz}c{XbAmMEr-?Gote+V4f)h5T%=70fV_@NvVBi<$JHWq=Phzt`z!%=h1_B~E zF)X}nk_^tyoD2-Y9I_muM|Xcub`oHCwzd1k`l&_+Mn<{@mb!+<3WnxZh6Yw9MtT+o zW~Qcw7TBfC4J}QK4ULQ;+LMdwf*hh8lMCZbIbd?lzv8$5if827u$)DJQDHla0n;CO0L4Z< A*Z=?k diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs index fde0871c..fffcbe3d 100644 --- a/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs @@ -52,5 +52,20 @@ namespace Yi.Framework.Interface /// /// Task UpdateInfo(RoleInfoDto roleDto); + + /// + /// 给角色设置部门 + /// + /// + /// + /// + Task GiveRoleSetDept(List roleIds, List deptIds); + + /// + /// 更新角色数据权限 + /// + /// + /// + Task UpdateDataScpoce(RoleInfoDto roleDto); } } diff --git a/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs b/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs index 290165e3..47dc8f9c 100644 --- a/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs +++ b/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs @@ -28,8 +28,6 @@ namespace Yi.Framework.Service //遍历用户 foreach (var roleId in roleIds) { - - //添加新的关系 List roleMenuEntity = new(); foreach (var menu in menuIds) @@ -76,12 +74,46 @@ namespace Yi.Framework.Service return !0.Equals(res1) && res2; } + public async Task GiveRoleSetDept(List roleIds,List deptIds) + { + var _repositoryRoleDept = _repository.ChangeRepository>(); + //多次操作,需要事务确保原子性 + return await _repositoryRoleDept.UseTranAsync(async () => + { //删除用户之前所有的用户角色关系(物理删除,没有恢复的必要) + await _repositoryRoleDept.DeleteAsync(u => roleIds.Contains((long)u.RoleId)); + + //遍历角色 + foreach (var roleId in roleIds) + { + //添加新的关系 + List roleDeptEntity = new(); + foreach (var dept in deptIds) + { + roleDeptEntity.Add(new RoleDeptEntity() { RoleId = roleId, DeptId = dept }); + } + + //一次性批量添加 + await _repositoryRoleDept.InsertReturnSnowflakeIdAsync(roleDeptEntity); + } + }); + } public async Task UpdateInfo(RoleInfoDto roleDto) { var res1 = await _repository.UpdateIgnoreNullAsync(roleDto.Role); var res2 = await GiveRoleSetMenu(new List { roleDto.Role.Id }, roleDto.MenuIds); - return res1 && res2; + var res3 = await GiveRoleSetDept(new List { roleDto.Role.Id }, roleDto.DeptIds); + return res1 && res2&& res3; + } + + public async Task UpdateDataScpoce(RoleInfoDto roleDto) + { + var role= new RoleEntity(); + role.Id = roleDto.Role.Id; + role.DataScope = roleDto.Role.DataScope; + var res1 = await _repository.UpdateIgnoreNullAsync(role); + var res3 = await GiveRoleSetDept(new List { roleDto.Role.Id }, roleDto.DeptIds); + return res1 && res3; } } } diff --git a/Yi.Vue3.X.RuoYi/src/api/system/role.js b/Yi.Vue3.X.RuoYi/src/api/system/role.js index 7f401116..f000bd81 100644 --- a/Yi.Vue3.X.RuoYi/src/api/system/role.js +++ b/Yi.Vue3.X.RuoYi/src/api/system/role.js @@ -40,7 +40,7 @@ export function updateRole(data) { // 角色数据权限 export function dataScope(data) { return request({ - url: '/system/role/dataScope', + url: '/role/UpdateDataScpoce', method: 'put', data: data }) diff --git a/Yi.Vue3.X.RuoYi/src/views/system/role/index.vue b/Yi.Vue3.X.RuoYi/src/views/system/role/index.vue index ea2bfefb..194a43b8 100644 --- a/Yi.Vue3.X.RuoYi/src/views/system/role/index.vue +++ b/Yi.Vue3.X.RuoYi/src/views/system/role/index.vue @@ -1,58 +1,139 @@ - + - + - +