mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 13:03:43 +08:00
refactor: 项目结构优化
This commit is contained in:
parent
458ef77cf2
commit
bae6ff9640
@ -1,7 +1,7 @@
|
||||
package com.youlai.admin.component.handler;
|
||||
|
||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||
import com.youlai.admin.pojo.vo.LoginUserVO;
|
||||
import com.youlai.admin.pojo.vo.user.LoginUserVO;
|
||||
import com.youlai.common.result.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
@ -20,9 +20,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author haoxr
|
||||
* @Date 2021-02-25 15:36
|
||||
* @Version 1.0.0
|
||||
* @author haoxr
|
||||
* @date 2021-02-25 15:36
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSwagger2WebMvc
|
||||
@ -33,27 +32,27 @@ public class SwaggerConfiguration {
|
||||
@Bean
|
||||
public Docket restApi() {
|
||||
//schema
|
||||
List<GrantType> grantTypes=new ArrayList<>();
|
||||
List<GrantType> grantTypes = new ArrayList<>();
|
||||
//密码模式
|
||||
String passwordTokenUrl="http://localhost:9999/youlai-auth/oauth/token";
|
||||
ResourceOwnerPasswordCredentialsGrant resourceOwnerPasswordCredentialsGrant=new ResourceOwnerPasswordCredentialsGrant(passwordTokenUrl);
|
||||
String passwordTokenUrl = "http://localhost:9999/youlai-auth/oauth/token";
|
||||
ResourceOwnerPasswordCredentialsGrant resourceOwnerPasswordCredentialsGrant = new ResourceOwnerPasswordCredentialsGrant(passwordTokenUrl);
|
||||
grantTypes.add(resourceOwnerPasswordCredentialsGrant);
|
||||
OAuth oAuth=new OAuthBuilder().name("oauth2")
|
||||
OAuth oAuth = new OAuthBuilder().name("oauth2")
|
||||
.grantTypes(grantTypes).build();
|
||||
//context
|
||||
//scope方位
|
||||
List<AuthorizationScope> scopes=new ArrayList<>();
|
||||
scopes.add(new AuthorizationScope("read","read resources"));
|
||||
scopes.add(new AuthorizationScope("write","write resources"));
|
||||
scopes.add(new AuthorizationScope("reads","read all resources"));
|
||||
scopes.add(new AuthorizationScope("writes","write all resources"));
|
||||
List<AuthorizationScope> scopes = new ArrayList<>();
|
||||
scopes.add(new AuthorizationScope("read", "read resources"));
|
||||
scopes.add(new AuthorizationScope("write", "write resources"));
|
||||
scopes.add(new AuthorizationScope("reads", "read all resources"));
|
||||
scopes.add(new AuthorizationScope("writes", "write all resources"));
|
||||
|
||||
SecurityReference securityReference=new SecurityReference("oauth2",scopes.toArray(new AuthorizationScope[]{}));
|
||||
SecurityContext securityContext=new SecurityContext(Lists.newArrayList(securityReference),PathSelectors.ant("/**"));
|
||||
SecurityReference securityReference = new SecurityReference("oauth2", scopes.toArray(new AuthorizationScope[]{}));
|
||||
SecurityContext securityContext = new SecurityContext(Lists.newArrayList(securityReference), PathSelectors.ant("/**"));
|
||||
//schemas
|
||||
List<SecurityScheme> securitySchemes=Lists.newArrayList(oAuth);
|
||||
List<SecurityScheme> securitySchemes = Lists.newArrayList(oAuth);
|
||||
//securyContext
|
||||
List<SecurityContext> securityContexts=Lists.newArrayList(securityContext);
|
||||
List<SecurityContext> securityContexts = Lists.newArrayList(securityContext);
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.youlai.admin.controller"))
|
||||
|
@ -1,9 +1,8 @@
|
||||
package com.youlai.admin.controller;
|
||||
|
||||
import com.youlai.admin.pojo.entity.SysDept;
|
||||
import com.youlai.admin.pojo.vo.DeptVO;
|
||||
import com.youlai.admin.pojo.vo.SelectVO;
|
||||
import com.youlai.admin.pojo.vo.TreeSelectVO;
|
||||
import com.youlai.admin.pojo.vo.dept.DeptVO;
|
||||
import com.youlai.admin.pojo.vo.IdLabelVO;
|
||||
import com.youlai.admin.service.ISysDeptService;
|
||||
import com.youlai.common.result.Result;
|
||||
import io.swagger.annotations.*;
|
||||
@ -40,7 +39,7 @@ public class DeptController {
|
||||
@ApiOperation(value = "部门下拉(TreeSelect)层级列表")
|
||||
@GetMapping("/select")
|
||||
public Result getSelectList() {
|
||||
List<TreeSelectVO> deptSelectList = deptService.listTreeSelect();
|
||||
List<IdLabelVO> deptSelectList = deptService.listTreeSelect();
|
||||
return Result.success(deptSelectList);
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,10 @@ package com.youlai.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.youlai.admin.pojo.entity.SysMenu;
|
||||
import com.youlai.admin.pojo.vo.MenuVO;
|
||||
import com.youlai.admin.pojo.vo.RouteVO;
|
||||
import com.youlai.admin.pojo.vo.SelectVO;
|
||||
import com.youlai.admin.pojo.vo.TreeSelectVO;
|
||||
import com.youlai.admin.pojo.vo.menu.MenuVO;
|
||||
import com.youlai.admin.pojo.vo.menu.RouteVO;
|
||||
import com.youlai.admin.pojo.vo.ValueLabelVO;
|
||||
import com.youlai.admin.pojo.vo.IdLabelVO;
|
||||
import com.youlai.admin.service.ISysMenuService;
|
||||
import com.youlai.admin.service.ISysPermissionService;
|
||||
import com.youlai.common.result.Result;
|
||||
@ -48,14 +48,14 @@ public class MenuController {
|
||||
@ApiOperation(value = "菜单下拉(Select)层级列表")
|
||||
@GetMapping("/select")
|
||||
public Result getSelectList() {
|
||||
List<SelectVO> menuList = menuService.listSelect();
|
||||
List<ValueLabelVO> menuList = menuService.listSelect();
|
||||
return Result.success(menuList);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "菜单树形(TreeSelect)层级列表")
|
||||
@GetMapping("/tree_select")
|
||||
public Result getTreeSelectList() {
|
||||
List<TreeSelectVO> menuList = menuService.listTreeSelect();
|
||||
List<IdLabelVO> menuList = menuService.listTreeSelect();
|
||||
return Result.success(menuList);
|
||||
}
|
||||
|
||||
|
@ -2,15 +2,12 @@ package com.youlai.admin.controller;
|
||||
|
||||
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.youlai.admin.pojo.entity.SysPermission;
|
||||
import com.youlai.admin.pojo.vo.PermissionVO;
|
||||
import com.youlai.admin.pojo.query.PermissionPageQuery;
|
||||
import com.youlai.admin.pojo.vo.permission.PermissionPageVO;
|
||||
import com.youlai.admin.service.ISysPermissionService;
|
||||
import com.youlai.common.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -26,38 +23,40 @@ public class PermissionController {
|
||||
private final ISysPermissionService iSysPermissionService;
|
||||
|
||||
@ApiOperation(value = "列表分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "pageNum", defaultValue = "1", value = "页码", paramType = "query", dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "pageSize", defaultValue = "10", value = "每页数量", paramType = "query", dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "name", value = "权限名称", paramType = "query", dataType = "String"),
|
||||
@ApiImplicitParam(name = "menuId", value = "菜单ID", paramType = "query", dataType = "Long")
|
||||
})
|
||||
@GetMapping("/page")
|
||||
public Result pageList(long pageNum, long pageSize, String name, Long menuId) {
|
||||
IPage<PermissionVO> result = iSysPermissionService.list(new Page<>(pageNum, pageSize), name, menuId);
|
||||
public Result listPermissionsWithPage(
|
||||
PermissionPageQuery permissionPageQuery
|
||||
) {
|
||||
IPage<PermissionPageVO> result = iSysPermissionService.listPermissionsWithPage(permissionPageQuery);
|
||||
return Result.success(result.getRecords(), result.getTotal());
|
||||
}
|
||||
|
||||
@ApiOperation(value = "权限列表")
|
||||
@ApiImplicitParam(name = "menuId", value = "菜单ID", paramType = "query", dataType = "Long")
|
||||
@GetMapping
|
||||
public Result list(Long menuId) {
|
||||
List<SysPermission> list = iSysPermissionService.list(new LambdaQueryWrapper<SysPermission>()
|
||||
.eq(SysPermission::getMenuId, menuId));
|
||||
public Result listPermissions(
|
||||
@ApiParam(value = "菜单ID") @RequestParam(required = false) Long menuId
|
||||
) {
|
||||
List<SysPermission> list = iSysPermissionService.list(
|
||||
new LambdaQueryWrapper<SysPermission>()
|
||||
.eq(menuId != null, SysPermission::getMenuId, menuId)
|
||||
);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "权限详情")
|
||||
@ApiImplicitParam(name = "id", value = "权限ID", required = true, paramType = "path", dataType = "Long")
|
||||
@GetMapping("/{id}")
|
||||
public Result detail(@PathVariable Long id) {
|
||||
SysPermission permission = iSysPermissionService.getById(id);
|
||||
@GetMapping("/{permissionId}")
|
||||
public Result getPermissionDetail(
|
||||
@ApiParam("权限ID") @PathVariable Long permissionId
|
||||
) {
|
||||
SysPermission permission = iSysPermissionService.getById(permissionId);
|
||||
return Result.success(permission);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增权限")
|
||||
@PostMapping
|
||||
public Result add(@RequestBody SysPermission permission) {
|
||||
public Result addPermission(
|
||||
@RequestBody SysPermission permission
|
||||
) {
|
||||
boolean result = iSysPermissionService.save(permission);
|
||||
if (result) {
|
||||
iSysPermissionService.refreshPermRolesRules();
|
||||
@ -66,10 +65,11 @@ public class PermissionController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "修改权限")
|
||||
@PutMapping(value = "/{id}")
|
||||
public Result update(
|
||||
@PathVariable Long id,
|
||||
@RequestBody SysPermission permission) {
|
||||
@PutMapping(value = "/{permissionId}")
|
||||
public Result updatePermission(
|
||||
@ApiParam("权限ID") @PathVariable Long permissionId,
|
||||
@RequestBody SysPermission permission
|
||||
) {
|
||||
boolean result = iSysPermissionService.updateById(permission);
|
||||
if (result) {
|
||||
iSysPermissionService.refreshPermRolesRules();
|
||||
@ -78,9 +78,10 @@ public class PermissionController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除权限")
|
||||
@ApiImplicitParam(name = "ids", value = "id集合", required = true, paramType = "query", dataType = "Long")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result delete(@PathVariable String ids) {
|
||||
public Result deletePermissions(
|
||||
@ApiParam("权限ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
boolean status = iSysPermissionService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Result.judge(status);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.youlai.admin.dto.AuthUserDTO;
|
||||
import com.youlai.admin.pojo.entity.SysUser;
|
||||
import com.youlai.admin.pojo.query.UserPageQuery;
|
||||
import com.youlai.admin.pojo.vo.LoginUserVO;
|
||||
import com.youlai.admin.pojo.vo.user.LoginUserVO;
|
||||
import com.youlai.admin.pojo.vo.user.UserFormVO;
|
||||
import com.youlai.admin.pojo.vo.user.UserPageVO;
|
||||
import com.youlai.admin.service.ISysPermissionService;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.youlai.admin.controller.v2;
|
||||
|
||||
import com.youlai.admin.pojo.vo.NextRouteVO;
|
||||
import com.youlai.admin.pojo.vo.menu.NextRouteVO;
|
||||
import com.youlai.admin.service.ISysMenuService;
|
||||
import com.youlai.common.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
|
@ -3,18 +3,38 @@ package com.youlai.admin.mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.youlai.admin.pojo.entity.SysPermission;
|
||||
import com.youlai.admin.pojo.vo.PermissionVO;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import com.youlai.admin.pojo.query.PermissionPageQuery;
|
||||
import com.youlai.admin.pojo.vo.permission.PermissionPageVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SysPermissionMapper extends BaseMapper<SysPermission> {
|
||||
|
||||
/**
|
||||
* 获取权限分页列表
|
||||
*
|
||||
* @param page
|
||||
* @param queryParams
|
||||
* @return
|
||||
*/
|
||||
List<PermissionPageVO> listPermissionsWithPage(Page<PermissionPageVO> page, PermissionPageQuery queryParams);
|
||||
|
||||
/**
|
||||
* 获取权限和拥有权限的角色映射
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<SysPermission> listPermRoles();
|
||||
|
||||
/**
|
||||
* 根据角色编码集合获取按钮权限
|
||||
*
|
||||
* @param roles
|
||||
* @return
|
||||
*/
|
||||
List<String> listBtnPermByRoles(List<String> roles);
|
||||
|
||||
List<PermissionVO> list(Page<PermissionVO> page, String name, Long menuId);
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,14 @@
|
||||
package com.youlai.admin.pojo.form;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
|
||||
* @date 2021/12/19 11:46
|
||||
*/
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色权限传输层对象
|
||||
*
|
||||
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
|
||||
* @date 2021/12/19 11:46
|
||||
*/
|
||||
@Data
|
||||
public class RolePermsForm {
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.youlai.admin.pojo.query;
|
||||
|
||||
import com.youlai.common.base.BasePageQuery;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 权限分页查询对象
|
||||
*
|
||||
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
|
||||
* @date 2022/1/14 22:22
|
||||
*/
|
||||
@Data
|
||||
@ApiModel
|
||||
public class PermissionPageQuery extends BasePageQuery {
|
||||
|
||||
@ApiModelProperty("权限名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("菜单ID")
|
||||
private Long menuId;
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.youlai.admin.pojo.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 级联视图对象
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class CascadeVO {
|
||||
|
||||
private Long value;
|
||||
|
||||
private String label;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
private List<CascadeVO> children;
|
||||
}
|
@ -12,9 +12,9 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class TreeSelectVO {
|
||||
public class IdLabelVO {
|
||||
|
||||
public TreeSelectVO(Long id, String label) {
|
||||
public IdLabelVO(Long id, String label) {
|
||||
this.id = id;
|
||||
this.label = label;
|
||||
}
|
||||
@ -24,6 +24,6 @@ public class TreeSelectVO {
|
||||
private String label;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private List<TreeSelectVO> children;
|
||||
private List<IdLabelVO> children;
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.youlai.admin.pojo.vo;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class SelectVO {
|
||||
|
||||
public SelectVO(Long value, String label) {
|
||||
this.value = value;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
private Long value;
|
||||
|
||||
private String label;
|
||||
|
||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||
private List<SelectVO> children;
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.youlai.admin.pojo.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Select选择器默认Option属性
|
||||
*
|
||||
* @author haoxr
|
||||
* @date 2022/1/22
|
||||
*/
|
||||
@ApiModel("Select选择器默认Option属性")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class ValueLabelVO {
|
||||
|
||||
public ValueLabelVO(Long value, String label) {
|
||||
this.value = value;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@ApiModelProperty("选项的值")
|
||||
private Long value;
|
||||
|
||||
@ApiModelProperty("选项的标签,若不设置则默认与value相同")
|
||||
private String label;
|
||||
|
||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||
private List<ValueLabelVO> children;
|
||||
|
||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||
@ApiModelProperty("是否禁用该选项,默认false")
|
||||
public Boolean disabled;
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.youlai.admin.pojo.vo;
|
||||
package com.youlai.admin.pojo.vo.dept;
|
||||
|
||||
import lombok.Data;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.youlai.admin.pojo.vo;
|
||||
package com.youlai.admin.pojo.vo.menu;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.youlai.common.base.BaseEntity;
|
@ -1,9 +1,7 @@
|
||||
package com.youlai.admin.pojo.vo;
|
||||
package com.youlai.admin.pojo.vo.menu;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.youlai.admin.pojo.vo;
|
||||
package com.youlai.admin.pojo.vo.menu;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.AllArgsConstructor;
|
@ -1,16 +1,18 @@
|
||||
package com.youlai.admin.pojo.vo;
|
||||
package com.youlai.admin.pojo.vo.permission;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 权限视图对象
|
||||
*
|
||||
* @author <a href="mailto:xianrui0365@163.com">haoxr</a>
|
||||
* @date 2021/10/30 10:54
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("权限视图对象")
|
||||
public class PermissionVO {
|
||||
public class PermissionPageVO {
|
||||
|
||||
@ApiModelProperty("权限ID")
|
||||
private Long id;
|
@ -1,4 +1,4 @@
|
||||
package com.youlai.admin.pojo.vo;
|
||||
package com.youlai.admin.pojo.vo.user;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@ -7,7 +7,7 @@ import lombok.Data;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 当前登录用户视图对象
|
||||
* 登录用户视图层对象
|
||||
*
|
||||
* @author haoxr
|
||||
* @date 2022/1/14
|
@ -2,9 +2,8 @@ package com.youlai.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.admin.pojo.entity.SysDept;
|
||||
import com.youlai.admin.pojo.vo.DeptVO;
|
||||
import com.youlai.admin.pojo.vo.SelectVO;
|
||||
import com.youlai.admin.pojo.vo.TreeSelectVO;
|
||||
import com.youlai.admin.pojo.vo.dept.DeptVO;
|
||||
import com.youlai.admin.pojo.vo.IdLabelVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -29,7 +28,7 @@ public interface ISysDeptService extends IService<SysDept> {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<TreeSelectVO> listTreeSelect();
|
||||
List<IdLabelVO> listTreeSelect();
|
||||
|
||||
/**
|
||||
* 新增/修改部门
|
||||
|
@ -4,6 +4,9 @@ package com.youlai.admin.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.admin.pojo.entity.SysMenu;
|
||||
import com.youlai.admin.pojo.vo.*;
|
||||
import com.youlai.admin.pojo.vo.menu.MenuVO;
|
||||
import com.youlai.admin.pojo.vo.menu.NextRouteVO;
|
||||
import com.youlai.admin.pojo.vo.menu.RouteVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -28,7 +31,7 @@ public interface ISysMenuService extends IService<SysMenu> {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<SelectVO> listSelect();
|
||||
List<ValueLabelVO> listSelect();
|
||||
|
||||
|
||||
/**
|
||||
@ -43,7 +46,7 @@ public interface ISysMenuService extends IService<SysMenu> {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<TreeSelectVO> listTreeSelect();
|
||||
List<IdLabelVO> listTreeSelect();
|
||||
|
||||
/**
|
||||
* 新增菜单
|
||||
|
@ -1,18 +1,29 @@
|
||||
package com.youlai.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.youlai.admin.pojo.entity.SysPermission;
|
||||
import com.youlai.admin.pojo.vo.PermissionVO;
|
||||
import com.youlai.admin.pojo.query.PermissionPageQuery;
|
||||
import com.youlai.admin.pojo.vo.permission.PermissionPageVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 权限业务接口
|
||||
*
|
||||
* @author haoxr
|
||||
* @date 2022/1/22
|
||||
*/
|
||||
public interface ISysPermissionService extends IService<SysPermission> {
|
||||
|
||||
List<SysPermission> listPermRoles();
|
||||
|
||||
|
||||
/**
|
||||
* 根据角色编码集合获取按钮权限标识
|
||||
*
|
||||
* @param roles 角色权限编码集合
|
||||
* @return
|
||||
*/
|
||||
List<String> listBtnPermByRoles(List<String> roles);
|
||||
|
||||
/**
|
||||
@ -20,5 +31,11 @@ public interface ISysPermissionService extends IService<SysPermission> {
|
||||
*/
|
||||
boolean refreshPermRolesRules();
|
||||
|
||||
IPage<PermissionVO> list(Page<PermissionVO> page, String name, Long menuId);
|
||||
/**
|
||||
* 获取权限分页列表
|
||||
*
|
||||
* @param permissionPageQuery
|
||||
* @return
|
||||
*/
|
||||
IPage<PermissionPageVO> listPermissionsWithPage(PermissionPageQuery permissionPageQuery);
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.admin.constant.SystemConstants;
|
||||
import com.youlai.admin.mapper.SysDeptMapper;
|
||||
import com.youlai.admin.pojo.entity.SysDept;
|
||||
import com.youlai.admin.pojo.vo.DeptVO;
|
||||
import com.youlai.admin.pojo.vo.TreeSelectVO;
|
||||
import com.youlai.admin.pojo.vo.dept.DeptVO;
|
||||
import com.youlai.admin.pojo.vo.IdLabelVO;
|
||||
import com.youlai.admin.service.ISysDeptService;
|
||||
import com.youlai.admin.service.ISysUserService;
|
||||
import com.youlai.common.constant.GlobalConstants;
|
||||
@ -115,13 +115,13 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<TreeSelectVO> listTreeSelect() {
|
||||
public List<IdLabelVO> listTreeSelect() {
|
||||
List<SysDept> deptList = this.list(new LambdaQueryWrapper<SysDept>()
|
||||
.eq(SysDept::getStatus, GlobalConstants.STATUS_YES)
|
||||
.orderByAsc(SysDept::getSort)
|
||||
);
|
||||
SysDept sysDept = this.getById(JwtUtils.getJwtPayload().getLong("deptId"));
|
||||
List<TreeSelectVO> deptSelectList = recursionTreeSelectList(sysDept.getParentId(), deptList);
|
||||
List<IdLabelVO> deptSelectList = recursionTreeSelectList(sysDept.getParentId(), deptList);
|
||||
return deptSelectList;
|
||||
}
|
||||
|
||||
@ -133,18 +133,18 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
* @param deptList
|
||||
* @return
|
||||
*/
|
||||
public static List<TreeSelectVO> recursionTreeSelectList(long parentId, List<SysDept> deptList) {
|
||||
List<TreeSelectVO> deptTreeSelectList = new ArrayList<>();
|
||||
public static List<IdLabelVO> recursionTreeSelectList(long parentId, List<SysDept> deptList) {
|
||||
List<IdLabelVO> deptTreeSelectList = new ArrayList<>();
|
||||
Optional.ofNullable(deptList).orElse(new ArrayList<>())
|
||||
.stream()
|
||||
.filter(dept -> dept.getParentId().equals(parentId))
|
||||
.forEach(dept -> {
|
||||
TreeSelectVO treeSelectVO = new TreeSelectVO(dept.getId(), dept.getName());
|
||||
List<TreeSelectVO> children = recursionTreeSelectList(dept.getId(), deptList);
|
||||
IdLabelVO idLabelVO = new IdLabelVO(dept.getId(), dept.getName());
|
||||
List<IdLabelVO> children = recursionTreeSelectList(dept.getId(), deptList);
|
||||
if (CollectionUtil.isNotEmpty(children)) {
|
||||
treeSelectVO.setChildren(children);
|
||||
idLabelVO.setChildren(children);
|
||||
}
|
||||
deptTreeSelectList.add(treeSelectVO);
|
||||
deptTreeSelectList.add(idLabelVO);
|
||||
});
|
||||
return deptTreeSelectList;
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ import com.youlai.admin.constant.SystemConstants;
|
||||
import com.youlai.admin.pojo.entity.SysMenu;
|
||||
import com.youlai.admin.pojo.vo.*;
|
||||
import com.youlai.admin.mapper.SysMenuMapper;
|
||||
import com.youlai.admin.pojo.vo.menu.MenuVO;
|
||||
import com.youlai.admin.pojo.vo.menu.NextRouteVO;
|
||||
import com.youlai.admin.pojo.vo.menu.RouteVO;
|
||||
import com.youlai.admin.service.ISysMenuService;
|
||||
import com.youlai.admin.service.ISysPermissionService;
|
||||
import com.youlai.common.constant.GlobalConstants;
|
||||
@ -115,9 +118,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SelectVO> listSelect() {
|
||||
public List<ValueLabelVO> listSelect() {
|
||||
List<SysMenu> menuList = this.list(new LambdaQueryWrapper<SysMenu>().orderByAsc(SysMenu::getSort));
|
||||
List<SelectVO> menuSelectList = recursionSelectList(SystemConstants.ROOT_MENU_ID, menuList);
|
||||
List<ValueLabelVO> menuSelectList = recursionSelectList(SystemConstants.ROOT_MENU_ID, menuList);
|
||||
return menuSelectList;
|
||||
}
|
||||
|
||||
@ -129,18 +132,18 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
* @param menuList 菜单列表
|
||||
* @return
|
||||
*/
|
||||
private static List<SelectVO> recursionSelectList(Long parentId, List<SysMenu> menuList) {
|
||||
List<SelectVO> menuSelectList = new ArrayList<>();
|
||||
private static List<ValueLabelVO> recursionSelectList(Long parentId, List<SysMenu> menuList) {
|
||||
List<ValueLabelVO> menuSelectList = new ArrayList<>();
|
||||
Optional.ofNullable(menuList).orElse(new ArrayList<>())
|
||||
.stream()
|
||||
.filter(menu -> menu.getParentId().equals(parentId))
|
||||
.forEach(menu -> {
|
||||
SelectVO selectVO = new SelectVO(menu.getId(), menu.getName());
|
||||
List<SelectVO> children = recursionSelectList(menu.getId(), menuList);
|
||||
ValueLabelVO valueLabelVO = new ValueLabelVO(menu.getId(), menu.getName());
|
||||
List<ValueLabelVO> children = recursionSelectList(menu.getId(), menuList);
|
||||
if (CollectionUtil.isNotEmpty(children)) {
|
||||
selectVO.setChildren(children);
|
||||
valueLabelVO.setChildren(children);
|
||||
}
|
||||
menuSelectList.add(selectVO);
|
||||
menuSelectList.add(valueLabelVO);
|
||||
});
|
||||
return menuSelectList;
|
||||
}
|
||||
@ -201,9 +204,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<TreeSelectVO> listTreeSelect() {
|
||||
public List<IdLabelVO> listTreeSelect() {
|
||||
List<SysMenu> menuList = this.list(new LambdaQueryWrapper<SysMenu>().orderByAsc(SysMenu::getSort));
|
||||
List<TreeSelectVO> menuSelectList = recursionTreeSelectList(SystemConstants.ROOT_MENU_ID, menuList);
|
||||
List<IdLabelVO> menuSelectList = recursionTreeSelectList(SystemConstants.ROOT_MENU_ID, menuList);
|
||||
return menuSelectList;
|
||||
}
|
||||
|
||||
@ -262,18 +265,18 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
||||
* @param menuList 菜单列表
|
||||
* @return
|
||||
*/
|
||||
private static List<TreeSelectVO> recursionTreeSelectList(Long parentId, List<SysMenu> menuList) {
|
||||
List<TreeSelectVO> menuSelectList = new ArrayList<>();
|
||||
private static List<IdLabelVO> recursionTreeSelectList(Long parentId, List<SysMenu> menuList) {
|
||||
List<IdLabelVO> menuSelectList = new ArrayList<>();
|
||||
Optional.ofNullable(menuList).orElse(new ArrayList<>())
|
||||
.stream()
|
||||
.filter(menu -> menu.getParentId().equals(parentId))
|
||||
.forEach(menu -> {
|
||||
TreeSelectVO treeSelectVO = new TreeSelectVO(menu.getId(), menu.getName());
|
||||
List<TreeSelectVO> children = recursionTreeSelectList(menu.getId(), menuList);
|
||||
IdLabelVO idLabelVO = new IdLabelVO(menu.getId(), menu.getName());
|
||||
List<IdLabelVO> children = recursionTreeSelectList(menu.getId(), menuList);
|
||||
if (CollectionUtil.isNotEmpty(children)) {
|
||||
treeSelectVO.setChildren(children);
|
||||
idLabelVO.setChildren(children);
|
||||
}
|
||||
menuSelectList.add(treeSelectVO);
|
||||
menuSelectList.add(idLabelVO);
|
||||
});
|
||||
return menuSelectList;
|
||||
}
|
||||
|
@ -7,7 +7,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.youlai.admin.mapper.SysPermissionMapper;
|
||||
import com.youlai.admin.pojo.entity.SysPermission;
|
||||
import com.youlai.admin.pojo.vo.PermissionVO;
|
||||
import com.youlai.admin.pojo.query.PermissionPageQuery;
|
||||
import com.youlai.admin.pojo.vo.permission.PermissionPageVO;
|
||||
import com.youlai.admin.service.ISysPermissionService;
|
||||
import com.youlai.common.constant.GlobalConstants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -20,9 +21,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* 权限业务类
|
||||
* 权限业务实现类
|
||||
*
|
||||
* @author haoxr
|
||||
* @date 2022/1/22
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ -30,18 +33,47 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
|
||||
|
||||
private final RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 获取权限分页列表
|
||||
*
|
||||
* @param queryParams
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public IPage<PermissionVO> list(Page<PermissionVO> page, String name, Long menuId) {
|
||||
List<PermissionVO> list= this.baseMapper.list(page, name,menuId);
|
||||
public IPage<PermissionPageVO> listPermissionsWithPage(PermissionPageQuery queryParams) {
|
||||
Page<PermissionPageVO> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize());
|
||||
List<PermissionPageVO> list = this.baseMapper.listPermissionsWithPage(page, queryParams);
|
||||
page.setRecords(list);
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色编码集合获取按钮权限
|
||||
*
|
||||
* @param roles 角色权限编码集合
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<String> listBtnPermByRoles(List<String> roles) {
|
||||
List<String> perms = this.baseMapper.listBtnPermByRoles(roles);
|
||||
return perms;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取权限和拥有权限的角色映射
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysPermission> listPermRoles() {
|
||||
return this.baseMapper.listPermRoles();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新权限角色缓存
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean refreshPermRolesRules() {
|
||||
redisTemplate.delete(Arrays.asList(GlobalConstants.URL_PERM_ROLES_KEY, GlobalConstants.BTN_PERM_ROLES_KEY));
|
||||
@ -78,9 +110,5 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listBtnPermByRoles(List<String> roles) {
|
||||
List<String> perms = this.baseMapper.listBtnPermByRoles(roles);
|
||||
return perms;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,31 +24,8 @@
|
||||
gmt_modified
|
||||
</sql>
|
||||
|
||||
<select id="listPermRoles" resultMap="BaseResultMap">
|
||||
SELECT t1.id,
|
||||
t1.NAME,
|
||||
t1.menu_id,
|
||||
t1.url_perm,
|
||||
t1.btn_perm,
|
||||
t3.CODE
|
||||
FROM sys_permission t1
|
||||
LEFT JOIN sys_role_permission t2 ON t1.id = t2.permission_id
|
||||
LEFT JOIN sys_role t3 ON t2.role_id = t3.id
|
||||
</select>
|
||||
|
||||
<select id="listBtnPermByRoles" resultType="java.lang.String">
|
||||
SELECT
|
||||
distinct (t1.btn_perm)
|
||||
FROM
|
||||
sys_permission t1,sys_role_permission t2 ,sys_role t3
|
||||
WHERE t1.btn_perm is not null and t1.id=t2.permission_id and t2.role_id=t3.id and
|
||||
t3.code IN
|
||||
<foreach collection='roles' item='role' open='(' separator=',' close=')'>
|
||||
#{role}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="list" resultType="com.youlai.admin.pojo.vo.PermissionVO">
|
||||
<!-- 获取权限分页列表 -->
|
||||
<select id="listPermissionsWithPage" resultType="com.youlai.admin.pojo.vo.permission.PermissionPageVO">
|
||||
SELECT
|
||||
t1.id,
|
||||
t1.menu_id,
|
||||
@ -66,20 +43,52 @@
|
||||
btn_perm,
|
||||
SUBSTRING_INDEX( url_perm, ':', 1 ) requestMethod,
|
||||
SUBSTRING_INDEX( SUBSTR( SUBSTRING_INDEX( url_perm, ':',- 1 ), 2 ), '/', 1 ) serviceName,
|
||||
SUBSTR( SUBSTRING_INDEX( url_perm, ':', - 1 ),LENGTH(SUBSTRING_INDEX( SUBSTR( SUBSTRING_INDEX( url_perm, ':',- 1 ), 2 ), '/', 1 ))+ 2) requestPath
|
||||
SUBSTR(
|
||||
SUBSTRING_INDEX( url_perm, ':', - 1 ),
|
||||
LENGTH(
|
||||
SUBSTRING_INDEX( SUBSTR( SUBSTRING_INDEX( url_perm, ':',- 1 ), 2 ), '/', 1 ))+ 2
|
||||
) requestPath
|
||||
FROM
|
||||
sys_permission
|
||||
) t1
|
||||
LEFT JOIN sys_menu t2 ON t1.menu_id = t2.id
|
||||
LEFT JOIN sys_dict_item t3 ON t3.`value` = t1.requestMethod
|
||||
LEFT JOIN sys_dict_item t4 ON t4.`value` = t1.serviceName
|
||||
WHERE 1 =1
|
||||
<if test='name != null and name.trim() neq ""'>
|
||||
and t1.name like concat('%',#{permission.name},'%')
|
||||
</if>
|
||||
<if test='menuId !=null '>
|
||||
and t1.menu_id = #{menuId}
|
||||
</if>
|
||||
LEFT JOIN sys_menu t2 ON t1.menu_id = t2.id
|
||||
LEFT JOIN sys_dict_item t3 ON t3.`value` = t1.requestMethod
|
||||
LEFT JOIN sys_dict_item t4 ON t4.`value` = t1.serviceName
|
||||
<where>
|
||||
<if test='queryParams.name != null and queryParams.name.trim() neq ""'>
|
||||
and t1.name like concat('%',#{queryParams.name},'%')
|
||||
</if>
|
||||
<if test='queryParams.menuId !=null '>
|
||||
and t1.menu_id = #{queryParams.menuId}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY t1.id DESC
|
||||
</select>
|
||||
|
||||
<!-- 获取权限和拥有权限的角色映射 -->
|
||||
<select id="listPermRoles" resultMap="BaseResultMap">
|
||||
SELECT t1.id,
|
||||
t1.NAME,
|
||||
t1.menu_id,
|
||||
t1.url_perm,
|
||||
t1.btn_perm,
|
||||
t3.CODE
|
||||
FROM sys_permission t1
|
||||
LEFT JOIN sys_role_permission t2 ON t1.id = t2.permission_id
|
||||
LEFT JOIN sys_role t3 ON t2.role_id = t3.id
|
||||
</select>
|
||||
|
||||
<!-- 根据角色编码集合获取按钮权限 -->
|
||||
<select id="listBtnPermByRoles" resultType="java.lang.String">
|
||||
SELECT
|
||||
distinct (t1.btn_perm)
|
||||
FROM
|
||||
sys_permission t1,sys_role_permission t2 ,sys_role t3
|
||||
WHERE t1.btn_perm is not null and t1.id=t2.permission_id and t2.role_id=t3.id and
|
||||
t3.code IN
|
||||
<foreach collection='roles' item='role' open='(' separator=',' close=')'>
|
||||
#{role}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue
Block a user