角色菜单-未做完
This commit is contained in:
parent
aab1b953cb
commit
c8db8de256
|
@ -21,13 +21,11 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
|
|||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// .excludePathPatterns("/admin/system/index/login", "/admin.system/index/generateValidateCode")
|
||||
|
||||
// registry.addInterceptor(loginAuthInterceptor)
|
||||
// .addPathPatterns("/**")
|
||||
// .excludePathPatterns(userProperties.getNoAuthUrls());
|
||||
|
||||
registry.addInterceptor(loginAuthInterceptor)
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns(userProperties.getNoAuthUrls());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 解决跨域
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
|
|
|
@ -7,7 +7,9 @@ import cn.bunny.common.spzx.model.entity.user.UserInfo;
|
|||
import cn.bunny.common.spzx.model.vo.common.Result;
|
||||
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
|
||||
import cn.bunny.common.spzx.model.vo.system.LoginVo;
|
||||
import cn.bunny.common.spzx.model.vo.system.SysMenuVo;
|
||||
import cn.bunny.common.spzx.model.vo.system.ValidateCodeVo;
|
||||
import cn.bunny.service.SysMenuService;
|
||||
import cn.bunny.service.SysUserService;
|
||||
import cn.bunny.service.ValidateCodeService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
@ -16,6 +18,8 @@ import lombok.extern.log4j.Log4j2;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "用户接口")
|
||||
@Log4j2
|
||||
@RestController
|
||||
|
@ -27,7 +31,16 @@ public class IndexController {
|
|||
@Autowired
|
||||
private ValidateCodeService validateCodeService;
|
||||
|
||||
// 用户登录
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
|
||||
@Operation(summary = "查询用户可以操作菜单", description = "菜单查询")
|
||||
@GetMapping("/menus")
|
||||
public Result menus() {
|
||||
List<SysMenuVo> list = sysMenuService.findMenusByUserId();
|
||||
return Result.build(list, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@Operation(summary = "用户登录", description = "用户登录获取token")
|
||||
@PostMapping("login")
|
||||
public Result login(@RequestBody LoginDto loginDto) {
|
||||
|
@ -37,7 +50,6 @@ public class IndexController {
|
|||
return Result.build(loginVo, ResultCodeEnum.LOGIN_SUCCESS);
|
||||
}
|
||||
|
||||
// 生成验证码
|
||||
@Operation(summary = "获取验证码", description = "会获得两个值:codeKey + codeValue")
|
||||
@GetMapping(value = "/generateValidateCode")
|
||||
public Result<ValidateCodeVo> generateValidateCode() {
|
||||
|
@ -47,7 +59,6 @@ public class IndexController {
|
|||
return Result.build(validateCodeVo, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
// 获取用户登录信息
|
||||
@Operation(summary = "获取用户登录信息", description = "获取token")
|
||||
@GetMapping(value = "getUserInfo")
|
||||
// public Result getUserInfo(HttpServletRequest httpServletRequest) {
|
||||
|
@ -67,7 +78,6 @@ public class IndexController {
|
|||
return Result.build(sysUser, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
// 用户退出
|
||||
@Operation(summary = "用户退出", description = "清除Redis中token")
|
||||
@GetMapping("logout")
|
||||
public Result logout(@RequestHeader(name = "token") String token) {
|
||||
|
|
|
@ -21,4 +21,7 @@ public interface SysMenuMapper {
|
|||
|
||||
// 查询是否有子菜单
|
||||
Long selectById(Long id);
|
||||
|
||||
// 根据userid查询可以操作菜单
|
||||
List<SysMenu> findMenuByUserId(Long userId);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.bunny.service;
|
||||
|
||||
import cn.bunny.common.spzx.model.entity.system.SysMenu;
|
||||
import cn.bunny.common.spzx.model.vo.system.SysMenuVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -16,4 +17,7 @@ public interface SysMenuService {
|
|||
|
||||
// 删除菜单
|
||||
void removeById(Long id);
|
||||
|
||||
// 查询用户可以操作菜单
|
||||
List<SysMenuVo> findMenusByUserId();
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package cn.bunny.service.impl;
|
||||
|
||||
import cn.bunny.common.AuthContextUtil;
|
||||
import cn.bunny.common.exception.BunnyException;
|
||||
import cn.bunny.common.spzx.model.entity.system.SysMenu;
|
||||
import cn.bunny.common.spzx.model.entity.system.SysUser;
|
||||
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
|
||||
import cn.bunny.common.spzx.model.vo.system.SysMenuVo;
|
||||
import cn.bunny.mapper.SysMenuMapper;
|
||||
import cn.bunny.service.SysMenuService;
|
||||
import cn.bunny.utils.MenuHelper;
|
||||
|
@ -10,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
|
@ -49,4 +53,36 @@ public class SysMenuServiceImpl implements SysMenuService {
|
|||
}
|
||||
sysMenuMapper.removeById(id);
|
||||
}
|
||||
|
||||
// 查询用户可以操作菜单
|
||||
@Override
|
||||
public List<SysMenuVo> findMenusByUserId() {
|
||||
// 获取当前用户id
|
||||
SysUser sysUser = AuthContextUtil.get();
|
||||
Long userId = sysUser.getId();
|
||||
|
||||
// 根据userid查询可以操作菜单
|
||||
List<SysMenu> sysMenuList = sysMenuMapper.findMenuByUserId(userId);
|
||||
List<SysMenu> sysMenus = MenuHelper.buildTree(sysMenuList);
|
||||
|
||||
return this.buildMenus(sysMenus);
|
||||
}
|
||||
|
||||
|
||||
// 将List<SysMenu>对象转换成List<SysMenuVo>对象
|
||||
private List<SysMenuVo> buildMenus(List<SysMenu> menus) {
|
||||
|
||||
List<SysMenuVo> sysMenuVoList = new LinkedList<SysMenuVo>();
|
||||
for (SysMenu sysMenu : menus) {
|
||||
SysMenuVo sysMenuVo = new SysMenuVo();
|
||||
sysMenuVo.setTitle(sysMenu.getTitle());
|
||||
sysMenuVo.setName(sysMenu.getComponent());
|
||||
List<SysMenu> children = sysMenu.getChildren();
|
||||
if (!CollectionUtils.isEmpty(children)) {
|
||||
sysMenuVo.setChildren(buildMenus(children));
|
||||
}
|
||||
sysMenuVoList.add(sysMenuVo);
|
||||
}
|
||||
return sysMenuVoList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ spring:
|
|||
max-request-size: 20MB
|
||||
|
||||
|
||||
server:
|
||||
servlet:
|
||||
context-path: /api
|
||||
#server:
|
||||
# servlet:
|
||||
# context-path: /api
|
||||
|
||||
spzx:
|
||||
auth:
|
||||
|
|
|
@ -65,4 +65,14 @@
|
|||
where parent_id = #{id}
|
||||
and is_deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 根据userid查询可以操作菜单 -->
|
||||
<select id="findMenuByUserId" resultMap="sysRoleMap">
|
||||
select *
|
||||
from sys_menu m
|
||||
inner join sys_role_menu srm on m.id = srm.menu_id
|
||||
inner join sys_user_role sur on srm.role_id = sur.role_id
|
||||
where sur.user_id = 1
|
||||
and m.is_deleted = 0
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue