mirror of https://github.com/elunez/eladmin
[代码完善](master): 代码优化
parent
2dc528a103
commit
b7b721b13b
|
@ -49,13 +49,13 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
|
|||
* @param pid /
|
||||
* @return /
|
||||
*/
|
||||
List<Menu> findByPid(long pid);
|
||||
List<Menu> findByPidOrderByMenuSort(long pid);
|
||||
|
||||
/**
|
||||
* 查询顶级菜单
|
||||
* @return /
|
||||
*/
|
||||
List<Menu> findByPidIsNull();
|
||||
List<Menu> findByPidIsNullOrderByMenuSort();
|
||||
|
||||
/**
|
||||
* 根据角色ID与菜单类型查询菜单
|
||||
|
|
|
@ -189,7 +189,7 @@ public class MenuServiceImpl implements MenuService {
|
|||
public Set<Menu> getChildMenus(List<Menu> menuList, Set<Menu> menuSet) {
|
||||
for (Menu menu : menuList) {
|
||||
menuSet.add(menu);
|
||||
List<Menu> menus = menuRepository.findByPid(menu.getId());
|
||||
List<Menu> menus = menuRepository.findByPidOrderByMenuSort(menu.getId());
|
||||
if(menus!=null && menus.size()!=0){
|
||||
getChildMenus(menus, menuSet);
|
||||
}
|
||||
|
@ -213,9 +213,9 @@ public class MenuServiceImpl implements MenuService {
|
|||
public List<MenuDto> getMenus(Long pid) {
|
||||
List<Menu> menus;
|
||||
if(pid != null && !pid.equals(0L)){
|
||||
menus = menuRepository.findByPid(pid);
|
||||
menus = menuRepository.findByPidOrderByMenuSort(pid);
|
||||
} else {
|
||||
menus = menuRepository.findByPidIsNull();
|
||||
menus = menuRepository.findByPidIsNullOrderByMenuSort();
|
||||
}
|
||||
return menuMapper.toDto(menus);
|
||||
}
|
||||
|
@ -223,10 +223,10 @@ public class MenuServiceImpl implements MenuService {
|
|||
@Override
|
||||
public List<MenuDto> getSuperior(MenuDto menuDto, List<Menu> menus) {
|
||||
if(menuDto.getPid() == null){
|
||||
menus.addAll(menuRepository.findByPidIsNull());
|
||||
menus.addAll(menuRepository.findByPidIsNullOrderByMenuSort());
|
||||
return menuMapper.toDto(menus);
|
||||
}
|
||||
menus.addAll(menuRepository.findByPid(menuDto.getPid()));
|
||||
menus.addAll(menuRepository.findByPidOrderByMenuSort(menuDto.getPid()));
|
||||
return getSuperior(findById(menuDto.getPid()), menus);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue