diff --git a/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/RoleService.cs b/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/RoleService.cs index 0a8c946b..7286c1a2 100644 --- a/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/RoleService.cs +++ b/Yi.Furion.Net6/Yi.Furion.Application/Rbac/Services/Impl/RoleService.cs @@ -1,3 +1,5 @@ +using System.Linq.Expressions; +using System.Reflection.Metadata; using Furion.DatabaseAccessor; using SqlSugar; using Yi.Framework.Infrastructure.Ddd.Dtos; @@ -6,6 +8,7 @@ using Yi.Framework.Infrastructure.Ddd.Services; using Yi.Framework.Infrastructure.Helper; using Yi.Furion.Application.Rbac.Domain; using Yi.Furion.Core.Rbac.Dtos.Role; +using Yi.Furion.Core.Rbac.Dtos.User; using Yi.Furion.Core.Rbac.Entities; using Yi.Furion.Core.Rbac.Enums; @@ -17,13 +20,14 @@ namespace Yi.Furion.Application.Rbac.Services.Impl public class RoleService : CrudAppService, IRoleService, ITransient, IDynamicApiController { - public RoleService(RoleManager roleManager, IRepository roleDeptRepository) => - (_roleManager, _roleDeptRepository) = - (roleManager, roleDeptRepository); + public RoleService(RoleManager roleManager, IRepository roleDeptRepository, IRepository userRoleRepository) => + (_roleManager, _roleDeptRepository, _userRoleRepository) = + (roleManager, roleDeptRepository, userRoleRepository); private RoleManager _roleManager { get; set; } private IRepository _roleDeptRepository; + private IRepository _userRoleRepository; [UnitOfWork] public async Task UpdateDataScpoceAsync(UpdateDataScpoceInput input) { @@ -31,7 +35,7 @@ namespace Yi.Furion.Application.Rbac.Services.Impl if (input.DataScope == DataScopeEnum.CUSTOM) { await _roleDeptRepository.DeleteAsync(x => x.RoleId == input.RoleId); - var insertEntities = input.DeptIds.Select(x => new RoleDeptEntity {Id=SnowflakeHelper.NextId, DeptId = x, RoleId = input.RoleId }).ToList(); + var insertEntities = input.DeptIds.Select(x => new RoleDeptEntity { Id = SnowflakeHelper.NextId, DeptId = x, RoleId = input.RoleId }).ToList(); await _roleDeptRepository.InsertRangeAsync(insertEntities); } await _repository._Db.Updateable(new RoleEntity() { Id = input.RoleId, DataScope = input.DataScope }).UpdateColumns(x => x.DataScope).ExecuteCommandAsync(); @@ -116,5 +120,71 @@ namespace Yi.Furion.Application.Rbac.Services.Impl await _repository.UpdateAsync(entity); return await MapToGetOutputDtoAsync(entity); } + + + /// + /// 获取角色下的用户 + /// + /// + /// + /// 是否在该角色下 + /// + [Route("/api/role/auth-user/{roleId}/{isAllocated}")] + public async Task> GetAuthUserByRoleIdAsync([FromRoute] long roleId, [FromRoute] bool isAllocated, [FromQuery] RoleAuthUserGetListInput input) + { + + //角色下已授权用户 + if (isAllocated == true) + { + RefAsync total = 0; + var output = await _userRoleRepository._DbQueryable + .LeftJoin((ur, u) => ur.UserId == u.Id && ur.RoleId == roleId) + .Where((ur, u) => ur.RoleId == roleId) + .WhereIF(!string.IsNullOrEmpty(input.UserName), (ur, u) => u.UserName.Contains(input.UserName)) + .WhereIF(input.Phone is not null, (ur, u) => u.Phone.ToString().Contains(input.Phone.ToString())) + .Select((ur, u) => new UserGetListOutputDto { Id = u.Id }, true) + .ToPageListAsync(input.PageNum, input.PageSize, total); + return new PagedResultDto(total, output); + } + //角色下未授权用户 + else + { + RefAsync total = 0; + var entities = await _userRoleRepository._Db.Queryable() + .Where(u => SqlFunc.Subqueryable().Where(x => x.RoleId == roleId).Where(x => x.UserId == u.Id).NotAny()) + .WhereIF(!string.IsNullOrEmpty(input.UserName), u => u.UserName.Contains(input.UserName)) + .WhereIF(input.Phone is not null, u => u.Phone.ToString().Contains(input.Phone.ToString())) + .ToPageListAsync(input.PageNum, input.PageSize, total); + var output = entities.Adapt>(); + return new PagedResultDto(total, output); + } + } + + + + + /// + /// 批量给用户授权 + /// + /// + /// + public async Task CreateAuthUserAsync(RoleAuthUserCreateOrDeleteInput input) + { + var userRoleEntities = input.UserIds.Select(u => new UserRoleEntity { Id = SnowflakeHelper.NextId, RoleId = input.RoleId, UserId = u }).ToList(); + await _userRoleRepository.InsertRangeAsync(userRoleEntities); + } + + + /// + /// 批量取消授权 + /// + /// + /// + public async Task DeleteAuthUserAsync(RoleAuthUserCreateOrDeleteInput input) + { + await _userRoleRepository._Db.Deleteable().Where(x => x.RoleId == input.RoleId) + .Where(x => input.UserIds.Contains(x.UserId)) + .ExecuteCommandAsync(); ; + } } } diff --git a/Yi.Furion.Net6/Yi.Furion.Application/Yi.Furion.Application.xml b/Yi.Furion.Net6/Yi.Furion.Application/Yi.Furion.Application.xml index dd0d09be..0fc6d1b4 100644 --- a/Yi.Furion.Net6/Yi.Furion.Application/Yi.Furion.Application.xml +++ b/Yi.Furion.Net6/Yi.Furion.Application/Yi.Furion.Application.xml @@ -451,6 +451,29 @@ + + + 获取角色下的用户 + + + + 是否在该角色下 + + + + + 批量给用户授权 + + + + + + + 批量取消授权 + + + + 单查job diff --git a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Dtos/Role/RoleAuthUserCreateOrDeleteInput.cs b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Dtos/Role/RoleAuthUserCreateOrDeleteInput.cs new file mode 100644 index 00000000..a9858bea --- /dev/null +++ b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Dtos/Role/RoleAuthUserCreateOrDeleteInput.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Infrastructure.Ddd.Dtos; + +namespace Yi.Furion.Core.Rbac.Dtos.Role +{ + public class RoleAuthUserCreateOrDeleteInput + { + [Required] + public long RoleId { get; set; } + + [Required] + public List UserIds { get; set; } + } +} diff --git a/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Dtos/Role/RoleAuthUserGetListInput.cs b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Dtos/Role/RoleAuthUserGetListInput.cs new file mode 100644 index 00000000..3195fe0d --- /dev/null +++ b/Yi.Furion.Net6/Yi.Furion.Core/Rbac/Dtos/Role/RoleAuthUserGetListInput.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Yi.Framework.Infrastructure.Ddd.Dtos; + +namespace Yi.Furion.Core.Rbac.Dtos.Role +{ + public class RoleAuthUserGetListInput: PagedAndSortedResultRequestDto + { + public string? UserName { get; set; } + + public long? Phone { get; set; } + } +} diff --git a/Yi.RuoYi.Vue3/src/api/system/role.js b/Yi.RuoYi.Vue3/src/api/system/role.js index 3b90a13d..e40cee8e 100644 --- a/Yi.RuoYi.Vue3/src/api/system/role.js +++ b/Yi.RuoYi.Vue3/src/api/system/role.js @@ -63,18 +63,18 @@ export function delRole(roleId) { } // 查询角色已授权用户列表 -export function allocatedUserList(query) { +export function allocatedUserList(roleId,query) { return request({ - url: '/system/role/authUser/allocatedList', + url: `/role/auth-user/${roleId}/true`, method: 'get', params: query }) } // 查询角色未授权用户列表 -export function unallocatedUserList(query) { +export function unallocatedUserList(roleId,query) { return request({ - url: '/system/role/authUser/unallocatedList', + url: `/role/auth-user/${roleId}/false`, method: 'get', params: query }) @@ -83,8 +83,8 @@ export function unallocatedUserList(query) { // 取消用户授权角色 export function authUserCancel(data) { return request({ - url: '/system/role/authUser/cancel', - method: 'put', + url: '/role/auth-user', + method: 'delete', data: data }) } @@ -92,18 +92,18 @@ export function authUserCancel(data) { // 批量取消用户授权角色 export function authUserCancelAll(data) { return request({ - url: '/system/role/authUser/cancelAll', - method: 'put', - params: data + url: '/role/auth-user', + method: 'delete', + data: data }) } // 授权用户选择 export function authUserSelectAll(data) { return request({ - url: '/system/role/authUser/selectAll', - method: 'put', - params: data + url: '/role/auth-user', + method: 'post', + data: data }) } diff --git a/Yi.RuoYi.Vue3/src/store/modules/permission.js b/Yi.RuoYi.Vue3/src/store/modules/permission.js index 4c0c1867..dee66d5b 100644 --- a/Yi.RuoYi.Vue3/src/store/modules/permission.js +++ b/Yi.RuoYi.Vue3/src/store/modules/permission.js @@ -346,7 +346,6 @@ const usePermissionStore = defineStore( // } // } // ]; -console.log(response.data,"response.data") const res=response.data; const sdata = JSON.parse(JSON.stringify(res)) diff --git a/Yi.RuoYi.Vue3/src/views/system/role/authUser.vue b/Yi.RuoYi.Vue3/src/views/system/role/authUser.vue index ef92df0d..7fd8df6d 100644 --- a/Yi.RuoYi.Vue3/src/views/system/role/authUser.vue +++ b/Yi.RuoYi.Vue3/src/views/system/role/authUser.vue @@ -11,9 +11,9 @@ @keyup.enter="handleQuery" /> - + - + - - + + - + @@ -116,15 +116,15 @@ const queryParams = reactive({ pageSize: 10, roleId: route.params.roleId, userName: undefined, - phonenumber: undefined, + phone: undefined, }); /** 查询授权用户列表 */ function getList() { loading.value = true; - allocatedUserList(queryParams).then(response => { - userList.value = response.rows; - total.value = response.total; + allocatedUserList(queryParams.roleId,queryParams).then(response => { + userList.value = response.data.items; + total.value = response.data.total; loading.value = false; }); } @@ -155,7 +155,7 @@ function openSelectUser() { /** 取消授权按钮操作 */ function cancelAuthUser(row) { proxy.$modal.confirm('确认要取消该用户"' + row.userName + '"角色吗?').then(function () { - return authUserCancel({ userId: row.userId, roleId: queryParams.roleId }); + return authUserCancel({ userIds: [row.id], roleId: queryParams.roleId }); }).then(() => { getList(); proxy.$modal.msgSuccess("取消授权成功"); diff --git a/Yi.RuoYi.Vue3/src/views/system/role/index.vue b/Yi.RuoYi.Vue3/src/views/system/role/index.vue index e2256395..9b7c7b41 100644 --- a/Yi.RuoYi.Vue3/src/views/system/role/index.vue +++ b/Yi.RuoYi.Vue3/src/views/system/role/index.vue @@ -325,7 +325,7 @@ function handleCommand(command, row) { } /** 分配用户 */ function handleAuthUser(row) { - router.push("/system/role-auth/user/" + row.roleId); + router.push("/system/role-auth/user/" + row.id); } /** 查询菜单树结构 */ function getMenuTreeselect() { diff --git a/Yi.RuoYi.Vue3/src/views/system/role/selectUser.vue b/Yi.RuoYi.Vue3/src/views/system/role/selectUser.vue index 51c8585c..8035ec93 100644 --- a/Yi.RuoYi.Vue3/src/views/system/role/selectUser.vue +++ b/Yi.RuoYi.Vue3/src/views/system/role/selectUser.vue @@ -10,9 +10,9 @@ @keyup.enter="handleQuery" /> - + - + - - + + - + @@ -80,7 +80,7 @@ const queryParams = reactive({ pageSize: 10, roleId: undefined, userName: undefined, - phonenumber: undefined + phone: undefined }); // 显示弹框 @@ -95,13 +95,13 @@ function clickRow(row) { } // 多选框选中数据 function handleSelectionChange(selection) { - userIds.value = selection.map(item => item.userId); + userIds.value = selection.map(item => item.id); } // 查询表数据 function getList() { - unallocatedUserList(queryParams).then(res => { - userList.value = res.rows; - total.value = res.total; + unallocatedUserList(queryParams.roleId,queryParams).then(res => { + userList.value = res.data.items; + total.value = res.data.total; }); } /** 搜索按钮操作 */ @@ -123,8 +123,8 @@ function handleSelectUser() { proxy.$modal.msgError("请选择要分配的用户"); return; } - authUserSelectAll({ roleId: roleId, userIds: uIds }).then(res => { - proxy.$modal.msgSuccess(res.msg); + authUserSelectAll({ roleId: roleId, userIds: [uIds] }).then(res => { + proxy.$modal.msgSuccess("成功"); if (res.code === 200) { visible.value = false; emit("ok"); diff --git a/Yi.RuoYi.Vue3/src/views/system/user/index.vue b/Yi.RuoYi.Vue3/src/views/system/user/index.vue index 5ad0a1ce..fa01ca09 100644 --- a/Yi.RuoYi.Vue3/src/views/system/user/index.vue +++ b/Yi.RuoYi.Vue3/src/views/system/user/index.vue @@ -100,10 +100,10 @@ - +