Compare commits
2 Commits
04559a57b2
...
4b2141bb5a
Author | SHA1 | Date |
---|---|---|
|
4b2141bb5a | |
|
db21e70786 |
|
@ -9,7 +9,7 @@
|
|||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
2
pom.xml
2
pom.xml
|
@ -9,7 +9,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>spzx-parent</artifactId>
|
||||
<artifactId>spzx-parent-v2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
|
|
@ -47,7 +47,9 @@ public class LoginAuthInterceptor implements HandlerInterceptor {
|
|||
}
|
||||
|
||||
// 将用户信息放到ThreadLocal中
|
||||
BaseContext.setSysUser(JSON.parseObject(sysUserString, SysUser.class));
|
||||
SysUser sysUser = JSON.parseObject(sysUserString, SysUser.class);
|
||||
BaseContext.setSysUser(sysUser);
|
||||
BaseContext.setUserId(sysUser.getId());
|
||||
|
||||
// 更新Redis过期时间
|
||||
redisTemplate.expire(token, 7, TimeUnit.DAYS);
|
||||
|
|
|
@ -2,8 +2,11 @@ package com.atguigu.utils;
|
|||
|
||||
|
||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||
import com.atguigu.spzx.model.vo.system.SysMenuVo;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -43,4 +46,26 @@ public class MenuHelper {
|
|||
|
||||
return sysMenu;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将List<SysMenu>对象转换成List<SysMenuVo>对象
|
||||
*
|
||||
* @param menus 全部菜单列表
|
||||
* @return 系统菜单响应结果实体类列表
|
||||
*/
|
||||
public static List<SysMenuVo> buildMenus(List<SysMenu> menus) {
|
||||
LinkedList<SysMenuVo> sysMenuVos = new LinkedList<>();
|
||||
menus.forEach(menu -> {
|
||||
SysMenuVo menuVo = new SysMenuVo();
|
||||
menuVo.setTitle(menu.getTitle());
|
||||
menuVo.setName(menu.getComponent());
|
||||
List<SysMenu> children = menu.getChildren();
|
||||
if (!CollectionUtils.isEmpty(children)) {
|
||||
menuVo.setChildren(buildMenus(children));
|
||||
}
|
||||
sysMenuVos.add(menuVo);
|
||||
});
|
||||
return sysMenuVos;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>spzx-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>spzx-parent-v2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>spzx-common</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<artifactId>spzx-common</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>spzx-common</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
<modules>
|
||||
<module>common-util</module>
|
||||
<module>common-service</module>
|
||||
</modules>
|
||||
<name>spzx-common</name>
|
||||
<url>https://maven.apache.org</url>
|
||||
<modules>
|
||||
<module>common-util</module>
|
||||
<module>common-service</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- hutool工具包 -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.25</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<!-- hutool工具包 -->
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.25</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>spzx-parent</artifactId>
|
||||
<artifactId>spzx-parent-v2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -9,13 +9,13 @@ import org.springframework.context.annotation.ComponentScan;
|
|||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@Slf4j
|
||||
@MapperScan("com.atguigu.spzx.manger.mapper")
|
||||
@EnableCaching// 开启缓存注解
|
||||
@ComponentScan("com.atguigu")
|
||||
@EnableScheduling
|
||||
@SpringBootApplication
|
||||
@EnableTransactionManagement // 开启注解方式的事务管理
|
||||
@EnableCaching// 开启缓存注解
|
||||
@EnableScheduling
|
||||
@ComponentScan("com.atguigu")
|
||||
@MapperScan("com.atguigu.spzx.manger.mapper")
|
||||
@Slf4j
|
||||
public class MangerApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MangerApplication.class, args);
|
||||
|
|
|
@ -1,18 +1,22 @@
|
|||
package com.atguigu.spzx.manger.controller;
|
||||
|
||||
import com.atguigu.context.BaseContext;
|
||||
import com.atguigu.spzx.manger.service.SysMenuService;
|
||||
import com.atguigu.spzx.manger.service.SysUserService;
|
||||
import com.atguigu.spzx.manger.service.ValidateCodeService;
|
||||
import com.atguigu.spzx.model.dto.system.LoginDto;
|
||||
import com.atguigu.spzx.model.entity.system.SysUser;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.atguigu.spzx.model.vo.system.LoginVo;
|
||||
import com.atguigu.spzx.model.vo.system.SysMenuVo;
|
||||
import com.atguigu.spzx.model.vo.system.ValidateCodeVo;
|
||||
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;
|
||||
|
||||
@Tag(name = "用户相关接口")
|
||||
@RestController
|
||||
@RequestMapping("/admin/system/index")
|
||||
|
@ -20,6 +24,8 @@ public class IndexController {
|
|||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
@Autowired
|
||||
private ValidateCodeService validateCodeService;
|
||||
|
||||
@Operation(summary = "生成验证码", description = "生成验证码信息")
|
||||
|
@ -49,4 +55,11 @@ public class IndexController {
|
|||
sysUserService.logout(token);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "动态菜单", description = "动态菜单")
|
||||
@GetMapping("menus")
|
||||
public Result<List<SysMenuVo>> menus() {
|
||||
List<SysMenuVo> sysMenuVoList = sysMenuService.findUserMenuList();
|
||||
return Result.success(sysMenuVoList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,12 @@ package com.atguigu.spzx.manger.controller;
|
|||
import com.atguigu.spzx.manger.service.SysRoleMenuService;
|
||||
import com.atguigu.spzx.model.dto.system.AssginMenuDto;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
|
||||
import com.atguigu.spzx.model.vo.system.SysRoleMenuVo;
|
||||
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.Map;
|
||||
|
||||
@Tag(name = "分配菜单")
|
||||
@RestController
|
||||
@RequestMapping(value = "/admin/system/sysRoleMenu")
|
||||
|
@ -17,15 +16,17 @@ public class SysRoleMenuController {
|
|||
@Autowired
|
||||
private SysRoleMenuService sysRoleMenuService;
|
||||
|
||||
@GetMapping(value = "/findSysRoleMenuByRoleId/{roleId}")
|
||||
public Result<Map<String, Object>> findSysRoleMenuByRoleId(@PathVariable(value = "roleId") Long roleId) {
|
||||
Map<String, Object> sysRoleMenuList = sysRoleMenuService.findSysRoleMenuByRoleId(roleId);
|
||||
return Result.build(sysRoleMenuList, ResultCodeEnum.SUCCESS);
|
||||
@Operation(summary = "查询菜单", description = "查询菜单")
|
||||
@GetMapping(value = "findSysRoleMenuByRoleId/{roleId}")
|
||||
public Result<SysRoleMenuVo> findSysRoleMenuByRoleId(@PathVariable(value = "roleId") Long roleId) {
|
||||
SysRoleMenuVo sysRoleMenuList = sysRoleMenuService.findSysRoleMenuByRoleId(roleId);
|
||||
return Result.success(sysRoleMenuList);
|
||||
}
|
||||
|
||||
@PostMapping("/doAssign")
|
||||
@Operation(summary = "保存菜单", description = "保存菜单")
|
||||
@PostMapping("doAssign")
|
||||
public Result doAssign(@RequestBody AssginMenuDto assginMenuDto) {
|
||||
sysRoleMenuService.doAssign(assginMenuDto);
|
||||
return Result.build(null, ResultCodeEnum.SUCCESS);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
|
@ -42,4 +42,12 @@ public interface SysMenuMapper {
|
|||
* @param id 菜单id
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 根据用户ID查找
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 菜单列表
|
||||
*/
|
||||
List<SysMenu> selectListByUserId(Long userId);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||
import com.atguigu.spzx.model.vo.system.SysMenuVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -32,4 +33,11 @@ public interface SysMenuService {
|
|||
* @param id 菜单id
|
||||
*/
|
||||
void removeById(Long id);
|
||||
|
||||
/**
|
||||
* 动态菜单
|
||||
*
|
||||
* @return 动态菜单列表
|
||||
*/
|
||||
List<SysMenuVo> findUserMenuList();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,21 @@
|
|||
package com.atguigu.spzx.manger.service;
|
||||
|
||||
import com.atguigu.spzx.model.dto.system.AssginMenuDto;
|
||||
|
||||
import java.util.Map;
|
||||
import com.atguigu.spzx.model.vo.system.SysRoleMenuVo;
|
||||
|
||||
public interface SysRoleMenuService {
|
||||
Map<String, Object> findSysRoleMenuByRoleId(Long roleId);
|
||||
/**
|
||||
* 查询菜单
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return 查询菜单返回实体类
|
||||
*/
|
||||
SysRoleMenuVo findSysRoleMenuByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 保存菜单
|
||||
*
|
||||
* @param assginMenuDto 请求参数实体类
|
||||
*/
|
||||
void doAssign(AssginMenuDto assginMenuDto);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package com.atguigu.spzx.manger.service.impl;
|
||||
|
||||
import com.atguigu.constant.MessageConstant;
|
||||
import com.atguigu.context.BaseContext;
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import com.atguigu.spzx.manger.mapper.SysMenuMapper;
|
||||
import com.atguigu.spzx.manger.service.SysMenuService;
|
||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||
import com.atguigu.spzx.model.vo.system.SysMenuVo;
|
||||
import com.atguigu.utils.MenuHelper;
|
||||
import com.atguigu.utils.StringEmptyUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -64,4 +66,18 @@ public class SysMenuServiceImpl implements SysMenuService {
|
|||
}
|
||||
sysMenuMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态菜单
|
||||
*
|
||||
* @return 动态菜单列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenuVo> findUserMenuList() {
|
||||
Long userId = BaseContext.getUserId();
|
||||
// 根据用户ID查找
|
||||
List<SysMenu> sysMenuList = sysMenuMapper.selectListByUserId(userId);
|
||||
sysMenuList = MenuHelper.buildTree(sysMenuList);
|
||||
return MenuHelper.buildMenus(sysMenuList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@ import com.atguigu.spzx.manger.service.SysMenuService;
|
|||
import com.atguigu.spzx.manger.service.SysRoleMenuService;
|
||||
import com.atguigu.spzx.model.dto.system.AssginMenuDto;
|
||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||
import com.atguigu.spzx.model.vo.system.SysRoleMenuVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -21,9 +21,14 @@ public class SysRoleMenuServiceImpl implements SysRoleMenuService {
|
|||
@Autowired
|
||||
private SysRoleMenuMapper sysRoleMenuMapper;
|
||||
|
||||
/**
|
||||
* 查询菜单
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return 查询菜单返回实体类
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> findSysRoleMenuByRoleId(Long roleId) {
|
||||
|
||||
public SysRoleMenuVo findSysRoleMenuByRoleId(Long roleId) {
|
||||
// 查询所有的菜单数据
|
||||
List<SysMenu> sysMenuList = sysMenuService.findNodes();
|
||||
|
||||
|
@ -31,18 +36,17 @@ public class SysRoleMenuServiceImpl implements SysRoleMenuService {
|
|||
List<Long> roleMenuIds = sysRoleMenuMapper.findSysRoleMenuByRoleId(roleId);
|
||||
|
||||
// 将数据存储到Map中进行返回
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("sysMenuList", sysMenuList);
|
||||
result.put("roleMenuIds", roleMenuIds);
|
||||
|
||||
// 返回
|
||||
return result;
|
||||
return SysRoleMenuVo.builder().roleMenuIds(roleMenuIds).sysMenuList(sysMenuList).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存菜单
|
||||
*
|
||||
* @param assginMenuDto 请求参数实体类
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public void doAssign(AssginMenuDto assginMenuDto) {
|
||||
|
||||
// 根据角色的id删除其所对应的菜单数据
|
||||
sysRoleMenuMapper.deleteByRoleId(assginMenuDto.getRoleId());
|
||||
|
||||
|
|
|
@ -59,4 +59,9 @@
|
|||
<include refid="columns"/>
|
||||
from sys_menu where is_deleted = 0 order by sort_value
|
||||
</select>
|
||||
|
||||
<!-- 根据用户ID查找 -->
|
||||
<select id="selectListByUserId" resultType="com.atguigu.spzx.model.entity.system.SysMenu">
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.atguigu</groupId>
|
||||
<artifactId>spzx-parent</artifactId>
|
||||
<artifactId>spzx-parent-v2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package com.atguigu.spzx.model.vo.system;
|
||||
|
||||
import com.atguigu.spzx.model.entity.system.SysMenu;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Schema(description = "查询菜单返回实体类")
|
||||
public class SysRoleMenuVo {
|
||||
@Schema(description = "所有的菜单数据")
|
||||
List<SysMenu> sysMenuList;
|
||||
@Schema(description = "角色的菜单数据")
|
||||
List<Long> roleMenuIds;
|
||||
}
|
Loading…
Reference in New Issue