feat(新增): 路由查询,路由分页查询优化
This commit is contained in:
parent
388579409e
commit
0fc1567c82
|
@ -14,8 +14,8 @@ public class NewCodeGet {
|
||||||
// 作者名称
|
// 作者名称
|
||||||
public static final String author = "Bunny";
|
public static final String author = "Bunny";
|
||||||
// 公共路径
|
// 公共路径
|
||||||
public static final String outputDir = "D:\\MyFolder\\auth-admin\\auth-server-java\\service";
|
// public static final String outputDir = "D:\\MyFolder\\auth-admin\\auth-server-java\\service";
|
||||||
// public static final String outputDir = "D:\\Project\\web\\PC\\auth\\auth-server\\services";
|
public static final String outputDir = "D:\\Project\\web\\PC\\auth\\auth-server-java\\service";
|
||||||
// 实体类名称
|
// 实体类名称
|
||||||
public static final String entity = "Bunny";
|
public static final String entity = "Bunny";
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package cn.bunny.dao.dto.router;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Schema(name = "RouterManageDto对象", title = "路由查询表单", description = "路由查询表单")
|
||||||
|
public class RouterManageDto {
|
||||||
|
|
||||||
|
@Schema(name = "title", title = "路由标题")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Schema(name = "visible", title = "是否显示")
|
||||||
|
private Boolean visible;
|
||||||
|
}
|
|
@ -1,11 +1,7 @@
|
||||||
package cn.bunny.dao.entity.system;
|
package cn.bunny.dao.entity.system;
|
||||||
|
|
||||||
import cn.bunny.dao.entity.BaseEntity;
|
import cn.bunny.dao.entity.BaseEntity;
|
||||||
import com.alibaba.fastjson2.annotation.JSONField;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -14,17 +10,17 @@ import lombok.experimental.Accessors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
*
|
* 系统菜单表
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Bunny
|
* @author Bunny
|
||||||
* @since 2024-09-27
|
* @since 2024-09-28
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@TableName("sys_router")
|
@TableName("sys_router")
|
||||||
@ApiModel(value = "Router对象", description = "系统路由表")
|
@ApiModel(value = "Router对象", description = "系统菜单表")
|
||||||
public class Router extends BaseEntity {
|
public class Router extends BaseEntity {
|
||||||
|
|
||||||
@ApiModelProperty("在项目中路径")
|
@ApiModelProperty("在项目中路径")
|
||||||
|
@ -34,21 +30,26 @@ public class Router extends BaseEntity {
|
||||||
private String routeName;
|
private String routeName;
|
||||||
|
|
||||||
@ApiModelProperty("父级id")
|
@ApiModelProperty("父级id")
|
||||||
@JsonProperty("parentId")
|
|
||||||
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
|
||||||
@JSONField(serializeUsing = ToStringSerializer.class)
|
|
||||||
private Long parentId;
|
private Long parentId;
|
||||||
|
|
||||||
|
@ApiModelProperty("菜单类型 (`0`代表菜单、`1`代表`iframe`、`2`代表外链、`3`代表按钮)")
|
||||||
|
private Integer menuType;
|
||||||
|
|
||||||
@ApiModelProperty("路由title")
|
@ApiModelProperty("路由title")
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@ApiModelProperty("图标")
|
@ApiModelProperty("图标")
|
||||||
private String icon;
|
private String icon;
|
||||||
|
|
||||||
|
@ApiModelProperty("进入动画")
|
||||||
|
private String enterTransition;
|
||||||
|
|
||||||
|
@ApiModelProperty("退出动画")
|
||||||
|
private String leaveTransition;
|
||||||
|
|
||||||
@ApiModelProperty("等级")
|
@ApiModelProperty("等级")
|
||||||
private Integer routerRank;
|
private Integer routerRank;
|
||||||
|
|
||||||
@ApiModelProperty("是否显示")
|
@ApiModelProperty("是否显示")
|
||||||
private Boolean visible;
|
private Boolean visible;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,11 @@ import java.util.List;
|
||||||
@Builder
|
@Builder
|
||||||
public class PageResult<T> implements Serializable {
|
public class PageResult<T> implements Serializable {
|
||||||
// 当前页
|
// 当前页
|
||||||
private Integer pageNo;
|
private Long pageNo;
|
||||||
// 每页记录数
|
// 每页记录数
|
||||||
private Integer pageSize;
|
private Long pageSize;
|
||||||
// 总记录数
|
// 总记录数
|
||||||
private long total;
|
private Long total;
|
||||||
// 当前页数据集合
|
// 当前页数据集合
|
||||||
private List<T> list;
|
private List<T> list;
|
||||||
}
|
}
|
|
@ -1,46 +0,0 @@
|
||||||
package cn.bunny.dao.vo.router;
|
|
||||||
|
|
||||||
import cn.bunny.dao.vo.BaseVo;
|
|
||||||
import com.alibaba.fastjson2.annotation.JSONField;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Builder
|
|
||||||
@ApiModel(value = "RouterControllerVo对象", description = "路由管理端返回对象")
|
|
||||||
public class RouterControllerVo extends BaseVo {
|
|
||||||
|
|
||||||
@ApiModelProperty("在项目中路径")
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
@ApiModelProperty("路由名称")
|
|
||||||
private String routeName;
|
|
||||||
|
|
||||||
@ApiModelProperty("父级id")
|
|
||||||
@JsonFormat(shape = JsonFormat.Shape.STRING)
|
|
||||||
@JSONField(serializeUsing = ToStringSerializer.class)
|
|
||||||
private Long parentId;
|
|
||||||
|
|
||||||
@ApiModelProperty("title名称")
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
@ApiModelProperty("图标")
|
|
||||||
private String icon;
|
|
||||||
|
|
||||||
@ApiModelProperty("等级")
|
|
||||||
private Integer routerRank;
|
|
||||||
|
|
||||||
@ApiModelProperty("是否显示")
|
|
||||||
private Boolean visible;
|
|
||||||
|
|
||||||
@ApiModelProperty("子路由")
|
|
||||||
private List<RouterControllerVo> children;
|
|
||||||
}
|
|
|
@ -30,4 +30,7 @@ public class RouterMeta {
|
||||||
|
|
||||||
@ApiModelProperty(value = "权限列表")
|
@ApiModelProperty(value = "权限列表")
|
||||||
private List<String> auths;
|
private List<String> auths;
|
||||||
|
|
||||||
|
@ApiModelProperty("路由动画")
|
||||||
|
private RouterTransition transition;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package cn.bunny.dao.vo.router;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@ApiModel(value = "RouterTransition对象", description = "路由动画")
|
||||||
|
public class RouterTransition {
|
||||||
|
@ApiModelProperty("进入动画")
|
||||||
|
private String enterTransition;
|
||||||
|
|
||||||
|
@ApiModelProperty("退出动画")
|
||||||
|
private String leaveTransition;
|
||||||
|
}
|
|
@ -35,10 +35,16 @@ public class UserRouterVo {
|
||||||
@ApiModelProperty("在项目中路径")
|
@ApiModelProperty("在项目中路径")
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
|
@ApiModelProperty("菜单类型")
|
||||||
|
private Integer menuType;
|
||||||
|
|
||||||
@ApiModelProperty("路由名称")
|
@ApiModelProperty("路由名称")
|
||||||
@JsonProperty("name")
|
@JsonProperty("name")
|
||||||
private String routeName;
|
private String routeName;
|
||||||
|
|
||||||
|
@ApiModelProperty("路由动画")
|
||||||
|
private RouterTransition transition;
|
||||||
|
|
||||||
@ApiModelProperty("meta内容")
|
@ApiModelProperty("meta内容")
|
||||||
private RouterMeta meta;
|
private RouterMeta meta;
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,22 @@
|
||||||
package cn.bunny.services.controller;
|
package cn.bunny.services.controller;
|
||||||
|
|
||||||
|
import cn.bunny.dao.dto.router.RouterManageDto;
|
||||||
|
import cn.bunny.dao.entity.system.Router;
|
||||||
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
import cn.bunny.dao.pojo.result.Result;
|
import cn.bunny.dao.pojo.result.Result;
|
||||||
|
import cn.bunny.dao.vo.router.RouterManageVo;
|
||||||
import cn.bunny.dao.vo.router.UserRouterVo;
|
import cn.bunny.dao.vo.router.UserRouterVo;
|
||||||
import cn.bunny.services.service.RouterService;
|
import cn.bunny.services.service.RouterService;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -30,8 +38,30 @@ public class RouterController {
|
||||||
|
|
||||||
@Operation(summary = "获取用户菜单", description = "获取用户菜单")
|
@Operation(summary = "获取用户菜单", description = "获取用户菜单")
|
||||||
@GetMapping("getRouterAsync")
|
@GetMapping("getRouterAsync")
|
||||||
public Result<List<UserRouterVo>> getRouterAsync() {
|
public Mono<Result<List<UserRouterVo>>> getRouterAsync() {
|
||||||
List<UserRouterVo> voList = routerService.getRouterAsync();
|
List<UserRouterVo> voList = routerService.getRouterAsync();
|
||||||
return Result.success(voList);
|
return Mono.just(Result.success(voList));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "分页管理菜单列表", description = "分页管理菜单列表")
|
||||||
|
@GetMapping("getMenusByPage/{page}/{limit}")
|
||||||
|
public Mono<Result<PageResult<RouterManageVo>>> getMenusByPage(
|
||||||
|
@Parameter(name = "page", description = "当前页", required = true)
|
||||||
|
@PathVariable("page") Integer page,
|
||||||
|
@Parameter(name = "limit", description = "每页记录数", required = true)
|
||||||
|
@PathVariable("limit") Integer limit,
|
||||||
|
RouterManageDto dto) {
|
||||||
|
Page<Router> pageParams = new Page<>(page, limit);
|
||||||
|
PageResult<RouterManageVo> voPageResult = routerService.getMenusByPage(pageParams, dto);
|
||||||
|
|
||||||
|
return Mono.just(Result.success(voPageResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "管理菜单列表", description = "管理菜单列表")
|
||||||
|
@GetMapping("getMenus")
|
||||||
|
public Mono<Result<List<RouterManageVo>>> getMenu(RouterManageDto dto) {
|
||||||
|
List<RouterManageVo> voPageResult = routerService.getMenu(dto);
|
||||||
|
|
||||||
|
return Mono.just(Result.success(voPageResult));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,9 @@ public class UserController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "退出登录", description = "退出登录")
|
@Operation(summary = "退出登录", description = "退出登录")
|
||||||
@PostMapping("logOut")
|
@PostMapping("logout")
|
||||||
public Result<String> logOut() {
|
public Result<String> logout() {
|
||||||
userService.logOut();
|
userService.logout();
|
||||||
return Result.success(ResultCodeEnum.LOGOUT_SUCCESS);
|
return Result.success(ResultCodeEnum.LOGOUT_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,13 @@
|
||||||
package cn.bunny.services.mapper;
|
package cn.bunny.services.mapper;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.bunny.dao.dto.router.RouterManageDto;
|
||||||
import cn.bunny.dao.entity.system.Router;
|
import cn.bunny.dao.entity.system.Router;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -32,4 +37,13 @@ public interface RouterMapper extends BaseMapper<Router> {
|
||||||
* @return 路由列表
|
* @return 路由列表
|
||||||
*/
|
*/
|
||||||
List<Router> selectParentListByRouterId(List<Long> ids);
|
List<Router> selectParentListByRouterId(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 管理菜单列表
|
||||||
|
*
|
||||||
|
* @param pageParams 分页想去
|
||||||
|
* @param dto 路由查询表单
|
||||||
|
* @return 分页结果
|
||||||
|
*/
|
||||||
|
IPage<Router> selectListByPage(@Param("page") Page<Router> pageParams, @Param("dto") RouterManageDto dto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import cn.bunny.dao.entity.system.Power;
|
||||||
import cn.bunny.services.mapper.PowerMapper;
|
import cn.bunny.services.mapper.PowerMapper;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.security.authorization.AuthorizationDecision;
|
import org.springframework.security.authorization.AuthorizationDecision;
|
||||||
import org.springframework.security.authorization.AuthorizationManager;
|
import org.springframework.security.authorization.AuthorizationManager;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
|
@ -24,9 +26,11 @@ import java.util.function.Supplier;
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CustomAuthorizationManagerServiceImpl implements AuthorizationManager<RequestAuthorizationContext> {
|
public class CustomAuthorizationManagerServiceImpl implements AuthorizationManager<RequestAuthorizationContext> {
|
||||||
private final PowerMapper powerMapper;
|
@Autowired
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
@Autowired
|
||||||
|
private PowerMapper powerMapper;
|
||||||
|
|
||||||
public CustomAuthorizationManagerServiceImpl(PowerMapper powerMapper) {this.powerMapper = powerMapper;}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthorizationDecision check(Supplier<Authentication> authentication, RequestAuthorizationContext context) {
|
public AuthorizationDecision check(Supplier<Authentication> authentication, RequestAuthorizationContext context) {
|
||||||
|
@ -47,16 +51,18 @@ public class CustomAuthorizationManagerServiceImpl implements AuthorizationManag
|
||||||
List<String> roleCodeList = authentication.get().getAuthorities().stream().map(GrantedAuthority::getAuthority).toList();
|
List<String> roleCodeList = authentication.get().getAuthorities().stream().map(GrantedAuthority::getAuthority).toList();
|
||||||
|
|
||||||
// 校验权限
|
// 校验权限
|
||||||
return new AuthorizationDecision(hasAuth(requestURI, roleCodeList));
|
return new AuthorizationDecision(hasAuth(requestURI));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询用户所属的角色信息
|
* 查询用户所属的角色信息
|
||||||
*
|
*
|
||||||
* @param requestURI 请求url地址
|
* @param requestURI 请求url地址
|
||||||
* @param roleCodeList 角色列表
|
|
||||||
*/
|
*/
|
||||||
private Boolean hasAuth(String requestURI, List<String> roleCodeList) {
|
private Boolean hasAuth(String requestURI) {
|
||||||
|
// 角色代码列表
|
||||||
|
List<String> roleCodeList = BaseContext.getLoginVo().getRoles();
|
||||||
|
|
||||||
// 判断是否是 admin
|
// 判断是否是 admin
|
||||||
boolean isAdmin = roleCodeList.stream().anyMatch(role -> role.equals("admin"));
|
boolean isAdmin = roleCodeList.stream().anyMatch(role -> role.equals("admin"));
|
||||||
if (isAdmin) return true;
|
if (isAdmin) return true;
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package cn.bunny.services.service;
|
package cn.bunny.services.service;
|
||||||
|
|
||||||
|
import cn.bunny.dao.dto.router.RouterManageDto;
|
||||||
import cn.bunny.dao.entity.system.Router;
|
import cn.bunny.dao.entity.system.Router;
|
||||||
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
|
import cn.bunny.dao.vo.router.RouterManageVo;
|
||||||
import cn.bunny.dao.vo.router.UserRouterVo;
|
import cn.bunny.dao.vo.router.UserRouterVo;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -21,4 +25,21 @@ public interface RouterService extends IService<Router> {
|
||||||
* @return 路遇列表
|
* @return 路遇列表
|
||||||
*/
|
*/
|
||||||
List<UserRouterVo> getRouterAsync();
|
List<UserRouterVo> getRouterAsync();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 管理菜单列表
|
||||||
|
*
|
||||||
|
* @param pageParams 分页想去
|
||||||
|
* @param dto 路由查询表单
|
||||||
|
* @return 系统菜单表分页
|
||||||
|
*/
|
||||||
|
PageResult<RouterManageVo> getMenusByPage(Page<Router> pageParams, RouterManageDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 管理菜单列表
|
||||||
|
*
|
||||||
|
* @param dto 路由查询表单
|
||||||
|
* @return 系统菜单表
|
||||||
|
*/
|
||||||
|
List<RouterManageVo> getMenu(RouterManageDto dto);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,5 +35,5 @@ public interface UserService extends IService<AdminUser> {
|
||||||
/**
|
/**
|
||||||
* * 退出登录
|
* * 退出登录
|
||||||
*/
|
*/
|
||||||
void logOut();
|
void logout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,21 @@ package cn.bunny.services.service.impl;
|
||||||
|
|
||||||
import cn.bunny.common.service.context.BaseContext;
|
import cn.bunny.common.service.context.BaseContext;
|
||||||
import cn.bunny.common.service.exception.BunnyException;
|
import cn.bunny.common.service.exception.BunnyException;
|
||||||
|
import cn.bunny.dao.dto.router.RouterManageDto;
|
||||||
import cn.bunny.dao.entity.system.Router;
|
import cn.bunny.dao.entity.system.Router;
|
||||||
import cn.bunny.dao.pojo.constant.RedisUserConstant;
|
import cn.bunny.dao.pojo.constant.RedisUserConstant;
|
||||||
|
import cn.bunny.dao.pojo.result.PageResult;
|
||||||
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||||
|
import cn.bunny.dao.vo.router.RouterManageVo;
|
||||||
import cn.bunny.dao.vo.router.RouterMeta;
|
import cn.bunny.dao.vo.router.RouterMeta;
|
||||||
import cn.bunny.dao.vo.router.UserRouterVo;
|
import cn.bunny.dao.vo.router.UserRouterVo;
|
||||||
import cn.bunny.dao.vo.user.LoginVo;
|
import cn.bunny.dao.vo.user.LoginVo;
|
||||||
import cn.bunny.services.mapper.RouterMapper;
|
import cn.bunny.services.mapper.RouterMapper;
|
||||||
import cn.bunny.services.service.RouterService;
|
import cn.bunny.services.service.RouterService;
|
||||||
import cn.bunny.services.service.process.RouterServiceProcess;
|
import cn.bunny.services.service.process.RouterServiceProcess;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -63,9 +69,8 @@ public class RouterServiceImpl extends ServiceImpl<RouterMapper, Router> impleme
|
||||||
|
|
||||||
// 查询用户角色,判断是否是管理员角色
|
// 查询用户角色,判断是否是管理员角色
|
||||||
boolean isAdmin = roleList.stream().anyMatch(authUserRole -> authUserRole.equals("admin"));
|
boolean isAdmin = roleList.stream().anyMatch(authUserRole -> authUserRole.equals("admin"));
|
||||||
if (isAdmin) {
|
if (isAdmin) routerList = list();
|
||||||
routerList = list();
|
else {
|
||||||
} else {
|
|
||||||
List<Long> routerIds = baseMapper.selectListByUserId(loginVo.getId());
|
List<Long> routerIds = baseMapper.selectListByUserId(loginVo.getId());
|
||||||
routerList = baseMapper.selectParentListByRouterId(routerIds);
|
routerList = baseMapper.selectParentListByRouterId(routerIds);
|
||||||
}
|
}
|
||||||
|
@ -100,4 +105,54 @@ public class RouterServiceImpl extends ServiceImpl<RouterMapper, Router> impleme
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 管理菜单列表
|
||||||
|
*
|
||||||
|
* @param pageParams 分页想去
|
||||||
|
* @param dto 路由查询表单
|
||||||
|
* @return 系统菜单表分页
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult<RouterManageVo> getMenusByPage(Page<Router> pageParams, RouterManageDto dto) {
|
||||||
|
IPage<Router> page = baseMapper.selectListByPage(pageParams, dto);
|
||||||
|
|
||||||
|
// 构建返回对象
|
||||||
|
List<RouterManageVo> voList = page.getRecords().stream().map(router -> {
|
||||||
|
RouterManageVo routerManageVo = new RouterManageVo();
|
||||||
|
BeanUtils.copyProperties(router, routerManageVo);
|
||||||
|
return routerManageVo;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
return PageResult.<RouterManageVo>builder()
|
||||||
|
.list(voList)
|
||||||
|
.pageNo(page.getCurrent())
|
||||||
|
.pageSize(page.getSize())
|
||||||
|
.total(page.getTotal())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 管理菜单列表
|
||||||
|
*
|
||||||
|
* @param dto 路由查询表单
|
||||||
|
* @return 系统菜单表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<RouterManageVo> getMenu(RouterManageDto dto) {
|
||||||
|
String title = dto.getTitle();
|
||||||
|
Boolean visible = dto.getVisible();
|
||||||
|
|
||||||
|
// 构建查询条件
|
||||||
|
LambdaQueryWrapper<Router> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
lambdaQueryWrapper.like(title != null, Router::getTitle, title)
|
||||||
|
.or()
|
||||||
|
.eq(visible != null, Router::getVisible, visible);
|
||||||
|
|
||||||
|
return list().stream().map(router -> {
|
||||||
|
RouterManageVo routerManageVo = new RouterManageVo();
|
||||||
|
BeanUtils.copyProperties(router, routerManageVo);
|
||||||
|
return routerManageVo;
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, AdminUser> implemen
|
||||||
* 退出登录
|
* 退出登录
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void logOut() {
|
public void logout() {
|
||||||
LoginVo loginVo = BaseContext.getLoginVo();
|
LoginVo loginVo = BaseContext.getLoginVo();
|
||||||
redisTemplate.delete(RedisUserConstant.getAdminLoginInfoPrefix(loginVo.getUsername()));
|
redisTemplate.delete(RedisUserConstant.getAdminLoginInfoPrefix(loginVo.getUsername()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package cn.bunny.services.service.process;
|
package cn.bunny.services.service.process;
|
||||||
|
|
||||||
import cn.bunny.dao.vo.common.TreeSelectVo;
|
import cn.bunny.dao.vo.common.TreeSelectVo;
|
||||||
import cn.bunny.dao.vo.router.RouterControllerVo;
|
import cn.bunny.dao.vo.router.RouterManageVo;
|
||||||
import cn.bunny.dao.vo.router.UserRouterVo;
|
import cn.bunny.dao.vo.router.UserRouterVo;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -38,7 +38,7 @@ public class RouterServiceProcess {
|
||||||
* @param nodeList 返回VO列表
|
* @param nodeList 返回VO列表
|
||||||
* @return 返回路由列表
|
* @return 返回路由列表
|
||||||
*/
|
*/
|
||||||
public List<RouterControllerVo> handleGetChildrenWithRouterControllerVo(Long nodeId, List<RouterControllerVo> nodeList) {
|
public List<RouterManageVo> handleGetChildrenWithRouterControllerVo(Long nodeId, List<RouterManageVo> nodeList) {
|
||||||
return nodeList.stream()
|
return nodeList.stream()
|
||||||
.filter(node -> node.getParentId().equals(nodeId))
|
.filter(node -> node.getParentId().equals(nodeId))
|
||||||
.peek(node -> node.setChildren(handleGetChildrenWithRouterControllerVo(node.getId(), nodeList)))
|
.peek(node -> node.setChildren(handleGetChildrenWithRouterControllerVo(node.getId(), nodeList)))
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
<?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="cn.bunny.services.mapper.RouterMapper">
|
|
||||||
|
|
||||||
<!-- 通用查询映射结果 -->
|
|
||||||
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.system.Router">
|
|
||||||
<id column="id" property="id"/>
|
|
||||||
<result column="path" property="path"/>
|
|
||||||
<result column="route_name" property="routeName"/>
|
|
||||||
<result column="parent_id" property="parentId"/>
|
|
||||||
<result column="title" property="title"/>
|
|
||||||
<result column="icon" property="icon"/>
|
|
||||||
<result column="router_rank" property="routerRank"/>
|
|
||||||
<result column="visible" property="visible"/>
|
|
||||||
<result column="create_user" property="createUser"/>
|
|
||||||
<result column="update_user" property="updateUser"/>
|
|
||||||
<result column="update_time" property="updateTime"/>
|
|
||||||
<result column="create_time" property="createTime"/>
|
|
||||||
<result column="is_deleted" property="isDeleted"/>
|
|
||||||
</resultMap>
|
|
||||||
|
|
||||||
<!-- 通用查询结果列 -->
|
|
||||||
<sql id="Base_Column_List">
|
|
||||||
id, path, route_name, parent_id, title, icon, router_rank, visible, create_user, update_user, update_time, create_time, is_deleted
|
|
||||||
</sql>
|
|
||||||
<select id="selectListByUserId" resultType="java.lang.Long">
|
|
||||||
SELECT router.id
|
|
||||||
FROM sys_user_role user_role
|
|
||||||
LEFT JOIN sys_user user ON user_role.user_id = user.id
|
|
||||||
LEFT JOIN sys_router_role router_role ON user_role.role_id = router_role.role_id
|
|
||||||
LEFT JOIN sys_router router ON router_role.router_id = router.id
|
|
||||||
WHERE user.id = #{userId}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<!-- 递归查询所有父级Id,直到查询到父级Id为0 -->
|
|
||||||
<select id="selectParentListByRouterId" resultType="cn.bunny.dao.entity.system.Router">
|
|
||||||
WITH RECURSIVE ParentChain AS (
|
|
||||||
SELECT * FROM sys_router
|
|
||||||
WHERE id IN
|
|
||||||
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
|
||||||
#{id}
|
|
||||||
</foreach>
|
|
||||||
UNION ALL
|
|
||||||
SELECT r.* FROM sys_router r
|
|
||||||
INNER JOIN ParentChain pc ON r.id = pc.parent_id
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
<include refid="Base_Column_List"/>
|
|
||||||
FROM ParentChain;
|
|
||||||
</select>
|
|
||||||
|
|
||||||
</mapper>
|
|
Loading…
Reference in New Issue