diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysTenantController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysTenantController.java index 5a582caf..2d9d7cd2 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysTenantController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysTenantController.java @@ -122,8 +122,8 @@ public class SysTenantController extends BaseController { * 状态修改 */ @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) - @SaCheckPermission("system:tenantPackage:edit") - @Log(title = "租户套餐", businessType = BusinessType.UPDATE) + @SaCheckPermission("system:tenant:edit") + @Log(title = "租户", businessType = BusinessType.UPDATE) @PutMapping("/changeStatus") public R changeStatus(@RequestBody SysTenantBo bo) { return toAjax(sysTenantService.updateTenantStatus(bo)); @@ -165,4 +165,19 @@ public class SysTenantController extends BaseController { return R.ok(); } + + /** + * 同步租户套餐 + * + * @param tenantId 租户id + * @param packageId 套餐id + */ + @SaCheckRole(TenantConstants.SUPER_ADMIN_ROLE_KEY) + @SaCheckPermission("system:tenant:edit") + @Log(title = "租户", businessType = BusinessType.UPDATE) + @GetMapping("/syncTenantPackage") + public R syncTenantPackage(@NotBlank(message = "租户ID不能为空") String tenantId, @NotBlank(message = "套餐ID不能为空") String packageId) { + return toAjax(sysTenantService.syncTenantPackage(tenantId, packageId)); + } + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysTenantService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysTenantService.java index ee707255..1885bc8d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysTenantService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysTenantService.java @@ -69,4 +69,9 @@ public interface ISysTenantService { * 校验有效期 */ String checkExpireTime(String tenantId); + + /** + * 同步租户套餐 + */ + Boolean syncTenantPackage(String tenantId, String packageId); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTenantServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTenantServiceImpl.java index ea2bc54f..02665add 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTenantServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTenantServiceImpl.java @@ -335,4 +335,38 @@ public class SysTenantServiceImpl implements ISysTenantService { return TenantConstants.NOT_PASS; } + /** + * 同步租户套餐 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean syncTenantPackage(String tenantId, String packageId) { + TenantHelper.enableIgnore(); + SysTenantPackage tenantPackage = sysTenantPackageMapper.selectById(packageId); + List roles = sysRoleMapper.selectList( + new LambdaQueryWrapper().eq(SysRole::getTenantId, tenantId)); + List roleIds = new ArrayList<>(roles.size() - 1); + List menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong); + roles.forEach(item -> { + if (TenantConstants.TENANT_ADMIN_ROLE_KEY.equals(item.getRoleKey())) { + List roleMenus = new ArrayList<>(menuIds.size()); + menuIds.forEach(menuId -> { + SysRoleMenu roleMenu = new SysRoleMenu(); + roleMenu.setRoleId(item.getRoleId()); + roleMenu.setMenuId(menuId); + roleMenus.add(roleMenu); + }); + sysRoleMenuMapper.delete(new LambdaQueryWrapper().eq(SysRoleMenu::getRoleId, item.getRoleId())); + sysRoleMenuMapper.insertBatch(roleMenus); + } else { + roleIds.add(item.getRoleId()); + } + }); + if (!roleIds.isEmpty()) { + sysRoleMenuMapper.delete( + new LambdaQueryWrapper().in(SysRoleMenu::getRoleId, roleIds).notIn(!menuIds.isEmpty(), SysRoleMenu::getMenuId, menuIds)); + } + TenantHelper.disableIgnore(); + return true; + } } diff --git a/ruoyi-ui/src/api/system/tenant.js b/ruoyi-ui/src/api/system/tenant.js index bb8ebfa0..82535af5 100644 --- a/ruoyi-ui/src/api/system/tenant.js +++ b/ruoyi-ui/src/api/system/tenant.js @@ -73,3 +73,16 @@ export function dynamicClear() { }) } +// 同步租户套餐 +export function syncTenantPackage(tenantId, packageId) { + const data = { + tenantId, + packageId + } + return request({ + url: '/system/tenant/syncTenantPackage', + method: 'get', + params: data + }) +} + diff --git a/ruoyi-ui/src/views/system/tenant/index.vue b/ruoyi-ui/src/views/system/tenant/index.vue index 5f137d2d..571e33a0 100644 --- a/ruoyi-ui/src/views/system/tenant/index.vue +++ b/ruoyi-ui/src/views/system/tenant/index.vue @@ -117,6 +117,13 @@ @click="handleUpdate(scope.row)" v-hasPermi="['system:tenant:edit']" >修改 + 同步套餐