Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
|
36e627c461 | |
|
970a13bc5b | |
|
8f20d4c82f |
|
@ -34,5 +34,11 @@
|
|||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>model</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.atguigu.common.utlis;
|
||||
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MenuHelper {
|
||||
/**
|
||||
* 构建树型结构
|
||||
*
|
||||
* @param sysMenuList 系统菜单列表
|
||||
* @return 菜单结构列表
|
||||
*/
|
||||
public static List<SysMenu> buildTree(List<SysMenu> sysMenuList) {
|
||||
ArrayList<SysMenu> tress = new ArrayList<>();
|
||||
// 把菜单数据进行遍历
|
||||
sysMenuList.forEach(sysMenu -> {
|
||||
if (sysMenu.getParentId() == 0) tress.add(getChildren(sysMenu, sysMenuList));
|
||||
});
|
||||
return tress;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建递归循环
|
||||
*
|
||||
* @param sysMenu 当前菜单对象
|
||||
* @param sysMenuList 全部菜单列表
|
||||
* @return 菜单
|
||||
*/
|
||||
private static SysMenu getChildren(SysMenu sysMenu, List<SysMenu> sysMenuList) {
|
||||
// 遍历所有菜单数据,判断id和parentID对应关系
|
||||
sysMenu.setChildren(new ArrayList<>());
|
||||
|
||||
sysMenuList.forEach(menu -> {
|
||||
if (menu.getChildren() == null) menu.setChildren(new ArrayList<>());
|
||||
if (sysMenu.getId().equals(menu.getParentId())) {
|
||||
sysMenu.getChildren().add(getChildren(menu, sysMenuList));
|
||||
}
|
||||
});
|
||||
|
||||
return sysMenu;
|
||||
}
|
||||
}
|
|
@ -55,7 +55,7 @@ public class CodeGet {
|
|||
private static StrategyConfig getStrategyConfig() {
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
// TODO 要生成的表
|
||||
strategy.setInclude("sys_user", "sys_role","sys_user_role");
|
||||
strategy.setInclude("sys_menu", "sys_role_menu");
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);// 数据库表映射到实体的命名策略
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 数据库表字段映射到实体的命名策略
|
||||
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
|
||||
|
|
|
@ -32,7 +32,5 @@ public class MessageConstant {
|
|||
public static final String LOGIN_DTO_IS_EMPTY = "登录参数不能为空";
|
||||
public static final String TOKEN_IS_EMPTY = "token为空";
|
||||
public static final String DATA_IS_EMPTY = "数据为空";
|
||||
public static final String STOCK_LESS = "库存不足";
|
||||
public static final String SKU_NUM_CANNOT_BE_LESS = "商品数量不能再少了";
|
||||
public static final String CART_IS_EMPTY = "购物车为空";
|
||||
public static final String DELETE_MENU_ERROR_HAS_MENUS = "有下级菜单";
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -102,3 +102,17 @@
|
|||
18:39:51:555 INFO 6652 --- [http-nio-8800-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
|
||||
18:40:02:303 INFO 6652 --- [http-nio-8800-exec-4] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
|
||||
18:40:02:498 INFO 6652 --- [http-nio-8800-exec-4] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
|
||||
17:35:19:249 INFO 12196 --- [main] com.atguigu.auth.ServiceAuthApplication : Starting ServiceAuthApplication on bunny with PID 12196 (G:\java项目\guigu-oa\guigu-oa\service-oa\target\classes started by 13199 in G:\java项目\guigu-oa\guigu-oa)
|
||||
17:35:19:250 INFO 12196 --- [main] com.atguigu.auth.ServiceAuthApplication : The following profiles are active: dev
|
||||
17:35:19:892 INFO 12196 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8800 (http)
|
||||
17:35:19:897 INFO 12196 --- [main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
|
||||
17:35:19:897 INFO 12196 --- [main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.39]
|
||||
17:35:19:938 INFO 12196 --- [main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
|
||||
17:35:19:938 INFO 12196 --- [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 664 ms
|
||||
17:35:20:021 INFO 12196 --- [main] com.atguigu.config.MybatisPlusConfig : 注入MybatisPlus配置类...
|
||||
17:35:20:622 INFO 12196 --- [main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
|
||||
17:35:20:708 INFO 12196 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8800 (http) with context path ''
|
||||
17:35:20:847 INFO 12196 --- [main] com.atguigu.auth.ServiceAuthApplication : Started ServiceAuthApplication in 1.834 seconds (JVM running for 2.625)
|
||||
17:35:45:707 INFO 12196 --- [http-nio-8800-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
|
||||
17:35:45:707 INFO 12196 --- [http-nio-8800-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
|
||||
17:35:45:710 INFO 12196 --- [http-nio-8800-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 3 ms
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package com.atguigu.auth.controller;
|
||||
|
||||
|
||||
import com.atguigu.auth.service.SysMenuService;
|
||||
import com.atguigu.common.result.Result;
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.atguigu.vo.system.AssginMenuVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@Tag(name = "菜单管理")
|
||||
@RestController
|
||||
@RequestMapping("/admin/system/sysMenu")
|
||||
public class SysMenuController {
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
|
||||
@Operation(summary = "获取菜单", description = "获取菜单")
|
||||
@GetMapping("findNodes")
|
||||
public Result<List<SysMenu>> findNodes() {
|
||||
List<SysMenu> list = sysMenuService.findNodes();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增菜单", description = "新增菜单")
|
||||
@PostMapping("save")
|
||||
public Result<SysMenu> save(@RequestBody SysMenu permission) {
|
||||
sysMenuService.save(permission);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "修改菜单", description = "修改菜单")
|
||||
@PutMapping("update")
|
||||
public Result<SysMenu> updateById(@RequestBody SysMenu permission) {
|
||||
sysMenuService.updateById(permission);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除菜单", description = "删除菜单")
|
||||
@DeleteMapping("remove/{id}")
|
||||
public Result<SysMenu> remove(@PathVariable Long id) {
|
||||
sysMenuService.removeMenuById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "根据角色获取菜单", description = "根据角色获取菜单")
|
||||
@GetMapping("toAssign/{roleId}")
|
||||
public Result<List<SysMenu>> toAssign(@PathVariable Long roleId) {
|
||||
List<SysMenu> sysMenuList = sysMenuService.findSysMenuByRoleId(roleId);
|
||||
return Result.success(sysMenuList);
|
||||
}
|
||||
|
||||
@Operation(summary = "给角色分配权限", description = "给角色分配权限")
|
||||
@PostMapping("doAssign")
|
||||
public Result<AssginMenuVo> doAssign(@RequestBody AssginMenuVo assginMenuVo) {
|
||||
sysMenuService.doAssign(assginMenuVo);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.atguigu.auth.controller;
|
||||
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色菜单 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/auth/sys-role-menu")
|
||||
public class SysRoleMenuController {
|
||||
|
||||
}
|
||||
|
|
@ -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 bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
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 bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package com.atguigu.auth.service;
|
||||
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.atguigu.vo.system.AssginMenuVo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 菜单表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysMenuService extends IService<SysMenu> {
|
||||
|
||||
/**
|
||||
* 获取菜单
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> findNodes();
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单id
|
||||
*/
|
||||
void removeMenuById(Long id);
|
||||
|
||||
/**
|
||||
* 根据角色获取菜单
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> findSysMenuByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 给角色分配权限
|
||||
*
|
||||
* @param assginMenuVo 分配条件
|
||||
*/
|
||||
void doAssign(AssginMenuVo assginMenuVo);
|
||||
}
|
|
@ -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 bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
public interface SysRoleMenuService extends IService<SysRoleMenu> {
|
||||
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package com.atguigu.auth.service.impl;
|
||||
|
||||
import com.atguigu.auth.mapper.SysMenuMapper;
|
||||
import com.atguigu.auth.service.SysMenuService;
|
||||
import com.atguigu.common.utlis.MenuHelper;
|
||||
import com.atguigu.constant.MessageConstant;
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import com.atguigu.model.system.SysMenu;
|
||||
import com.atguigu.vo.system.AssginMenuVo;
|
||||
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 bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@Service
|
||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
||||
|
||||
/**
|
||||
* 获取菜单
|
||||
*
|
||||
* @return 菜单列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findNodes() {
|
||||
return MenuHelper.buildTree(list());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单
|
||||
*
|
||||
* @param id 菜单id
|
||||
*/
|
||||
@Override
|
||||
public void removeMenuById(Long id) {
|
||||
// 判断当前菜单是否有下级菜单
|
||||
LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SysMenu::getParentId, id);
|
||||
|
||||
// 查询菜单列表
|
||||
List<SysMenu> sysMenuList = list(wrapper);
|
||||
|
||||
// 为空时可以删除
|
||||
if (sysMenuList == null) removeById(id);
|
||||
|
||||
// 如果不为空抛出异常
|
||||
throw new BunnyException(MessageConstant.DELETE_MENU_ERROR_HAS_MENUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色获取菜单
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return 菜单列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findSysMenuByRoleId(Long roleId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给角色分配权限
|
||||
*
|
||||
* @param assginMenuVo 分配条件
|
||||
*/
|
||||
@Override
|
||||
public void doAssign(AssginMenuVo assginMenuVo) {
|
||||
|
||||
}
|
||||
}
|
|
@ -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 bunny
|
||||
* @since 2024-04-23
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {
|
||||
|
||||
}
|
|
@ -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>
|
Loading…
Reference in New Issue