完成资源列表的前端对接和调整
This commit is contained in:
parent
6bddebafff
commit
3a23ca72e6
@ -1,5 +1,5 @@
|
|||||||
import { message } from 'antd';
|
import { message } from 'antd';
|
||||||
import { resourceTree, resourceAdd, resourceUpdate, resourceDelete } from '../../services/system';
|
import { resourceTree, resourceCreate, resourceUpdate, resourceDelete } from '../../services/system';
|
||||||
|
|
||||||
const buildSelectTree = list => {
|
const buildSelectTree = list => {
|
||||||
return list.map(item => {
|
return list.map(item => {
|
||||||
@ -27,7 +27,7 @@ export default {
|
|||||||
effects: {
|
effects: {
|
||||||
*add({ payload }, { call, put }) {
|
*add({ payload }, { call, put }) {
|
||||||
const { callback, body } = payload;
|
const { callback, body } = payload;
|
||||||
const response = yield call(resourceAdd, body);
|
const response = yield call(resourceCreate, body);
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(response);
|
callback(response);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import isEqual from 'lodash/isEqual';
|
|||||||
import { formatMessage } from 'umi/locale';
|
import { formatMessage } from 'umi/locale';
|
||||||
import Authorized from '@/utils/Authorized';
|
import Authorized from '@/utils/Authorized';
|
||||||
import { menu } from '../defaultSettings';
|
import { menu } from '../defaultSettings';
|
||||||
import { authorizationMenuResourceTree, authorizationResourcePermissions } from '../services/system';
|
import { resourceTreeAdminMenu, authorizationResourcePermissions } from '../services/system';
|
||||||
|
|
||||||
const { check } = Authorized;
|
const { check } = Authorized;
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ export default {
|
|||||||
|
|
||||||
effects: {
|
effects: {
|
||||||
*getMenuData({ payload }, { put, call }) {
|
*getMenuData({ payload }, { put, call }) {
|
||||||
const { data } = yield call(authorizationMenuResourceTree);
|
const { data } = yield call(resourceTreeAdminMenu);
|
||||||
const { routes, authority } = payload;
|
const { routes, authority } = payload;
|
||||||
|
|
||||||
// authority 已经不适用
|
// authority 已经不适用
|
||||||
|
@ -215,7 +215,7 @@ class ResourceList extends PureComponent {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: 'resourceList/delete',
|
type: 'resourceList/delete',
|
||||||
payload: {
|
payload: {
|
||||||
id: row.id,
|
resourceId: row.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -12,12 +12,6 @@ export async function passportLogin(params) {
|
|||||||
|
|
||||||
// ========== Authorization 模块 ==========
|
// ========== Authorization 模块 ==========
|
||||||
|
|
||||||
export async function authorizationMenuResourceTree() {
|
|
||||||
return request('/system-api/admins/authorization/menu-resource-tree', {
|
|
||||||
method: 'GET',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function authorizationResourcePermissions(params) {
|
export async function authorizationResourcePermissions(params) {
|
||||||
return request(`/system-api/admins/authorization/resource-permissions`, {
|
return request(`/system-api/admins/authorization/resource-permissions`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -40,29 +34,35 @@ export async function authorizationRoleAssignResource(params) {
|
|||||||
// ========== Resource 模块 ==========
|
// ========== Resource 模块 ==========
|
||||||
|
|
||||||
export async function resourceTree(params) {
|
export async function resourceTree(params) {
|
||||||
return request(`/system-api/admins/resource/tree`, {
|
return request(`/management-api/resource/tree`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resourceAdd(params) {
|
export async function resourceCreate(params) {
|
||||||
return request(`/system-api/admins/resource/add?${stringify(params)}`, {
|
return request(`/management-api/resource/create?${stringify(params)}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resourceUpdate(params) {
|
export async function resourceUpdate(params) {
|
||||||
return request(`/system-api/admins/resource/update?${stringify(params)}`, {
|
return request(`/management-api/resource/update?${stringify(params)}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function resourceDelete(params) {
|
export async function resourceDelete(params) {
|
||||||
return request(`/system-api/admins/resource/delete?${stringify(params)}`, {
|
return request(`/management-api/resource/delete?${stringify(params)}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function resourceTreeAdminMenu() {
|
||||||
|
return request('/management-api/resource/tree-admin-menu', {
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ========== Role 模块 ==========
|
// ========== Role 模块 ==========
|
||||||
|
|
||||||
export async function rolePage(params) {
|
export async function rolePage(params) {
|
||||||
|
@ -4,6 +4,9 @@ import cn.iocoder.mall.web.core.handler.GlobalExceptionHandler;
|
|||||||
import cn.iocoder.mall.web.core.handler.GlobalResponseBodyHandler;
|
import cn.iocoder.mall.web.core.handler.GlobalResponseBodyHandler;
|
||||||
import cn.iocoder.mall.web.core.interceptor.AccessLogInterceptor;
|
import cn.iocoder.mall.web.core.interceptor.AccessLogInterceptor;
|
||||||
import cn.iocoder.mall.web.core.servlet.CorsFilter;
|
import cn.iocoder.mall.web.core.servlet.CorsFilter;
|
||||||
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||||
|
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||||
|
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
@ -13,9 +16,15 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
|
|||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
||||||
public class CommonWebAutoConfiguration implements WebMvcConfigurer {
|
public class CommonWebAutoConfiguration implements WebMvcConfigurer {
|
||||||
@ -66,4 +75,21 @@ public class CommonWebAutoConfiguration implements WebMvcConfigurer {
|
|||||||
return registrationBean;
|
return registrationBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========== MessageConverter 相关 ==========
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
|
// 创建 FastJsonHttpMessageConverter 对象
|
||||||
|
FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
|
||||||
|
// 自定义 FastJson 配置
|
||||||
|
FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
||||||
|
fastJsonConfig.setCharset(Charset.defaultCharset()); // 设置字符集
|
||||||
|
fastJsonConfig.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect); // 剔除循环引用
|
||||||
|
fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
|
||||||
|
// 设置支持的 MediaType
|
||||||
|
fastJsonHttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||||
|
// 添加到 converters 中
|
||||||
|
converters.add(0, fastJsonHttpMessageConverter); // 注意,添加到最开头,放在 MappingJackson2XmlHttpMessageConverter 前面
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,5 +29,14 @@ GET {{baseUrl}}/resource/list?resourceIds=61,63
|
|||||||
Content-Type: application/x-www-form-urlencoded
|
Content-Type: application/x-www-form-urlencoded
|
||||||
Authorization: Bearer {{accessToken}}
|
Authorization: Bearer {{accessToken}}
|
||||||
|
|
||||||
###
|
### /resource/tree 成功
|
||||||
|
GET {{baseUrl}}/resource/tree
|
||||||
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
Authorization: Bearer {{accessToken}}
|
||||||
|
|
||||||
|
### /resource/tree-admin-menu 成功
|
||||||
|
GET {{baseUrl}}/resource/tree-admin-menu
|
||||||
|
Content-Type: application/x-www-form-urlencoded
|
||||||
|
Authorization: Bearer {{accessToken}}
|
||||||
|
|
||||||
|
###
|
||||||
|
@ -3,6 +3,8 @@ package cn.iocoder.mall.managementweb.controller.permission;
|
|||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceCreateDTO;
|
import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceCreateDTO;
|
||||||
import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceUpdateDTO;
|
import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceUpdateDTO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.permission.vo.AdminMenuTreeNodeVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceTreeNodeVO;
|
||||||
import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO;
|
import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO;
|
||||||
import cn.iocoder.mall.managementweb.manager.permission.ResourceManager;
|
import cn.iocoder.mall.managementweb.manager.permission.ResourceManager;
|
||||||
import cn.iocoder.mall.security.admin.core.context.AdminSecurityContextHolder;
|
import cn.iocoder.mall.security.admin.core.context.AdminSecurityContextHolder;
|
||||||
@ -60,8 +62,20 @@ public class ResourceController {
|
|||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ApiOperation("获得资源列表")
|
@ApiOperation("获得资源列表")
|
||||||
@ApiImplicitParam(name = "resourceId", value = "资源编号列表", required = true)
|
@ApiImplicitParam(name = "resourceId", value = "资源编号列表", required = true)
|
||||||
public CommonResult<List<ResourceVO>> getResources(@RequestParam("resourceIds") List<Integer> resourceIds) {
|
public CommonResult<List<ResourceVO>> listResource(@RequestParam("resourceIds") List<Integer> resourceIds) {
|
||||||
return success(resourceManager.listResource(resourceIds));
|
return success(resourceManager.listResource(resourceIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/tree")
|
||||||
|
@ApiOperation("获得资源树")
|
||||||
|
public CommonResult<List<ResourceTreeNodeVO>> treeResource() {
|
||||||
|
return success(resourceManager.treeResource());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/tree-admin-menu")
|
||||||
|
@ApiOperation("获得当前登陆的管理员的菜单树")
|
||||||
|
public CommonResult<List<AdminMenuTreeNodeVO>> treeAdminMenu() {
|
||||||
|
return success(resourceManager.treeAdminMenu(AdminSecurityContextHolder.getAdminId()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
package cn.iocoder.mall.managementweb.controller.permission.vo;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.validator.InEnum;
|
||||||
|
import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ApiModel("资源树节点 VO")
|
||||||
|
@Data
|
||||||
|
public class ResourceTreeNodeVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "资源编号", required = true, example = "1")
|
||||||
|
@NotNull(message = "资源编号不能为空")
|
||||||
|
private Integer id;
|
||||||
|
@ApiModelProperty(value = "菜单名", required = true, example = "商品管理")
|
||||||
|
@NotEmpty(message = "菜单名不能为空")
|
||||||
|
private String name;
|
||||||
|
@ApiModelProperty(value = "权限标识", example = "resource:add")
|
||||||
|
private String permission;
|
||||||
|
@ApiModelProperty(value = "资源类型", required = true, example = "1")
|
||||||
|
@NotNull(message = "资源类型不能为空")
|
||||||
|
@InEnum(value = ResourceTypeEnum.class, message = "资源类型必须是 {value}")
|
||||||
|
private Integer type;
|
||||||
|
@ApiModelProperty(value = "排序", required = true, example = "1")
|
||||||
|
@NotNull(message = "排序不能为空")
|
||||||
|
private Integer sort;
|
||||||
|
@ApiModelProperty(value = "父级资源编号", required = true, example = "1", notes = "如果无父资源,则值为 0")
|
||||||
|
@NotNull(message = "父级资源编号不能为空")
|
||||||
|
private Integer pid;
|
||||||
|
@ApiModelProperty(value = "前端路由", example = "/resource/list")
|
||||||
|
private String route;
|
||||||
|
@ApiModelProperty(value = "菜单图标", example = "add")
|
||||||
|
private String icon;
|
||||||
|
@ApiModelProperty(value = "添加时间", required = true)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子节点
|
||||||
|
*/
|
||||||
|
private List<ResourceTreeNodeVO> children;
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.mall.managementweb.convert.permission;
|
package cn.iocoder.mall.managementweb.convert.permission;
|
||||||
|
|
||||||
import cn.iocoder.mall.managementweb.controller.permission.vo.AdminMenuTreeNodeVO;
|
import cn.iocoder.mall.managementweb.controller.permission.vo.AdminMenuTreeNodeVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceTreeNodeVO;
|
||||||
import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO;
|
import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO;
|
import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO;
|
||||||
import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceUpdateDTO;
|
import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceUpdateDTO;
|
||||||
@ -22,6 +23,8 @@ public interface ResourceConvert {
|
|||||||
|
|
||||||
List<ResourceVO> convertList(List<cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO> list);
|
List<ResourceVO> convertList(List<cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO> list);
|
||||||
|
|
||||||
AdminMenuTreeNodeVO convertTreeNode(cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO bean);
|
ResourceTreeNodeVO convertTreeNode(cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO bean);
|
||||||
|
|
||||||
|
List<AdminMenuTreeNodeVO> convert(List<ResourceTreeNodeVO> list);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import cn.iocoder.common.framework.vo.CommonResult;
|
|||||||
import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceCreateDTO;
|
import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceCreateDTO;
|
||||||
import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceUpdateDTO;
|
import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceUpdateDTO;
|
||||||
import cn.iocoder.mall.managementweb.controller.permission.vo.AdminMenuTreeNodeVO;
|
import cn.iocoder.mall.managementweb.controller.permission.vo.AdminMenuTreeNodeVO;
|
||||||
|
import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceTreeNodeVO;
|
||||||
import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO;
|
import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO;
|
||||||
import cn.iocoder.mall.managementweb.convert.permission.ResourceConvert;
|
import cn.iocoder.mall.managementweb.convert.permission.ResourceConvert;
|
||||||
import cn.iocoder.mall.systemservice.enums.permission.ResourceIdEnum;
|
import cn.iocoder.mall.systemservice.enums.permission.ResourceIdEnum;
|
||||||
@ -86,6 +87,19 @@ public class ResourceManager {
|
|||||||
return ResourceConvert.INSTANCE.convertList(listResourceResult.getData());
|
return ResourceConvert.INSTANCE.convertList(listResourceResult.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得资源树结构
|
||||||
|
*
|
||||||
|
* @return 资源树结构
|
||||||
|
*/
|
||||||
|
public List<ResourceTreeNodeVO> treeResource() {
|
||||||
|
// 获得资源全列表
|
||||||
|
CommonResult<List<cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO>> listResourceResult = resourceRpc.listResource();
|
||||||
|
listResourceResult.checkError();
|
||||||
|
// 构建菜单树
|
||||||
|
return this.buildResourceTree(listResourceResult.getData());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得管理员的菜单树
|
* 获得管理员的菜单树
|
||||||
*
|
*
|
||||||
@ -107,33 +121,47 @@ public class ResourceManager {
|
|||||||
return this.buildAdminMenuTree(resourceVOResult.getData());
|
return this.buildAdminMenuTree(resourceVOResult.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建菜单树
|
||||||
|
*
|
||||||
|
* @param resourceVOs 资源(都是菜单)列表
|
||||||
|
* @return 菜单树
|
||||||
|
*/
|
||||||
private List<AdminMenuTreeNodeVO> buildAdminMenuTree(List<cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO> resourceVOs) {
|
private List<AdminMenuTreeNodeVO> buildAdminMenuTree(List<cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO> resourceVOs) {
|
||||||
|
List<ResourceTreeNodeVO> treeNodeVOS = this.buildResourceTree(resourceVOs);
|
||||||
|
// 虽然多了一层转换,但是可维护性更好。
|
||||||
|
return ResourceConvert.INSTANCE.convert(treeNodeVOS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建资源树
|
||||||
|
*
|
||||||
|
* @param resourceVOs 资源列表
|
||||||
|
* @return 资源树
|
||||||
|
*/
|
||||||
|
private List<ResourceTreeNodeVO> buildResourceTree(List<cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO> resourceVOs) {
|
||||||
// 排序,保证菜单的有序性
|
// 排序,保证菜单的有序性
|
||||||
resourceVOs.sort(Comparator.comparing(cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO::getSort));
|
resourceVOs.sort(Comparator.comparing(cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO::getSort));
|
||||||
// 构建菜单树
|
// 构建菜单树
|
||||||
// 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。
|
// 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。
|
||||||
Map<Integer, AdminMenuTreeNodeVO> treeNodeMap = new LinkedHashMap<>();
|
Map<Integer, ResourceTreeNodeVO> treeNodeMap = new LinkedHashMap<>();
|
||||||
resourceVOs.forEach(resourceVO -> treeNodeMap.put(resourceVO.getId(), ResourceConvert.INSTANCE.convertTreeNode(resourceVO)));
|
resourceVOs.forEach(resourceVO -> treeNodeMap.put(resourceVO.getId(), ResourceConvert.INSTANCE.convertTreeNode(resourceVO)));
|
||||||
// 处理父子关系
|
// 处理父子关系
|
||||||
treeNodeMap.values().stream()
|
treeNodeMap.values().stream().filter(node -> !node.getPid().equals(ResourceIdEnum.ROOT.getId())).forEach((childNode) -> {
|
||||||
.filter(node -> !node.getPid().equals(ResourceIdEnum.ROOT.getId()))
|
// 获得父节点
|
||||||
.forEach((childNode) -> {
|
ResourceTreeNodeVO parentNode = treeNodeMap.get(childNode.getPid());
|
||||||
// 获得父节点
|
if (parentNode == null) {
|
||||||
AdminMenuTreeNodeVO parentNode = treeNodeMap.get(childNode.getPid());
|
log.error("[buildResourceTree][resource({}) 找不到父资源({})]", childNode.getId(), childNode.getPid());
|
||||||
if (parentNode == null) {
|
return;
|
||||||
log.error("[getResourceTree][resource({}) 找不到父资源({})]", childNode.getId(), childNode.getPid());
|
}
|
||||||
return;
|
// 将自己添加到父节点中
|
||||||
}
|
if (parentNode.getChildren() == null) {
|
||||||
if (parentNode.getChildren() == null) { // 初始化 children 数组
|
parentNode.setChildren(new ArrayList<>());
|
||||||
parentNode.setChildren(new ArrayList<>());
|
}
|
||||||
}
|
parentNode.getChildren().add(childNode);
|
||||||
// 将自己添加到父节点中
|
});
|
||||||
parentNode.getChildren().add(childNode);
|
|
||||||
});
|
|
||||||
// 获得到所有的根节点
|
// 获得到所有的根节点
|
||||||
return treeNodeMap.values().stream()
|
return treeNodeMap.values().stream().filter(node -> node.getPid().equals(ResourceIdEnum.ROOT.getId())).collect(Collectors.toList());
|
||||||
.filter(node -> node.getPid().equals(ResourceIdEnum.ROOT.getId()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,13 @@ public interface ResourceRpc {
|
|||||||
*/
|
*/
|
||||||
CommonResult<ResourceVO> getResource(Integer resourceId);
|
CommonResult<ResourceVO> getResource(Integer resourceId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得资源全列表
|
||||||
|
*
|
||||||
|
* @return 资源列表
|
||||||
|
*/
|
||||||
|
CommonResult<List<ResourceVO>> listResource();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得资源列表
|
* 获得资源列表
|
||||||
*
|
*
|
||||||
|
@ -25,7 +25,7 @@ public class AdminRoleDO extends DeletableDO {
|
|||||||
*
|
*
|
||||||
* 关联 {@link AdminDO#getId()}
|
* 关联 {@link AdminDO#getId()}
|
||||||
*/
|
*/
|
||||||
private Integer accountId;
|
private Integer adminId;
|
||||||
/**
|
/**
|
||||||
* 角色编号
|
* 角色编号
|
||||||
*
|
*
|
||||||
|
@ -64,6 +64,16 @@ public class ResourceManager {
|
|||||||
return ResourceConvert.INSTANCE.convert(resourceBO);
|
return ResourceConvert.INSTANCE.convert(resourceBO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得资源全列表
|
||||||
|
*
|
||||||
|
* @return 资源列表
|
||||||
|
*/
|
||||||
|
public List<ResourceVO> listResource() {
|
||||||
|
List<ResourceBO> resourceBOs = resourceService.listResource();
|
||||||
|
return ResourceConvert.INSTANCE.convertList02(resourceBOs);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得资源列表
|
* 获得资源列表
|
||||||
*
|
*
|
||||||
|
@ -44,6 +44,11 @@ public class ResourceRpcImpl implements ResourceRpc {
|
|||||||
return success(resourceManager.getResource(resourceId));
|
return success(resourceManager.getResource(resourceId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommonResult<List<ResourceVO>> listResource() {
|
||||||
|
return success(resourceManager.listResource());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<List<ResourceVO>> listResource(List<Integer> resourceIds) {
|
public CommonResult<List<ResourceVO>> listResource(List<Integer> resourceIds) {
|
||||||
return success(resourceManager.listResource(resourceIds));
|
return success(resourceManager.listResource(resourceIds));
|
||||||
|
@ -119,6 +119,16 @@ public class ResourceService {
|
|||||||
return ResourceConvert.INSTANCE.convertList(resourceDOs);
|
return ResourceConvert.INSTANCE.convertList(resourceDOs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得资源树结构
|
||||||
|
*
|
||||||
|
* @return 资源树结构
|
||||||
|
*/
|
||||||
|
public List<ResourceBO> listResource() {
|
||||||
|
List<ResourceDO> resourceDOs = resourceMapper.selectList(null);
|
||||||
|
return ResourceConvert.INSTANCE.convertList(resourceDOs);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得指定类型的资源列表
|
* 获得指定类型的资源列表
|
||||||
*
|
*
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.convert.authorization;
|
|
||||||
|
|
||||||
import cn.iocoder.common.framework.vo.PageResult;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.authorization.RoleBO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.authorization.RoleAddDTO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.authorization.RolePageDTO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.authorization.RoleUpdateDTO;
|
|
||||||
import cn.iocoder.mall.system.rest.request.authorization.AdminsRoleAddRequest;
|
|
||||||
import cn.iocoder.mall.system.rest.request.authorization.AdminsRolePageRequest;
|
|
||||||
import cn.iocoder.mall.system.rest.request.authorization.AdminsRoleUpdateRequest;
|
|
||||||
import cn.iocoder.mall.system.rest.response.authorization.AdminsRolePageResponse;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface AdminsRoleConvert {
|
|
||||||
|
|
||||||
AdminsRoleConvert INSTANCE = Mappers.getMapper(AdminsRoleConvert.class);
|
|
||||||
|
|
||||||
RoleAddDTO convert(AdminsRoleAddRequest bean);
|
|
||||||
|
|
||||||
RoleUpdateDTO convert(AdminsRoleUpdateRequest bean);
|
|
||||||
|
|
||||||
RolePageDTO convert(AdminsRolePageRequest bean);
|
|
||||||
|
|
||||||
PageResult<AdminsRolePageResponse> convertPage(PageResult<RoleBO> bean);
|
|
||||||
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.convert.oauth2;
|
|
||||||
|
|
||||||
import cn.iocoder.mall.system.biz.bo.admin.AdminBO;
|
|
||||||
import cn.iocoder.mall.system.biz.bo.ouath2.OAuth2AuthenticateBO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2UsernameAuthenticateDTO;
|
|
||||||
import cn.iocoder.mall.system.rest.request.oauth2.AdminsOAuth2UsernameAuthenticateRequest;
|
|
||||||
import cn.iocoder.mall.system.rest.response.oauth2.AdminsOAuth2AuthenticateResponse;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.Mapping;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface AdminsOAuth2Convert {
|
|
||||||
|
|
||||||
AdminsOAuth2Convert INSTANCE = Mappers.getMapper(AdminsOAuth2Convert.class);
|
|
||||||
|
|
||||||
OAuth2UsernameAuthenticateDTO convert(AdminsOAuth2UsernameAuthenticateRequest bean);
|
|
||||||
|
|
||||||
@Mapping(source = "adminBO", target = "admin")
|
|
||||||
@Mapping(source = "accessTokenBO.accessToken", target = "token.accessToken")
|
|
||||||
@Mapping(source = "accessTokenBO.refreshToken", target = "token.refreshToken")
|
|
||||||
@Mapping(source = "accessTokenBO.expiresTime", target = "token.expiresTime")
|
|
||||||
AdminsOAuth2AuthenticateResponse convert(AdminBO adminBO, OAuth2AuthenticateBO accessTokenBO);
|
|
||||||
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package cn.iocoder.mall.system.rest.convert.oauth2;
|
|
||||||
|
|
||||||
import cn.iocoder.mall.system.biz.bo.user.UserAuthenticateBO;
|
|
||||||
import cn.iocoder.mall.system.biz.dto.oatuh2.OAuth2MobileCodeAuthenticateDTO;
|
|
||||||
import cn.iocoder.mall.system.rest.request.oauth2.UsersOAuth2MobileCodeAuthenticateRequest;
|
|
||||||
import cn.iocoder.mall.system.rest.response.user.UsersOAuth2AuthenticateResponse;
|
|
||||||
import org.mapstruct.Mapper;
|
|
||||||
import org.mapstruct.factory.Mappers;
|
|
||||||
|
|
||||||
@Mapper
|
|
||||||
public interface UsersOAuth2Convert {
|
|
||||||
|
|
||||||
UsersOAuth2Convert INSTANCE = Mappers.getMapper(UsersOAuth2Convert.class);
|
|
||||||
|
|
||||||
OAuth2MobileCodeAuthenticateDTO convert(UsersOAuth2MobileCodeAuthenticateRequest bean);
|
|
||||||
|
|
||||||
UsersOAuth2AuthenticateResponse convert(UserAuthenticateBO bean);
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user