fixed: 菜单级联问题

This commit is contained in:
wangiegie@gmail.com 2017-11-08 21:33:48 +08:00
parent 272b870205
commit 2cac15d4ad
5 changed files with 180 additions and 60 deletions

View File

@ -5,16 +5,15 @@ import com.github.pig.admin.dto.MenuTree;
import com.github.pig.admin.entity.SysMenu;
import com.github.pig.admin.service.SysMenuService;
import com.github.pig.admin.util.TreeUtil;
import com.github.pig.common.constant.CommonConstant;
import com.github.pig.common.vo.MenuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
/**
* @author lengleng
@ -37,11 +36,62 @@ public class MenuController {
return menuService.findMenuByRole(role);
}
/**
* 返回树形菜单集合
*
* @return 树形菜单
*/
@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);
}
/**
* 通过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) {
List<MenuTree> trees = new ArrayList<MenuTree>();
MenuTree node = null;
@ -49,11 +99,11 @@ public class MenuController {
node = new MenuTree();
node.setId(menu.getMenuId());
node.setParentId(menu.getParentId());
node.setTitle(menu.getMenuName());
node.setTitle(menu.getName());
node.setHref(menu.getUrl());
node.setPath(menu.getUrl());
node.setCode(menu.getMenuName());
node.setLabel(menu.getMenuName());
node.setCode(menu.getPermission());
node.setLabel(menu.getName());
trees.add(node);
}
return TreeUtil.bulid(trees, root);

View File

@ -11,6 +11,7 @@ public class MenuTree extends TreeNode {
private String authority;
private String redirect;
private String code;
private String type;
public String getCode() {
return code;
@ -110,4 +111,12 @@ public class MenuTree extends TreeNode {
public void setSpread(boolean spread) {
this.spread = spread;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

View File

@ -2,12 +2,15 @@ package com.github.pig.admin.entity;
import java.io.Serializable;
import com.baomidou.mybatisplus.enums.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import org.omg.CORBA.IDLType;
import java.io.Serializable;
/**
* <p>
@ -25,18 +28,19 @@ public class SysMenu extends Model<SysMenu> {
/**
* 菜单ID
*/
@TableId(value="menu_id", type= IdType.INPUT)
@TableId(value = "menu_id",type = IdType.INPUT)
private Integer menuId;
/**
* 菜单名称
*/
@TableField("menu_name")
private String menuName;
private String name;
/**
* 菜单描述
* 菜单权限标识
*/
private String permission;
/**
* 请求链接
*/
@TableField("menu_desc")
private String menuDesc;
private String url;
/**
* 请求方法
@ -47,6 +51,14 @@ public class SysMenu extends Model<SysMenu> {
*/
@TableField("parent_id")
private Integer parentId;
/**
* 图标
*/
private String icon;
/**
* VUE页面
*/
private String component;
/**
* 排序值
*/
@ -80,20 +92,20 @@ public class SysMenu extends Model<SysMenu> {
this.menuId = menuId;
}
public String getMenuName() {
return menuName;
public String getName() {
return name;
}
public void setMenuName(String menuName) {
this.menuName = menuName;
public void setName(String name) {
this.name = name;
}
public String getMenuDesc() {
return menuDesc;
public String getPermission() {
return permission;
}
public void setMenuDesc(String menuDesc) {
this.menuDesc = menuDesc;
public void setPermission(String permission) {
this.permission = permission;
}
public String getUrl() {
@ -120,6 +132,22 @@ public class SysMenu extends Model<SysMenu> {
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() {
return sort;
}
@ -169,11 +197,13 @@ public class SysMenu extends Model<SysMenu> {
public String toString() {
return "SysMenu{" +
", menuId=" + menuId +
", menuName=" + menuName +
", menuDesc=" + menuDesc +
", name=" + name +
", permission=" + permission +
", url=" + url +
", method=" + method +
", parentId=" + parentId +
", icon=" + icon +
", component=" + component +
", sort=" + sort +
", type=" + type +
", createTime=" + createTime +

View File

@ -4,31 +4,35 @@
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.github.pig.admin.entity.SysMenu">
<id column="menu_id" property="menuId"/>
<result column="menu_name" property="menuName"/>
<result column="menu_desc" property="menuDesc"/>
<result column="url" property="url"/>
<result column="method" property="method"/>
<result column="parent_id" property="parentId"/>
<result column="sort" property="sort"/>
<result column="type" property="type"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="del_flag" property="delFlag"/>
<id column="menu_id" property="menuId" />
<result column="name" property="name" />
<result column="permission" property="permission" />
<result column="url" property="url" />
<result column="method" property="method" />
<result column="parent_id" property="parentId" />
<result column="icon" property="icon" />
<result column="component" property="component" />
<result column="sort" property="sort" />
<result column="type" property="type" />
<result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" />
<result column="del_flag" property="delFlag" />
</resultMap>
<resultMap id="MenuVoResultMap" type="com.github.pig.common.vo.MenuVo">
<id column="menu_id" property="menuId"/>
<result column="menu_name" property="menuName"/>
<result column="menu_desc" property="menuDesc"/>
<result column="url" property="url"/>
<result column="method" property="method"/>
<result column="parent_id" property="parentId"/>
<result column="sort" property="sort"/>
<result column="type" property="type"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="del_flag" property="delFlag"/>
<id column="menu_id" property="menuId" />
<result column="name" property="name" />
<result column="permission" property="permission" />
<result column="url" property="url" />
<result column="method" property="method" />
<result column="parent_id" property="parentId" />
<result column="icon" property="icon" />
<result column="component" property="component" />
<result column="sort" property="sort" />
<result column="type" property="type" />
<result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" />
<result column="del_flag" property="delFlag" />
</resultMap>
<select id="findMenuByRoleName" resultMap="MenuVoResultMap">

View File

@ -13,6 +13,8 @@ import java.util.Date;
*/
public class MenuVo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 菜单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;
/**
* 请求方法
@ -34,6 +39,14 @@ public class MenuVo implements Serializable {
* 父菜单ID
*/
private Integer parentId;
/**
* 图标
*/
private String icon;
/**
* VUE页面
*/
private String component;
/**
* 排序值
*/
@ -55,7 +68,6 @@ public class MenuVo implements Serializable {
*/
private String delFlag;
public Integer getMenuId() {
return menuId;
}
@ -64,20 +76,20 @@ public class MenuVo implements Serializable {
this.menuId = menuId;
}
public String getMenuName() {
return menuName;
public String getName() {
return name;
}
public void setMenuName(String menuName) {
this.menuName = menuName;
public void setName(String name) {
this.name = name;
}
public String getMenuDesc() {
return menuDesc;
public String getPermission() {
return permission;
}
public void setMenuDesc(String menuDesc) {
this.menuDesc = menuDesc;
public void setPermission(String permission) {
this.permission = permission;
}
public String getUrl() {
@ -104,6 +116,22 @@ public class MenuVo implements Serializable {
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() {
return sort;
}
@ -143,5 +171,4 @@ public class MenuVo implements Serializable {
public void setDelFlag(String delFlag) {
this.delFlag = delFlag;
}
}