This commit is contained in:
zuohuaijun 2025-03-23 23:07:02 +08:00
commit 2411564058
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 roleId = await _sysRoleRep.AsInsertable(input.Adapt<SysRole>()).ExecuteReturnSnowflakeIdAsync();
// 授权角色基础菜单集合 // 授权角色基础菜单集合
var menuIdList = new List<long> { 1300000000111,1300000000121, // 工作台 var menuIdList = new List<long>
1310000000161,1310000000162,1310000000163,1310000000164,1310000000165, // 个人中心 {
1300000000111, 1300000000121, // 工作台
1310000000161, 1310000000162, 1310000000163, 1310000000164, 1310000000165, // 个人中心
}; };
await _sysRoleMenuService.GrantRoleMenu(new RoleMenuInput() { Id = roleId, MenuIdList = menuIdList }); 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 (orgIdList.Count < 1) throw Oops.Oh(ErrorCodeEnum.D1016);
if (!grantOrgIdList.All(u => orgIdList.Any(c => c == u))) throw Oops.Oh(ErrorCodeEnum.D1016); if (!grantOrgIdList.All(u => orgIdList.Any(c => c == u))) throw Oops.Oh(ErrorCodeEnum.D1016);
} }
break; break;
} }
@ -236,6 +239,7 @@ public class SysRoleService : IDynamicApiController, ITransient
break; break;
} }
} }
role.DataScope = (DataScopeEnum)dataScope; role.DataScope = (DataScopeEnum)dataScope;
await _sysRoleRep.AsUpdateable(role).UpdateColumns(u => new { u.DataScope }).ExecuteCommandAsync(); await _sysRoleRep.AsUpdateable(role).UpdateColumns(u => new { u.DataScope }).ExecuteCommandAsync();
await _sysRoleOrgService.GrantRoleOrg(input); await _sysRoleOrgService.GrantRoleOrg(input);
@ -447,7 +451,8 @@ public class SysRoleService : IDynamicApiController, ITransient
/// </summary> /// </summary>
/// <param name="roleId"></param> /// <param name="roleId"></param>
/// <returns></returns> /// <returns></returns>
private async Task ClearUserApiCache(long roleId) [NonAction]
public async Task ClearUserApiCache(long roleId)
{ {
var userIdList = await _sysUserRoleService.GetUserIdList(roleId); var userIdList = await _sysUserRoleService.GetUserIdList(roleId);
foreach (var userId in userIdList) foreach (var userId in userIdList)

View File

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

View File

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