提交 | 用户 | 时间
|
fd2207
|
1 |
package com.jcdm.web.controller.system; |
懒 |
2 |
|
|
3 |
import java.util.List; |
|
4 |
import org.springframework.beans.factory.annotation.Autowired; |
|
5 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
6 |
import org.springframework.validation.annotation.Validated; |
|
7 |
import org.springframework.web.bind.annotation.DeleteMapping; |
|
8 |
import org.springframework.web.bind.annotation.GetMapping; |
|
9 |
import org.springframework.web.bind.annotation.PathVariable; |
|
10 |
import org.springframework.web.bind.annotation.PostMapping; |
|
11 |
import org.springframework.web.bind.annotation.PutMapping; |
|
12 |
import org.springframework.web.bind.annotation.RequestBody; |
|
13 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
14 |
import org.springframework.web.bind.annotation.RestController; |
|
15 |
import com.jcdm.common.annotation.Log; |
|
16 |
import com.jcdm.common.constant.UserConstants; |
|
17 |
import com.jcdm.common.core.controller.BaseController; |
|
18 |
import com.jcdm.common.core.domain.AjaxResult; |
|
19 |
import com.jcdm.common.core.domain.entity.SysMenu; |
|
20 |
import com.jcdm.common.enums.BusinessType; |
|
21 |
import com.jcdm.common.utils.StringUtils; |
|
22 |
import com.jcdm.system.service.ISysMenuService; |
|
23 |
|
|
24 |
/** |
|
25 |
* 菜单信息 |
|
26 |
* |
|
27 |
* @author jc |
|
28 |
*/ |
|
29 |
@RestController |
|
30 |
@RequestMapping("/system/menu") |
|
31 |
public class SysMenuController extends BaseController |
|
32 |
{ |
|
33 |
@Autowired |
|
34 |
private ISysMenuService menuService; |
|
35 |
|
|
36 |
/** |
|
37 |
* 获取菜单列表 |
|
38 |
*/ |
|
39 |
@PreAuthorize("@ss.hasPermi('system:menu:list')") |
|
40 |
@GetMapping("/list") |
|
41 |
public AjaxResult list(SysMenu menu) |
|
42 |
{ |
|
43 |
List<SysMenu> menus = menuService.selectMenuList(menu, getUserId()); |
|
44 |
return success(menus); |
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* 根据菜单编号获取详细信息 |
|
49 |
*/ |
|
50 |
@PreAuthorize("@ss.hasPermi('system:menu:query')") |
|
51 |
@GetMapping(value = "/{menuId}") |
|
52 |
public AjaxResult getInfo(@PathVariable Long menuId) |
|
53 |
{ |
|
54 |
return success(menuService.selectMenuById(menuId)); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* 获取菜单下拉树列表 |
|
59 |
*/ |
|
60 |
@GetMapping("/treeselect") |
|
61 |
public AjaxResult treeselect(SysMenu menu) |
|
62 |
{ |
|
63 |
List<SysMenu> menus = menuService.selectMenuList(menu, getUserId()); |
|
64 |
return success(menuService.buildMenuTreeSelect(menus)); |
|
65 |
} |
|
66 |
|
|
67 |
/** |
|
68 |
* 加载对应角色菜单列表树 |
|
69 |
*/ |
|
70 |
@GetMapping(value = "/roleMenuTreeselect/{roleId}") |
|
71 |
public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) |
|
72 |
{ |
|
73 |
List<SysMenu> menus = menuService.selectMenuList(getUserId()); |
|
74 |
AjaxResult ajax = AjaxResult.success(); |
|
75 |
ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId)); |
|
76 |
ajax.put("menus", menuService.buildMenuTreeSelect(menus)); |
|
77 |
return ajax; |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* 新增菜单 |
|
82 |
*/ |
|
83 |
@PreAuthorize("@ss.hasPermi('system:menu:add')") |
|
84 |
@Log(title = "菜单管理", businessType = BusinessType.INSERT) |
|
85 |
@PostMapping |
|
86 |
public AjaxResult add(@Validated @RequestBody SysMenu menu) |
|
87 |
{ |
|
88 |
if (!menuService.checkMenuNameUnique(menu)) |
|
89 |
{ |
|
90 |
return error("新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在"); |
|
91 |
} |
|
92 |
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) |
|
93 |
{ |
|
94 |
return error("新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头"); |
|
95 |
} |
|
96 |
menu.setCreateBy(getUsername()); |
|
97 |
return toAjax(menuService.insertMenu(menu)); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* 修改菜单 |
|
102 |
*/ |
|
103 |
@PreAuthorize("@ss.hasPermi('system:menu:edit')") |
|
104 |
@Log(title = "菜单管理", businessType = BusinessType.UPDATE) |
|
105 |
@PutMapping |
|
106 |
public AjaxResult edit(@Validated @RequestBody SysMenu menu) |
|
107 |
{ |
|
108 |
if (!menuService.checkMenuNameUnique(menu)) |
|
109 |
{ |
|
110 |
return error("修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在"); |
|
111 |
} |
|
112 |
else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getPath())) |
|
113 |
{ |
|
114 |
return error("修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头"); |
|
115 |
} |
|
116 |
else if (menu.getMenuId().equals(menu.getParentId())) |
|
117 |
{ |
|
118 |
return error("修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己"); |
|
119 |
} |
|
120 |
menu.setUpdateBy(getUsername()); |
|
121 |
return toAjax(menuService.updateMenu(menu)); |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* 删除菜单 |
|
126 |
*/ |
|
127 |
@PreAuthorize("@ss.hasPermi('system:menu:remove')") |
|
128 |
@Log(title = "菜单管理", businessType = BusinessType.DELETE) |
|
129 |
@DeleteMapping("/{menuId}") |
|
130 |
public AjaxResult remove(@PathVariable("menuId") Long menuId) |
|
131 |
{ |
|
132 |
if (menuService.hasChildByMenuId(menuId)) |
|
133 |
{ |
|
134 |
return warn("存在子菜单,不允许删除"); |
|
135 |
} |
|
136 |
if (menuService.checkMenuExistRole(menuId)) |
|
137 |
{ |
|
138 |
return warn("菜单已分配,不允许删除"); |
|
139 |
} |
|
140 |
return toAjax(menuService.deleteMenuById(menuId)); |
|
141 |
} |
|
142 |
} |