提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.system.controller.admin.permission; |
H |
2 |
|
|
3 |
import com.iailab.framework.common.enums.CommonStatusEnum; |
|
4 |
import com.iailab.framework.common.pojo.CommonResult; |
|
5 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
6 |
import com.iailab.module.system.controller.admin.permission.vo.menu.MenuListReqVO; |
|
7 |
import com.iailab.module.system.controller.admin.permission.vo.menu.MenuRespVO; |
|
8 |
import com.iailab.module.system.controller.admin.permission.vo.menu.MenuSaveVO; |
|
9 |
import com.iailab.module.system.controller.admin.permission.vo.menu.MenuSimpleRespVO; |
|
10 |
import com.iailab.module.system.dal.dataobject.permission.MenuDO; |
|
11 |
import com.iailab.module.system.service.permission.MenuService; |
|
12 |
import io.swagger.v3.oas.annotations.Operation; |
|
13 |
import io.swagger.v3.oas.annotations.Parameter; |
|
14 |
import io.swagger.v3.oas.annotations.tags.Tag; |
|
15 |
import org.springframework.security.access.prepost.PreAuthorize; |
|
16 |
import org.springframework.validation.annotation.Validated; |
|
17 |
import org.springframework.web.bind.annotation.*; |
|
18 |
|
|
19 |
import javax.annotation.Resource; |
|
20 |
import javax.validation.Valid; |
|
21 |
import java.util.Comparator; |
|
22 |
import java.util.List; |
|
23 |
|
ce910c
|
24 |
import static com.iailab.framework.common.pojo.CommonResult.error; |
e7c126
|
25 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
ce910c
|
26 |
import static com.iailab.framework.tenant.core.context.TenantContextHolder.getTenantId; |
e7c126
|
27 |
|
H |
28 |
@Tag(name = "管理后台 - 菜单") |
|
29 |
@RestController |
|
30 |
@RequestMapping("/system/menu") |
|
31 |
@Validated |
|
32 |
public class MenuController { |
|
33 |
|
|
34 |
@Resource |
|
35 |
private MenuService menuService; |
|
36 |
|
|
37 |
@PostMapping("/create") |
|
38 |
@Operation(summary = "创建菜单") |
|
39 |
@PreAuthorize("@ss.hasPermission('system:menu:create')") |
|
40 |
public CommonResult<Long> createMenu(@Valid @RequestBody MenuSaveVO createReqVO) { |
|
41 |
Long menuId = menuService.createMenu(createReqVO); |
|
42 |
return success(menuId); |
|
43 |
} |
|
44 |
|
818a01
|
45 |
@PostMapping("/createAppMenu") |
H |
46 |
@Operation(summary = "创建菜单") |
|
47 |
@PreAuthorize("@ss.hasPermission('system:app-menu:create')") |
|
48 |
public CommonResult<Long> createAppMenu(@Valid @RequestBody MenuSaveVO createReqVO) { |
|
49 |
Long menuId = menuService.createMenu(createReqVO); |
|
50 |
return success(menuId); |
|
51 |
} |
|
52 |
|
e7c126
|
53 |
@PutMapping("/update") |
H |
54 |
@Operation(summary = "修改菜单") |
|
55 |
@PreAuthorize("@ss.hasPermission('system:menu:update')") |
|
56 |
public CommonResult<Boolean> updateMenu(@Valid @RequestBody MenuSaveVO updateReqVO) { |
818a01
|
57 |
menuService.updateMenu(updateReqVO); |
H |
58 |
return success(true); |
|
59 |
} |
|
60 |
|
|
61 |
@PutMapping("/updateAppMenu") |
|
62 |
@Operation(summary = "修改菜单") |
|
63 |
@PreAuthorize("@ss.hasPermission('system:app-menu:update')") |
|
64 |
public CommonResult<Boolean> updateAppMenu(@Valid @RequestBody MenuSaveVO updateReqVO) { |
e7c126
|
65 |
menuService.updateMenu(updateReqVO); |
H |
66 |
return success(true); |
|
67 |
} |
|
68 |
|
|
69 |
@DeleteMapping("/delete") |
|
70 |
@Operation(summary = "删除菜单") |
|
71 |
@Parameter(name = "id", description = "菜单编号", required= true, example = "1024") |
|
72 |
@PreAuthorize("@ss.hasPermission('system:menu:delete')") |
|
73 |
public CommonResult<Boolean> deleteMenu(@RequestParam("id") Long id) { |
|
74 |
menuService.deleteMenu(id); |
|
75 |
return success(true); |
|
76 |
} |
|
77 |
|
818a01
|
78 |
@DeleteMapping("/deleteAppMenu") |
H |
79 |
@Operation(summary = "删除菜单") |
|
80 |
@Parameter(name = "id", description = "菜单编号", required= true, example = "1024") |
|
81 |
@PreAuthorize("@ss.hasPermission('system:app-menu:delete')") |
|
82 |
public CommonResult<Boolean> deleteAppMenu(@RequestParam("id") Long id) { |
|
83 |
menuService.deleteMenu(id); |
|
84 |
return success(true); |
|
85 |
} |
|
86 |
|
|
87 |
|
e7c126
|
88 |
@GetMapping("/list") |
H |
89 |
@Operation(summary = "获取菜单列表", description = "用于【菜单管理】界面") |
|
90 |
@PreAuthorize("@ss.hasPermission('system:menu:query')") |
|
91 |
public CommonResult<List<MenuRespVO>> getMenuList(MenuListReqVO reqVO) { |
|
92 |
List<MenuDO> list = menuService.getMenuList(reqVO); |
818a01
|
93 |
list.sort(Comparator.comparing(MenuDO::getSort)); |
H |
94 |
return success(BeanUtils.toBean(list, MenuRespVO.class)); |
|
95 |
} |
|
96 |
|
|
97 |
@GetMapping("/app-menu-list") |
|
98 |
@Operation(summary = "获取应用菜单列表", description = "用于【应用菜单】界面") |
|
99 |
@PreAuthorize("@ss.hasPermission('system:app-menu:query')") |
|
100 |
public CommonResult<List<MenuRespVO>> getAppMenuList(MenuListReqVO reqVO) { |
ce910c
|
101 |
// 获取 tenantId |
H |
102 |
Long tenantId = getTenantId(); |
|
103 |
// 管理员租户不在此管理菜单 |
|
104 |
if(tenantId == 1l) { |
|
105 |
return error(-1, "管理员租户请在“菜单管理”中管理菜单!"); |
|
106 |
} |
|
107 |
List<MenuDO> list = menuService.getAppMenuList(tenantId, reqVO); |
e7c126
|
108 |
list.sort(Comparator.comparing(MenuDO::getSort)); |
H |
109 |
return success(BeanUtils.toBean(list, MenuRespVO.class)); |
|
110 |
} |
|
111 |
|
|
112 |
@GetMapping({"/list-all-simple", "simple-list"}) |
|
113 |
@Operation(summary = "获取菜单精简信息列表", description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。" + |
|
114 |
"在多租户的场景下,会只返回租户所在套餐有的菜单") |
|
115 |
public CommonResult<List<MenuSimpleRespVO>> getSimpleMenuList() { |
|
116 |
List<MenuDO> list = menuService.getMenuListByTenant( |
|
117 |
new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); |
|
118 |
list.sort(Comparator.comparing(MenuDO::getSort)); |
|
119 |
return success(BeanUtils.toBean(list, MenuSimpleRespVO.class)); |
|
120 |
} |
|
121 |
|
818a01
|
122 |
@GetMapping({"simple-app-menus"}) |
H |
123 |
@Operation(summary = "获取应用菜单精简信息列表", description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。" + |
|
124 |
"在多租户的场景下,会只返回租户所在套餐有的菜单") |
|
125 |
public CommonResult<List<MenuSimpleRespVO>> getSimpleAppMenuList() { |
|
126 |
List<MenuDO> list = menuService.getAppMenuListByTenant( |
|
127 |
new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); |
|
128 |
list.sort(Comparator.comparing(MenuDO::getSort)); |
|
129 |
return success(BeanUtils.toBean(list, MenuSimpleRespVO.class)); |
|
130 |
} |
|
131 |
|
e7c126
|
132 |
@GetMapping("/get") |
H |
133 |
@Operation(summary = "获取菜单信息") |
|
134 |
@PreAuthorize("@ss.hasPermission('system:menu:query')") |
|
135 |
public CommonResult<MenuRespVO> getMenu(Long id) { |
|
136 |
MenuDO menu = menuService.getMenu(id); |
|
137 |
return success(BeanUtils.toBean(menu, MenuRespVO.class)); |
|
138 |
} |
|
139 |
|
818a01
|
140 |
@GetMapping("/getAppMenu") |
H |
141 |
@Operation(summary = "获取菜单信息") |
|
142 |
@PreAuthorize("@ss.hasPermission('system:app-menu:query')") |
|
143 |
public CommonResult<MenuRespVO> getAppMenu(Long id) { |
|
144 |
MenuDO menu = menuService.getMenu(id); |
|
145 |
return success(BeanUtils.toBean(menu, MenuRespVO.class)); |
|
146 |
} |
|
147 |
|
e7c126
|
148 |
} |