❤️ztree权限树形菜单多级数据封装和遍历

小明的学习圈子2023-08-13后端递归

一、参照1

这里主要介绍controller封装ztree参数,具体业务以实际为准,这里controller里封装的数据最好写在service层。

1.前台返回数据的格式

var zNodes =[
               { name:"父节点1 - 展开", open:true,
                   children: [
                       { name:"父节点11 - 折叠",
                           children: [
                               { name:"叶子节点111"},
                               { name:"叶子节点112"},
                               { name:"叶子节点113"},
                               { name:"叶子节点114"}
                           ]},
                       { name:"父节点12 - 折叠",
                           children: [
                               { name:"叶子节点121"},
                               { name:"叶子节点122"},
                               { name:"叶子节点123"},
                               { name:"叶子节点124"}
                           ]},
                       { name:"父节点13 - 没有子节点", isParent:true}
                   ]},
               { name:"父节点2 - 折叠",
                   children: [
                       { name:"父节点21 - 展开", open:true,
                           children: [
                               { name:"叶子节点211"},
                               { name:"叶子节点212"},
                               { name:"叶子节点213"},
                               { name:"叶子节点214"}
                           ]},
                       { name:"父节点22 - 折叠",
                           children: [
                               { name:"叶子节点221"},
                               { name:"叶子节点222"},
                               { name:"叶子节点223"},
                               { name:"叶子节点224"}
                           ]},
                       { name:"父节点23 - 折叠",
                           children: [
                               { name:"叶子节点231"},
                               { name:"叶子节点232"},
                               { name:"叶子节点233"},
                               { name:"叶子节点234"}
                           ]}
                   ]},
               { name:"父节点3 - 没有子节点", isParent:true}

           ];
    <c:forEach items="${sessionScope.permissionRoot.children }" var="permission">
        <c:if test="${empty permission.children}">
            <li class="list-group-item tree-closed" >
                <a href="${APP_PATH }/${permission.url }"><i class="${permission.icon}"></i> ${permission.name }</a> 
            </li>
        </c:if>
        <c:if test="${not empty permission.children}" >
            <li class="list-group-item tree-closed">
                <span><i class="${permission.icon}"></i> ${permission.name } <span class="badge" style="float:right">${fn:length(permission.children)}    <%-- ${permission.children.size() } --%></span></span> 
                <ul style="margin-top:10px;display:none;">
                    <c:forEach items="${permission.children }" var="innerPermission">
                        <li style="height:30px;">                    
                            <a href="${APP_PATH }/${innerPermission.url}"><i class="${innerPermission.icon }"></i> ${innerPermission.name }</a> 
                        </li>
                    </c:forEach>
                </ul>
            </li>
        </c:if>
    </c:forEach> 

2.封装的类

package com.stuwork.crowdfunding.bean;

import java.util.ArrayList;
import java.util.List;

public class Permission {
    private Integer id;

    private Integer pid;

    private String name;

    private String icon;

    private String url;
    private boolean open;
    private boolean checked;
    
    private List<Permission> children = new ArrayList<Permission>();

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon == null ? null : icon.trim();
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url == null ? null : url.trim();
    }

    public boolean isOpen() {
        return open;
    }

    public void setOpen(boolean open) {
        this.open = open;
    }

    public List<Permission> getChildren() {
        return children;
    }

    public void setChildren(List<Permission> children) {
        this.children = children;
    }

    public boolean isChecked() {
        return checked;
    }

    public void setChecked(boolean checked) {
        this.checked = checked;
    }
}
package com.stuwork.crowdfunding.util;
public class AjaxResult {
    private boolean success;
    private String message;
    private Page page;
    private Object data;
    
    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }

    public boolean getSuccess() {
        return success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
    
    
}

3.controller几种返回数据格式封装和优化

package com.stuwork.crowdfunding.manager.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stuwork.crowdfunding.bean.Permission;
import com.stuwork.crowdfunding.manager.service.PermissionService;
import com.stuwork.crowdfunding.util.AjaxResult;

@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;
    
    //最终版方式1
    //最终优化版,减少循环的次数
    @ResponseBody
    @RequestMapping("/loadData")
    public Object loadData(){
        AjaxResult result = new AjaxResult();

        try {
            List<Permission> root = new ArrayList<Permission>();
            List<Permission>  permissionList = permissionService.getAllPermission();//根菜单
            Map<Integer,Permission> map = new HashMap<Integer,Permission>();
            for(Permission bean :permissionList){
                map.put(bean.getId(), bean);
            }
            for(Permission bean :permissionList){
                Permission children = bean;
                if(bean.getPid() == 0){
                   root.add(bean);
                }else{
                    Permission parent = map.get(children.getPid());
                    parent.getChildren().add(children);     
                }
            }
            
            result.setData(root);
            result.setSuccess(true);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("许可树加载失败");
            e.printStackTrace();
        }
        
        return result;
        
    }   //方式2
    @ResponseBody //递归优化
    @RequestMapping("/loadData")
    public Object loadData(){
        AjaxResult result = new AjaxResult();

        try {
            List<Permission> root = new ArrayList<Permission>();
            List<Permission>  permissionList = permissionService.getAllPermission();//根菜单
            
            for(Permission bean :permissionList){
                Permission children = bean;//子菜单
                if(children.getPid() == 0){
                    root.add(bean);
                }else{
                    for(Permission innerPermission:permissionList){
                        if(children.getPid() == innerPermission.getId()){
                            innerPermission.getChildren().add(children);
                            break;
                        }
                    }
                    
                }
            }
            
            
            result.setData(root);
            result.setSuccess(true);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("许可树加载失败");
            e.printStackTrace();
        }
        
        return result;
        
    }
    //方式3
    //递归,解决多个层次 //效率低,多次调用数据库
    @ResponseBody
    @RequestMapping("/loadData")
    public Object loadData(){
        AjaxResult result = new AjaxResult();

        try {
            List<Permission> root = new ArrayList<Permission>();
            Permission  permission = permissionService.getRootPermission();//根菜单
            root.add(permission);
            getPermissionChildern(permission);
            result.setData(root);
            result.setSuccess(true);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("许可树加载失败");
            e.printStackTrace();
        }
        
        return result;
        
    }
    /**
     * 递归使用注意事项
     * 1.调用自身
     * 2.范围要不断缩小
     * 3.要有跳出条件
     * @param permission
     */
    private void getPermissionChildern(Permission  permission){
        List<Permission> childrenList = permissionService.getChildrenPermissionByPid(permission.getId());
        permission.setChildren(childrenList);
        for(Permission bean:childrenList){
            getPermissionChildern(bean);
        }
    
    }
    //方式4(这个是demo,没从数据库取数据)
    @ResponseBody
    @RequestMapping("/loadData")
    public Object loadData(){
        AjaxResult result = new AjaxResult();

        try {
            Permission  permission = new Permission();//父菜单
            Permission  permission1 = new Permission();//子菜单
            Permission  permission2 = new Permission();//子菜单
            List<Permission> list = new ArrayList<Permission>();//子菜单
            List<Permission> root = new ArrayList<Permission>();//根菜单
            
            permission.setName("系统权限菜单");
            permission.setOpen(true);
            permission1.setName("控制面板");
            permission2.setName("权限管理");
            list.add(permission1);
            list.add(permission2);
            permission.setChildren(list);
            root.add(permission);
            result.setData(root);
            result.setSuccess(true);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("许可树加载失败");
            e.printStackTrace();
        }
        
        return result;
        
    }    //方式5
    @ResponseBody
    @RequestMapping("/loadData")
    public Object loadData(){
        AjaxResult result = new AjaxResult();

        try {
            List<Permission> root = new ArrayList<Permission>();                            
            Permission  permission = permissionService.getRootPermission();//根菜单
            permission.setOpen(true);
            root.add(permission);
            List<Permission> childrenList = permissionService.getChildrenPermissionByPid(permission.getId());
            permission.setChildren(childrenList);
            for(Permission bean :childrenList){
                bean.setOpen(true);
                List<Permission> innerChildrenList = permissionService.getChildrenPermissionByPid(bean.getId());
                bean.setChildren(innerChildrenList);
            }
            result.setData(root);
            result.setSuccess(true);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("许可树加载失败");
            e.printStackTrace();
        }
        
        return result;
        
    }
}

4.mapper文件方法

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stuwork.crowdfunding.manager.dao.PermissionMapper">
  <resultMap id="BaseResultMap" type="Permission">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="pid" jdbcType="INTEGER" property="pid" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="icon" jdbcType="VARCHAR" property="icon" />
    <result column="url" jdbcType="VARCHAR" property="url" />
  </resultMap>
    <select id="getPermissionByRoleId" resultType="int">
    SELECT permissionid
      FROM t_role_permission 
     WHERE roleid = #{roleid}
  </select>
  <select id="getRootPermission" resultMap="BaseResultMap">
    SELECT id,pid,icon,url,name
      FROM t_permission 
     WHERE pid = 0
  </select>
  <select id="getChildrenPermissionByPid" resultMap="BaseResultMap">
    SELECT id,pid,icon,url,name
      FROM t_permission
     WHERE pid = #{id}
  </select>
  <select id="getAlltPermission" resultMap="BaseResultMap">
    SELECT id,pid,icon,url,name
      FROM t_permission 
  </select>

</mapper>

5.数据库表数据

img

二、参照2

1、实体类

package com.stu.aclservice.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 权限
 * </p>
 *
 * @author testjava
 * @since 2020-01-12
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("acl_permission")
@ApiModel(value="Permission对象", description="权限")
public class Permission implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "编号")
    @TableId(value = "id", type = IdType.ID_WORKER_STR)
    private String id;

    @ApiModelProperty(value = "所属上级")
    private String pid;

    @ApiModelProperty(value = "名称")
    private String name;

    @ApiModelProperty(value = "类型(1:菜单,2:按钮)")
    private Integer type;

    @ApiModelProperty(value = "权限值")
    private String permissionValue;

    @ApiModelProperty(value = "访问路径")
    private String path;

    @ApiModelProperty(value = "组件路径")
    private String component;

    @ApiModelProperty(value = "图标")
    private String icon;

    @ApiModelProperty(value = "状态(0:禁止,1:正常)")
    private Integer status;

    @ApiModelProperty(value = "层级")
    @TableField(exist = false)
    private Integer level;

    @ApiModelProperty(value = "下级")
    @TableField(exist = false)
    private List<Permission> children;

    @ApiModelProperty(value = "是否选中")
    @TableField(exist = false)
    private boolean isSelect;


    @ApiModelProperty(value = "逻辑删除 1(true)已删除, 0(false)未删除")
    private Boolean isDeleted;

    @ApiModelProperty(value = "创建时间")
    private Date gmtCreate;

    @ApiModelProperty(value = "更新时间")
    private Date gmtModified;


}

2、业务类

package com.stu.aclservice.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.stu.aclservice.entity.Permission;
import com.stu.aclservice.entity.RolePermission;
import com.stu.aclservice.entity.User;
import com.stu.aclservice.helper.MemuHelper;
import com.stu.aclservice.helper.PermissionHelper;
import com.stu.aclservice.mapper.PermissionMapper;
import com.stu.aclservice.service.PermissionService;
import com.stu.aclservice.service.RolePermissionService;
import com.stu.aclservice.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 权限 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-01-12
 */
@Service
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {

    @Autowired
    private RolePermissionService rolePermissionService;
    
    @Autowired
    private UserService userService;
    
    //获取全部菜单
    @Override
    public List<Permission> queryAllMenu() {

        QueryWrapper<Permission> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        List<Permission> permissionList = baseMapper.selectList(wrapper);

        List<Permission> result = bulid(permissionList);

        return result;
    }

    //根据角色获取菜单
    @Override
    public List<Permission> selectAllMenu(String roleId) {
        List<Permission> allPermissionList = baseMapper.selectList(new QueryWrapper<Permission>().orderByAsc("CAST(id AS SIGNED)"));

        //根据角色id获取角色权限
        List<RolePermission> rolePermissionList = rolePermissionService.list(new QueryWrapper<RolePermission>().eq("role_id",roleId));
        //转换给角色id与角色权限对应Map对象
//        List<String> permissionIdList = rolePermissionList.stream().map(e -> e.getPermissionId()).collect(Collectors.toList());
//        allPermissionList.forEach(permission -> {
//            if(permissionIdList.contains(permission.getId())) {
//                permission.setSelect(true);
//            } else {
//                permission.setSelect(false);
//            }
//        });
        for (int i = 0; i < allPermissionList.size(); i++) {
            Permission permission = allPermissionList.get(i);
            for (int m = 0; m < rolePermissionList.size(); m++) {
                RolePermission rolePermission = rolePermissionList.get(m);
                if(rolePermission.getPermissionId().equals(permission.getId())) {
                    permission.setSelect(true);
                }
            }
        }


        List<Permission> permissionList = bulid(allPermissionList);
        return permissionList;
    }

    //给角色分配权限
    @Override
    public void saveRolePermissionRealtionShip(String roleId, String[] permissionIds) {

        rolePermissionService.remove(new QueryWrapper<RolePermission>().eq("role_id", roleId));

  

        List<RolePermission> rolePermissionList = new ArrayList<>();
        for(String permissionId : permissionIds) {
            if(StringUtils.isEmpty(permissionId)) continue;
      
            RolePermission rolePermission = new RolePermission();
            rolePermission.setRoleId(roleId);
            rolePermission.setPermissionId(permissionId);
            rolePermissionList.add(rolePermission);
        }
        rolePermissionService.saveBatch(rolePermissionList);
    }

    //递归删除菜单
    @Override
    public void removeChildById(String id) {
        List<String> idList = new ArrayList<>();
        this.selectChildListById(id, idList);

        idList.add(id);
        baseMapper.deleteBatchIds(idList);
    }

    //根据用户id获取用户菜单
    @Override
    public List<String> selectPermissionValueByUserId(String id) {

        List<String> selectPermissionValueList = null;
        if(this.isSysAdmin(id)) {
            //如果是系统管理员,获取所有权限
            selectPermissionValueList = baseMapper.selectAllPermissionValue();
        } else {
            selectPermissionValueList = baseMapper.selectPermissionValueByUserId(id);
        }
        return selectPermissionValueList;
    }

    @Override
    public List<JSONObject> selectPermissionByUserId(String userId) {
        List<Permission> selectPermissionList = null;
        if(this.isSysAdmin(userId)) {
            //如果是超级管理员,获取所有菜单
            selectPermissionList = baseMapper.selectList(null);
        } else {
            selectPermissionList = baseMapper.selectPermissionByUserId(userId);
        }

        List<Permission> permissionList = PermissionHelper.bulid(selectPermissionList);
        List<JSONObject> result = MemuHelper.bulid(permissionList);
        return result;
    }

    /**
     * 判断用户是否系统管理员
     * @param userId
     * @return
     */
    private boolean isSysAdmin(String userId) {
        User user = userService.getById(userId);

        if(null != user && "admin".equals(user.getUsername())) {
            return true;
        }
        return false;
    }

    /**
     *    递归获取子节点
     * @param id
     * @param idList
     */
    private void selectChildListById(String id, List<String> idList) {
        List<Permission> childList = baseMapper.selectList(new QueryWrapper<Permission>().eq("pid", id).select("id"));
        childList.stream().forEach(item -> {
            idList.add(item.getId());
            this.selectChildListById(item.getId(), idList);
        });
    }

    /**
     * 使用递归方法建菜单
     * @param treeNodes
     * @return
     */
    private static List<Permission> bulid(List<Permission> treeNodes) {
        List<Permission> trees = new ArrayList<>();
        for (Permission treeNode : treeNodes) {
            if ("0".equals(treeNode.getPid())) {
                treeNode.setLevel(1);
                trees.add(findChildren(treeNode,treeNodes));
            }
        }
        return trees;
    }

    /**
     * 递归查找子节点
     * @param treeNodes
     * @return
     */
    private static Permission findChildren(Permission treeNode,List<Permission> treeNodes) {
        treeNode.setChildren(new ArrayList<Permission>());

        for (Permission it : treeNodes) {
            if(treeNode.getId().equals(it.getPid())) {
                int level = treeNode.getLevel() + 1;
                it.setLevel(level);
                if (treeNode.getChildren() == null) {
                    treeNode.setChildren(new ArrayList<>());
                }
                treeNode.getChildren().add(findChildren(it,treeNodes));
            }
        }
        return treeNode;
    }


    //========================递归查询所有菜单================================================
    //获取全部菜单
    @Override
    public List<Permission> queryAllMenuGuli() {
        //1 查询菜单表所有数据
        QueryWrapper<Permission> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        List<Permission> permissionList = baseMapper.selectList(wrapper);
        //2 把查询所有菜单list集合按照要求进行封装
        List<Permission> resultList = bulidPermission(permissionList);
        return resultList;
    }

    //把返回所有菜单list集合进行封装的方法
    public static List<Permission> bulidPermission(List<Permission> permissionList) {

        //创建list集合,用于数据最终封装
        List<Permission> finalNode = new ArrayList<>();
        //把所有菜单list集合遍历,得到顶层菜单 pid=0菜单,设置level是1
        for(Permission permissionNode : permissionList) {
            //得到顶层菜单 pid=0菜单
            if("0".equals(permissionNode.getPid())) {
                //设置顶层菜单的level是1
                permissionNode.setLevel(1);
                //根据顶层菜单,向里面进行查询子菜单,封装到finalNode里面
                finalNode.add(selectChildren(permissionNode,permissionList));
            }
        }
        return finalNode;
    }

    private static Permission selectChildren(Permission permissionNode, List<Permission> permissionList) {
        //1 因为向一层菜单里面放二层菜单,二层里面还要放三层,把对象初始化
        permissionNode.setChildren(new ArrayList<Permission>());

        //2 遍历所有菜单list集合,进行判断比较,比较id和pid值是否相同
        for(Permission it : permissionList) {
            //判断 id和pid值是否相同
            if(permissionNode.getId().equals(it.getPid())) {
                //把父菜单的level值+1
                int level = permissionNode.getLevel()+1;
                it.setLevel(level);
                //如果children为空,进行初始化操作
                if(permissionNode.getChildren() == null) {
                    permissionNode.setChildren(new ArrayList<Permission>());
                }
                //把查询出来的子菜单放到父菜单里面
                permissionNode.getChildren().add(selectChildren(it,permissionList));
            }
        }
        return permissionNode;
    }
    //=================递归查询所有菜单==========================
    //============递归删除菜单==================================
    @Override
    public void removeChildByIdGuli(String id) {
        //1 创建list集合,用于封装所有删除菜单id值
        List<String> idList = new ArrayList<>();
        //2 向idList集合设置删除菜单id
        this.selectPermissionChildById(id,idList);
        //把当前id封装到list里面
        idList.add(id);
        baseMapper.deleteBatchIds(idList);
    }

    //2 根据当前菜单id,查询菜单里面子菜单id,封装到list集合
    private void selectPermissionChildById(String id, List<String> idList) {
        //查询菜单里面子菜单id
        QueryWrapper<Permission>  wrapper = new QueryWrapper<>();
        wrapper.eq("pid",id);
        wrapper.select("id");
        List<Permission> childIdList = baseMapper.selectList(wrapper);
        //把childIdList里面菜单id值获取出来,封装idList里面,做递归查询
        childIdList.stream().forEach(item -> {
            //封装idList里面
            idList.add(item.getId());
            //递归查询
            this.selectPermissionChildById(item.getId(),idList);
        });
    }

    //=========================给角色分配菜单=======================
    @Override
    public void saveRolePermissionRealtionShipGuli(String roleId, String[] permissionIds) {
        //roleId角色id
        //permissionId菜单id 数组形式
        //1 创建list集合,用于封装添加数据
        List<RolePermission> rolePermissionList = new ArrayList<>();
        //遍历所有菜单数组
        for(String perId : permissionIds) {
            //RolePermission对象
            RolePermission rolePermission = new RolePermission();
            rolePermission.setRoleId(roleId);
            rolePermission.setPermissionId(perId);
            //封装到list集合
            rolePermissionList.add(rolePermission);
        }
        //添加到角色菜单关系表
        rolePermissionService.saveBatch(rolePermissionList);
    }
} 

3、数据库sql脚本

# Host: localhost  (Version 5.7.19)
# Date: 2019-11-18 15:49:15
# Generator: MySQL-Front 6.1  (Build 1.26)


#
# Structure for table "acl_permission"
#

CREATE TABLE `acl_permission` (
  `id` char(19) NOT NULL DEFAULT '' COMMENT '编号',
  `pid` char(19) NOT NULL DEFAULT '' COMMENT '所属上级',
  `name` varchar(20) NOT NULL DEFAULT '' COMMENT '名称',
  `type` tinyint(3) NOT NULL DEFAULT '0' COMMENT '类型(1:菜单,2:按钮)',
  `permission_value` varchar(50) DEFAULT NULL COMMENT '权限值',
  `path` varchar(100) DEFAULT NULL COMMENT '访问路径',
  `component` varchar(100) DEFAULT NULL COMMENT '组件路径',
  `icon` varchar(50) DEFAULT NULL COMMENT '图标',
  `status` tinyint(4) DEFAULT NULL COMMENT '状态(0:禁止,1:正常)',
  `is_deleted` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '逻辑删除 1(true)已删除, 0(false)未删除',
  `gmt_create` datetime DEFAULT NULL COMMENT '创建时间',
  `gmt_modified` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_pid` (`pid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='权限';

#
# Data for table "acl_permission"
#

INSERT INTO `acl_permission` VALUES ('1','0','全部数据',0,NULL,NULL,NULL,NULL,NULL,0,'2019-11-15 17:13:06','2019-11-15 17:13:06'),('1195268474480156673','1','权限管理',1,NULL,'/acl','Layout',NULL,NULL,0,'2019-11-15 17:13:06','2019-11-18 13:54:25'),('1195268616021139457','1195268474480156673','用户管理',1,NULL,'user/list','/acl/user/list',NULL,NULL,0,'2019-11-15 17:13:40','2019-11-18 13:53:12'),('1195268788138598401','1195268474480156673','角色管理',1,NULL,'role/list','/acl/role/list',NULL,NULL,0,'2019-11-15 17:14:21','2019-11-15 17:14:21'),('1195268893830864898','1195268474480156673','菜单管理',1,NULL,'menu/list','/acl/menu/list',NULL,NULL,0,'2019-11-15 17:14:46','2019-11-15 17:14:46'),('1195269143060602882','1195268616021139457','查看',2,'user.list','','',NULL,NULL,0,'2019-11-15 17:15:45','2019-11-17 21:57:16'),('1195269295926206466','1195268616021139457','添加',2,'user.add','user/add','/acl/user/form',NULL,NULL,0,'2019-11-15 17:16:22','2019-11-15 17:16:22'),('1195269473479483394','1195268616021139457','修改',2,'user.update','user/update/:id','/acl/user/form',NULL,NULL,0,'2019-11-15 17:17:04','2019-11-15 17:17:04'),('1195269547269873666','1195268616021139457','删除',2,'user.remove','','',NULL,NULL,0,'2019-11-15 17:17:22','2019-11-15 17:17:22'),('1195269821262782465','1195268788138598401','修改',2,'role.update','role/update/:id','/acl/role/form',NULL,NULL,0,'2019-11-15 17:18:27','2019-11-15 17:19:53'),('1195269903542444034','1195268788138598401','查看',2,'role.list','','',NULL,NULL,0,'2019-11-15 17:18:47','2019-11-15 17:18:47'),('1195270037005197313','1195268788138598401','添加',2,'role.add','role/add','/acl/role/form',NULL,NULL,0,'2019-11-15 17:19:19','2019-11-18 11:05:42'),('1195270442602782721','1195268788138598401','删除',2,'role.remove','','',NULL,NULL,0,'2019-11-15 17:20:55','2019-11-15 17:20:55'),('1195270621548568578','1195268788138598401','角色权限',2,'role.acl','role/distribution/:id','/acl/role/roleForm',NULL,NULL,0,'2019-11-15 17:21:38','2019-11-15 17:21:38'),('1195270744097742849','1195268893830864898','查看',2,'permission.list','','',NULL,NULL,0,'2019-11-15 17:22:07','2019-11-15 17:22:07'),('1195270810560684034','1195268893830864898','添加',2,'permission.add','','',NULL,NULL,0,'2019-11-15 17:22:23','2019-11-15 17:22:23'),('1195270862100291586','1195268893830864898','修改',2,'permission.update','','',NULL,NULL,0,'2019-11-15 17:22:35','2019-11-15 17:22:35'),('1195270887933009922','1195268893830864898','删除',2,'permission.remove','','',NULL,NULL,0,'2019-11-15 17:22:41','2019-11-15 17:22:41'),('1195349439240048642','1','讲师管理',1,NULL,'/edu/teacher','Layout',NULL,NULL,0,'2019-11-15 22:34:49','2019-11-15 22:34:49'),('1195349699995734017','1195349439240048642','讲师列表',1,NULL,'list','/edu/teacher/list',NULL,NULL,0,'2019-11-15 22:35:52','2019-11-15 22:35:52'),('1195349810561781761','1195349439240048642','添加讲师',1,NULL,'create','/edu/teacher/form',NULL,NULL,0,'2019-11-15 22:36:18','2019-11-15 22:36:18'),('1195349876252971010','1195349810561781761','添加',2,'teacher.add','','',NULL,NULL,0,'2019-11-15 22:36:34','2019-11-15 22:36:34'),('1195349979797753857','1195349699995734017','查看',2,'teacher.list','','',NULL,NULL,0,'2019-11-15 22:36:58','2019-11-15 22:36:58'),('1195350117270261762','1195349699995734017','修改',2,'teacher.update','edit/:id','/edu/teacher/form',NULL,NULL,0,'2019-11-15 22:37:31','2019-11-15 22:37:31'),('1195350188359520258','1195349699995734017','删除',2,'teacher.remove','','',NULL,NULL,0,'2019-11-15 22:37:48','2019-11-15 22:37:48'),('1195350299365969922','1','课程分类',1,NULL,'/edu/subject','Layout',NULL,NULL,0,'2019-11-15 22:38:15','2019-11-15 22:38:15'),('1195350397751758850','1195350299365969922','课程分类列表',1,NULL,'list','/edu/subject/list',NULL,NULL,0,'2019-11-15 22:38:38','2019-11-15 22:38:38'),('1195350500512206850','1195350299365969922','导入课程分类',1,NULL,'import','/edu/subject/import',NULL,NULL,0,'2019-11-15 22:39:03','2019-11-15 22:39:03'),('1195350612172967938','1195350397751758850','查看',2,'subject.list','','',NULL,NULL,0,'2019-11-15 22:39:29','2019-11-15 22:39:29'),('1195350687590748161','1195350500512206850','导入',2,'subject.import','','',NULL,NULL,0,'2019-11-15 22:39:47','2019-11-15 22:39:47'),('1195350831744782337','1','课程管理',1,NULL,'/edu/course','Layout',NULL,NULL,0,'2019-11-15 22:40:21','2019-11-15 22:40:21'),('1195350919074385921','1195350831744782337','课程列表',1,NULL,'list','/edu/course/list',NULL,NULL,0,'2019-11-15 22:40:42','2019-11-15 22:40:42'),('1195351020463296513','1195350831744782337','发布课程',1,NULL,'info','/edu/course/info',NULL,NULL,0,'2019-11-15 22:41:06','2019-11-15 22:41:06'),('1195351159672246274','1195350919074385921','完成发布',2,'course.publish','publish/:id','/edu/course/publish',NULL,NULL,0,'2019-11-15 22:41:40','2019-11-15 22:44:01'),('1195351326706208770','1195350919074385921','编辑课程',2,'course.update','info/:id','/edu/course/info',NULL,NULL,0,'2019-11-15 22:42:19','2019-11-15 22:42:19'),('1195351566221938690','1195350919074385921','编辑课程大纲',2,'chapter.update','chapter/:id','/edu/course/chapter',NULL,NULL,0,'2019-11-15 22:43:17','2019-11-15 22:43:17'),('1195351862889254913','1','统计分析',1,NULL,'/statistics/daily','Layout',NULL,NULL,0,'2019-11-15 22:44:27','2019-11-15 22:44:27'),('1195351968841568257','1195351862889254913','生成统计',1,NULL,'create','/statistics/daily/create',NULL,NULL,0,'2019-11-15 22:44:53','2019-11-15 22:44:53'),('1195352054917074946','1195351862889254913','统计图表',1,NULL,'chart','/statistics/daily/chart',NULL,NULL,0,'2019-11-15 22:45:13','2019-11-15 22:45:13'),('1195352127734386690','1195352054917074946','查看',2,'daily.list','','',NULL,NULL,0,'2019-11-15 22:45:30','2019-11-15 22:45:30'),('1195352215768633346','1195351968841568257','生成',2,'daily.add','','',NULL,NULL,0,'2019-11-15 22:45:51','2019-11-15 22:45:51'),('1195352547621965825','1','CMS管理',1,NULL,'/cms','Layout',NULL,NULL,0,'2019-11-15 22:47:11','2019-11-18 10:51:46'),('1195352856645701633','1195353513549205505','查看',2,'banner.list','',NULL,NULL,NULL,0,'2019-11-15 22:48:24','2019-11-15 22:48:24'),('1195352909401657346','1195353513549205505','添加',2,'banner.add','banner/add','/cms/banner/form',NULL,NULL,0,'2019-11-15 22:48:37','2019-11-18 10:52:10'),('1195353051395624961','1195353513549205505','修改',2,'banner.update','banner/update/:id','/cms/banner/form',NULL,NULL,0,'2019-11-15 22:49:11','2019-11-18 10:52:05'),('1195353513549205505','1195352547621965825','Bander列表',1,NULL,'banner/list','/cms/banner/list',NULL,NULL,0,'2019-11-15 22:51:01','2019-11-18 10:51:29'),('1195353672110673921','1195353513549205505','删除',2,'banner.remove','','',NULL,NULL,0,'2019-11-15 22:51:39','2019-11-15 22:51:39'),('1195354076890370050','1','订单管理',1,NULL,'/order','Layout',NULL,NULL,0,'2019-11-15 22:53:15','2019-11-15 22:53:15'),('1195354153482555393','1195354076890370050','订单列表',1,NULL,'list','/order/list',NULL,NULL,0,'2019-11-15 22:53:33','2019-11-15 22:53:58'),('1195354315093282817','1195354153482555393','查看',2,'order.list','','',NULL,NULL,0,'2019-11-15 22:54:12','2019-11-15 22:54:12'),('1196301740985311234','1195268616021139457','分配角色',2,'user.assgin','user/role/:id','/acl/user/roleForm',NULL,NULL,0,'2019-11-18 13:38:56','2019-11-18 13:38:56');

#
# Structure for table "acl_role"
#

CREATE TABLE `acl_role` (
  `id` char(19) NOT NULL DEFAULT '' COMMENT '角色id',
  `role_name` varchar(20) NOT NULL DEFAULT '' COMMENT '角色名称',
  `role_code` varchar(20) DEFAULT NULL COMMENT '角色编码',
  `remark` varchar(255) DEFAULT NULL COMMENT '备注',
  `is_deleted` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '逻辑删除 1(true)已删除, 0(false)未删除',
  `gmt_create` datetime NOT NULL COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

#
# Data for table "acl_role"
#

INSERT INTO `acl_role` VALUES ('1','普通管理员',NULL,NULL,0,'2019-11-11 13:09:32','2019-11-18 10:27:18'),('1193757683205607426','课程管理员',NULL,NULL,0,'2019-11-11 13:09:45','2019-11-18 10:25:44'),('1196300996034977794','test',NULL,NULL,0,'2019-11-18 13:35:58','2019-11-18 13:35:58');

#
# Structure for table "acl_role_permission"
#

CREATE TABLE `acl_role_permission` (
  `id` char(19) NOT NULL DEFAULT '',
  `role_id` char(19) NOT NULL DEFAULT '',
  `permission_id` char(19) NOT NULL DEFAULT '',
  `is_deleted` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '逻辑删除 1(true)已删除, 0(false)未删除',
  `gmt_create` datetime NOT NULL COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_role_id` (`role_id`),
  KEY `idx_permission_id` (`permission_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色权限';

#
# Data for table "acl_role_permission"
#

INSERT INTO `acl_role_permission` VALUES ('1196301979754455041','1','1',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301979792203778','1','1195268474480156673',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301979821563906','1','1195268616021139457',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301979842535426','1','1195269143060602882',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301979855118338','1','1195269295926206466',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301979880284161','1','1195269473479483394',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301979913838593','1','1195269547269873666',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301979926421506','1','1196301740985311234',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301979951587330','1','1195268788138598401',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980014501889','1','1195269821262782465',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980035473410','1','1195269903542444034',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980052250626','1','1195270037005197313',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980077416450','1','1195270442602782721',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980094193665','1','1195270621548568578',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980119359489','1','1195268893830864898',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980136136706','1','1195270744097742849',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980249382913','1','1195270810560684034',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980270354434','1','1195270862100291586',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980287131649','1','1195270887933009922',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980303908866','1','1195349439240048642',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980320686082','1','1195349699995734017',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980345851905','1','1195349979797753857',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980362629121','1','1195350117270261762',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980383600641','1','1195350188359520258',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980408766465','1','1195349810561781761',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980421349378','1','1195349876252971010',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980438126593','1','1195350299365969922',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980450709506','1','1195350397751758850',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980501041153','1','1195350612172967938',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980517818370','1','1195350500512206850',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980538789889','1','1195350687590748161',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980622675970','1','1195350831744782337',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980639453186','1','1195350919074385921',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980660424705','1','1195351159672246274',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980677201922','1','1195351326706208770',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980698173441','1','1195351566221938690',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980714950658','1','1195351020463296513',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980723339266','1','1195351862889254913',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980744310786','1','1195351968841568257',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980761088001','1','1195352215768633346',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980777865217','1','1195352054917074946',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980794642434','1','1195352127734386690',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980811419650','1','1195352547621965825',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980828196865','1','1195353513549205505',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980844974082','1','1195352856645701633',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980861751298','1','1195352909401657346',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980886917122','1','1195353051395624961',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980928860162','1','1195353672110673921',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980954025986','1','1195354076890370050',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980970803201','1','1195354153482555393',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196301980987580418','1','1195354315093282817',1,'2019-11-18 13:39:53','2019-11-18 13:39:53'),('1196305293070077953','1','1',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293099438081','1','1195268474480156673',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293120409602','1','1195268616021139457',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293153964034','1','1195269143060602882',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293183324162','1','1195269295926206466',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293212684290','1','1195269473479483394',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293237850114','1','1195269547269873666',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293271404545','1','1196301740985311234',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293485314049','1','1195268788138598401',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293506285569','1','1195269821262782465',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293527257089','1','1195269903542444034',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293552422914','1','1195270037005197313',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293565005825','1','1195270442602782721',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293594365954','1','1195270621548568578',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293611143169','1','1195268893830864898',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293627920385','1','1195270744097742849',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293657280513','1','1195349439240048642',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293674057729','1','1195349699995734017',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293690834946','1','1195349979797753857',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293716000770','1','1195350117270261762',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293736972290','1','1195350188359520258',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293749555202','1','1195349810561781761',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293766332417','1','1195349876252971010',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293795692546','1','1195350299365969922',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293812469762','1','1195350397751758850',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293837635586','1','1195350612172967938',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293858607106','1','1195350500512206850',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293875384322','1','1195350687590748161',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293892161538','1','1195350831744782337',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293950881794','1','1195350919074385921',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305293976047617','1','1195351159672246274',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294127042561','1','1195351326706208770',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294156402690','1','1195351566221938690',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294177374209','1','1195351862889254913',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294194151425','1','1195351968841568257',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294223511554','1','1195352215768633346',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294240288770','1','1195352054917074946',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294248677377','1','1195352127734386690',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294248677378','1','1195352547621965825',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294319980546','1','1195353513549205505',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294319980547','1','1195352856645701633',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294319980548','1','1195352909401657346',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294378700802','1','1195353051395624961',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294378700803','1','1195353672110673921',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294458392577','1','1195354076890370050',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294483558402','1','1195354153482555393',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305294500335618','1','1195354315093282817',1,'2019-11-18 13:53:03','2019-11-18 13:53:03'),('1196305566656139266','1','1',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566689693698','1','1195268474480156673',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566706470913','1','1195268616021139457',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566740025346','1','1195269143060602882',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566756802561','1','1195269295926206466',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566781968385','1','1195269473479483394',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566811328514','1','1195269547269873666',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566828105730','1','1196301740985311234',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566853271554','1','1195268788138598401',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566878437378','1','1195269821262782465',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566895214593','1','1195269903542444034',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566916186113','1','1195270037005197313',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566949740546','1','1195270442602782721',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566966517761','1','1195270621548568578',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305566991683585','1','1195268893830864898',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567012655106','1','1195270744097742849',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567029432322','1','1195270810560684034',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567042015233','1','1195270862100291586',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567100735490','1','1195270887933009922',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567117512705','1','1195349439240048642',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567142678530','1','1195349699995734017',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567155261442','1','1195349979797753857',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567172038658','1','1195350117270261762',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567188815873','1','1195350188359520258',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567218176001','1','1195349810561781761',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567234953217','1','1195349876252971010',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567251730434','1','1195350299365969922',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567272701954','1','1195350397751758850',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567289479170','1','1195350612172967938',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567310450690','1','1195350500512206850',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567327227905','1','1195350687590748161',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567448862722','1','1195350831744782337',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567478222850','1','1195350919074385921',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567495000065','1','1195351159672246274',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567520165889','1','1195351326706208770',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567541137409','1','1195351566221938690',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567570497538','1','1195351862889254913',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567587274754','1','1195351968841568257',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567604051970','1','1195352215768633346',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567633412098','1','1195352054917074946',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567683743745','1','1195352127734386690',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567721492481','1','1195352547621965825',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567742464002','1','1195353513549205505',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567771824129','1','1195352856645701633',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567792795650','1','1195352909401657346',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567809572866','1','1195353051395624961',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567843127298','1','1195353672110673921',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567868293122','1','1195354076890370050',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567885070338','1','1195354153482555393',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196305567910236162','1','1195354315093282817',1,'2019-11-18 13:54:08','2019-11-18 13:54:08'),('1196312702601695234','1','1',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312702652026881','1','1195268474480156673',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312702668804098','1','1195268616021139457',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312702698164226','1','1195269143060602882',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312702723330049','1','1195269295926206466',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312702744301569','1','1195269473479483394',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312702765273089','1','1195269547269873666',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312702790438913','1','1196301740985311234',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312702945628161','1','1195268788138598401',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312702970793985','1','1195269821262782465',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312703000154114','1','1195269903542444034',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312703025319938','1','1195270037005197313',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312703046291458','1','1195270442602782721',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312703063068673','1','1195270621548568578',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312703084040193','1','1195268893830864898',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312703113400321','1','1195270744097742849',0,'2019-11-18 14:22:29','2019-11-18 14:22:29'),('1196312703134371842','1','1195270810560684034',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703159537665','1','1195270862100291586',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703184703490','1','1195270887933009922',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703209869313','1','1195349439240048642',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703230840834','1','1195349699995734017',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703251812354','1','1195349979797753857',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703272783873','1','1195350117270261762',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703293755394','1','1195350188359520258',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703327309826','1','1195349810561781761',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703348281345','1','1195349876252971010',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703365058561','1','1195350299365969922',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703386030082','1','1195350397751758850',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703440556034','1','1195350612172967938',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703486693378','1','1195350500512206850',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703511859202','1','1195350687590748161',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703654465537','1','1195350831744782337',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703683825665','1','1195350919074385921',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703700602882','1','1195351159672246274',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703717380098','1','1195351326706208770',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703738351618','1','1195351566221938690',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703759323137','1','1195351020463296513',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703776100353','1','1195351862889254913',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703792877570','1','1195351968841568257',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703830626305','1','1195352215768633346',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703843209217','1','1195352054917074946',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703868375041','1','1195352127734386690',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703889346561','1','1195352547621965825',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703901929473','1','1195353513549205505',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703918706689','1','1195352856645701633',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703952261121','1','1195352909401657346',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703973232642','1','1195353051395624961',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312703990009857','1','1195353672110673921',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312704048730114','1','1195354076890370050',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312704069701633','1','1195354153482555393',0,'2019-11-18 14:22:30','2019-11-18 14:22:30'),('1196312704094867457','1','1195354315093282817',0,'2019-11-18 14:22:30','2019-11-18 14:22:30');

#
# Structure for table "acl_user"
#

CREATE TABLE `acl_user` (
  `id` char(19) NOT NULL COMMENT '会员id',
  `username` varchar(20) NOT NULL DEFAULT '' COMMENT '微信openid',
  `password` varchar(32) NOT NULL DEFAULT '' COMMENT '密码',
  `nick_name` varchar(50) DEFAULT NULL COMMENT '昵称',
  `salt` varchar(255) DEFAULT NULL COMMENT '用户头像',
  `token` varchar(100) DEFAULT NULL COMMENT '用户签名',
  `is_deleted` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '逻辑删除 1(true)已删除, 0(false)未删除',
  `gmt_create` datetime NOT NULL COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表';

#
# Data for table "acl_user"
#

INSERT INTO `acl_user` VALUES ('1','admin','96e79218965eb72c92a549dd5a330112','admin','',NULL,0,'2019-11-01 10:39:47','2019-11-01 10:39:47'),('2','test','96e79218965eb72c92a549dd5a330112','test',NULL,NULL,0,'2019-11-01 16:36:07','2019-11-01 16:40:08');

#
# Structure for table "acl_user_role"
#

CREATE TABLE `acl_user_role` (
  `id` char(19) NOT NULL DEFAULT '' COMMENT '主键id',
  `role_id` char(19) NOT NULL DEFAULT '0' COMMENT '角色id',
  `user_id` char(19) NOT NULL DEFAULT '0' COMMENT '用户id',
  `is_deleted` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '逻辑删除 1(true)已删除, 0(false)未删除',
  `gmt_create` datetime NOT NULL COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_role_id` (`role_id`),
  KEY `idx_user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

#
# Data for table "acl_user_role"
#

INSERT INTO `acl_user_role` VALUES ('1','1','2',0,'2019-11-11 13:09:53','2019-11-11 13:09:53');

4、代码优化版(这种方式不能给Level定义几级菜单,需要数据库指定)

    @Override
    public List<Permission> queryAllMenuGuli() {
        //1 查询菜单表所有数据
        QueryWrapper<Permission> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        List<Permission> permissionList = baseMapper.selectList(wrapper);

        List<Permission> resultList = new ArrayList<>();
        Map<String,Permission> map = new HashMap<>();

        for(Permission permission : permissionList){
            map.put(permission.getId(),permission);
        }

        for(Permission permission : permissionList){
            Permission child = permission;
            if("0".equals(permission.getPid())){
                //permission.setLevel(1);
                resultList.add(permission);
            }else{
                Permission parent = map.get(child.getPid());
                //把父菜单的level值+1
                //int level = parent.getLevel()+1;
                //child.setLevel(level);
                if(null ==  parent.getChildren()){

                    parent.setChildren(new ArrayList<Permission>());
                }
                parent.getChildren().add(child);
            }
        }

5、测试返回结果数据

{
  "success": true,
  "code": 20000,
  "message": "成功",
  "data": {
    "children": [
      {
        "id": "1",
        "pid": "0",
        "name": "全部数据",
        "type": 0,
        "permissionValue": null,
        "path": null,
        "component": null,
        "icon": null,
        "status": null,
        "level": 1,
        "children": [
          {
            "id": "1195354076890370050",
            "pid": "1",
            "name": "订单管理",
            "type": 1,
            "permissionValue": null,
            "path": "/order",
            "component": "Layout",
            "icon": null,
            "status": null,
            "level": 2,
            "children": [
              {
                "id": "1195354153482555393",
                "pid": "1195354076890370050",
                "name": "订单列表",
                "type": 1,
                "permissionValue": null,
                "path": "list",
                "component": "/order/list",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1195354315093282817",
                    "pid": "1195354153482555393",
                    "name": "查看",
                    "type": 2,
                    "permissionValue": "order.list",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:54:12",
                    "gmtModified": "2019-11-15 22:54:12",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 22:53:33",
                "gmtModified": "2019-11-15 22:53:58",
                "select": false
              }
            ],
            "isDeleted": false,
            "gmtCreate": "2019-11-15 22:53:15",
            "gmtModified": "2019-11-15 22:53:15",
            "select": false
          },
          {
            "id": "1195352547621965825",
            "pid": "1",
            "name": "CMS管理",
            "type": 1,
            "permissionValue": null,
            "path": "/cms",
            "component": "Layout",
            "icon": null,
            "status": null,
            "level": 2,
            "children": [
              {
                "id": "1195353513549205505",
                "pid": "1195352547621965825",
                "name": "Bander列表",
                "type": 1,
                "permissionValue": null,
                "path": "banner/list",
                "component": "/cms/banner/list",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1195353672110673921",
                    "pid": "1195353513549205505",
                    "name": "删除",
                    "type": 2,
                    "permissionValue": "banner.remove",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:51:39",
                    "gmtModified": "2019-11-15 22:51:39",
                    "select": false
                  },
                  {
                    "id": "1195353051395624961",
                    "pid": "1195353513549205505",
                    "name": "修改",
                    "type": 2,
                    "permissionValue": "banner.update",
                    "path": "banner/update/:id",
                    "component": "/cms/banner/form",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:49:11",
                    "gmtModified": "2019-11-18 10:52:05",
                    "select": false
                  },
                  {
                    "id": "1195352909401657346",
                    "pid": "1195353513549205505",
                    "name": "添加",
                    "type": 2,
                    "permissionValue": "banner.add",
                    "path": "banner/add",
                    "component": "/cms/banner/form",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:48:37",
                    "gmtModified": "2019-11-18 10:52:10",
                    "select": false
                  },
                  {
                    "id": "1195352856645701633",
                    "pid": "1195353513549205505",
                    "name": "查看",
                    "type": 2,
                    "permissionValue": "banner.list",
                    "path": "",
                    "component": null,
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:48:24",
                    "gmtModified": "2019-11-15 22:48:24",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 22:51:01",
                "gmtModified": "2019-11-18 10:51:29",
                "select": false
              }
            ],
            "isDeleted": false,
            "gmtCreate": "2019-11-15 22:47:11",
            "gmtModified": "2019-11-18 10:51:46",
            "select": false
          },
          {
            "id": "1195351862889254913",
            "pid": "1",
            "name": "统计分析",
            "type": 1,
            "permissionValue": null,
            "path": "/statistics/daily",
            "component": "Layout",
            "icon": null,
            "status": null,
            "level": 2,
            "children": [
              {
                "id": "1195352054917074946",
                "pid": "1195351862889254913",
                "name": "统计图表",
                "type": 1,
                "permissionValue": null,
                "path": "chart",
                "component": "/statistics/daily/chart",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1195352127734386690",
                    "pid": "1195352054917074946",
                    "name": "查看",
                    "type": 2,
                    "permissionValue": "daily.list",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:45:30",
                    "gmtModified": "2019-11-15 22:45:30",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 22:45:13",
                "gmtModified": "2019-11-15 22:45:13",
                "select": false
              },
              {
                "id": "1195351968841568257",
                "pid": "1195351862889254913",
                "name": "生成统计",
                "type": 1,
                "permissionValue": null,
                "path": "create",
                "component": "/statistics/daily/create",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1195352215768633346",
                    "pid": "1195351968841568257",
                    "name": "生成",
                    "type": 2,
                    "permissionValue": "daily.add",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:45:51",
                    "gmtModified": "2019-11-15 22:45:51",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 22:44:53",
                "gmtModified": "2019-11-15 22:44:53",
                "select": false
              }
            ],
            "isDeleted": false,
            "gmtCreate": "2019-11-15 22:44:27",
            "gmtModified": "2019-11-15 22:44:27",
            "select": false
          },
          {
            "id": "1195350831744782337",
            "pid": "1",
            "name": "课程管理",
            "type": 1,
            "permissionValue": null,
            "path": "/edu/course",
            "component": "Layout",
            "icon": null,
            "status": null,
            "level": 2,
            "children": [
              {
                "id": "1195351020463296513",
                "pid": "1195350831744782337",
                "name": "发布课程",
                "type": 1,
                "permissionValue": null,
                "path": "info",
                "component": "/edu/course/info",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 22:41:06",
                "gmtModified": "2019-11-15 22:41:06",
                "select": false
              },
              {
                "id": "1195350919074385921",
                "pid": "1195350831744782337",
                "name": "课程列表",
                "type": 1,
                "permissionValue": null,
                "path": "list",
                "component": "/edu/course/list",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1195351566221938690",
                    "pid": "1195350919074385921",
                    "name": "编辑课程大纲",
                    "type": 2,
                    "permissionValue": "chapter.update",
                    "path": "chapter/:id",
                    "component": "/edu/course/chapter",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:43:17",
                    "gmtModified": "2019-11-15 22:43:17",
                    "select": false
                  },
                  {
                    "id": "1195351326706208770",
                    "pid": "1195350919074385921",
                    "name": "编辑课程",
                    "type": 2,
                    "permissionValue": "course.update",
                    "path": "info/:id",
                    "component": "/edu/course/info",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:42:19",
                    "gmtModified": "2019-11-15 22:42:19",
                    "select": false
                  },
                  {
                    "id": "1195351159672246274",
                    "pid": "1195350919074385921",
                    "name": "完成发布",
                    "type": 2,
                    "permissionValue": "course.publish",
                    "path": "publish/:id",
                    "component": "/edu/course/publish",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:41:40",
                    "gmtModified": "2019-11-15 22:44:01",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 22:40:42",
                "gmtModified": "2019-11-15 22:40:42",
                "select": false
              }
            ],
            "isDeleted": false,
            "gmtCreate": "2019-11-15 22:40:21",
            "gmtModified": "2019-11-15 22:40:21",
            "select": false
          },
          {
            "id": "1195350299365969922",
            "pid": "1",
            "name": "课程分类",
            "type": 1,
            "permissionValue": null,
            "path": "/edu/subject",
            "component": "Layout",
            "icon": null,
            "status": null,
            "level": 2,
            "children": [
              {
                "id": "1195350500512206850",
                "pid": "1195350299365969922",
                "name": "导入课程分类",
                "type": 1,
                "permissionValue": null,
                "path": "import",
                "component": "/edu/subject/import",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1195350687590748161",
                    "pid": "1195350500512206850",
                    "name": "导入",
                    "type": 2,
                    "permissionValue": "subject.import",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:39:47",
                    "gmtModified": "2019-11-15 22:39:47",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 22:39:03",
                "gmtModified": "2019-11-15 22:39:03",
                "select": false
              },
              {
                "id": "1195350397751758850",
                "pid": "1195350299365969922",
                "name": "课程分类列表",
                "type": 1,
                "permissionValue": null,
                "path": "list",
                "component": "/edu/subject/list",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1195350612172967938",
                    "pid": "1195350397751758850",
                    "name": "查看",
                    "type": 2,
                    "permissionValue": "subject.list",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:39:29",
                    "gmtModified": "2019-11-15 22:39:29",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 22:38:38",
                "gmtModified": "2019-11-15 22:38:38",
                "select": false
              }
            ],
            "isDeleted": false,
            "gmtCreate": "2019-11-15 22:38:15",
            "gmtModified": "2019-11-15 22:38:15",
            "select": false
          },
          {
            "id": "1195349439240048642",
            "pid": "1",
            "name": "讲师管理",
            "type": 1,
            "permissionValue": null,
            "path": "/edu/teacher",
            "component": "Layout",
            "icon": null,
            "status": null,
            "level": 2,
            "children": [
              {
                "id": "1195349810561781761",
                "pid": "1195349439240048642",
                "name": "添加讲师",
                "type": 1,
                "permissionValue": null,
                "path": "create",
                "component": "/edu/teacher/form",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1195349876252971010",
                    "pid": "1195349810561781761",
                    "name": "添加",
                    "type": 2,
                    "permissionValue": "teacher.add",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:36:34",
                    "gmtModified": "2019-11-15 22:36:34",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 22:36:18",
                "gmtModified": "2019-11-15 22:36:18",
                "select": false
              },
              {
                "id": "1195349699995734017",
                "pid": "1195349439240048642",
                "name": "讲师列表",
                "type": 1,
                "permissionValue": null,
                "path": "list",
                "component": "/edu/teacher/list",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1195350188359520258",
                    "pid": "1195349699995734017",
                    "name": "删除",
                    "type": 2,
                    "permissionValue": "teacher.remove",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:37:48",
                    "gmtModified": "2019-11-15 22:37:48",
                    "select": false
                  },
                  {
                    "id": "1195350117270261762",
                    "pid": "1195349699995734017",
                    "name": "修改",
                    "type": 2,
                    "permissionValue": "teacher.update",
                    "path": "edit/:id",
                    "component": "/edu/teacher/form",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:37:31",
                    "gmtModified": "2019-11-15 22:37:31",
                    "select": false
                  },
                  {
                    "id": "1195349979797753857",
                    "pid": "1195349699995734017",
                    "name": "查看",
                    "type": 2,
                    "permissionValue": "teacher.list",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 22:36:58",
                    "gmtModified": "2019-11-15 22:36:58",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 22:35:52",
                "gmtModified": "2019-11-15 22:35:52",
                "select": false
              }
            ],
            "isDeleted": false,
            "gmtCreate": "2019-11-15 22:34:49",
            "gmtModified": "2019-11-15 22:34:49",
            "select": false
          },
          {
            "id": "1195268474480156673",
            "pid": "1",
            "name": "权限管理",
            "type": 1,
            "permissionValue": null,
            "path": "/acl",
            "component": "Layout",
            "icon": null,
            "status": null,
            "level": 2,
            "children": [
              {
                "id": "1195268893830864898",
                "pid": "1195268474480156673",
                "name": "菜单管理",
                "type": 1,
                "permissionValue": null,
                "path": "menu/list",
                "component": "/acl/menu/list",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1195270887933009922",
                    "pid": "1195268893830864898",
                    "name": "删除",
                    "type": 2,
                    "permissionValue": "permission.remove",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:22:41",
                    "gmtModified": "2019-11-15 17:22:41",
                    "select": false
                  },
                  {
                    "id": "1195270862100291586",
                    "pid": "1195268893830864898",
                    "name": "修改",
                    "type": 2,
                    "permissionValue": "permission.update",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:22:35",
                    "gmtModified": "2019-11-15 17:22:35",
                    "select": false
                  },
                  {
                    "id": "1195270810560684034",
                    "pid": "1195268893830864898",
                    "name": "添加",
                    "type": 2,
                    "permissionValue": "permission.add",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:22:23",
                    "gmtModified": "2019-11-15 17:22:23",
                    "select": false
                  },
                  {
                    "id": "1195270744097742849",
                    "pid": "1195268893830864898",
                    "name": "查看",
                    "type": 2,
                    "permissionValue": "permission.list",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:22:07",
                    "gmtModified": "2019-11-15 17:22:07",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 17:14:46",
                "gmtModified": "2019-11-15 17:14:46",
                "select": false
              },
              {
                "id": "1195268788138598401",
                "pid": "1195268474480156673",
                "name": "角色管理",
                "type": 1,
                "permissionValue": null,
                "path": "role/list",
                "component": "/acl/role/list",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1195270621548568578",
                    "pid": "1195268788138598401",
                    "name": "角色权限",
                    "type": 2,
                    "permissionValue": "role.acl",
                    "path": "role/distribution/:id",
                    "component": "/acl/role/roleForm",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:21:38",
                    "gmtModified": "2019-11-15 17:21:38",
                    "select": false
                  },
                  {
                    "id": "1195270442602782721",
                    "pid": "1195268788138598401",
                    "name": "删除",
                    "type": 2,
                    "permissionValue": "role.remove",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:20:55",
                    "gmtModified": "2019-11-15 17:20:55",
                    "select": false
                  },
                  {
                    "id": "1195270037005197313",
                    "pid": "1195268788138598401",
                    "name": "添加",
                    "type": 2,
                    "permissionValue": "role.add",
                    "path": "role/add",
                    "component": "/acl/role/form",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:19:19",
                    "gmtModified": "2019-11-18 11:05:42",
                    "select": false
                  },
                  {
                    "id": "1195269903542444034",
                    "pid": "1195268788138598401",
                    "name": "查看",
                    "type": 2,
                    "permissionValue": "role.list",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:18:47",
                    "gmtModified": "2019-11-15 17:18:47",
                    "select": false
                  },
                  {
                    "id": "1195269821262782465",
                    "pid": "1195268788138598401",
                    "name": "修改",
                    "type": 2,
                    "permissionValue": "role.update",
                    "path": "role/update/:id",
                    "component": "/acl/role/form",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:18:27",
                    "gmtModified": "2019-11-15 17:19:53",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 17:14:21",
                "gmtModified": "2019-11-15 17:14:21",
                "select": false
              },
              {
                "id": "1195268616021139457",
                "pid": "1195268474480156673",
                "name": "用户管理",
                "type": 1,
                "permissionValue": null,
                "path": "user/list",
                "component": "/acl/user/list",
                "icon": null,
                "status": null,
                "level": 3,
                "children": [
                  {
                    "id": "1196301740985311234",
                    "pid": "1195268616021139457",
                    "name": "分配角色",
                    "type": 2,
                    "permissionValue": "user.assgin",
                    "path": "user/role/:id",
                    "component": "/acl/user/roleForm",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-18 13:38:56",
                    "gmtModified": "2019-11-18 13:38:56",
                    "select": false
                  },
                  {
                    "id": "1195269547269873666",
                    "pid": "1195268616021139457",
                    "name": "删除",
                    "type": 2,
                    "permissionValue": "user.remove",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:17:22",
                    "gmtModified": "2019-11-15 17:17:22",
                    "select": false
                  },
                  {
                    "id": "1195269473479483394",
                    "pid": "1195268616021139457",
                    "name": "修改",
                    "type": 2,
                    "permissionValue": "user.update",
                    "path": "user/update/:id",
                    "component": "/acl/user/form",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:17:04",
                    "gmtModified": "2019-11-15 17:17:04",
                    "select": false
                  },
                  {
                    "id": "1195269295926206466",
                    "pid": "1195268616021139457",
                    "name": "添加",
                    "type": 2,
                    "permissionValue": "user.add",
                    "path": "user/add",
                    "component": "/acl/user/form",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:16:22",
                    "gmtModified": "2019-11-15 17:16:22",
                    "select": false
                  },
                  {
                    "id": "1195269143060602882",
                    "pid": "1195268616021139457",
                    "name": "查看",
                    "type": 2,
                    "permissionValue": "user.list",
                    "path": "",
                    "component": "",
                    "icon": null,
                    "status": null,
                    "level": 4,
                    "children": [],
                    "isDeleted": false,
                    "gmtCreate": "2019-11-15 17:15:45",
                    "gmtModified": "2019-11-17 21:57:16",
                    "select": false
                  }
                ],
                "isDeleted": false,
                "gmtCreate": "2019-11-15 17:13:40",
                "gmtModified": "2019-11-18 13:53:12",
                "select": false
              }
            ],
            "isDeleted": false,
            "gmtCreate": "2019-11-15 17:13:06",
            "gmtModified": "2019-11-18 13:54:25",
            "select": false
          }
        ],
        "isDeleted": false,
        "gmtCreate": "2019-11-15 17:13:06",
        "gmtModified": "2019-11-15 17:13:06",
        "select": false
      }
    ]
  }
}

三、参照3(vue)

1、封装的类

package com.stu.service.edu.entity.vo;

import com.stu.service.edu.entity.Subject;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/******************************
 * 用途说明:课程分类树形显示
 * 作者姓名: Administrator
 * 创建时间: 2022-05-07 18:37
 ******************************/
@Data
public class SubjectVo implements Serializable {
    private static final long serialVersionUID = 1L;

    private String id;
    private String title;
    private String sort;
    private String parentId;
    private List<SubjectVo> childList = new ArrayList<>();

}

2、controller的类

package com.stu.service.edu.controller.admin;


import com.stu.service.base.result.R;
import com.stu.service.edu.entity.vo.SubjectVo;
import com.stu.service.edu.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author stu
 * @since 2022-05-06
 */
@RestController
@RequestMapping("/admin/edu/subject")
@CrossOrigin
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    /***********************************
     * 用途说明:批量导入课程分类数据
     * 返回值说明: com.stu.service.base.result.R
     ***********************************/
    @PostMapping("batchImportExcel")
    public R batchImportExcel(MultipartFile file){
        subjectService.batchImport(file);
       return R.ok();
    }

    /***********************************
     * 用途说明:分类课程的树形结构数据
     * 返回值说明: com.stu.service.base.result.R
     ***********************************/
    @GetMapping("getTreeList")
    public R getTreeList(){
        return R.ok().data("treeList",subjectService.getAllSubject());
    }
}

3、service的类

package com.stu.service.edu.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.stu.service.edu.entity.Subject;
import com.stu.service.edu.entity.vo.SubjectVo;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 服务类
 * </p>
 *
 * @author stu
 * @since 2022-05-06
 */
public interface SubjectService extends IService<Subject> {

    /***********************************
     * 用途说明:批量导入
     * 返回值说明: void
     ***********************************/
    void batchImport(MultipartFile file);

    /***********************************
     * 用途说明:取得所有课程分类
     * 返回值说明: java.util.List<com.stu.service.edu.entity.Subject>
     ***********************************/
    List<SubjectVo> getAllSubject();
    

}

4、实现的类

package com.stu.service.edu.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.stu.service.edu.entity.Subject;
import com.stu.service.edu.entity.excel.SubjectExcelData;
import com.stu.service.edu.entity.vo.SubjectVo;
import com.stu.service.edu.listener.SubJectExcelListener;
import com.stu.service.edu.mapper.SubjectMapper;
import com.stu.service.edu.service.SubjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程科目 服务实现类
 * </p>
 *
 * @author stu
 * @since 2022-05-06
 */
@Service
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> implements SubjectService {

    @Autowired
    private SubjectMapper subjectMapper;

    @Override
    public void batchImport(MultipartFile file) {

        try {
            EasyExcel.read(file.getInputStream(), SubjectExcelData.class,
                    new SubJectExcelListener(subjectMapper)).excelType(ExcelTypeEnum.XLS).sheet().doRead();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public List<SubjectVo> getAllSubject() {
        //课程分类的树形结构集合
        List<SubjectVo> rootList = new ArrayList<>();

        Map<String, SubjectVo> tempMap = new HashMap<>();
        List<SubjectVo> tempList = new ArrayList<>();

        QueryWrapper<Subject> queryWrapper = new QueryWrapper<>();
        List<Subject> subjectList = baseMapper.selectList(queryWrapper);

        //组装树形结构数据的准备工作
        for (Subject subject : subjectList) {

            SubjectVo subjectVo = new SubjectVo();
            //返回的实体和前端需要的实体vo进行赋值

            BeanUtils.copyProperties(subject, subjectVo);
            tempMap.put(subjectVo.getId(), subjectVo);
            tempList.add(subjectVo);
        }
        //封装课程分类的树形结构数据
        for (SubjectVo vo : tempList) {
            SubjectVo child = vo;
            if ("0".equals(vo.getParentId())) {
                rootList.add(vo);
            } else {
                SubjectVo parent = tempMap.get(child.getParentId());
                parent.getChildList().add(child);
            }
        }

        return rootList;
    }
}

SubJectExcelListener

package com.stu.service.edu.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.stu.service.base.exception.CustomException;
import com.stu.service.base.result.ResultCodeEnum;
import com.stu.service.edu.entity.Subject;
import com.stu.service.edu.entity.excel.SubjectExcelData;
import com.stu.service.edu.mapper.SubjectMapper;

/******************************
 * 用途说明:excel导入的listener
 * 作者姓名: Administrator
 * 创建时间: 2022-05-06 0:23
 ******************************/
public class SubJectExcelListener extends AnalysisEventListener<SubjectExcelData> {

    //因为SubJectExcelListener不能交给spring进行管理,需要自己new,不能注入其他对象
    //不能实现数据库操作 new mapper

    private SubjectMapper subjectMapper;

    //让对象可以使用start,创建一个有参构造和一个无参构造
    public SubJectExcelListener() {
    }

    public SubJectExcelListener(SubjectMapper subjectMapper) {
        this.subjectMapper = subjectMapper;
    }
    //让对象可以使用end

    /***********************************
     * 用途说明:遍历每一行数据
     * 返回值说明: void
     ***********************************/
    @Override
    public void invoke(SubjectExcelData subjectExcelData, AnalysisContext analysisContext) {

        if (subjectExcelData == null) {
            throw new CustomException(ResultCodeEnum.EXCEL_DATA_IMPORT_ERROR);
        }
        String oneSubjectTitle = subjectExcelData.getOneSubjectTitle();
        String twoSubjectTitle = subjectExcelData.getTwoSubjectTitle();

        //验证是否已经存在一级分类
        Subject oneSbuject = this.checkOneSubject(oneSubjectTitle);

        if (oneSbuject == null) {
            oneSbuject = new Subject();
            oneSbuject.setTitle(oneSubjectTitle);
            oneSbuject.setParentId("0");
            subjectMapper.insert(oneSbuject);
        }

        //取得二级分类的父id
        String pid = oneSbuject.getId();
        //验证是否已经存在二级分类
        Subject twoSbuject = this.checkTwoSubject(twoSubjectTitle, pid);
        if (twoSbuject == null) {
            twoSbuject = new Subject();
            twoSbuject.setTitle(twoSubjectTitle);
            twoSbuject.setParentId(pid);
            subjectMapper.insert(twoSbuject);
        }

    }

    /***********************************
     * 用途说明:所有数据读取之后的收尾工作
     * 返回值说明: void
     ***********************************/
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

    /***********************************
     * 用途说明:验证是否已经存在一级分类
     * 返回值说明: com.stu.service.edu.entity.Subject
     ***********************************/
    private Subject checkOneSubject(String title) {
        QueryWrapper<Subject> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("title", title);
        return subjectMapper.selectOne(queryWrapper);

    }

    /***********************************
     * 用途说明:验证是否已经存在二级分类
     * 返回值说明: com.stu.service.edu.entity.Subject
     ***********************************/
    private Subject checkTwoSubject(String title, String pid) {
        QueryWrapper<Subject> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("title", title);
        queryWrapper.eq("parent_id", pid);
        return subjectMapper.selectOne(queryWrapper);

    }
}

5、vue页面

<template>
  <dev
    ><el-input placeholder="输入关键字进行过滤" v-model="filterText">
    </el-input>

    <el-tree
      class="filter-tree"
      :data="treeList"
      :props="defaultProps"
      default-expand-all
      :filter-node-method="filterNode"
      ref="tree"
    >
    </el-tree
  ></dev>
</template>

<script>
import subjectApi from "@/api/subject";
export default {
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  created() {
    this.getTreeList();
  },
  methods: {
    getTreeList() {
      subjectApi.treeList().then((res) => {
        if (res.code === 20000 && res.data.treeList) {
          this.treeList = res.data.treeList;
        }
      });
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.title.indexOf(value) !== -1;
    },
  },

  data() {
    return {
      filterText: "",
      treeList: [],
      defaultProps: {
        children: "childList",
        label: "title",
      },
    };
  },
};
</script>

6、vue的接口

import request from '@/utils/request'

export default {
    treeList() {
        return request({
            url: '/admin/edu/subject/getTreeList',
            method: 'get' 
        })
    },
}

7、数据库

img

8、页面效果

img

Last Updated 2024/4/6 11:55:17