| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.RoleMenuMapper; |
| | | import com.whyc.pojo.Menu; |
| | | import com.whyc.pojo.RoleMenu; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 角色-菜单 |
| | |
| | | @Resource |
| | | private RoleMenuMapper mapper; |
| | | |
| | | public List<Menu> getUserMenu(Integer id) { |
| | | return mapper.getUserMenu(id); |
| | | public List<Menu> getMenuByRoleId(Integer roleId,Integer status) { |
| | | |
| | | List<Menu> menuList = mapper.getMenuByRoleId(roleId,status); |
| | | |
| | | for (int i = 0; i < menuList.size(); i++) { |
| | | Integer parentId = menuList.get(i).getParentId(); |
| | | if(parentId !=0){ |
| | | //将这个menu插入到parent中 |
| | | for (int j = 0; j < menuList.size(); j++) { |
| | | if(menuList.get(j).getId()==parentId){ |
| | | List<Menu> menuListTemp = menuList.get(j).getMenuList(); |
| | | if(menuListTemp==null) { |
| | | menuListTemp = new LinkedList<>(); |
| | | } |
| | | menuListTemp.add(menuList.get(i)); |
| | | menuList.get(j).setMenuList(menuListTemp); |
| | | menuList.remove(i); |
| | | i--; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | return menuList; |
| | | } |
| | | |
| | | public boolean updateBatch(List<RoleMenu> roleMenus){ |
| | | return mapper.updateBatch(roleMenus); |
| | | } |
| | | |
| | | } |