♻️ Refactoring code. 菜单新增时菜单路径和权限字符串去重提示
This commit is contained in:
1 parent
5db9daee21
commit
9c521a7d34
1 file changed
+87
-78
+87
-78
@@ -19,6 +19,7 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysMenu;
|
||||
import com.pig4cloud.pigx.admin.service.SysMenuService;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
@@ -26,12 +27,13 @@ import com.pig4cloud.pigx.common.log.annotation.SysLog;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -47,89 +49,96 @@ import java.util.stream.Collectors;
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class SysMenuController {
|
||||
|
||||
private final SysMenuService sysMenuService;
|
||||
private final SysMenuService sysMenuService;
|
||||
|
||||
/**
|
||||
* 返回当前用户的树形菜单集合
|
||||
* @param type 类型
|
||||
* @param parentId 父节点ID
|
||||
* @return 当前用户的树形菜单
|
||||
*/
|
||||
@GetMapping
|
||||
public R getUserMenu(String type, Long parentId) {
|
||||
// 获取符合条件的菜单
|
||||
Set<SysMenu> all = new HashSet<>();
|
||||
SecurityUtils.getRoleIds().forEach(roleId -> all.addAll(sysMenuService.findMenuByRoleId(roleId)));
|
||||
return R.ok(sysMenuService.filterMenu(all, type, parentId));
|
||||
}
|
||||
/**
|
||||
* 返回当前用户的树形菜单集合
|
||||
*
|
||||
* @param type 类型
|
||||
* @param parentId 父节点ID
|
||||
* @return 当前用户的树形菜单
|
||||
*/
|
||||
@GetMapping
|
||||
public R getUserMenu(String type, Long parentId) {
|
||||
// 获取符合条件的菜单
|
||||
Set<SysMenu> all = new HashSet<>();
|
||||
SecurityUtils.getRoleIds().forEach(roleId -> all.addAll(sysMenuService.findMenuByRoleId(roleId)));
|
||||
return R.ok(sysMenuService.filterMenu(all, type, parentId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回树形菜单集合
|
||||
* @param parentId 父节点ID
|
||||
* @param menuName 菜单名称
|
||||
* @return 树形菜单
|
||||
*/
|
||||
@GetMapping(value = "/tree")
|
||||
public R getTree(Long parentId, String menuName, String type) {
|
||||
return R.ok(sysMenuService.treeMenu(parentId, menuName, type));
|
||||
}
|
||||
/**
|
||||
* 返回树形菜单集合
|
||||
*
|
||||
* @param parentId 父节点ID
|
||||
* @param menuName 菜单名称
|
||||
* @return 树形菜单
|
||||
*/
|
||||
@GetMapping(value = "/tree")
|
||||
public R getTree(Long parentId, String menuName, String type) {
|
||||
return R.ok(sysMenuService.treeMenu(parentId, menuName, type));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回角色的菜单集合
|
||||
* @param roleId 角色ID
|
||||
* @return 属性集合
|
||||
*/
|
||||
@GetMapping("/tree/{roleId}")
|
||||
public R getRoleTree(@PathVariable Long roleId) {
|
||||
return R
|
||||
.ok(sysMenuService.findMenuByRoleId(roleId).stream().map(SysMenu::getMenuId).collect(Collectors.toList()));
|
||||
}
|
||||
/**
|
||||
* 返回角色的菜单集合
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 属性集合
|
||||
*/
|
||||
@GetMapping("/tree/{roleId}")
|
||||
public R getRoleTree(@PathVariable Long roleId) {
|
||||
return R
|
||||
.ok(sysMenuService.findMenuByRoleId(roleId).stream().map(SysMenu::getMenuId).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ID查询菜单的详细信息
|
||||
* @param id 菜单ID
|
||||
* @return 菜单详细信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public R getById(@PathVariable Long id) {
|
||||
return R.ok(sysMenuService.getById(id));
|
||||
}
|
||||
/**
|
||||
* 通过ID查询菜单的详细信息
|
||||
*
|
||||
* @param id 菜单ID
|
||||
* @return 菜单详细信息
|
||||
*/
|
||||
@GetMapping("/details")
|
||||
public R getById(@ParameterObject SysMenu query) {
|
||||
return R.ok(sysMenuService.getOne(Wrappers.query(query), false));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增菜单
|
||||
* @param sysMenu 菜单信息
|
||||
* @return success/false
|
||||
*/
|
||||
@SysLog("新增菜单")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_menu_add')")
|
||||
public R save(@Valid @RequestBody SysMenu sysMenu) {
|
||||
sysMenuService.save(sysMenu);
|
||||
return R.ok(sysMenu);
|
||||
}
|
||||
/**
|
||||
* 新增菜单
|
||||
*
|
||||
* @param sysMenu 菜单信息
|
||||
* @return success/false
|
||||
*/
|
||||
@SysLog("新增菜单")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_menu_add')")
|
||||
public R save(@Valid @RequestBody SysMenu sysMenu) {
|
||||
sysMenuService.save(sysMenu);
|
||||
return R.ok(sysMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
* @param id 菜单ID
|
||||
* @return success/false
|
||||
*/
|
||||
@SysLog("删除菜单")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('sys_menu_del')")
|
||||
public R removeById(@PathVariable Long id) {
|
||||
return sysMenuService.removeMenuById(id);
|
||||
}
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单ID
|
||||
* @return success/false
|
||||
*/
|
||||
@SysLog("删除菜单")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('sys_menu_del')")
|
||||
public R removeById(@PathVariable Long id) {
|
||||
return sysMenuService.removeMenuById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新菜单
|
||||
* @param sysMenu
|
||||
* @return
|
||||
*/
|
||||
@SysLog("更新菜单")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_menu_edit')")
|
||||
public R update(@Valid @RequestBody SysMenu sysMenu) {
|
||||
return R.ok(sysMenuService.updateMenuById(sysMenu));
|
||||
}
|
||||
/**
|
||||
* 更新菜单
|
||||
*
|
||||
* @param sysMenu
|
||||
* @return
|
||||
*/
|
||||
@SysLog("更新菜单")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_menu_edit')")
|
||||
public R update(@Valid @RequestBody SysMenu sysMenu) {
|
||||
return R.ok(sysMenuService.updateMenuById(sysMenu));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user