| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.moral.api.entity.ManageMenu; |
| | | import com.moral.api.entity.ManageRole; |
| | | import com.moral.api.mapper.ManageMenuMapper; |
| | | import com.moral.api.mapper.ManageRoleMenuMapper; |
| | | import com.moral.api.service.ManageMenuService; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.function.Predicate; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | List<ManageMenu> manageMenus = manageMenuMapper.getManageRoleByNameFuzzy(limitMap); |
| | | return manageMenus; |
| | | } |
| | | |
| | | @Override |
| | | public List<ManageMenu> getParentChildrenMenusByRoles(List<ManageRole> roles) { |
| | | List<ManageMenu> allMenus = manageMenuMapper.getAllMenusByRoles(roles); |
| | | Map<Integer, ManageMenu> menusMap = new HashMap<>(); |
| | | for (ManageMenu menu : allMenus) { |
| | | menu.setChildren(new ArrayList<>());//初始化 |
| | | menusMap.put(menu.getId(), menu); |
| | | } |
| | | for (ManageMenu menu : allMenus) { |
| | | combinationParentChildrenMenus(menusMap, menu); |
| | | } |
| | | //已经封装好父子菜单,去除parentId不是0的菜单,去除重复 |
| | | allMenus.removeIf(new Predicate<ManageMenu>() { |
| | | @Override |
| | | public boolean test(ManageMenu manageMenu) { |
| | | if(manageMenu.getParentId().equals(0)) |
| | | return false; |
| | | return true; |
| | | } |
| | | }); |
| | | return allMenus; |
| | | } |
| | | |
| | | /** |
| | | * @Description: 组合多级菜单 |
| | | * @Param: [menuMap, menu]menuMap:key为menuid,value为menu |
| | | * @return: void |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/4/7 |
| | | */ |
| | | private void combinationParentChildrenMenus(Map<Integer, ManageMenu> menuMap, ManageMenu menu) { |
| | | Integer parentId = menu.getParentId(); |
| | | ManageMenu parentMenu = menuMap.get(parentId); |
| | | if (!ObjectUtils.isEmpty(parentMenu)) { |
| | | parentMenu.getChildren().add(menu); |
| | | } |
| | | } |
| | | } |