From 625a92ce8ecff9abf6c3eb243e944ead484452dd Mon Sep 17 00:00:00 2001
From: lorne <1991wangliang@gmail.com>
Date: Mon, 25 May 2026 20:10:02 +0800
Subject: [PATCH 01/10] add GroovyMetadata
---
.../example-app-cmd-domain/pom.xml | 2 +-
.../example-app/example-app-cmd-meta/pom.xml | 2 +-
example/example-app/example-app-query/pom.xml | 2 +-
example/example-app/pom.xml | 2 +-
.../example-domain-leave/pom.xml | 2 +-
.../example-domain-user/pom.xml | 2 +-
example/example-domain/pom.xml | 2 +-
.../example-infra/example-infra-flow/pom.xml | 2 +-
.../example-infra/example-infra-jpa/pom.xml | 2 +-
.../example-infra-security/pom.xml | 2 +-
example/example-infra/pom.xml | 2 +-
example/example-interface/pom.xml | 2 +-
example/example-server/pom.xml | 2 +-
example/pom.xml | 2 +-
pom.xml | 2 +-
springboot-starter-data-authorization/pom.xml | 2 +-
springboot-starter-data-fast/pom.xml | 2 +-
springboot-starter-flow/pom.xml | 2 +-
springboot-starter-security/pom.xml | 2 +-
springboot-starter/pom.xml | 2 +-
.../script/GroovyScriptRunningContext.java | 12 +--
.../script/annotation/ScriptFunction.java | 33 ++++++
.../script/annotation/ScriptType.java | 29 +++++
.../framework/script/meta/GroovyFunction.java | 45 ++++++++
.../framework/script/meta/GroovyMetadata.java | 53 +++++++++
.../framework/script/meta/GroovyType.java | 89 +++++++++++++++
...eBindObject.java => GroovyBindObject.java} | 9 +-
.../script/request/GroovyMethodScript.java | 59 ----------
.../script/request/GroovyRunningScript.java | 102 ++++++++++++++++++
.../service/GroovyMetadataParserService.java | 74 +++++++++++++
.../script/service/GroovyTypeParser.java | 93 ++++++++++++++++
.../script/service/TempGroovyTypeCache.java | 57 ++++++++++
.../GroovyScriptRunningContextTest.java | 28 ++++-
.../script/request/MyScriptRequest.java | 39 +++++++
34 files changed, 673 insertions(+), 89 deletions(-)
create mode 100644 springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptFunction.java
create mode 100644 springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptType.java
create mode 100644 springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyFunction.java
create mode 100644 springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyMetadata.java
create mode 100644 springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyType.java
rename springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/{RuntimeBindObject.java => GroovyBindObject.java} (65%)
delete mode 100644 springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyMethodScript.java
create mode 100644 springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyRunningScript.java
create mode 100644 springboot-starter/src/main/java/com/codingapi/springboot/framework/script/service/GroovyMetadataParserService.java
create mode 100644 springboot-starter/src/main/java/com/codingapi/springboot/framework/script/service/GroovyTypeParser.java
create mode 100644 springboot-starter/src/main/java/com/codingapi/springboot/framework/script/service/TempGroovyTypeCache.java
create mode 100644 springboot-starter/src/test/java/com/codingapi/springboot/framework/script/request/MyScriptRequest.java
diff --git a/example/example-app/example-app-cmd-domain/pom.xml b/example/example-app/example-app-cmd-domain/pom.xml
index c0698a4c..cdbea2e3 100644
--- a/example/example-app/example-app-cmd-domain/pom.xml
+++ b/example/example-app/example-app-cmd-domain/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-app
- 3.4.44
+ 3.4.45
../pom.xml
diff --git a/example/example-app/example-app-cmd-meta/pom.xml b/example/example-app/example-app-cmd-meta/pom.xml
index 66f5138c..6c9b04b3 100644
--- a/example/example-app/example-app-cmd-meta/pom.xml
+++ b/example/example-app/example-app-cmd-meta/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-app
- 3.4.44
+ 3.4.45
../pom.xml
diff --git a/example/example-app/example-app-query/pom.xml b/example/example-app/example-app-query/pom.xml
index ac105c9b..0645e7ee 100644
--- a/example/example-app/example-app-query/pom.xml
+++ b/example/example-app/example-app-query/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-app
- 3.4.44
+ 3.4.45
../pom.xml
diff --git a/example/example-app/pom.xml b/example/example-app/pom.xml
index f0841b3e..9f076296 100644
--- a/example/example-app/pom.xml
+++ b/example/example-app/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-example
- 3.4.44
+ 3.4.45
../pom.xml
pom
diff --git a/example/example-domain/example-domain-leave/pom.xml b/example/example-domain/example-domain-leave/pom.xml
index feca9e30..d7c2ada9 100644
--- a/example/example-domain/example-domain-leave/pom.xml
+++ b/example/example-domain/example-domain-leave/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-domain
- 3.4.44
+ 3.4.45
../pom.xml
diff --git a/example/example-domain/example-domain-user/pom.xml b/example/example-domain/example-domain-user/pom.xml
index c03892c6..2f188b31 100644
--- a/example/example-domain/example-domain-user/pom.xml
+++ b/example/example-domain/example-domain-user/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-domain
- 3.4.44
+ 3.4.45
../pom.xml
diff --git a/example/example-domain/pom.xml b/example/example-domain/pom.xml
index 64b78ab4..98a5ca27 100644
--- a/example/example-domain/pom.xml
+++ b/example/example-domain/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
springboot-example
- 3.4.44
+ 3.4.45
../pom.xml
4.0.0
diff --git a/example/example-infra/example-infra-flow/pom.xml b/example/example-infra/example-infra-flow/pom.xml
index 7c6f1875..ef2c201d 100644
--- a/example/example-infra/example-infra-flow/pom.xml
+++ b/example/example-infra/example-infra-flow/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
example-infra
- 3.4.44
+ 3.4.45
../pom.xml
diff --git a/example/example-infra/example-infra-jpa/pom.xml b/example/example-infra/example-infra-jpa/pom.xml
index 2d561e57..c6e9ba9d 100644
--- a/example/example-infra/example-infra-jpa/pom.xml
+++ b/example/example-infra/example-infra-jpa/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
example-infra
- 3.4.44
+ 3.4.45
../pom.xml
diff --git a/example/example-infra/example-infra-security/pom.xml b/example/example-infra/example-infra-security/pom.xml
index f1a1c3c2..33fa1f61 100644
--- a/example/example-infra/example-infra-security/pom.xml
+++ b/example/example-infra/example-infra-security/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-infra
- 3.4.44
+ 3.4.45
../pom.xml
diff --git a/example/example-infra/pom.xml b/example/example-infra/pom.xml
index 36605591..ce319bb6 100644
--- a/example/example-infra/pom.xml
+++ b/example/example-infra/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-example
- 3.4.44
+ 3.4.45
../pom.xml
pom
diff --git a/example/example-interface/pom.xml b/example/example-interface/pom.xml
index 5f23d1e0..270dfbed 100644
--- a/example/example-interface/pom.xml
+++ b/example/example-interface/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-example
- 3.4.44
+ 3.4.45
example-interface
diff --git a/example/example-server/pom.xml b/example/example-server/pom.xml
index e6a43cd7..a62efec3 100644
--- a/example/example-server/pom.xml
+++ b/example/example-server/pom.xml
@@ -5,7 +5,7 @@
springboot-example
com.codingapi.springboot
- 3.4.44
+ 3.4.45
4.0.0
diff --git a/example/pom.xml b/example/pom.xml
index f73e7ee6..cc114850 100644
--- a/example/pom.xml
+++ b/example/pom.xml
@@ -19,7 +19,7 @@
springboot-example
- 3.4.44
+ 3.4.45
springboot-example
springboot-example project for Spring Boot
diff --git a/pom.xml b/pom.xml
index 2fc26ce5..ecbbd600 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
com.codingapi.springboot
springboot-parent
- 3.4.44
+ 3.4.45
https://github.com/codingapi/springboot-framewrok
springboot-parent
diff --git a/springboot-starter-data-authorization/pom.xml b/springboot-starter-data-authorization/pom.xml
index d89f6d06..fdcccbc7 100644
--- a/springboot-starter-data-authorization/pom.xml
+++ b/springboot-starter-data-authorization/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-parent
- 3.4.44
+ 3.4.45
springboot-starter-data-authorization
diff --git a/springboot-starter-data-fast/pom.xml b/springboot-starter-data-fast/pom.xml
index 9f44ba99..6fe6420c 100644
--- a/springboot-starter-data-fast/pom.xml
+++ b/springboot-starter-data-fast/pom.xml
@@ -5,7 +5,7 @@
springboot-parent
com.codingapi.springboot
- 3.4.44
+ 3.4.45
4.0.0
diff --git a/springboot-starter-flow/pom.xml b/springboot-starter-flow/pom.xml
index ef49d453..6e6a60a9 100644
--- a/springboot-starter-flow/pom.xml
+++ b/springboot-starter-flow/pom.xml
@@ -6,7 +6,7 @@
springboot-parent
com.codingapi.springboot
- 3.4.44
+ 3.4.45
springboot-starter-flow
diff --git a/springboot-starter-security/pom.xml b/springboot-starter-security/pom.xml
index 761cdbac..9b411bd8 100644
--- a/springboot-starter-security/pom.xml
+++ b/springboot-starter-security/pom.xml
@@ -6,7 +6,7 @@
springboot-parent
com.codingapi.springboot
- 3.4.44
+ 3.4.45
springboot-starter-security
diff --git a/springboot-starter/pom.xml b/springboot-starter/pom.xml
index 8181bd0d..eeae0aaa 100644
--- a/springboot-starter/pom.xml
+++ b/springboot-starter/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
springboot-parent
- 3.4.44
+ 3.4.45
springboot-starter
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyScriptRunningContext.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyScriptRunningContext.java
index f430dcb1..1bedd671 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyScriptRunningContext.java
+++ b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/GroovyScriptRunningContext.java
@@ -1,8 +1,8 @@
package com.codingapi.springboot.framework.script;
import com.codingapi.springboot.framework.crypto.SHA256;
-import com.codingapi.springboot.framework.script.request.RuntimeBindObject;
-import com.codingapi.springboot.framework.script.request.GroovyMethodScript;
+import com.codingapi.springboot.framework.script.request.GroovyBindObject;
+import com.codingapi.springboot.framework.script.request.GroovyRunningScript;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
@@ -99,7 +99,7 @@ public void compile(String script) {
* @param args 函数参数
* @return 返回数据
*/
- public T run(String method, String script, Class returnType, List binds, Object... args) {
+ public T run(String method, String script, Class returnType, List binds, Object... args) {
String key = SHA256.sha256(script);
Script runtime = this.cache.get(key);
if (runtime == null) {
@@ -108,8 +108,8 @@ public T run(String method, String script, Class returnType, List T run(String method, String script, Class returnType, Object... ar
* @param request 脚本参数
* @return 返回数据
*/
- public T run(GroovyMethodScript request) {
+ public T run(GroovyRunningScript request) {
return this.run(request.getMethod(),request.getScript(),request.getReturnType(),request.getBinds(),request.getParams());
}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptFunction.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptFunction.java
new file mode 100644
index 00000000..c2920ab4
--- /dev/null
+++ b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptFunction.java
@@ -0,0 +1,33 @@
+package com.codingapi.springboot.framework.script.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * 脚本函数对象定义
+ */
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface ScriptFunction {
+
+ /**
+ * 名称
+ */
+ String name();
+
+ /**
+ * 描述
+ */
+ String description() default "";
+
+ /**
+ * 参数对象
+ */
+ ScriptType[] requests() default {};
+
+ /**
+ * 返回数据类型
+ */
+ Class> returnType();
+
+}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptType.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptType.java
new file mode 100644
index 00000000..f89ae836
--- /dev/null
+++ b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/annotation/ScriptType.java
@@ -0,0 +1,29 @@
+package com.codingapi.springboot.framework.script.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * 脚本对象
+ */
+@Target({ElementType.TYPE,ElementType.METHOD,ElementType.FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface ScriptType {
+
+ /**
+ * 名称
+ */
+ String name() default "";
+
+ /**
+ * 描述
+ */
+ String description() default "";
+
+ /**
+ * 数据类型
+ */
+ Class> dataType();
+
+
+}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyFunction.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyFunction.java
new file mode 100644
index 00000000..6184ba5b
--- /dev/null
+++ b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyFunction.java
@@ -0,0 +1,45 @@
+package com.codingapi.springboot.framework.script.meta;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 脚本函数对象
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class GroovyFunction {
+
+ /**
+ * 对象访问名称
+ */
+ private String name;
+ /**
+ * 对象描述信息
+ */
+ private String description;
+ /**
+ * 返回类型
+ */
+ private GroovyType returnType;
+ /**
+ * 参数类型
+ */
+ private List requests;
+
+
+ public void addRequest(GroovyType request){
+ if(this.requests ==null){
+ this.requests = new ArrayList<>();
+ }
+ this.requests.add(request);
+ }
+
+}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyMetadata.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyMetadata.java
new file mode 100644
index 00000000..a6bf75f0
--- /dev/null
+++ b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyMetadata.java
@@ -0,0 +1,53 @@
+package com.codingapi.springboot.framework.script.meta;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * 脚本对象元数据结构
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class GroovyMetadata {
+
+ /**
+ * 请求参数
+ */
+ private List requests;
+
+ /**
+ * 绑定参数
+ */
+ private List binds;
+
+ /**
+ * 返回类型
+ */
+ private GroovyType returnType;
+
+
+ public void addRequest(GroovyType request){
+ if(this.requests==null){
+ this.requests = new ArrayList<>();
+ }
+ this.requests.add(request);
+ }
+
+
+ public void addBind(GroovyType bind){
+ if(this.binds==null){
+ this.binds = new ArrayList<>();
+ }
+ this.binds.add(bind);
+ }
+
+
+}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyType.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyType.java
new file mode 100644
index 00000000..0c23f9ab
--- /dev/null
+++ b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/meta/GroovyType.java
@@ -0,0 +1,89 @@
+package com.codingapi.springboot.framework.script.meta;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 脚本对象类型
+ */
+@Getter
+@AllArgsConstructor
+@NoArgsConstructor
+public class GroovyType {
+
+ /**
+ * 访问名称
+ */
+ @Setter
+ private String name;
+
+ /**
+ * 描述信息
+ */
+ @Setter
+ private String description;
+
+ /**
+ * 数据类型
+ */
+ @Setter
+ private Class> dataType;
+
+ /**
+ * 属性列表
+ */
+ private List fields;
+
+ /**
+ * 函数列表
+ */
+ private List functions;
+
+
+ public void initFields(){
+ if(this.fields ==null){
+ this.fields = new ArrayList<>();
+ }
+ }
+
+
+ public void initFunctions(){
+ if(this.functions==null){
+ this.functions = new ArrayList<>();
+ }
+ }
+
+ public void addFunction(GroovyFunction function){
+ if(this.functions==null){
+ this.functions = new ArrayList<>();
+ }
+
+ this.functions.add(function);
+ }
+
+
+ public void addField(GroovyType field){
+ if(this.fields ==null){
+ this.fields = new ArrayList<>();
+ }
+ this.fields.add(field);
+ }
+
+
+ /**
+ * 保留函数和属性
+ */
+ public GroovyType cacheFieldsAndMethods(){
+ GroovyType cache = new GroovyType();
+ cache.functions = this.functions;
+ cache.fields = this.fields;
+ cache.dataType = this.dataType;
+ return cache;
+ }
+
+}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/RuntimeBindObject.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyBindObject.java
similarity index 65%
rename from springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/RuntimeBindObject.java
rename to springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyBindObject.java
index 8797b1ba..aa518529 100644
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/RuntimeBindObject.java
+++ b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyBindObject.java
@@ -8,8 +8,15 @@
*/
@Getter
@AllArgsConstructor
-public class RuntimeBindObject {
+public class GroovyBindObject {
+ /**
+ * 绑定的访问对象
+ */
private String key;
+ /**
+ * 绑定的对象实例
+ */
private Object object;
+
}
diff --git a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyMethodScript.java b/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyMethodScript.java
deleted file mode 100644
index 3c92807a..00000000
--- a/springboot-starter/src/main/java/com/codingapi/springboot/framework/script/request/GroovyMethodScript.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.codingapi.springboot.framework.script.request;
-
-import lombok.Getter;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * 脚本执行对象
- *
- * @param 返回格式
- */
-@Getter
-public class GroovyMethodScript {
-
- private final String method;
-
- private final String script;
-
- private final Class returnType;
-
- private final List