| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.common.cache.SysCache; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.secure.BladeUser; |
| | |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springblade.modules.house.dto.UserHouseLabelDTO; |
| | | import org.springblade.modules.house.service.IUserHouseLabelService; |
| | | import org.springblade.modules.system.dto.MenuDTO; |
| | | import org.springblade.modules.system.entity.*; |
| | | import org.springblade.modules.system.mapper.MenuMapper; |
| | |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.Serializable; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private final static String PARENT_ID = "parentId"; |
| | | private final static Integer MENU_CATEGORY = 1; |
| | | |
| | | @Resource |
| | | private IUserHouseLabelService iUserHouseLabelService; |
| | | |
| | | @Override |
| | | public List<MenuVO> lazyList(Long parentId, Map<String, Object> param) { |
| | | if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) { |
| | |
| | | return baseMapper.lazyMenuList(parentId, param); |
| | | } |
| | | |
| | | public static final List<Integer> list1 = Arrays.asList(1, 2, 3, 4, 5, 6, 11, null); |
| | | public static final List<Integer> list2 = Arrays.asList(1, 11, null); |
| | | |
| | | /** |
| | | * apache测试方法 |
| | | */ |
| | | public static void main(String[] args) { |
| | | System.out.println("交集:" + CollectionUtils.intersection(list1, list2)); // 交集 |
| | | System.out.println("补集:" + CollectionUtils.disjunction(list1, list2)); // 补集 |
| | | System.out.println("并集:" + CollectionUtils.union(list1, list2)); // 并集 |
| | | System.out.println("list1的差集:" + CollectionUtils.subtract(list1, list2)); // list1的差集 |
| | | System.out.println("list2的差集:" + CollectionUtils.subtract(list2, list1)); // list2的差集 |
| | | } |
| | | |
| | | @Override |
| | | public List<MenuVO> routes(String roleId, Long topMenuId) { |
| | | public List<MenuVO> routes(String roleId, Long topMenuId, Integer labelType) { |
| | | if (StringUtil.isBlank(roleId)) { |
| | | return null; |
| | | } |
| | |
| | | // 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单 |
| | | else if (!AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) { |
| | | roleMenus = tenantPackageMenu(baseMapper.roleMenuByRoleId(Func.toLongList(roleId))); |
| | | UserHouseLabelDTO userHouseLabelDTO = new UserHouseLabelDTO(); |
| | | userHouseLabelDTO.setUserId(AuthUtil.getUserId()); |
| | | userHouseLabelDTO.setLableType(labelType); |
| | | List<Integer> integers = iUserHouseLabelService.selectUserLabelList(userHouseLabelDTO); |
| | | Iterator<Menu> iterator = roleMenus.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Menu next = iterator.next(); |
| | | if (!next.getParentId().equals(0)) { |
| | | if (StringUtils.isNotBlank(next.getLabelId())) { |
| | | String[] split = next.getLabelId().split(","); |
| | | List<Integer> integerList = Arrays.stream(split).map(Integer::valueOf).collect(Collectors.toList()); |
| | | Collection<? extends Serializable> union = CollectionUtils.intersection(integerList, integers); |
| | | if (union.size() == 0) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 顶部菜单请求返回对应角色权限菜单 |
| | | else { |
| | |
| | | routes.stream().anyMatch(route -> route.getId().longValue() == x.getId().longValue()) |
| | | ).collect(Collectors.toList()); |
| | | } |
| | | |
| | | return buildRoutes(allMenus, roleMenus); |
| | | } |
| | | |
| | |
| | | wrapper -> wrapper.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY) |
| | | ); |
| | | } else { |
| | | menuQueryWrapper.ne(Menu::getId, menu.getId()).and( |
| | | menuQueryWrapper.ne(Menu::getId, menu.getId()).eq(Menu::getIsDeleted,0).and( |
| | | wrapper -> wrapper.eq(Menu::getCode, menu.getCode()).or( |
| | | o -> o.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY) |
| | | ) |