提交 | 用户 | 时间
|
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 |
|
|
24 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
|
25 |
|
|
26 |
@Tag(name = "管理后台 - 菜单") |
|
27 |
@RestController |
|
28 |
@RequestMapping("/system/menu") |
|
29 |
@Validated |
|
30 |
public class MenuController { |
|
31 |
|
|
32 |
@Resource |
|
33 |
private MenuService menuService; |
|
34 |
|
|
35 |
@PostMapping("/create") |
|
36 |
@Operation(summary = "创建菜单") |
|
37 |
@PreAuthorize("@ss.hasPermission('system:menu:create')") |
|
38 |
public CommonResult<Long> createMenu(@Valid @RequestBody MenuSaveVO createReqVO) { |
|
39 |
Long menuId = menuService.createMenu(createReqVO); |
|
40 |
return success(menuId); |
|
41 |
} |
|
42 |
|
|
43 |
@PutMapping("/update") |
|
44 |
@Operation(summary = "修改菜单") |
|
45 |
@PreAuthorize("@ss.hasPermission('system:menu:update')") |
|
46 |
public CommonResult<Boolean> updateMenu(@Valid @RequestBody MenuSaveVO updateReqVO) { |
|
47 |
menuService.updateMenu(updateReqVO); |
|
48 |
return success(true); |
|
49 |
} |
|
50 |
|
|
51 |
@DeleteMapping("/delete") |
|
52 |
@Operation(summary = "删除菜单") |
|
53 |
@Parameter(name = "id", description = "菜单编号", required= true, example = "1024") |
|
54 |
@PreAuthorize("@ss.hasPermission('system:menu:delete')") |
|
55 |
public CommonResult<Boolean> deleteMenu(@RequestParam("id") Long id) { |
|
56 |
menuService.deleteMenu(id); |
|
57 |
return success(true); |
|
58 |
} |
|
59 |
|
|
60 |
@GetMapping("/list") |
|
61 |
@Operation(summary = "获取菜单列表", description = "用于【菜单管理】界面") |
|
62 |
@PreAuthorize("@ss.hasPermission('system:menu:query')") |
|
63 |
public CommonResult<List<MenuRespVO>> getMenuList(MenuListReqVO reqVO) { |
|
64 |
List<MenuDO> list = menuService.getMenuList(reqVO); |
|
65 |
list.sort(Comparator.comparing(MenuDO::getSort)); |
|
66 |
return success(BeanUtils.toBean(list, MenuRespVO.class)); |
|
67 |
} |
|
68 |
|
|
69 |
@GetMapping({"/list-all-simple", "simple-list"}) |
|
70 |
@Operation(summary = "获取菜单精简信息列表", description = "只包含被开启的菜单,用于【角色分配菜单】功能的选项。" + |
|
71 |
"在多租户的场景下,会只返回租户所在套餐有的菜单") |
|
72 |
public CommonResult<List<MenuSimpleRespVO>> getSimpleMenuList() { |
|
73 |
List<MenuDO> list = menuService.getMenuListByTenant( |
|
74 |
new MenuListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); |
|
75 |
list.sort(Comparator.comparing(MenuDO::getSort)); |
|
76 |
return success(BeanUtils.toBean(list, MenuSimpleRespVO.class)); |
|
77 |
} |
|
78 |
|
|
79 |
@GetMapping("/get") |
|
80 |
@Operation(summary = "获取菜单信息") |
|
81 |
@PreAuthorize("@ss.hasPermission('system:menu:query')") |
|
82 |
public CommonResult<MenuRespVO> getMenu(Long id) { |
|
83 |
MenuDO menu = menuService.getMenu(id); |
|
84 |
return success(BeanUtils.toBean(menu, MenuRespVO.class)); |
|
85 |
} |
|
86 |
|
|
87 |
} |