Skip to content

Commit

Permalink
[Improve] Optimize the logic for constructing role menus. (#3952)
Browse files Browse the repository at this point in the history
Co-authored-by: 夏洋 <[email protected]>
  • Loading branch information
MaoMiMao and 夏洋 authored Nov 26, 2024
1 parent 904f4fe commit bb55f4a
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

Expand All @@ -73,7 +74,6 @@
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -558,12 +558,17 @@ public UserDTO buildUserInfo(Integer userId) {
// query role menu
List<RoleMenu> roleMenus =
roleMenuService.list(new LambdaQueryWrapper<RoleMenu>().eq(RoleMenu::getRoleId, role.getId()));
roleMenus.forEach(roleMenu -> {
Menu menu = menuService.getById(roleMenu.getMenuId());
if (Asserts.isNotNull(menu) && !StrUtil.equals("M", menu.getType())) {
menuList.add(menu);
}
});
List<Integer> collect =
roleMenus.stream().map(RoleMenu::getMenuId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(collect)) {
return;
}
List<Menu> list = menuService.list(new LambdaQueryWrapper<Menu>()
.in(
Menu::getId,
roleMenus.stream().map(RoleMenu::getMenuId).collect(Collectors.toList()))
.ne(Menu::getType, "M"));
menuList.addAll(list);
}
});

Expand Down

0 comments on commit bb55f4a

Please sign in to comment.