mirror of https://gitee.com/maxjhandsome/pig
fixed: 菜单级联问题
This commit is contained in:
parent
272b870205
commit
2cac15d4ad
|
@ -5,16 +5,15 @@ import com.github.pig.admin.dto.MenuTree;
|
||||||
import com.github.pig.admin.entity.SysMenu;
|
import com.github.pig.admin.entity.SysMenu;
|
||||||
import com.github.pig.admin.service.SysMenuService;
|
import com.github.pig.admin.service.SysMenuService;
|
||||||
import com.github.pig.admin.util.TreeUtil;
|
import com.github.pig.admin.util.TreeUtil;
|
||||||
|
import com.github.pig.common.constant.CommonConstant;
|
||||||
import com.github.pig.common.vo.MenuVo;
|
import com.github.pig.common.vo.MenuVo;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lengleng
|
* @author lengleng
|
||||||
|
@ -37,11 +36,62 @@ public class MenuController {
|
||||||
return menuService.findMenuByRole(role);
|
return menuService.findMenuByRole(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回树形菜单集合
|
||||||
|
*
|
||||||
|
* @return 树形菜单
|
||||||
|
*/
|
||||||
@GetMapping(value = "/tree")
|
@GetMapping(value = "/tree")
|
||||||
public List<MenuTree> getTree(String title) {
|
public List<MenuTree> getTree() {
|
||||||
|
SysMenu condition = new SysMenu();
|
||||||
|
condition.setDelFlag(CommonConstant.STATUS_NORMAL);
|
||||||
return getMenuTree(menuService.selectList(new EntityWrapper<>()), -1);
|
return getMenuTree(menuService.selectList(new EntityWrapper<>()), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询菜单的详细信息
|
||||||
|
*
|
||||||
|
* @param id 菜单ID
|
||||||
|
* @return 菜单详细信息
|
||||||
|
*/
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public SysMenu menu(@PathVariable Integer id) {
|
||||||
|
return menuService.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增菜单
|
||||||
|
*
|
||||||
|
* @param sysMenu 菜单信息
|
||||||
|
* @return success/false
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
public Boolean menu(@RequestBody SysMenu sysMenu) {
|
||||||
|
return menuService.insert(sysMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除菜单
|
||||||
|
*
|
||||||
|
* @param id 菜单ID
|
||||||
|
* @return success/false
|
||||||
|
* TODO 级联删除下级节点
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public Boolean menuDel(@PathVariable Integer id) {
|
||||||
|
SysMenu condition1 = new SysMenu();
|
||||||
|
condition1.setMenuId(id);
|
||||||
|
condition1.setDelFlag(CommonConstant.STATUS_DEL);
|
||||||
|
menuService.updateById(condition1);
|
||||||
|
|
||||||
|
SysMenu conditon2 = new SysMenu();
|
||||||
|
conditon2.setParentId(id);
|
||||||
|
SysMenu sysMenu = new SysMenu();
|
||||||
|
sysMenu.setDelFlag(CommonConstant.STATUS_DEL);
|
||||||
|
menuService.update(sysMenu,new EntityWrapper<>(conditon2));
|
||||||
|
return menuService.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
private List<MenuTree> getMenuTree(List<SysMenu> menus, int root) {
|
private List<MenuTree> getMenuTree(List<SysMenu> menus, int root) {
|
||||||
List<MenuTree> trees = new ArrayList<MenuTree>();
|
List<MenuTree> trees = new ArrayList<MenuTree>();
|
||||||
MenuTree node = null;
|
MenuTree node = null;
|
||||||
|
@ -49,11 +99,11 @@ public class MenuController {
|
||||||
node = new MenuTree();
|
node = new MenuTree();
|
||||||
node.setId(menu.getMenuId());
|
node.setId(menu.getMenuId());
|
||||||
node.setParentId(menu.getParentId());
|
node.setParentId(menu.getParentId());
|
||||||
node.setTitle(menu.getMenuName());
|
node.setTitle(menu.getName());
|
||||||
node.setHref(menu.getUrl());
|
node.setHref(menu.getUrl());
|
||||||
node.setPath(menu.getUrl());
|
node.setPath(menu.getUrl());
|
||||||
node.setCode(menu.getMenuName());
|
node.setCode(menu.getPermission());
|
||||||
node.setLabel(menu.getMenuName());
|
node.setLabel(menu.getName());
|
||||||
trees.add(node);
|
trees.add(node);
|
||||||
}
|
}
|
||||||
return TreeUtil.bulid(trees, root);
|
return TreeUtil.bulid(trees, root);
|
||||||
|
|
|
@ -11,6 +11,7 @@ public class MenuTree extends TreeNode {
|
||||||
private String authority;
|
private String authority;
|
||||||
private String redirect;
|
private String redirect;
|
||||||
private String code;
|
private String code;
|
||||||
|
private String type;
|
||||||
|
|
||||||
public String getCode() {
|
public String getCode() {
|
||||||
return code;
|
return code;
|
||||||
|
@ -110,4 +111,12 @@ public class MenuTree extends TreeNode {
|
||||||
public void setSpread(boolean spread) {
|
public void setSpread(boolean spread) {
|
||||||
this.spread = spread;
|
this.spread = spread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,15 @@ package com.github.pig.admin.entity;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.enums.IdType;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import com.baomidou.mybatisplus.annotations.TableId;
|
import com.baomidou.mybatisplus.annotations.TableId;
|
||||||
import com.baomidou.mybatisplus.annotations.TableField;
|
import com.baomidou.mybatisplus.annotations.TableField;
|
||||||
import com.baomidou.mybatisplus.activerecord.Model;
|
import com.baomidou.mybatisplus.activerecord.Model;
|
||||||
import com.baomidou.mybatisplus.annotations.TableName;
|
import com.baomidou.mybatisplus.annotations.TableName;
|
||||||
|
import com.baomidou.mybatisplus.enums.IdType;
|
||||||
|
import org.omg.CORBA.IDLType;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -25,18 +28,19 @@ public class SysMenu extends Model<SysMenu> {
|
||||||
/**
|
/**
|
||||||
* 菜单ID
|
* 菜单ID
|
||||||
*/
|
*/
|
||||||
@TableId(value="menu_id", type= IdType.INPUT)
|
@TableId(value = "menu_id",type = IdType.INPUT)
|
||||||
private Integer menuId;
|
private Integer menuId;
|
||||||
/**
|
/**
|
||||||
* 菜单名称
|
* 菜单名称
|
||||||
*/
|
*/
|
||||||
@TableField("menu_name")
|
private String name;
|
||||||
private String menuName;
|
|
||||||
/**
|
/**
|
||||||
* 菜单描述
|
* 菜单权限标识
|
||||||
|
*/
|
||||||
|
private String permission;
|
||||||
|
/**
|
||||||
|
* 请求链接
|
||||||
*/
|
*/
|
||||||
@TableField("menu_desc")
|
|
||||||
private String menuDesc;
|
|
||||||
private String url;
|
private String url;
|
||||||
/**
|
/**
|
||||||
* 请求方法
|
* 请求方法
|
||||||
|
@ -47,6 +51,14 @@ public class SysMenu extends Model<SysMenu> {
|
||||||
*/
|
*/
|
||||||
@TableField("parent_id")
|
@TableField("parent_id")
|
||||||
private Integer parentId;
|
private Integer parentId;
|
||||||
|
/**
|
||||||
|
* 图标
|
||||||
|
*/
|
||||||
|
private String icon;
|
||||||
|
/**
|
||||||
|
* VUE页面
|
||||||
|
*/
|
||||||
|
private String component;
|
||||||
/**
|
/**
|
||||||
* 排序值
|
* 排序值
|
||||||
*/
|
*/
|
||||||
|
@ -80,20 +92,20 @@ public class SysMenu extends Model<SysMenu> {
|
||||||
this.menuId = menuId;
|
this.menuId = menuId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMenuName() {
|
public String getName() {
|
||||||
return menuName;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMenuName(String menuName) {
|
public void setName(String name) {
|
||||||
this.menuName = menuName;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMenuDesc() {
|
public String getPermission() {
|
||||||
return menuDesc;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMenuDesc(String menuDesc) {
|
public void setPermission(String permission) {
|
||||||
this.menuDesc = menuDesc;
|
this.permission = permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
|
@ -120,6 +132,22 @@ public class SysMenu extends Model<SysMenu> {
|
||||||
this.parentId = parentId;
|
this.parentId = parentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(String icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getComponent() {
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComponent(String component) {
|
||||||
|
this.component = component;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getSort() {
|
public Integer getSort() {
|
||||||
return sort;
|
return sort;
|
||||||
}
|
}
|
||||||
|
@ -169,11 +197,13 @@ public class SysMenu extends Model<SysMenu> {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SysMenu{" +
|
return "SysMenu{" +
|
||||||
", menuId=" + menuId +
|
", menuId=" + menuId +
|
||||||
", menuName=" + menuName +
|
", name=" + name +
|
||||||
", menuDesc=" + menuDesc +
|
", permission=" + permission +
|
||||||
", url=" + url +
|
", url=" + url +
|
||||||
", method=" + method +
|
", method=" + method +
|
||||||
", parentId=" + parentId +
|
", parentId=" + parentId +
|
||||||
|
", icon=" + icon +
|
||||||
|
", component=" + component +
|
||||||
", sort=" + sort +
|
", sort=" + sort +
|
||||||
", type=" + type +
|
", type=" + type +
|
||||||
", createTime=" + createTime +
|
", createTime=" + createTime +
|
||||||
|
|
|
@ -4,31 +4,35 @@
|
||||||
|
|
||||||
<!-- 通用查询映射结果 -->
|
<!-- 通用查询映射结果 -->
|
||||||
<resultMap id="BaseResultMap" type="com.github.pig.admin.entity.SysMenu">
|
<resultMap id="BaseResultMap" type="com.github.pig.admin.entity.SysMenu">
|
||||||
<id column="menu_id" property="menuId"/>
|
<id column="menu_id" property="menuId" />
|
||||||
<result column="menu_name" property="menuName"/>
|
<result column="name" property="name" />
|
||||||
<result column="menu_desc" property="menuDesc"/>
|
<result column="permission" property="permission" />
|
||||||
<result column="url" property="url"/>
|
<result column="url" property="url" />
|
||||||
<result column="method" property="method"/>
|
<result column="method" property="method" />
|
||||||
<result column="parent_id" property="parentId"/>
|
<result column="parent_id" property="parentId" />
|
||||||
<result column="sort" property="sort"/>
|
<result column="icon" property="icon" />
|
||||||
<result column="type" property="type"/>
|
<result column="component" property="component" />
|
||||||
<result column="create_time" property="createTime"/>
|
<result column="sort" property="sort" />
|
||||||
<result column="update_time" property="updateTime"/>
|
<result column="type" property="type" />
|
||||||
<result column="del_flag" property="delFlag"/>
|
<result column="create_time" property="createTime" />
|
||||||
|
<result column="update_time" property="updateTime" />
|
||||||
|
<result column="del_flag" property="delFlag" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<resultMap id="MenuVoResultMap" type="com.github.pig.common.vo.MenuVo">
|
<resultMap id="MenuVoResultMap" type="com.github.pig.common.vo.MenuVo">
|
||||||
<id column="menu_id" property="menuId"/>
|
<id column="menu_id" property="menuId" />
|
||||||
<result column="menu_name" property="menuName"/>
|
<result column="name" property="name" />
|
||||||
<result column="menu_desc" property="menuDesc"/>
|
<result column="permission" property="permission" />
|
||||||
<result column="url" property="url"/>
|
<result column="url" property="url" />
|
||||||
<result column="method" property="method"/>
|
<result column="method" property="method" />
|
||||||
<result column="parent_id" property="parentId"/>
|
<result column="parent_id" property="parentId" />
|
||||||
<result column="sort" property="sort"/>
|
<result column="icon" property="icon" />
|
||||||
<result column="type" property="type"/>
|
<result column="component" property="component" />
|
||||||
<result column="create_time" property="createTime"/>
|
<result column="sort" property="sort" />
|
||||||
<result column="update_time" property="updateTime"/>
|
<result column="type" property="type" />
|
||||||
<result column="del_flag" property="delFlag"/>
|
<result column="create_time" property="createTime" />
|
||||||
|
<result column="update_time" property="updateTime" />
|
||||||
|
<result column="del_flag" property="delFlag" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<select id="findMenuByRoleName" resultMap="MenuVoResultMap">
|
<select id="findMenuByRoleName" resultMap="MenuVoResultMap">
|
||||||
|
|
|
@ -13,6 +13,8 @@ import java.util.Date;
|
||||||
*/
|
*/
|
||||||
public class MenuVo implements Serializable {
|
public class MenuVo implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜单ID
|
* 菜单ID
|
||||||
*/
|
*/
|
||||||
|
@ -20,11 +22,14 @@ public class MenuVo implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 菜单名称
|
* 菜单名称
|
||||||
*/
|
*/
|
||||||
private String menuName;
|
private String name;
|
||||||
/**
|
/**
|
||||||
* 菜单描述
|
* 菜单权限标识
|
||||||
|
*/
|
||||||
|
private String permission;
|
||||||
|
/**
|
||||||
|
* 请求链接
|
||||||
*/
|
*/
|
||||||
private String menuDesc;
|
|
||||||
private String url;
|
private String url;
|
||||||
/**
|
/**
|
||||||
* 请求方法
|
* 请求方法
|
||||||
|
@ -34,6 +39,14 @@ public class MenuVo implements Serializable {
|
||||||
* 父菜单ID
|
* 父菜单ID
|
||||||
*/
|
*/
|
||||||
private Integer parentId;
|
private Integer parentId;
|
||||||
|
/**
|
||||||
|
* 图标
|
||||||
|
*/
|
||||||
|
private String icon;
|
||||||
|
/**
|
||||||
|
* VUE页面
|
||||||
|
*/
|
||||||
|
private String component;
|
||||||
/**
|
/**
|
||||||
* 排序值
|
* 排序值
|
||||||
*/
|
*/
|
||||||
|
@ -55,7 +68,6 @@ public class MenuVo implements Serializable {
|
||||||
*/
|
*/
|
||||||
private String delFlag;
|
private String delFlag;
|
||||||
|
|
||||||
|
|
||||||
public Integer getMenuId() {
|
public Integer getMenuId() {
|
||||||
return menuId;
|
return menuId;
|
||||||
}
|
}
|
||||||
|
@ -64,20 +76,20 @@ public class MenuVo implements Serializable {
|
||||||
this.menuId = menuId;
|
this.menuId = menuId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMenuName() {
|
public String getName() {
|
||||||
return menuName;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMenuName(String menuName) {
|
public void setName(String name) {
|
||||||
this.menuName = menuName;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMenuDesc() {
|
public String getPermission() {
|
||||||
return menuDesc;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMenuDesc(String menuDesc) {
|
public void setPermission(String permission) {
|
||||||
this.menuDesc = menuDesc;
|
this.permission = permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
|
@ -104,6 +116,22 @@ public class MenuVo implements Serializable {
|
||||||
this.parentId = parentId;
|
this.parentId = parentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getIcon() {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIcon(String icon) {
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getComponent() {
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComponent(String component) {
|
||||||
|
this.component = component;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getSort() {
|
public Integer getSort() {
|
||||||
return sort;
|
return sort;
|
||||||
}
|
}
|
||||||
|
@ -143,5 +171,4 @@ public class MenuVo implements Serializable {
|
||||||
public void setDelFlag(String delFlag) {
|
public void setDelFlag(String delFlag) {
|
||||||
this.delFlag = delFlag;
|
this.delFlag = delFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue