| | |
| | | baseEquipmentMapper.deleteById(id); |
| | | } |
| | | |
| | | public List<Map<String, Object>> tenants() { |
| | | return Collections.singletonList(row("id", 1L, "name", "临抢修租户")); |
| | | } |
| | | |
| | | public Map<String, Object> menuPermissions(Long roleId, Long tenantId) { |
| | | List<Long> roleMenuIds = roleMenuMapper.selectList(Wrappers.<SysRoleMenu>lambdaQuery() |
| | | .eq(roleId != null, SysRoleMenu::getRoleId, roleId)) |
| | | .stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList()); |
| | | List<Long> tenantMenuIds = tenantMenuMapper.selectList(Wrappers.<SysTenantMenu>lambdaQuery() |
| | | .eq(tenantId != null, SysTenantMenu::getTenantId, tenantId)) |
| | | .stream().map(SysTenantMenu::getMenuId).collect(Collectors.toList()); |
| | | List<Long> effective = roleMenuIds.stream().filter(tenantMenuIds::contains).collect(Collectors.toList()); |
| | | public Map<String, Object> menuPermissions(Long roleId) { |
| | | if (roleId == null) { |
| | | throw new BusinessException("请选择角色"); |
| | | } |
| | | List<String> roleMenuIds = roleMenuMapper.selectList(Wrappers.<SysRoleMenu>lambdaQuery() |
| | | .eq(SysRoleMenu::getRoleId, roleId)) |
| | | .stream().map(SysRoleMenu::getMenuId).map(String::valueOf).collect(Collectors.toList()); |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | result.put("roleMenuIds", roleMenuIds); |
| | | result.put("tenantMenuIds", tenantMenuIds); |
| | | result.put("effectiveMenuIds", effective); |
| | | result.put("effectiveMenuIds", roleMenuIds); |
| | | return result; |
| | | } |
| | | |
| | | @Transactional |
| | | public void saveMenuPermissions(Long roleId, Long tenantId, List<Long> roleMenuIds, List<Long> tenantMenuIds) { |
| | | if (roleId == null || tenantId == null) { |
| | | throw new BusinessException("请选择角色和租户"); |
| | | public void saveMenuPermissions(Long roleId, List<Long> roleMenuIds) { |
| | | if (roleId == null) { |
| | | throw new BusinessException("请选择角色"); |
| | | } |
| | | roleMenuMapper.delete(Wrappers.<SysRoleMenu>lambdaQuery().eq(SysRoleMenu::getRoleId, roleId)); |
| | | tenantMenuMapper.delete(Wrappers.<SysTenantMenu>lambdaQuery().eq(SysTenantMenu::getTenantId, tenantId)); |
| | | List<Long> effectiveRoleMenuIds = expandWithAncestors(roleMenuIds); |
| | | List<Long> effectiveTenantMenuIds = expandWithAncestors(tenantMenuIds); |
| | | for (Long menuId : effectiveRoleMenuIds) { |
| | | SysRoleMenu relation = new SysRoleMenu(); |
| | | relation.setRoleId(roleId); |
| | | relation.setMenuId(menuId); |
| | | relation.setCreateTime(LocalDateTime.now()); |
| | | roleMenuMapper.insert(relation); |
| | | } |
| | | for (Long menuId : effectiveTenantMenuIds) { |
| | | SysTenantMenu relation = new SysTenantMenu(); |
| | | relation.setTenantId(tenantId); |
| | | relation.setMenuId(menuId); |
| | | relation.setCreateTime(LocalDateTime.now()); |
| | | tenantMenuMapper.insert(relation); |
| | | } |
| | | } |
| | | |
| | |
| | | Set<Long> roleMenuIds = new LinkedHashSet<>(roleMenuMapper.selectList(Wrappers.<SysRoleMenu>lambdaQuery() |
| | | .in(SysRoleMenu::getRoleId, roleIds)) |
| | | .stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList())); |
| | | Set<Long> tenantMenuIds = new LinkedHashSet<>(tenantMenuMapper.selectList(Wrappers.<SysTenantMenu>lambdaQuery() |
| | | .eq(SysTenantMenu::getTenantId, 1L)) |
| | | .stream().map(SysTenantMenu::getMenuId).collect(Collectors.toList())); |
| | | if (tenantMenuIds.isEmpty()) { |
| | | result.addAll(roleMenuIds); |
| | | } else { |
| | | for (Long menuId : roleMenuIds) { |
| | | if (tenantMenuIds.contains(menuId)) { |
| | | result.add(menuId); |
| | | } |
| | | } |
| | | } |
| | | result.addAll(roleMenuIds); |
| | | return result; |
| | | } |
| | | |