潘志宝
4 天以前 b8a0affd03b5fa9fa33cd6f870e90394c2df86c7
iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/controller/admin/permission/MenuController.java
@@ -21,7 +21,9 @@
import java.util.Comparator;
import java.util.List;
import static com.iailab.framework.common.pojo.CommonResult.error;
import static com.iailab.framework.common.pojo.CommonResult.success;
import static com.iailab.framework.tenant.core.context.TenantContextHolder.getTenantId;
@Tag(name = "管理后台 - 菜单")
@RestController
@@ -40,10 +42,26 @@
        return success(menuId);
    }
    @PostMapping("/createAppMenu")
    @Operation(summary = "创建菜单")
    @PreAuthorize("@ss.hasPermission('system:app-menu:create')")
    public CommonResult<Long> createAppMenu(@Valid @RequestBody MenuSaveVO createReqVO) {
        Long menuId = menuService.createMenu(createReqVO);
        return success(menuId);
    }
    @PutMapping("/update")
    @Operation(summary = "修改菜单")
    @PreAuthorize("@ss.hasPermission('system:menu:update')")
    public CommonResult<Boolean> updateMenu(@Valid @RequestBody MenuSaveVO updateReqVO) {
        menuService.updateMenu(updateReqVO);
        return success(true);
    }
    @PutMapping("/updateAppMenu")
    @Operation(summary = "修改菜单")
    @PreAuthorize("@ss.hasPermission('system:app-menu:update')")
    public CommonResult<Boolean> updateAppMenu(@Valid @RequestBody MenuSaveVO updateReqVO) {
        menuService.updateMenu(updateReqVO);
        return success(true);
    }
@@ -57,11 +75,36 @@
        return success(true);
    }
    @DeleteMapping("/deleteAppMenu")
    @Operation(summary = "删除菜单")
    @Parameter(name = "id", description = "菜单编号", required= true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:app-menu:delete')")
    public CommonResult<Boolean> deleteAppMenu(@RequestParam("id") Long id) {
        menuService.deleteMenu(id);
        return success(true);
    }
    @GetMapping("/list")
    @Operation(summary = "获取菜单列表", description = "用于【菜单管理】界面")
    @PreAuthorize("@ss.hasPermission('system:menu:query')")
    public CommonResult<List<MenuRespVO>> getMenuList(MenuListReqVO reqVO) {
        List<MenuDO> list = menuService.getMenuList(reqVO);
        list.sort(Comparator.comparing(MenuDO::getSort));
        return success(BeanUtils.toBean(list, MenuRespVO.class));
    }
    @GetMapping("/app-menu-list")
    @Operation(summary = "获取应用菜单列表", description = "用于【应用菜单】界面")
    @PreAuthorize("@ss.hasPermission('system:app-menu:query')")
    public CommonResult<List<MenuRespVO>> getAppMenuList(MenuListReqVO reqVO) {
        // 获取 tenantId
        Long tenantId = getTenantId();
        // 管理员租户不在此管理菜单
        if(tenantId == 1l) {
            return error(-1, "管理员租户请在“菜单管理”中管理菜单!");
        }
        List<MenuDO> list = menuService.getAppMenuList(tenantId, reqVO);
        list.sort(Comparator.comparing(MenuDO::getSort));
        return success(BeanUtils.toBean(list, MenuRespVO.class));
    }
@@ -76,6 +119,16 @@
        return success(BeanUtils.toBean(list, MenuSimpleRespVO.class));
    }
    @GetMapping({"simple-app-menus"})
    @Operation(summary = "获取应用菜单精简信息列表", description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。" +
            "在多租户的场景下,会只返回租户所在套餐有的菜单")
    public CommonResult<List<MenuSimpleRespVO>> getSimpleAppMenuList() {
        List<MenuDO> list = menuService.getAppMenuListByTenant(
                new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()));
        list.sort(Comparator.comparing(MenuDO::getSort));
        return success(BeanUtils.toBean(list, MenuSimpleRespVO.class));
    }
    @GetMapping("/get")
    @Operation(summary = "获取菜单信息")
    @PreAuthorize("@ss.hasPermission('system:menu:query')")
@@ -84,4 +137,12 @@
        return success(BeanUtils.toBean(menu, MenuRespVO.class));
    }
    @GetMapping("/getAppMenu")
    @Operation(summary = "获取菜单信息")
    @PreAuthorize("@ss.hasPermission('system:app-menu:query')")
    public CommonResult<MenuRespVO> getAppMenu(Long id) {
        MenuDO menu = menuService.getMenu(id);
        return success(BeanUtils.toBean(menu, MenuRespVO.class));
    }
}