Initial commit
This commit is contained in:
parent
599356c6d4
commit
4e11a347e9
@ -0,0 +1,82 @@
|
||||
package com.atguigu.auth.controller;
|
||||
|
||||
|
||||
import com.atguigu.auth.service.SysMenuService;
|
||||
import com.atguigu.common.result.Result;
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单管理 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-06-09
|
||||
*/
|
||||
@Api(tags = "菜单管理接口")
|
||||
@RestController
|
||||
@RequestMapping("/admin/system/sysMenu")
|
||||
public class SysMenuController {
|
||||
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
|
||||
/**
|
||||
* 菜单列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "菜单列表")
|
||||
@GetMapping("/findNodes")
|
||||
public Result findNodes() {
|
||||
List<SysMenu> list = sysMenuService.findNodes();
|
||||
return Result.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增菜单
|
||||
*
|
||||
* @param sysMenu
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "新增菜单")
|
||||
@PostMapping("save")
|
||||
public Result save(@RequestBody SysMenu sysMenu) {
|
||||
sysMenuService.save(sysMenu);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改菜单
|
||||
*
|
||||
* @param sysMenu
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "修改菜单")
|
||||
@PutMapping("update")
|
||||
public Result updateById(@RequestBody SysMenu sysMenu) {
|
||||
sysMenuService.updateById(sysMenu);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "删除菜单")
|
||||
@DeleteMapping("remove/{id}")
|
||||
public Result remove(@PathVariable Long id) {
|
||||
sysMenuService.removeMenuById(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.atguigu.auth.mapper;
|
||||
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-06-09
|
||||
*/
|
||||
public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.atguigu.auth.mapper;
|
||||
|
||||
import com.atguigu.model.system.SysRoleMenu;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-06-09
|
||||
*/
|
||||
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
<?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.atguigu.auth.mapper.SysMenuMapper">
|
||||
|
||||
</mapper>
|
@ -0,0 +1,5 @@
|
||||
<?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.atguigu.auth.mapper.SysRoleMenuMapper">
|
||||
|
||||
</mapper>
|
@ -0,0 +1,32 @@
|
||||
package com.atguigu.auth.service;
|
||||
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-06-09
|
||||
*/
|
||||
public interface SysMenuService extends IService<SysMenu> {
|
||||
|
||||
/**
|
||||
* 菜单列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<SysMenu> findNodes();
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
void removeMenuById(Long id);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.atguigu.auth.service;
|
||||
|
||||
import com.atguigu.model.system.SysRoleMenu;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-06-09
|
||||
*/
|
||||
public interface SysRoleMenuService extends IService<SysRoleMenu> {
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.atguigu.auth.service.impl;
|
||||
|
||||
import com.atguigu.auth.mapper.SysMenuMapper;
|
||||
import com.atguigu.auth.service.SysMenuService;
|
||||
import com.atguigu.auth.utils.MenuHelper;
|
||||
import com.atguigu.common.execption.GuiguException;
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-06-09
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
||||
|
||||
/**
|
||||
* 菜单列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findNodes() {
|
||||
// 1、查询所有 的数据
|
||||
List<SysMenu> sysMenuList = baseMapper.selectList(null);
|
||||
|
||||
// 2、构建树形结构
|
||||
List<SysMenu> list = MenuHelper.buildTree(sysMenuList);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void removeMenuById(Long id) {
|
||||
// 判断当前菜单是否有下一层菜单
|
||||
LambdaQueryWrapper<SysMenu> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(SysMenu::getParentId, id);
|
||||
|
||||
Integer count = baseMapper.selectCount(lambdaQueryWrapper);
|
||||
|
||||
if (count > 0) {
|
||||
throw new GuiguException(201, "菜单不能删除");
|
||||
}
|
||||
baseMapper.deleteById(id);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.atguigu.auth.service.impl;
|
||||
|
||||
import com.atguigu.auth.mapper.SysRoleMenuMapper;
|
||||
import com.atguigu.auth.service.SysRoleMenuService;
|
||||
import com.atguigu.model.system.SysRoleMenu;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author yovinchen
|
||||
* @since 2023-06-09
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.atguigu.auth.utils;
|
||||
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ClassName: MenuHelper
|
||||
* Package: com.atguigu.auth.utils
|
||||
*
|
||||
* @author yovinchen
|
||||
* @Create 2023/6/9 23:31
|
||||
*/
|
||||
public class MenuHelper {
|
||||
|
||||
/**
|
||||
* 使用递归方法建菜单
|
||||
*
|
||||
* @param sysMenuList
|
||||
* @return
|
||||
*/
|
||||
public static List<SysMenu> buildTree(List<SysMenu> sysMenuList) {
|
||||
// 存放最终数据
|
||||
List<SysMenu> trees = new ArrayList<>();
|
||||
|
||||
// 把所有的菜单数据进行遍历
|
||||
for (SysMenu sysMenu : sysMenuList) {
|
||||
// 递归入口 parentId = 0
|
||||
if (sysMenu.getParentId().longValue() == 0) {
|
||||
trees.add(getChildren(sysMenu, sysMenuList));
|
||||
}
|
||||
|
||||
}
|
||||
return trees;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归查找子节点
|
||||
*
|
||||
* @param sysMenu
|
||||
* @param sysMenuList
|
||||
* @return
|
||||
*/
|
||||
public static SysMenu getChildren(SysMenu sysMenu, List<SysMenu> sysMenuList) {
|
||||
sysMenu.setChildren(new ArrayList<SysMenu>());
|
||||
|
||||
// 遍历所有的菜单数据,判断id和parent_id的对应关系
|
||||
for (SysMenu menu : sysMenuList) {
|
||||
if (sysMenu.getId().longValue() == menu.getParentId().longValue()) {
|
||||
if (sysMenu.getChildren() == null) {
|
||||
sysMenu.setChildren(new ArrayList<>());
|
||||
}
|
||||
sysMenu.getChildren().add(getChildren(menu, sysMenuList));
|
||||
}
|
||||
}
|
||||
return sysMenu;
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@ public class CodeGet {
|
||||
// 5、策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
|
||||
strategy.setInclude("sys_user_role");
|
||||
strategy.setInclude("sys_menu","sys_role_menu");
|
||||
//数据库表映射到实体的命名策略
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
//数据库表字段映射到实体的命名策略
|
||||
|
Loading…
Reference in New Issue
Block a user