| | |
| | | /* |
| | | * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are met: |
| | | * |
| | | * Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * Redistributions in binary form must reproduce the above copyright |
| | | * notice, this list of conditions and the following disclaimer in the |
| | | * documentation and/or other materials provided with the distribution. |
| | | * Neither the name of the dreamlu.net developer nor the names of its |
| | | * contributors may be used to endorse or promote products derived from |
| | | * this software without specific prior written permission. |
| | | * Author: Chill 庄骞 (smallchill@163.com) |
| | | */ |
| | | package org.springblade.modules.system.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | |
| | | 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 net.logstash.logback.encoder.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; |
| | |
| | | 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)))) { |
| | |
| | | } |
| | | List<MenuVO> menuVOS = baseMapper.lazyList(parentId, param); |
| | | for (MenuVO menuVO : menuVOS) { |
| | | if(StringUtils.isNotBlank(menuVO.getLabelStr())){ |
| | | List<List<String>> lists = (List<List<String>>)JSON.parse(menuVO.getLabelStr() ); |
| | | if (StringUtils.isNotBlank(menuVO.getLabelStr())) { |
| | | List<List<String>> lists = (List<List<String>>) JSON.parse(menuVO.getLabelStr()); |
| | | menuVO.setLabelList(lists); |
| | | } |
| | | } |
| | |
| | | } |
| | | List<MenuVO> menuVOS = baseMapper.lazyList(parentId, param); |
| | | for (MenuVO menuVO : menuVOS) { |
| | | if(StringUtils.isNotBlank(menuVO.getLabelStr())){ |
| | | List<List<String>> lists = (List<List<String>>)JSON.parse(menuVO.getLabelStr() ); |
| | | if (StringUtils.isNotBlank(menuVO.getLabelStr())) { |
| | | List<List<String>> lists = (List<List<String>>) JSON.parse(menuVO.getLabelStr()); |
| | | menuVO.setLabelList(lists); |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | @Override |
| | | public List<MenuVO> routes(String roleId, Long topMenuId, Integer labelType) { |
| | | public List<MenuVO> routes(String roleId, Long topMenuId, Integer labelType, Integer menuType, String roleName,String houseCode) { |
| | | 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(); |
| | | } |
| | | } else { |
| | | if (next.getName().trim().equals("标签报事")) { |
| | | iterator.remove(); |
| | | } |
| | | if (next.getName().trim().equals("取保候审")) { |
| | | iterator.remove(); |
| | | } |
| | | if (next.getName().trim().equals("打金店")) { |
| | | iterator.remove(); |
| | | } |
| | | if (next.getName().trim().equals("旅馆安全")) { |
| | | iterator.remove(); |
| | | } |
| | | if (next.getName().trim().equals("二手车交易")) { |
| | | iterator.remove(); |
| | | } |
| | | if (next.getName().trim().equals("二手手机维修")) { |
| | | iterator.remove(); |
| | | } |
| | | if (next.getName().trim().equals("校园安全")) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | roleMenus = tenantPackageMenu(baseMapper.roleMenuByRoleId(Func.toLongList(roleId), menuType)); |
| | | } |
| | | // 顶部菜单请求返回对应角色权限菜单 |
| | | 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,String houseCode) { |
| | | Iterator<Menu> iterator = roleMenus.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Menu next = iterator.next(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | wrapper -> wrapper.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY) |
| | | ); |
| | | } else { |
| | | menuQueryWrapper.ne(Menu::getId, menu.getId()).eq(Menu::getIsDeleted,0).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) |
| | | ) |
| | |
| | | List<List<String>> labelList = menu.getLabelList(); |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | for (List<String> strings : labelList) { |
| | | stringBuffer.append(strings.get(strings.size()-1)).append(","); |
| | | stringBuffer.append(strings.get(strings.size() - 1)).append(","); |
| | | } |
| | | menu.setLabelId(stringBuffer.toString()); |
| | | menu.setIsDeleted(BladeConstant.DB_NOT_DELETED); |