| | |
| | | import org.springframework.web.bind.annotation.RequestBody;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RestController;
|
| | | import com.ruoyi.common.core.constant.Constants;
|
| | | import com.ruoyi.common.core.constant.UserConstants;
|
| | | import com.ruoyi.common.core.utils.StringUtils;
|
| | | import com.ruoyi.common.core.web.controller.BaseController;
|
| | | import com.ruoyi.common.core.web.domain.AjaxResult;
|
| | | import com.ruoyi.common.log.annotation.Log;
|
| | | import com.ruoyi.common.log.enums.BusinessType;
|
| | | import com.ruoyi.common.security.annotation.PreAuthorize;
|
| | | import com.ruoyi.common.security.annotation.RequiresPermissions;
|
| | | import com.ruoyi.common.security.utils.SecurityUtils;
|
| | | import com.ruoyi.system.domain.SysMenu;
|
| | | import com.ruoyi.system.service.ISysMenuService;
|
| | |
| | | /**
|
| | | * 获取菜单列表
|
| | | */
|
| | | @PreAuthorize(hasPermi = "system:menu:list")
|
| | | @RequiresPermissions("system:menu:list")
|
| | | @GetMapping("/list")
|
| | | public AjaxResult list(SysMenu menu)
|
| | | {
|
| | | Long userId = SecurityUtils.getUserId();
|
| | | List<SysMenu> menus = menuService.selectMenuList(menu, userId);
|
| | | return AjaxResult.success(menus);
|
| | | return success(menus);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 根据菜单编号获取详细信息
|
| | | */
|
| | | @PreAuthorize(hasPermi = "system:menu:query")
|
| | | @RequiresPermissions("system:menu:query")
|
| | | @GetMapping(value = "/{menuId}")
|
| | | public AjaxResult getInfo(@PathVariable Long menuId)
|
| | | {
|
| | | return AjaxResult.success(menuService.selectMenuById(menuId));
|
| | | return success(menuService.selectMenuById(menuId));
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | {
|
| | | Long userId = SecurityUtils.getUserId();
|
| | | List<SysMenu> menus = menuService.selectMenuList(menu, userId);
|
| | | return AjaxResult.success(menuService.buildMenuTreeSelect(menus));
|
| | | return success(menuService.buildMenuTreeSelect(menus));
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | /**
|
| | | * 新增菜单
|
| | | */
|
| | | @PreAuthorize(hasPermi = "system:menu:add")
|
| | | @RequiresPermissions("system:menu:add")
|
| | | @Log(title = "菜单管理", businessType = BusinessType.INSERT)
|
| | | @PostMapping
|
| | | public AjaxResult add(@Validated @RequestBody SysMenu menu)
|
| | | {
|
| | | if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
|
| | | if (!menuService.checkMenuNameUnique(menu))
|
| | | {
|
| | | return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
| | | return error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
| | | }
|
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
|
| | | && !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS))
|
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath()))
|
| | | {
|
| | | return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
| | | return error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
| | | }
|
| | | menu.setCreateBy(SecurityUtils.getUsername());
|
| | | return toAjax(menuService.insertMenu(menu));
|
| | |
| | | /**
|
| | | * 修改菜单
|
| | | */
|
| | | @PreAuthorize(hasPermi = "system:menu:edit")
|
| | | @RequiresPermissions("system:menu:edit")
|
| | | @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
|
| | | @PutMapping
|
| | | public AjaxResult edit(@Validated @RequestBody SysMenu menu)
|
| | | {
|
| | | if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))
|
| | | if (!menuService.checkMenuNameUnique(menu))
|
| | | {
|
| | | return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
| | | return error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
| | | }
|
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame())
|
| | | && !StringUtils.startsWithAny(menu.getPath(), Constants.HTTP, Constants.HTTPS))
|
| | | else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath()))
|
| | | {
|
| | | return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
| | | return error("修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
| | | }
|
| | | else if (menu.getMenuId().equals(menu.getParentId()))
|
| | | {
|
| | | return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
|
| | | return error("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
|
| | | }
|
| | | menu.setUpdateBy(SecurityUtils.getUsername());
|
| | | return toAjax(menuService.updateMenu(menu));
|
| | |
| | | /**
|
| | | * 删除菜单
|
| | | */
|
| | | @PreAuthorize(hasPermi = "system:menu:remove")
|
| | | @RequiresPermissions("system:menu:remove")
|
| | | @Log(title = "菜单管理", businessType = BusinessType.DELETE)
|
| | | @DeleteMapping("/{menuId}")
|
| | | public AjaxResult remove(@PathVariable("menuId") Long menuId)
|
| | | {
|
| | | if (menuService.hasChildByMenuId(menuId))
|
| | | {
|
| | | return AjaxResult.error("存在子菜单,不允许删除");
|
| | | return warn("存在子菜单,不允许删除");
|
| | | }
|
| | | if (menuService.checkMenuExistRole(menuId))
|
| | | {
|
| | | return AjaxResult.error("菜单已分配,不允许删除");
|
| | | return warn("菜单已分配,不允许删除");
|
| | | }
|
| | | return toAjax(menuService.deleteMenuById(menuId));
|
| | | }
|
| | |
| | | {
|
| | | Long userId = SecurityUtils.getUserId();
|
| | | List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
|
| | | return AjaxResult.success(menuService.buildMenus(menus));
|
| | | return success(menuService.buildMenus(menus));
|
| | | }
|
| | | } |