mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 10:29:19 +08:00
完善动态路由菜单接口
This commit is contained in:
+46
-1
@@ -6,10 +6,12 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.service.CompanyMenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.CreateMenuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.menu.UpdateMenuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.MenuService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,9 +24,13 @@ import java.util.List;
|
||||
public class MenuController {
|
||||
|
||||
private final MenuService menuService;
|
||||
private final CompanyMenuService companyMenuService;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
|
||||
public MenuController(MenuService menuService) {
|
||||
public MenuController(MenuService menuService, CompanyMenuService companyMenuService, CurrentUserContext currentUserContext) {
|
||||
this.menuService = menuService;
|
||||
this.companyMenuService = companyMenuService;
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建菜单", description = "创建新的菜单")
|
||||
@@ -79,4 +85,43 @@ public class MenuController {
|
||||
List<MenuVO> menuTree = menuService.getMenuTreeByRole(userRole);
|
||||
return ApiResponse.success(menuTree);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户菜单(动态路由)", description = "根据用户角色获取对应的菜单,用于前端动态路由")
|
||||
@GetMapping("/all")
|
||||
public ApiResponse<List<MenuVO>> getUserMenus() {
|
||||
// 获取当前用户信息
|
||||
String userRole = currentUserContext.getCurrentUserRole();
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
Long positionId = currentUserContext.getCurrentUserPositionId();
|
||||
|
||||
List<MenuVO> menus;
|
||||
|
||||
switch (userRole) {
|
||||
case "super":
|
||||
// 超级管理员获取所有系统菜单
|
||||
menus = menuService.getAllMenus();
|
||||
break;
|
||||
case "admin":
|
||||
// 公司管理员获取公司所有菜单
|
||||
if (companyId == null) {
|
||||
menus = List.of();
|
||||
} else {
|
||||
menus = companyMenuService.getCompanyMenusForRoute(companyId);
|
||||
}
|
||||
break;
|
||||
case "user":
|
||||
// 普通用户根据职位获取菜单
|
||||
if (positionId == null) {
|
||||
menus = List.of();
|
||||
} else {
|
||||
menus = companyMenuService.getPositionMenusForRoute(positionId);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
menus = List.of();
|
||||
break;
|
||||
}
|
||||
|
||||
return ApiResponse.success(menus);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user