|
|
|
@ -1,18 +1,26 @@ |
|
|
|
package edu.ncst.award.controller; |
|
|
|
package edu.ncst.award.controller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.tree.Tree; |
|
|
|
|
|
|
|
import edu.ncst.award.common.annotation.Log; |
|
|
|
|
|
|
|
import edu.ncst.award.common.annotation.enums.BusinessType; |
|
|
|
|
|
|
|
import edu.ncst.award.common.constant.UserConstants; |
|
|
|
|
|
|
|
import edu.ncst.award.common.core.controller.BaseController; |
|
|
|
import edu.ncst.award.domain.vo.R; |
|
|
|
import edu.ncst.award.domain.vo.R; |
|
|
|
import edu.ncst.award.model.system.Menu; |
|
|
|
import edu.ncst.award.model.system.Menu; |
|
|
|
import edu.ncst.award.service.IMenuService; |
|
|
|
import edu.ncst.award.service.IMenuService; |
|
|
|
import edu.ncst.award.service.IUserService; |
|
|
|
import edu.ncst.award.service.IUserService; |
|
|
|
|
|
|
|
import edu.ncst.award.utils.StringUtils; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -23,7 +31,7 @@ import java.util.List; |
|
|
|
@RequiredArgsConstructor |
|
|
|
@RequiredArgsConstructor |
|
|
|
@RestController |
|
|
|
@RestController |
|
|
|
@RequestMapping("/api/menu") |
|
|
|
@RequestMapping("/api/menu") |
|
|
|
public class MenuController { |
|
|
|
public class MenuController extends BaseController { |
|
|
|
|
|
|
|
|
|
|
|
private final IMenuService menuService; |
|
|
|
private final IMenuService menuService; |
|
|
|
private final IUserService userService; |
|
|
|
private final IUserService userService; |
|
|
|
@ -38,25 +46,88 @@ public class MenuController { |
|
|
|
return R.ok(menus); |
|
|
|
return R.ok(menus); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
/** |
|
|
|
// public MenuController(IMenuService menuService) {
|
|
|
|
* 根据菜单编号获取详细信息 |
|
|
|
// this.menuService = menuService;
|
|
|
|
*/ |
|
|
|
// }
|
|
|
|
@ApiOperation("根据菜单编号获取详细信息") |
|
|
|
//
|
|
|
|
@GetMapping(value = "/{menuId}") |
|
|
|
// @ApiOperation("获取菜单列表")
|
|
|
|
public R<Menu> getInfo(@ApiParam("菜单ID") @PathVariable Long menuId) { |
|
|
|
// @GetMapping("/list")
|
|
|
|
return R.ok(menuService.selectMenuById(menuId)); |
|
|
|
// public ResultVO<ListResultVO<Menu>> getMenuList(Query query) {
|
|
|
|
} |
|
|
|
// ListResultVO<Menu> menuList = menuService.getMenuList(query);
|
|
|
|
|
|
|
|
//
|
|
|
|
/** |
|
|
|
// return ResultUtils.success("ok", menuList);
|
|
|
|
* 获取菜单下拉树列表 |
|
|
|
// }
|
|
|
|
*/ |
|
|
|
//
|
|
|
|
@ApiOperation("获取菜单下拉树列表") |
|
|
|
// @ApiOperation("获取菜单树")
|
|
|
|
@GetMapping("/treeSelect") |
|
|
|
// @GetMapping("/tree")
|
|
|
|
public R<List<Tree<Integer>>> treeSelect(Menu menu) { |
|
|
|
// public ResultVO<List<Menu>> getMenuTree() {
|
|
|
|
List<Menu> menus = menuService.selectMenuList(menu, userService.getCurrentUser().getId()); |
|
|
|
// List<Menu> menuTree = menuService.getMenuTree();
|
|
|
|
return R.ok(menuService.buildMenuTreeSelect(menus)); |
|
|
|
// return ResultUtils.success("ok", menuTree);
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 加载对应角色菜单列表树 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@ApiOperation("加载对应角色菜单列表树") |
|
|
|
|
|
|
|
@GetMapping(value = "/roleMenuTreeSelect/{roleId}") |
|
|
|
|
|
|
|
public R<Map<String, Object>> roleMenuTreeSelect(@ApiParam("角色ID") @PathVariable("roleId") Long roleId) { |
|
|
|
|
|
|
|
List<Menu> menus = menuService.selectMenuList(userService.getCurrentUser().getId()); |
|
|
|
|
|
|
|
Map<String, Object> ajax = new HashMap<>(); |
|
|
|
|
|
|
|
ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId)); |
|
|
|
|
|
|
|
ajax.put("menus", menuService.buildMenuTreeSelect(menus)); |
|
|
|
|
|
|
|
return R.ok(ajax); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 新增菜单 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@ApiOperation("新增菜单") |
|
|
|
|
|
|
|
@Log(title = "菜单管理", businessType = BusinessType.INSERT) |
|
|
|
|
|
|
|
@PostMapping |
|
|
|
|
|
|
|
public R<Void> add(@Validated @RequestBody Menu menu) { |
|
|
|
|
|
|
|
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) { |
|
|
|
|
|
|
|
return R.fail("新增菜单'" + menu.getName() + "'失败,菜单名称已存在"); |
|
|
|
|
|
|
|
} else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getRoutePath())) { |
|
|
|
|
|
|
|
return R.fail("新增菜单'" + menu.getName() + "'失败,地址必须以http(s)://开头"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return toAjax(menuService.insertMenu(menu)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 修改菜单 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@ApiOperation("修改菜单") |
|
|
|
|
|
|
|
@Log(title = "菜单管理", businessType = BusinessType.UPDATE) |
|
|
|
|
|
|
|
@PutMapping |
|
|
|
|
|
|
|
public R<Void> edit(@Validated @RequestBody Menu menu) { |
|
|
|
|
|
|
|
if (UserConstants.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) { |
|
|
|
|
|
|
|
return R.fail("修改菜单'" + menu.getName() + "'失败,菜单名称已存在"); |
|
|
|
|
|
|
|
} else if (UserConstants.YES_FRAME.equals(menu.getIsFrame()) && !StringUtils.ishttp(menu.getRoutePath())) { |
|
|
|
|
|
|
|
return R.fail("修改菜单'" + menu.getName() + "'失败,地址必须以http(s)://开头"); |
|
|
|
|
|
|
|
} else if (menu.getId().equals(menu.getParentId())) { |
|
|
|
|
|
|
|
return R.fail("修改菜单'" + menu.getName() + "'失败,上级菜单不能选择自己"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return toAjax(menuService.updateMenu(menu)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 删除菜单 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@ApiOperation("删除菜单") |
|
|
|
|
|
|
|
@Log(title = "菜单管理", businessType = BusinessType.DELETE) |
|
|
|
|
|
|
|
@DeleteMapping("/{menuId}") |
|
|
|
|
|
|
|
public R<Void> remove(@ApiParam("菜单ID") @PathVariable("menuId") Long menuId) { |
|
|
|
|
|
|
|
if (menuService.hasChildByMenuId(menuId)) { |
|
|
|
|
|
|
|
return R.fail("存在子菜单,不允许删除"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (menuService.checkMenuExistRole(menuId)) { |
|
|
|
|
|
|
|
return R.fail("菜单已分配,不允许删除"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return toAjax(menuService.deleteMenuById(menuId)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// @ApiOperation("获取指定角色能够访问的菜单ID列表")
|
|
|
|
// @ApiOperation("获取指定角色能够访问的菜单ID列表")
|
|
|
|
// @GetMapping("/ids/role")
|
|
|
|
// @GetMapping("/ids/role")
|
|
|
|
@ -64,40 +135,7 @@ public class MenuController { |
|
|
|
// List<Integer> menuIds = menuService.getRoleMenuIds(roleId,true);
|
|
|
|
// List<Integer> menuIds = menuService.getRoleMenuIds(roleId,true);
|
|
|
|
// return ResultUtils.success("ok", menuIds);
|
|
|
|
// return ResultUtils.success("ok", menuIds);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
|
|
|
|
// @ApiOperation("获取菜单详情")
|
|
|
|
|
|
|
|
// @PostMapping("/detail")
|
|
|
|
|
|
|
|
// public ResultVO<Menu> getMenuDetail(@RequestParam Integer id) {
|
|
|
|
|
|
|
|
// Menu menuDetail = menuService.getMenuDetail(id);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return ResultUtils.success("ok", menuDetail);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// @ApiOperation("添加菜单")
|
|
|
|
|
|
|
|
// @PostMapping("/add")
|
|
|
|
|
|
|
|
// public ResultVO<Menu> addMenu(@RequestBody Menu menu) {
|
|
|
|
|
|
|
|
// log.info("将要添加的菜单:" + menu);
|
|
|
|
|
|
|
|
// Menu result = menuService.addMenu(menu);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return ResultUtils.success("ok", result);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// @ApiOperation("修改菜单")
|
|
|
|
|
|
|
|
// @PostMapping("/modify")
|
|
|
|
|
|
|
|
// public ResultVO<Menu> modifyMenu(@RequestBody Menu menu) {
|
|
|
|
|
|
|
|
// Menu result = menuService.modifyMenu(menu);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return ResultUtils.success("ok", result);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// @ApiOperation("删除菜单")
|
|
|
|
|
|
|
|
// @PostMapping("/delete")
|
|
|
|
|
|
|
|
// public ResultVO<Menu> deleteMenu(@RequestParam Integer id) {
|
|
|
|
|
|
|
|
// menuService.deleteMenu(id);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return ResultUtils.success("ok", null);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// @ApiOperation("获取指定用户可访问的菜单列表")
|
|
|
|
// @ApiOperation("获取指定用户可访问的菜单列表")
|
|
|
|
// @GetMapping("/user/{userId}")
|
|
|
|
// @GetMapping("/user/{userId}")
|
|
|
|
|