|
|
|
|
package com.glxp.api.controller.auth;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
import com.glxp.api.constant.Constant;
|
|
|
|
|
import com.glxp.api.controller.BaseController;
|
|
|
|
|
import com.glxp.api.entity.auth.AuthAdmin;
|
|
|
|
|
import com.glxp.api.entity.auth.SysMenu;
|
|
|
|
|
import com.glxp.api.service.auth.CustomerService;
|
|
|
|
|
import com.glxp.api.service.auth.ISysMenuService;
|
|
|
|
|
import com.glxp.api.common.res.BaseResponse;
|
|
|
|
|
import com.glxp.api.common.util.ResultVOUtils;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 菜单信息
|
|
|
|
|
*
|
|
|
|
|
* @author Lion Li
|
|
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/system/menu")
|
|
|
|
|
public class SysMenuController extends BaseController {
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
ISysMenuService menuService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
CustomerService customerService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取菜单列表
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/list")
|
|
|
|
|
public BaseResponse list(SysMenu menu) {
|
|
|
|
|
AuthAdmin authAdmin = customerService.getUserBean();
|
|
|
|
|
List<SysMenu> menus = menuService.selectMenuList(menu, authAdmin.getId());
|
|
|
|
|
return ResultVOUtils.success(menus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据菜单编号获取详细信息
|
|
|
|
|
*
|
|
|
|
|
* @param menuId 菜单ID
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/{menuId}")
|
|
|
|
|
public BaseResponse getInfo(@PathVariable Long menuId) {
|
|
|
|
|
return ResultVOUtils.success(menuService.selectMenuById(menuId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取菜单下拉树列表
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping("/treeselect")
|
|
|
|
|
public BaseResponse treeselect(SysMenu menu) {
|
|
|
|
|
AuthAdmin authAdmin = customerService.getUserBean();
|
|
|
|
|
List<SysMenu> menus = menuService.selectMenuList(menu, authAdmin.getId());
|
|
|
|
|
return ResultVOUtils.success(menuService.buildMenuTreeSelect(menus));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载对应角色菜单列表树
|
|
|
|
|
*
|
|
|
|
|
* @param roleId 角色ID
|
|
|
|
|
*/
|
|
|
|
|
@GetMapping(value = "/roleMenuTreeselect/{roleId}")
|
|
|
|
|
public BaseResponse roleMenuTreeselect(@PathVariable("roleId") Long roleId) {
|
|
|
|
|
AuthAdmin authAdmin = customerService.getUserBean();
|
|
|
|
|
List<SysMenu> menus = menuService.selectMenuList(authAdmin.getId());
|
|
|
|
|
Map<String, Object> ajax = new HashMap<>();
|
|
|
|
|
ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId));
|
|
|
|
|
ajax.put("menus", menuService.buildMenuTreeSelect(menus));
|
|
|
|
|
return ResultVOUtils.success(ajax);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增菜单
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping
|
|
|
|
|
public BaseResponse add(@Validated @RequestBody SysMenu menu) {
|
|
|
|
|
if (Constant.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) {
|
|
|
|
|
return ResultVOUtils.error(500, "新增菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
|
|
|
|
} else if (Constant.YES_FRAME.equals(menu.getIsFrame()) && !HttpUtil.isHttp(menu.getPath())) {
|
|
|
|
|
return ResultVOUtils.error(500, "新增菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
|
|
|
|
}
|
|
|
|
|
menu.setCreateTime(new Date());
|
|
|
|
|
menu.setCreateBy(getUser().getEmployeeName());
|
|
|
|
|
menuService.insertMenu(menu);
|
|
|
|
|
return ResultVOUtils.success("修改成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 修改菜单
|
|
|
|
|
*/
|
|
|
|
|
@PutMapping
|
|
|
|
|
public BaseResponse edit(@Validated @RequestBody SysMenu menu) {
|
|
|
|
|
menu.setNeMenuId(menu.getMenuId());
|
|
|
|
|
if (Constant.NOT_UNIQUE.equals(menuService.checkMenuNameUnique(menu))) {
|
|
|
|
|
return ResultVOUtils.error(500, "修改菜单'" + menu.getMenuName() + "'失败,菜单名称已存在");
|
|
|
|
|
} else if (Constant.YES_FRAME.equals(menu.getIsFrame()) && !HttpUtil.isHttp(menu.getPath())) {
|
|
|
|
|
return ResultVOUtils.error(500, "修改菜单'" + menu.getMenuName() + "'失败,地址必须以http(s)://开头");
|
|
|
|
|
} else if (menu.getMenuId().equals(menu.getParentId())) {
|
|
|
|
|
return ResultVOUtils.error(500, "修改菜单'" + menu.getMenuName() + "'失败,上级菜单不能选择自己");
|
|
|
|
|
}
|
|
|
|
|
menuService.updateMenu(menu);
|
|
|
|
|
return ResultVOUtils.success("修改成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除菜单
|
|
|
|
|
*
|
|
|
|
|
* @param menuId 菜单ID
|
|
|
|
|
*/
|
|
|
|
|
@DeleteMapping("/{menuId}")
|
|
|
|
|
public BaseResponse remove(@PathVariable("menuId") Long menuId) {
|
|
|
|
|
if (menuService.hasChildByMenuId(menuId)) {
|
|
|
|
|
return ResultVOUtils.error(500, "存在子菜单,不允许删除");
|
|
|
|
|
}
|
|
|
|
|
if (menuService.checkMenuExistRole(menuId)) {
|
|
|
|
|
return ResultVOUtils.error(500, "菜单已分配,不允许删除");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
menuService.deleteMenuById(menuId);
|
|
|
|
|
|
|
|
|
|
return ResultVOUtils.success("修改成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|