Blame view

ruoyi/src/main/java/com/ruoyi/project/system/controller/SysMenuController.java 4.33 KB
46444bd0   RuoYi   RuoYi-Vue 1.0
1
2
3
4
5
6
7
8
9
10
11
12
13
  package com.ruoyi.project.system.controller;

  

  import java.util.List;

  import org.springframework.beans.factory.annotation.Autowired;

  import org.springframework.security.access.prepost.PreAuthorize;

  import org.springframework.validation.annotation.Validated;

  import org.springframework.web.bind.annotation.DeleteMapping;

  import org.springframework.web.bind.annotation.GetMapping;

  import org.springframework.web.bind.annotation.PathVariable;

  import org.springframework.web.bind.annotation.PostMapping;

  import org.springframework.web.bind.annotation.PutMapping;

  import org.springframework.web.bind.annotation.RequestBody;

  import org.springframework.web.bind.annotation.RequestMapping;

46444bd0   RuoYi   RuoYi-Vue 1.0
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  import org.springframework.web.bind.annotation.RestController;

  import com.ruoyi.common.constant.UserConstants;

  import com.ruoyi.common.utils.SecurityUtils;

  import com.ruoyi.framework.aspectj.lang.annotation.Log;

  import com.ruoyi.framework.aspectj.lang.enums.BusinessType;

  import com.ruoyi.framework.web.controller.BaseController;

  import com.ruoyi.framework.web.domain.AjaxResult;

  import com.ruoyi.project.system.domain.SysMenu;

  import com.ruoyi.project.system.service.ISysMenuService;

  

  /**

   * 菜单信息

   * 

   * @author ruoyi

   */

  @RestController

  @RequestMapping("/system/menu")

  public class SysMenuController extends BaseController

  {

      @Autowired

      private ISysMenuService menuService;

  

      /**

       * 获取菜单列表

       */

      @PreAuthorize("@ss.hasPermi('system:menu:list')")

      @GetMapping("/list")

      public AjaxResult list(SysMenu menu)

      {

          List<SysMenu> menus = menuService.selectMenuList(menu);

          return AjaxResult.success(menuService.buildMenuTree(menus));

      }

  

      /**

       * 根据菜单编号获取详细信息

       */

      @PreAuthorize("@ss.hasPermi('system:menu:query')")

      @GetMapping(value = "/{menuId}")

      public AjaxResult getInfo(@PathVariable Long menuId)

      {

          return AjaxResult.success(menuService.selectMenuById(menuId));

      }

  

      /**

       * 获取菜单下拉树列表

       */

46444bd0   RuoYi   RuoYi-Vue 1.0
60
61
62
63
64
65
66
67
68
69
      @GetMapping("/treeselect")

      public AjaxResult treeselect(SysMenu dept)

      {

          List<SysMenu> menus = menuService.selectMenuList(dept);

          return AjaxResult.success(menuService.buildMenuTreeSelect(menus));

      }

  

      /**

       * 加载对应角色菜单列表树

       */

46444bd0   RuoYi   RuoYi-Vue 1.0
70
      @GetMapping(value = "/roleMenuTreeselect/{roleId}")

46444bd0   RuoYi   RuoYi-Vue 1.0
71
72
73
74
75
76
77
78
79
80
81
      public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId)

      {

          return AjaxResult.success(menuService.selectMenuListByRoleId(roleId));

      }

  

      /**

       * 新增菜单

       */

      @PreAuthorize("@ss.hasPermi('system:menu:add')")

      @Log(title = "菜单管理", businessType = BusinessType.INSERT)

      @PostMapping

bcee37b8   RuoYi   若依 1.1
82
      public AjaxResult add(@Validated @RequestBody SysMenu menu)

46444bd0   RuoYi   RuoYi-Vue 1.0
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
      {

          if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))

          {

              return AjaxResult.error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");

          }

          menu.setCreateBy(SecurityUtils.getUsername());

          return toAjax(menuService.insertMenu(menu));

      }

  

      /**

       * 修改菜单

       */

      @PreAuthorize("@ss.hasPermi('system:menu:edit')")

      @Log(title = "菜单管理", businessType = BusinessType.UPDATE)

      @PutMapping

bcee37b8   RuoYi   若依 1.1
98
      public AjaxResult edit(@Validated @RequestBody SysMenu menu)

46444bd0   RuoYi   RuoYi-Vue 1.0
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
      {

          if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu)))

          {

              return AjaxResult.error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");

          }

          menu.setUpdateBy(SecurityUtils.getUsername());

          return toAjax(menuService.updateMenu(menu));

      }

  

      /**

       * 删除菜单

       */

      @PreAuthorize("@ss.hasPermi('system:menu:remove')")

      @Log(title = "菜单管理", businessType = BusinessType.DELETE)

      @DeleteMapping("/{menuId}")

      public AjaxResult remove(@PathVariable("menuId") Long menuId)

      {

          if (menuService.hasChildByMenuId(menuId))

          {

              return AjaxResult.error("存在子菜单,不允许删除");

          }

          if (menuService.checkMenuExistRole(menuId))

          {

              return AjaxResult.error("菜单已分配,不允许删除");

          }

          return toAjax(menuService.deleteMenuById(menuId));

      }

  }