fix: 租户授权菜单时没有清理缓存问题

This commit is contained in:
许俊杰 2025-03-23 22:17:28 +08:00
parent 16a49a8540
commit 09b905e44d
3 changed files with 60 additions and 48 deletions

View File

@ -104,8 +104,10 @@ public class SysRoleService : IDynamicApiController, ITransient
var roleId = await _sysRoleRep.AsInsertable(input.Adapt<SysRole>()).ExecuteReturnSnowflakeIdAsync();
// 授权角色基础菜单集合
var menuIdList = new List<long> { 1300000000111,1300000000121, // 工作台
1310000000161,1310000000162,1310000000163,1310000000164,1310000000165, // 个人中心
var menuIdList = new List<long>
{
1300000000111, 1300000000121, // 工作台
1310000000161, 1310000000162, 1310000000163, 1310000000164, 1310000000165, // 个人中心
};
await _sysRoleMenuService.GrantRoleMenu(new RoleMenuInput() { Id = roleId, MenuIdList = menuIdList });
}
@ -229,6 +231,7 @@ public class SysRoleService : IDynamicApiController, ITransient
if (orgIdList.Count < 1) throw Oops.Oh(ErrorCodeEnum.D1016);
if (!grantOrgIdList.All(u => orgIdList.Any(c => c == u))) throw Oops.Oh(ErrorCodeEnum.D1016);
}
break;
}
@ -236,6 +239,7 @@ public class SysRoleService : IDynamicApiController, ITransient
break;
}
}
role.DataScope = (DataScopeEnum)dataScope;
await _sysRoleRep.AsUpdateable(role).UpdateColumns(u => new { u.DataScope }).ExecuteCommandAsync();
await _sysRoleOrgService.GrantRoleOrg(input);
@ -436,10 +440,10 @@ public class SysRoleService : IDynamicApiController, ITransient
private async Task<List<string>> GetButtonList(List<long> menuIds = null, bool isAll = true)
{
return await _sysRoleRep.ChangeRepository<SqlSugarRepository<SysMenu>>().AsQueryable()
.WhereIF(menuIds != null && menuIds.Count > 0, u => menuIds.Contains(u.Id))
.WhereIF(!isAll, u => u.Status == StatusEnum.Enable)
.Where(u => u.Type == MenuTypeEnum.Btn)
.Select(u => u.Permission).ToListAsync();
.WhereIF(menuIds != null && menuIds.Count > 0, u => menuIds.Contains(u.Id))
.WhereIF(!isAll, u => u.Status == StatusEnum.Enable)
.Where(u => u.Type == MenuTypeEnum.Btn)
.Select(u => u.Permission).ToListAsync();
}
/// <summary>
@ -447,7 +451,8 @@ public class SysRoleService : IDynamicApiController, ITransient
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
private async Task ClearUserApiCache(long roleId)
[NonAction]
public async Task ClearUserApiCache(long roleId)
{
var userIdList = await _sysUserRoleService.GetUserIdList(roleId);
foreach (var userId in userIdList)

View File

@ -23,6 +23,7 @@ public class SysTenantService : IDynamicApiController, ITransient
private readonly SqlSugarRepository<SysUserRole> _userRoleRep;
private readonly SqlSugarRepository<SysFile> _fileRep;
private readonly SysUserRoleService _sysUserRoleService;
private readonly SysRoleService _sysRoleService;
private readonly SysRoleMenuService _sysRoleMenuService;
private readonly SysConfigService _sysConfigService;
private readonly SysCacheService _sysCacheService;
@ -40,6 +41,7 @@ public class SysTenantService : IDynamicApiController, ITransient
SqlSugarRepository<SysUserRole> userRoleRep,
SqlSugarRepository<SysFile> fileRep,
SysUserRoleService sysUserRoleService,
SysRoleService sysRoleService,
SysRoleMenuService sysRoleMenuService,
SysConfigService sysConfigService,
SysCacheService sysCacheService,
@ -57,6 +59,7 @@ public class SysTenantService : IDynamicApiController, ITransient
_userRoleRep = userRoleRep;
_fileRep = fileRep;
_sysUserRoleService = sysUserRoleService;
_sysRoleService = sysRoleService;
_sysRoleMenuService = sysRoleMenuService;
_sysConfigService = sysConfigService;
_sysCacheService = sysCacheService;
@ -345,6 +348,7 @@ public class SysTenantService : IDynamicApiController, ITransient
default:
throw Oops.Oh(ErrorCodeEnum.D3004);
}
// 从库配置判断
if (input.TenantType == TenantTypeEnum.Db && !string.IsNullOrWhiteSpace(input.SlaveConnections) && !JSON.IsValid(input.SlaveConnections, true))
throw Oops.Oh(ErrorCodeEnum.D1302);
@ -379,6 +383,8 @@ public class SysTenantService : IDynamicApiController, ITransient
input.Id = adminRole.Id; // 重置租户管理员角色Id
await _sysRoleMenuService.GrantRoleMenu(input);
await _sysRoleService.ClearUserApiCache(input.Id);
}
/// <summary>
@ -440,6 +446,7 @@ public class SysTenantService : IDynamicApiController, ITransient
if (!string.IsNullOrWhiteSpace(tenant.Connection))
tenant.Connection = CryptogramUtil.SM2Encrypt(tenant.Connection);
}
_sysCacheService.Set(CacheConst.KeyTenant, tenantList);
}

View File

@ -5,14 +5,14 @@
<template #toolbar_buttons>
<el-form :inlineMessage="true" label-width="auto" style="flex: 1 1 0%">
<el-row :gutter="10">
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
<el-form-item label="库名" prop="configId">
<el-select v-model="state.configId" placeholder="库名" filterable>
<el-option v-for="item in state.dbData" :key="item.configId" :label="`${item.dbName}(${item.configId})`" :value="item.configId" />
</el-select>
</el-form-item>
</el-col>
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
<el-button type="primary" icon="ele-Plus" @click="handleAdd" v-auth="'dbBackup/add'" :loading="state.loading"> 新增 </el-button>
</el-col>
</el-row>