| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Constants; |
| | | 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.common.constant.CommonConstant; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.secure.BladeUser; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | |
| | | 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, Integer labelType) { |
| | | public List<MenuVO> routes(String roleId, Long topMenuId, Integer labelType,Integer menuType) { |
| | | if (StringUtil.isBlank(roleId)) { |
| | | return null; |
| | | } |
| | | List<Menu> allMenus = baseMapper.allMenu(); |
| | | List<Menu> allMenus = baseMapper.selectList(Wrappers.<Menu>lambdaQuery().eq(Menu::getCategory,1).eq(Menu::getMenuType,menuType)); |
| | | List<Menu> roleMenus; |
| | | // 超级管理员并且不是顶部菜单请求则返回全部菜单 |
| | | if (AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) { |
| | |
| | | } |
| | | // 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单 |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | roleMenus = tenantPackageMenu(baseMapper.roleMenuByRoleId(Func.toLongList(roleId), menuType)); |
| | | // 1:居民,居民需要通过人的标签来显示取保候审 |
| | | if(CommonConstant.NUMBER_ONE.equals(labelType)){ |
| | | extracted(labelType, roleMenus); |
| | | } |
| | | } |
| | | // 顶部菜单请求返回对应角色权限菜单 |
| | | else { |
| | | // 角色配置对应菜单 |
| | | List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId)); |
| | | List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId),menuType); |
| | | // 反向递归角色菜单所有父级 |
| | | List<Menu> routes = new LinkedList<>(roleIdMenus); |
| | | roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu)); |
| | |
| | | } |
| | | |
| | | return buildRoutes(allMenus, roleMenus); |
| | | } |
| | | |
| | | /** |
| | | * 房屋的时候才通过人的标签过滤 |
| | | * @param roleMenus |
| | | * @param labelType |
| | | */ |
| | | private void extracted(Integer labelType, List<Menu> roleMenus) { |
| | | 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 { |
| | | if (next.getName().trim().equals("取保候审")) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | List<List<String>> labelList = menu.getLabelList(); |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | for (List<String> strings : labelList) { |
| | | stringBuffer.append(strings.get(2)).append(","); |
| | | stringBuffer.append(strings.get(strings.size()-1)).append(","); |
| | | } |
| | | menu.setLabelId(stringBuffer.toString()); |
| | | menu.setIsDeleted(BladeConstant.DB_NOT_DELETED); |