diff --git a/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/resource/api/pojo/resource/ResourceDefinition.java b/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/resource/api/pojo/resource/ResourceDefinition.java
index a55bdb36d..55917d3f7 100644
--- a/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/resource/api/pojo/resource/ResourceDefinition.java
+++ b/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/resource/api/pojo/resource/ResourceDefinition.java
@@ -20,6 +20,16 @@ public class ResourceDefinition implements Serializable {
*/
private String appCode;
+ /**
+ * 资源的标识
+ */
+ private String resourceCode;
+
+ /**
+ * 资源名称
+ */
+ private String resourceName;
+
/**
* 项目编码(如果您不设置的话,默认使用spring.application.name填充)
*
@@ -50,14 +60,9 @@ public class ResourceDefinition implements Serializable {
private String modularName;
/**
- * 资源的标识
+ * 初始化资源的机器的ip地址
*/
- private String code;
-
- /**
- * 资源名称
- */
- private String name;
+ private String ipAddress;
/**
* 资源的请求路径
@@ -69,30 +74,15 @@ public class ResourceDefinition implements Serializable {
*/
private String httpMethod;
- /**
- * 是否是菜单(true-是,false-否)
- */
- private Boolean menuFlag;
-
/**
* 是否需要登录
*/
- private Boolean requiredLogin;
+ private Boolean requiredLoginFlag;
/**
* 是否需要鉴权
*/
- private Boolean requiredPermission;
-
- /**
- * 资源添加日期
- */
- private Date createTime;
-
- /**
- * 初始化资源的机器的ip地址
- */
- private String ipAddress;
+ private Boolean requiredPermissionFlag;
/**
* 需要进行参数校验的分组
@@ -102,11 +92,16 @@ public class ResourceDefinition implements Serializable {
/**
* 接口参数的字段描述
*/
- private Set paramFieldMetadata;
+ private Set paramFieldDescriptions;
/**
* 接口返回结果的字段描述
*/
- private Set responseFieldMetadata;
+ private Set responseFieldDescriptions;
+
+ /**
+ * 资源添加日期
+ */
+ private Date createTime;
}
diff --git a/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/resource/scanner/ApiResourceScanner.java b/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/resource/scanner/ApiResourceScanner.java
index b95208e60..b27f19f8e 100644
--- a/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/resource/scanner/ApiResourceScanner.java
+++ b/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/resource/scanner/ApiResourceScanner.java
@@ -206,9 +206,9 @@ public class ApiResourceScanner implements BeanPostProcessor {
// 如果没有填写code则用"模块名称_方法名称"为默认的标识
String code = invokeAnnotationMethod(apiResource, "code", String.class);
if (StrUtil.isEmpty(code)) {
- resourceDefinition.setCode(resourceDefinition.getAppCode() + scannerProperties.getLinkSymbol() + StrUtil.toUnderlineCase(modular) + scannerProperties.getLinkSymbol() + StrUtil.toUnderlineCase(method.getName()));
+ resourceDefinition.setResourceCode(resourceDefinition.getAppCode() + scannerProperties.getLinkSymbol() + StrUtil.toUnderlineCase(modular) + scannerProperties.getLinkSymbol() + StrUtil.toUnderlineCase(method.getName()));
} else {
- resourceDefinition.setCode(resourceDefinition.getAppCode() + scannerProperties.getLinkSymbol() + StrUtil.toUnderlineCase(modular) + scannerProperties.getLinkSymbol() + StrUtil.toUnderlineCase(code));
+ resourceDefinition.setResourceCode(resourceDefinition.getAppCode() + scannerProperties.getLinkSymbol() + StrUtil.toUnderlineCase(modular) + scannerProperties.getLinkSymbol() + StrUtil.toUnderlineCase(code));
}
// 填充其他属性
@@ -219,10 +219,9 @@ public class ApiResourceScanner implements BeanPostProcessor {
Boolean requiredLogin = invokeAnnotationMethod(apiResource, "requiredLogin", Boolean.class);
Boolean requiredPermission = invokeAnnotationMethod(apiResource, "requiredPermission", Boolean.class);
- resourceDefinition.setRequiredLogin(requiredLogin);
- resourceDefinition.setRequiredPermission(requiredPermission);
- resourceDefinition.setMenuFlag(menuFlag);
- resourceDefinition.setName(name);
+ resourceDefinition.setRequiredLoginFlag(requiredLogin);
+ resourceDefinition.setRequiredPermissionFlag(requiredPermission);
+ resourceDefinition.setResourceName(name);
resourceDefinition.setUrl(getControllerClassRequestPath(clazz, path[0]));
StringBuilder methodNames = new StringBuilder();
for (RequestMethod requestMethod : requestMethods) {
@@ -257,15 +256,15 @@ public class ApiResourceScanner implements BeanPostProcessor {
// @ApiResource注解上标识了responseClass属性,则用responseClass的值为准,否则按真实方法的返回值class
Class> responseClass = invokeAnnotationMethod(apiResource, "responseClass", Class.class);
if (!Void.class.equals(responseClass)) {
- resourceDefinition.setResponseFieldMetadata(ClassReflectUtil.getClassFieldDescription(responseClass));
+ resourceDefinition.setResponseFieldDescriptions(ClassReflectUtil.getClassFieldDescription(responseClass));
} else {
Class> methodReturnClass = MethodReflectUtil.getMethodReturnClass(method);
- resourceDefinition.setResponseFieldMetadata(ClassReflectUtil.getClassFieldDescription(methodReturnClass));
+ resourceDefinition.setResponseFieldDescriptions(ClassReflectUtil.getClassFieldDescription(methodReturnClass));
}
// 填充方法的请求参数字段的详细信息
Class> firstParamClass = MethodReflectUtil.getMethodFirstParamClass(method);
- resourceDefinition.setParamFieldMetadata(ClassReflectUtil.getClassFieldDescription(firstParamClass));
+ resourceDefinition.setParamFieldDescriptions(ClassReflectUtil.getClassFieldDescription(firstParamClass));
return resourceDefinition;
}
diff --git a/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/resource/scanner/DefaultResourceCollector.java b/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/resource/scanner/DefaultResourceCollector.java
index b377d89a8..be03444a9 100644
--- a/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/resource/scanner/DefaultResourceCollector.java
+++ b/kernel-d-scanner/scanner-sdk-scanner/src/main/java/cn/stylefeng/roses/kernel/resource/scanner/DefaultResourceCollector.java
@@ -39,25 +39,25 @@ public class DefaultResourceCollector implements ResourceCollectorApi {
public void collectResources(List apiResource) {
if (apiResource != null && apiResource.size() > 0) {
for (ResourceDefinition resourceDefinition : apiResource) {
- ResourceDefinition alreadyFlag = resourceDefinitions.get(resourceDefinition.getCode());
+ ResourceDefinition alreadyFlag = resourceDefinitions.get(resourceDefinition.getResourceCode());
if (alreadyFlag != null) {
throw new RuntimeException("资源扫描过程中存在重复资源!\n已存在资源:" + alreadyFlag + "\n新资源为: " + resourceDefinition);
}
- resourceDefinitions.put(resourceDefinition.getCode(), resourceDefinition);
+ resourceDefinitions.put(resourceDefinition.getResourceCode(), resourceDefinition);
urlDefineResources.put(resourceDefinition.getUrl(), resourceDefinition);
// 存储模块资源
Map modularResources = modularResourceDefinitions.get(StrUtil.toUnderlineCase(resourceDefinition.getModularCode()));
if (modularResources == null) {
modularResources = new HashMap<>();
- modularResources.put(resourceDefinition.getCode(), resourceDefinition);
+ modularResources.put(resourceDefinition.getResourceCode(), resourceDefinition);
modularResourceDefinitions.put(StrUtil.toUnderlineCase(resourceDefinition.getModularCode()), modularResources);
} else {
- modularResources.put(resourceDefinition.getCode(), resourceDefinition);
+ modularResources.put(resourceDefinition.getResourceCode(), resourceDefinition);
}
// 添加资源code-中文名称字典
- this.bindResourceName(resourceDefinition.getCode(), resourceDefinition.getName());
+ this.bindResourceName(resourceDefinition.getResourceCode(), resourceDefinition.getResourceName());
}
}
}
diff --git a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/controller/ResourceController.java b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/controller/ResourceController.java
index 303f2ada0..6472b3629 100644
--- a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/controller/ResourceController.java
+++ b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/controller/ResourceController.java
@@ -2,13 +2,17 @@ package cn.stylefeng.roses.kernel.resource.modular.controller;
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
+import cn.stylefeng.roses.kernel.resource.api.pojo.resource.ResourceDefinition;
import cn.stylefeng.roses.kernel.resource.modular.entity.SysResource;
+import cn.stylefeng.roses.kernel.resource.modular.pojo.ResourceTreeNode;
import cn.stylefeng.roses.kernel.resource.modular.service.SysResourceService;
+import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.system.pojo.resource.request.ResourceRequest;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@@ -50,4 +54,28 @@ public class ResourceController {
return new SuccessResponseData(menuResourceList);
}
+ /**
+ * 获取资源树列表,用于接口文档页面
+ *
+ * @author fengshuonan
+ * @date 2020/12/18 15:50
+ */
+ @GetResource(name = "获取资源树列表,用于接口文档页面", path = "/resource/getTree", requiredLogin = false, requiredPermission = false)
+ public ResponseData getTree() {
+ List resourceTree = sysResourceService.getResourceTree();
+ return new SuccessResponseData(resourceTree);
+ }
+
+ /**
+ * 获取接口详情
+ *
+ * @author fengshuonan
+ * @date 2020/12/18 15:50
+ */
+ @GetResource(name = "获取接口详情", path = "/resource/getDetail", requiredLogin = false, requiredPermission = false)
+ public ResponseData getResourceDetail(@Validated(BaseRequest.detail.class) ResourceRequest resourceRequest) {
+ ResourceDefinition resourceDetail = sysResourceService.getResourceDetail(resourceRequest);
+ return new SuccessResponseData(resourceDetail);
+ }
+
}
diff --git a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/entity/SysResource.java b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/entity/SysResource.java
index 04f6e0e4b..b0345b3cd 100644
--- a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/entity/SysResource.java
+++ b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/entity/SysResource.java
@@ -21,8 +21,8 @@ public class SysResource extends BaseEntity {
/**
* 资源id
*/
- @TableId("id")
- private String id;
+ @TableId("resource_id")
+ private Long resourceId;
/**
* 应用编码
@@ -33,14 +33,14 @@ public class SysResource extends BaseEntity {
/**
* 资源编码
*/
- @TableField("code")
- private String code;
+ @TableField("resource_code")
+ private String resourceCode;
/**
* 资源名称
*/
- @TableField("name")
- private String name;
+ @TableField("resource_name")
+ private String resourceName;
/**
* 项目编码
@@ -91,19 +91,13 @@ public class SysResource extends BaseEntity {
private String httpMethod;
/**
- * 是否是方法(Y-页面,N-API接口)
- */
- @TableField("menu_flag")
- private String menuFlag;
-
- /**
- * 是否需要登录(Y-是,N-否)
+ * 是否需要登录:Y-是,N-否
*/
@TableField("required_login_flag")
private String requiredLoginFlag;
/**
- * 是否需要鉴权(Y-是,N-否)
+ * 是否需要鉴权:Y-是,N-否
*/
@TableField("required_permission_flag")
private String requiredPermissionFlag;
diff --git a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/factory/ResourceFactory.java b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/factory/ResourceFactory.java
index e23c30599..f2fec0c80 100644
--- a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/factory/ResourceFactory.java
+++ b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/factory/ResourceFactory.java
@@ -30,21 +30,15 @@ public class ResourceFactory {
public static SysResource createResource(ResourceDefinition resourceDefinition) {
SysResource resource = new SysResource();
BeanUtils.copyProperties(resourceDefinition, resource);
- resource.setId(resourceDefinition.getCode());
+ resource.setResourceCode(resourceDefinition.getResourceCode());
- if (resourceDefinition.getMenuFlag()) {
- resource.setMenuFlag(YesOrNotEnum.Y.name());
- } else {
- resource.setMenuFlag(YesOrNotEnum.N.name());
- }
-
- if (resourceDefinition.getRequiredLogin()) {
+ if (resourceDefinition.getRequiredLoginFlag()) {
resource.setRequiredLoginFlag(YesOrNotEnum.Y.name());
} else {
resource.setRequiredLoginFlag(YesOrNotEnum.N.name());
}
- if (resourceDefinition.getRequiredPermission()) {
+ if (resourceDefinition.getRequiredPermissionFlag()) {
resource.setRequiredPermissionFlag(YesOrNotEnum.Y.name());
} else {
resource.setRequiredPermissionFlag(YesOrNotEnum.N.name());
@@ -56,13 +50,13 @@ public class ResourceFactory {
}
// 转化接口参数的字段描述
- if (ObjectUtil.isNotEmpty(resourceDefinition.getParamFieldMetadata())) {
- resource.setParamFieldDescriptions(JSON.toJSONString(resourceDefinition.getParamFieldMetadata(), SerializerFeature.WriteClassName));
+ if (ObjectUtil.isNotEmpty(resourceDefinition.getParamFieldDescriptions())) {
+ resource.setParamFieldDescriptions(JSON.toJSONString(resourceDefinition.getParamFieldDescriptions(), SerializerFeature.WriteClassName));
}
// 转化接口返回结果的字段描述
- if (ObjectUtil.isNotEmpty(resourceDefinition.getResponseFieldMetadata())) {
- resource.setResponseFieldDescriptions(JSON.toJSONString(resourceDefinition.getResponseFieldMetadata(), SerializerFeature.WriteClassName));
+ if (ObjectUtil.isNotEmpty(resourceDefinition.getResponseFieldDescriptions())) {
+ resource.setResponseFieldDescriptions(JSON.toJSONString(resourceDefinition.getResponseFieldDescriptions(), SerializerFeature.WriteClassName));
}
return resource;
@@ -82,10 +76,10 @@ public class ResourceFactory {
BeanUtil.copyProperties(sysResource, resourceDefinition, CopyOptions.create().ignoreError());
// 设置是否需要登录标识,Y为需要登录
- resourceDefinition.setRequiredLogin(YesOrNotEnum.Y.name().equals(sysResource.getRequiredLoginFlag()));
+ resourceDefinition.setRequiredLoginFlag(YesOrNotEnum.Y.name().equals(sysResource.getRequiredLoginFlag()));
// 设置是否需要权限认证标识,Y为需要权限认证
- resourceDefinition.setRequiredPermission(YesOrNotEnum.Y.name().equals(sysResource.getRequiredPermissionFlag()));
+ resourceDefinition.setRequiredPermissionFlag(YesOrNotEnum.Y.name().equals(sysResource.getRequiredPermissionFlag()));
// 转化校验组
if (ObjectUtil.isNotEmpty(sysResource.getValidateGroups())) {
@@ -94,12 +88,12 @@ public class ResourceFactory {
// 转化接口参数的字段描述
if (ObjectUtil.isNotEmpty(sysResource.getParamFieldDescriptions())) {
- resourceDefinition.setParamFieldMetadata(JSON.parseObject(sysResource.getParamFieldDescriptions(), Set.class, Feature.SupportAutoType));
+ resourceDefinition.setParamFieldDescriptions(JSON.parseObject(sysResource.getParamFieldDescriptions(), Set.class, Feature.SupportAutoType));
}
// 转化接口返回结果的字段描述
if (ObjectUtil.isNotEmpty(sysResource.getResponseFieldDescriptions())) {
- resourceDefinition.setResponseFieldMetadata(JSON.parseObject(sysResource.getResponseFieldDescriptions(), Set.class, Feature.SupportAutoType));
+ resourceDefinition.setResponseFieldDescriptions(JSON.parseObject(sysResource.getResponseFieldDescriptions(), Set.class, Feature.SupportAutoType));
}
return resourceDefinition;
diff --git a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/mapper/mapping/SysResourceMapper.xml b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/mapper/mapping/SysResourceMapper.xml
index 8618cf6cd..8d3bf96bf 100644
--- a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/mapper/mapping/SysResourceMapper.xml
+++ b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/mapper/mapping/SysResourceMapper.xml
@@ -2,27 +2,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/service/impl/SysResourceServiceImpl.java b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/service/impl/SysResourceServiceImpl.java
index 7056f218f..867a7fd61 100644
--- a/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/service/impl/SysResourceServiceImpl.java
+++ b/kernel-s-system/system-business-resource/src/main/java/cn/stylefeng/roses/kernel/resource/modular/service/impl/SysResourceServiceImpl.java
@@ -60,18 +60,15 @@ public class SysResourceServiceImpl extends ServiceImpl wrapper = createWrapper(resourceRequest);
- // 查询为菜单的
- wrapper.eq(SysResource::getMenuFlag, YesOrNotEnum.Y.getCode());
-
// 只查询code和name
- wrapper.select(SysResource::getCode, SysResource::getName);
+ wrapper.select(SysResource::getResourceCode, SysResource::getResourceName);
List menuResourceList = this.list(wrapper);
// 增加返回虚拟菜单的情况
SysResource sysResource = new SysResource();
- sysResource.setCode("");
- sysResource.setName("虚拟目录(空)");
+ sysResource.setResourceCode("");
+ sysResource.setResourceName("虚拟目录(空)");
menuResourceList.add(0, sysResource);
return menuResourceList;
@@ -89,7 +86,7 @@ public class SysResourceServiceImpl extends ServiceImpl sysResourceLambdaQueryWrapper = new LambdaQueryWrapper<>();
- sysResourceLambdaQueryWrapper.select(SysResource::getAppCode, SysResource::getModularCode, SysResource::getModularName, SysResource::getCode, SysResource::getUrl, SysResource::getName);
+ sysResourceLambdaQueryWrapper.select(SysResource::getAppCode, SysResource::getModularCode, SysResource::getModularName, SysResource::getResourceCode, SysResource::getUrl, SysResource::getResourceName);
List allResource = this.list(sysResourceLambdaQueryWrapper);
// 2. 按应用和模块编码设置map
@@ -102,7 +99,7 @@ public class SysResourceServiceImpl extends ServiceImpl sysResourceLambdaQueryWrapper = new LambdaQueryWrapper<>();
- sysResourceLambdaQueryWrapper.eq(SysResource::getCode, resourceRequest.getResourceCode());
+ sysResourceLambdaQueryWrapper.eq(SysResource::getResourceCode, resourceRequest.getResourceCode());
SysResource sysResource = this.getOne(sysResourceLambdaQueryWrapper);
if (sysResource != null) {
return ResourceFactory.createResourceDefinition(sysResource);
@@ -161,15 +158,11 @@ public class SysResourceServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.in(SysResource::getId, resourceIds);
+ queryWrapper.in(SysResource::getResourceId, resourceIds);
// 获取资源详情
List list = this.list(queryWrapper);
@@ -210,7 +203,7 @@ public class SysResourceServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.in(SysResource::getId, resourceIds);
+ queryWrapper.in(SysResource::getResourceId, resourceIds);
queryWrapper.select(SysResource::getUrl);
// 获取资源详情
@@ -235,12 +228,7 @@ public class SysResourceServiceImpl extends ServiceImpl