refactor(system): 优化菜单选项接口和相关服务
- 更新 MenuController 中 listMenuOptions 方法的返回类型为 Result<List<Option<Long>>>- 更新 MenuService 接口中 listMenuOptions 方法的返回类型为 List<Option<Long>> - 更新 MenuServiceImpl 中 listMenuOptions 和 buildMenuOptions 方法的返回类型为 List<Option<Long>> - 优化相关方法的参数类型和泛型使用,提高代码可读性
This commit is contained in:
@@ -47,11 +47,11 @@ public class MenuController {
|
||||
|
||||
@Operation(summary = "菜单下拉列表")
|
||||
@GetMapping("/options")
|
||||
public Result<?> listMenuOptions(
|
||||
public Result<List<Option<Long>>> listMenuOptions(
|
||||
@Parameter(description = "是否只查询父级菜单")
|
||||
@RequestParam(required = false, defaultValue = "false") boolean onlyParent
|
||||
) {
|
||||
List<Option> menus = menuService.listMenuOptions(onlyParent);
|
||||
List<Option<Long>> menus = menuService.listMenuOptions(onlyParent);
|
||||
return Result.success(menus);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface MenuService extends IService<Menu> {
|
||||
*
|
||||
* @param onlyParent 是否只查询父级菜单
|
||||
*/
|
||||
List<Option> listMenuOptions(boolean onlyParent);
|
||||
List<Option<Long>> listMenuOptions(boolean onlyParent);
|
||||
|
||||
/**
|
||||
* 新增菜单
|
||||
|
||||
@@ -106,7 +106,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
||||
* @param onlyParent 是否只查询父级菜单 如果为true,排除按钮
|
||||
*/
|
||||
@Override
|
||||
public List<Option> listMenuOptions(boolean onlyParent) {
|
||||
public List<Option<Long>> listMenuOptions(boolean onlyParent) {
|
||||
List<Menu> menuList = this.list(new LambdaQueryWrapper<Menu>()
|
||||
.in(onlyParent, Menu::getType, MenuTypeEnum.CATALOG.getValue(), MenuTypeEnum.MENU.getValue())
|
||||
.orderByAsc(Menu::getSort)
|
||||
@@ -121,13 +121,13 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
||||
* @param menuList 菜单列表
|
||||
* @return 菜单下拉列表
|
||||
*/
|
||||
private List<Option> buildMenuOptions(Long parentId, List<Menu> menuList) {
|
||||
List<Option> menuOptions = new ArrayList<>();
|
||||
private List<Option<Long>> buildMenuOptions(Long parentId, List<Menu> menuList) {
|
||||
List<Option<Long>> menuOptions = new ArrayList<>();
|
||||
|
||||
for (Menu menu : menuList) {
|
||||
if (menu.getParentId().equals(parentId)) {
|
||||
Option option = new Option(menu.getId(), menu.getName());
|
||||
List<Option> subMenuOptions = buildMenuOptions(menu.getId(), menuList);
|
||||
Option<Long> option = new Option<>(menu.getId(), menu.getName());
|
||||
List<Option<Long>> subMenuOptions = buildMenuOptions(menu.getId(), menuList);
|
||||
if (!subMenuOptions.isEmpty()) {
|
||||
option.setChildren(subMenuOptions);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user