| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.dev33.satoken.secure.BCrypt; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.constant.TenantConstants; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.MapstructUtils; |
| | | import com.ruoyi.common.core.utils.SpringUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.mybatis.core.page.PageQuery; |
| | |
| | | public Boolean insertByBo(SysTenantBo bo) { |
| | | TenantHelper.enableIgnore(); |
| | | |
| | | SysTenant add = BeanUtil.toBean(bo, SysTenant.class); |
| | | SysTenant add = MapstructUtils.convert(bo, SysTenant.class); |
| | | |
| | | // 获取所有租户编号 |
| | | List<String> tenantIds = baseMapper.selectObjs( |
| | |
| | | add.setTenantId(tenantId); |
| | | boolean flag = baseMapper.insert(add) > 0; |
| | | if (!flag) { |
| | | TenantHelper.disableIgnore(); |
| | | throw new ServiceException("创建租户失败"); |
| | | } |
| | | bo.setId(add.getId()); |
| | |
| | | @CacheEvict(cacheNames = CacheNames.SYS_TENANT, key = "#bo.tenantId") |
| | | @Override |
| | | public Boolean updateByBo(SysTenantBo bo) { |
| | | SysTenant tenant = BeanUtil.toBean(bo, SysTenant.class); |
| | | SysTenant tenant = MapstructUtils.convert(bo, SysTenant.class); |
| | | tenant.setTenantId(null); |
| | | tenant.setPackageId(null); |
| | | return baseMapper.updateById(tenant) > 0; |
| | |
| | | @CacheEvict(cacheNames = CacheNames.SYS_TENANT, key = "#bo.tenantId") |
| | | @Override |
| | | public int updateTenantStatus(SysTenantBo bo) { |
| | | SysTenant tenant = BeanUtil.toBean(bo, SysTenant.class); |
| | | SysTenant tenant = MapstructUtils.convert(bo, SysTenant.class); |
| | | return baseMapper.updateById(tenant); |
| | | } |
| | | |
| | |
| | | return TenantConstants.NOT_PASS; |
| | | } |
| | | |
| | | /** |
| | | * 同步租户套餐 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean syncTenantPackage(String tenantId, String packageId) { |
| | | TenantHelper.enableIgnore(); |
| | | SysTenantPackage tenantPackage = sysTenantPackageMapper.selectById(packageId); |
| | | List<SysRole> roles = sysRoleMapper.selectList( |
| | | new LambdaQueryWrapper<SysRole>().eq(SysRole::getTenantId, tenantId)); |
| | | List<Long> roleIds = new ArrayList<>(roles.size() - 1); |
| | | List<Long> menuIds = StringUtils.splitTo(tenantPackage.getMenuIds(), Convert::toLong); |
| | | roles.forEach(item -> { |
| | | if (TenantConstants.TENANT_ADMIN_ROLE_KEY.equals(item.getRoleKey())) { |
| | | List<SysRoleMenu> 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<SysRoleMenu>().eq(SysRoleMenu::getRoleId, item.getRoleId())); |
| | | sysRoleMenuMapper.insertBatch(roleMenus); |
| | | } else { |
| | | roleIds.add(item.getRoleId()); |
| | | } |
| | | }); |
| | | if (!roleIds.isEmpty()) { |
| | | sysRoleMenuMapper.delete( |
| | | new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getRoleId, roleIds).notIn(!menuIds.isEmpty(), SysRoleMenu::getMenuId, menuIds)); |
| | | } |
| | | TenantHelper.disableIgnore(); |
| | | return true; |
| | | } |
| | | } |