From 2cac15d4ad72ae08d813bb08023bbffdfffa6508 Mon Sep 17 00:00:00 2001 From: "wangiegie@gmail.com" Date: Wed, 8 Nov 2017 21:33:48 +0800 Subject: [PATCH] =?UTF-8?q?fixed=EF=BC=9A=20=E8=8F=9C=E5=8D=95=E7=BA=A7?= =?UTF-8?q?=E8=81=94=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pig/admin/controller/MenuController.java | 66 ++++++++++++++++--- .../com/github/pig/admin/dto/MenuTree.java | 9 +++ .../com/github/pig/admin/entity/SysMenu.java | 64 +++++++++++++----- .../main/resources/mapper/SysMenuMapper.xml | 48 +++++++------- .../java/com/github/pig/common/vo/MenuVo.java | 53 +++++++++++---- 5 files changed, 180 insertions(+), 60 deletions(-) diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/controller/MenuController.java b/pig-admin-service/src/main/java/com/github/pig/admin/controller/MenuController.java index 33e75020..25e66380 100644 --- a/pig-admin-service/src/main/java/com/github/pig/admin/controller/MenuController.java +++ b/pig-admin-service/src/main/java/com/github/pig/admin/controller/MenuController.java @@ -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 getTree(String title) { + public List 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 getMenuTree(List menus, int root) { List trees = new ArrayList(); 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); diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/dto/MenuTree.java b/pig-admin-service/src/main/java/com/github/pig/admin/dto/MenuTree.java index a0af0acd..125c3bca 100644 --- a/pig-admin-service/src/main/java/com/github/pig/admin/dto/MenuTree.java +++ b/pig-admin-service/src/main/java/com/github/pig/admin/dto/MenuTree.java @@ -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; + } } diff --git a/pig-admin-service/src/main/java/com/github/pig/admin/entity/SysMenu.java b/pig-admin-service/src/main/java/com/github/pig/admin/entity/SysMenu.java index e45b3d06..07f57ffa 100644 --- a/pig-admin-service/src/main/java/com/github/pig/admin/entity/SysMenu.java +++ b/pig-admin-service/src/main/java/com/github/pig/admin/entity/SysMenu.java @@ -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; /** *

@@ -25,18 +28,19 @@ public class SysMenu extends Model { /** * 菜单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 { */ @TableField("parent_id") private Integer parentId; + /** + * 图标 + */ + private String icon; + /** + * VUE页面 + */ + private String component; /** * 排序值 */ @@ -80,20 +92,20 @@ public class SysMenu extends Model { 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 { 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 { 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 + diff --git a/pig-admin-service/src/main/resources/mapper/SysMenuMapper.xml b/pig-admin-service/src/main/resources/mapper/SysMenuMapper.xml index d5377188..ad744732 100644 --- a/pig-admin-service/src/main/resources/mapper/SysMenuMapper.xml +++ b/pig-admin-service/src/main/resources/mapper/SysMenuMapper.xml @@ -4,31 +4,35 @@ - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + + +