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 6010d8eb..9861e3b1 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.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 @@ - + - + - +