Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
workflow-core
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
workflow-core
Commits
f5a40a4d
提交
f5a40a4d
authored
3月 17, 2021
作者:
黄夏豪
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
42c0fd43
4c5954c7
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
60 行增加
和
27 行删除
+60
-27
ApiController.java
...a/com/tykj/workflowcore/api/controller/ApiController.java
+7
-3
ApiInfo.java
src/main/java/com/tykj/workflowcore/api/entity/ApiInfo.java
+6
-0
EntityInfo.java
...ain/java/com/tykj/workflowcore/api/entity/EntityInfo.java
+2
-0
ApiService.java
...in/java/com/tykj/workflowcore/api/service/ApiService.java
+30
-18
SpringBeanService.java
.../com/tykj/workflowcore/api/service/SpringBeanService.java
+13
-4
ModelImpl.java
...tykj/workflowcore/model_layer/service/impl/ModelImpl.java
+2
-2
没有找到文件。
src/main/java/com/tykj/workflowcore/api/controller/ApiController.java
浏览文件 @
f5a40a4d
package
com
.
tykj
.
workflowcore
.
api
.
controller
;
import
com.tykj.workflowcore.api.annotations.Callable
;
import
com.tykj.workflowcore.api.annotations.CallableApi
;
import
com.tykj.workflowcore.api.entity.ApiInfo
;
import
com.tykj.workflowcore.api.entity.ClassInfo
;
import
com.tykj.workflowcore.api.entity.InvokeRequest
;
import
com.tykj.workflowcore.api.service.ApiService
;
...
...
@@ -21,16 +24,17 @@ public class ApiController {
this
.
apiService
=
apiService
;
}
@ApiOperation
(
value
=
"查询所有可调用函数信息"
)
@ApiOperation
(
value
=
"查询所有可调用函数信息"
)
@GetMapping
public
ResponseEntity
<
List
<
Class
Info
>>
findAll
()
{
public
ResponseEntity
<
List
<
Api
Info
>>
findAll
()
{
return
ResponseEntity
.
ok
(
apiService
.
findAll
());
}
@ApiOperation
(
value
=
"调用指定函数"
)
@PostMapping
public
void
invoke
(
@RequestBody
InvokeRequest
invokeRequest
)
{
apiService
.
invoke
(
invokeRequest
.
getClassName
(),
invokeRequest
.
getName
(),
invokeRequest
.
getParams
());
apiService
.
invoke
(
invokeRequest
.
getClassName
(),
invokeRequest
.
getName
(),
invokeRequest
.
getParams
());
}
}
src/main/java/com/tykj/workflowcore/api/entity/ApiInfo.java
浏览文件 @
f5a40a4d
...
...
@@ -16,10 +16,16 @@ public class ApiInfo {
@ApiModelProperty
(
value
=
"所属类名"
)
private
String
className
;
@ApiModelProperty
(
value
=
"方法名"
)
private
String
name
;
@ApiModelProperty
(
value
=
"参数信息"
)
private
List
<
EntityInfo
>
params
;
@ApiModelProperty
(
value
=
"返回信息"
)
private
EntityInfo
ret
;
@ApiModelProperty
(
value
=
"描述信息"
)
private
String
description
;
}
src/main/java/com/tykj/workflowcore/api/entity/EntityInfo.java
浏览文件 @
f5a40a4d
...
...
@@ -21,4 +21,6 @@ public class EntityInfo {
@ApiModelProperty
(
value
=
"变量信息"
)
private
List
<
EntityInfo
>
fields
;
@ApiModelProperty
(
value
=
"描述信息"
)
private
String
description
;
}
src/main/java/com/tykj/workflowcore/api/service/ApiService.java
浏览文件 @
f5a40a4d
...
...
@@ -4,11 +4,13 @@ import com.alibaba.fastjson.JSON;
import
com.tykj.workflowcore.api.annotations.Callable
;
import
com.tykj.workflowcore.api.annotations.CallableApi
;
import
com.tykj.workflowcore.api.entity.ApiInfo
;
import
com.tykj.workflowcore.api.entity.ClassInfo
;
import
com.tykj.workflowcore.api.entity.EntityInfo
;
import
com.tykj.workflowcore.api.entity.Parameter
;
import
com.tykj.workflowcore.base.util.ClassUtil
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.logging.log4j.util.Strings
;
import
org.springframework.stereotype.Service
;
import
java.lang.reflect.Field
;
...
...
@@ -18,7 +20,7 @@ import java.util.*;
import
java.util.stream.Collectors
;
import
static
java
.
lang
.
String
.
format
;
import
static
java
.
util
.
Objects
.
nonNull
;
@Slf4j
@Service
...
...
@@ -36,59 +38,68 @@ public class ApiService {
*
* @return 结构化列表数据,内容为带有指定注解的方法列表,也就是列出主项目中可调用的方法。
*/
public
List
<
Class
Info
>
findAll
()
{
public
List
<
Api
Info
>
findAll
()
{
//获取所有类
List
<
Class
<?>>
classes
=
ClassUtil
.
loadClassByLoader
(
getClass
().
getClassLoader
());
return
classes
.
stream
()
.
map
(
this
::
classInfo
)
.
flatMap
(
clz
->
classInfo
(
clz
).
stream
()
)
.
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toList
());
}
private
ClassInfo
classInfo
(
Class
<?>
clz
)
{
private
List
<
ApiInfo
>
classInfo
(
Class
<?>
clz
)
{
try
{
//确认Callable注解
if
(
clz
.
isAnnotationPresent
(
Callable
.
class
))
{
List
<
ApiInfo
>
apiInfos
=
Arrays
.
stream
(
clz
.
getMethods
())
.
map
(
this
::
apiInfo
)
return
Arrays
.
stream
(
clz
.
getMethods
())
.
map
(
method
->
apiInfo
(
clz
.
getName
(),
method
)
)
.
filter
(
Objects:
:
nonNull
)
.
collect
(
Collectors
.
toList
());
return
new
ClassInfo
(
clz
.
getName
(),
apiInfos
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
n
ull
;
return
n
ew
ArrayList
<>()
;
}
private
ApiInfo
apiInfo
(
Method
method
)
{
private
ApiInfo
apiInfo
(
String
className
,
Method
method
)
{
//确认CallableApi注解
if
(
method
.
isAnnotationPresent
(
CallableApi
.
class
))
{
List
<
EntityInfo
>
params
=
Arrays
.
stream
(
method
.
getParameters
())
.
map
(
parameter
->
entityInfo
(
parameter
.
getType
(),
parameter
.
getName
()))
.
map
(
parameter
->
entityInfo
(
parameter
.
getType
(),
parameter
.
getName
()
,
Strings
.
EMPTY
))
.
collect
(
Collectors
.
toList
());
EntityInfo
ret
=
entityInfo
(
method
.
getReturnType
(),
null
);
return
new
ApiInfo
(
method
.
getName
(),
params
,
ret
);
EntityInfo
ret
=
entityInfo
(
method
.
getReturnType
(),
Strings
.
EMPTY
,
Strings
.
EMPTY
);
ApiOperation
methodAnnotation
=
method
.
getAnnotation
(
ApiOperation
.
class
);
String
description
=
Strings
.
EMPTY
;
if
(
nonNull
(
methodAnnotation
))
{
description
=
methodAnnotation
.
notes
();
}
return
new
ApiInfo
(
className
,
method
.
getName
(),
params
,
ret
,
description
);
}
else
{
return
null
;
}
}
private
EntityInfo
entityInfo
(
Class
<?>
clz
,
String
name
)
{
String
classType
=
clz
.
getName
();
private
EntityInfo
entityInfo
(
Class
<?>
clz
,
String
name
,
String
description
)
{
String
classType
=
clz
.
get
Canonical
Name
();
List
<
EntityInfo
>
fields
=
new
ArrayList
<>();
if
(
isNotBasicClass
(
clz
))
{
for
(
Field
field
:
clz
.
getDeclaredFields
())
{
Class
<?>
fieldClass
=
field
.
getType
();
String
fieldName
=
field
.
getName
();
field
.
setAccessible
(
true
);
//读取swagger描述信息
ApiModelProperty
fieldAnnotation
=
field
.
getAnnotation
(
ApiModelProperty
.
class
);
if
(
nonNull
(
fieldAnnotation
))
{
description
=
fieldAnnotation
.
value
();
}
//确认类中是否嵌套了相同类型的字段 防止死循环
boolean
isDifferentClass
=
!
Objects
.
equals
(
clz
,
fieldClass
);
EntityInfo
fieldClassInfo
;
if
(
isDifferentClass
)
{
fieldClassInfo
=
entityInfo
(
fieldClass
,
fieldName
);
fieldClassInfo
=
entityInfo
(
fieldClass
,
fieldName
,
description
);
}
else
{
fieldClassInfo
=
new
EntityInfo
(
fieldClass
.
getSimpleName
(),
field
.
getName
(),
new
ArrayList
<>());
fieldClassInfo
=
new
EntityInfo
(
fieldClass
.
getSimpleName
(),
field
.
getName
(),
new
ArrayList
<>()
,
description
);
}
fields
.
add
(
fieldClassInfo
);
}
...
...
@@ -96,7 +107,8 @@ public class ApiService {
return
new
EntityInfo
(
classType
,
name
,
fields
fields
,
description
);
}
...
...
src/main/java/com/tykj/workflowcore/api/service/SpringBeanService.java
浏览文件 @
f5a40a4d
...
...
@@ -18,22 +18,31 @@ public class SpringBeanService implements ApplicationContextAware {
this
.
applicationContext
=
applicationContext
;
}
}
//获取applicationContext
/**
* 获取applicationContext
*/
public
ApplicationContext
getApplicationContext
()
{
return
this
.
applicationContext
;
}
//通过name获取 Bean.
/**
* 通过name获取 Bean.
*/
public
Object
getBean
(
String
name
){
return
getApplicationContext
().
getBean
(
name
);
}
//通过class获取Bean.
/**
* 通过class获取Bean.
*/
public
<
T
>
T
getBean
(
Class
<
T
>
clazz
){
return
getApplicationContext
().
getBean
(
clazz
);
}
//通过name,以及Clazz返回指定的Bean
/**
* 通过name,以及Clazz返回指定的Bean
*/
public
<
T
>
T
getBean
(
String
name
,
Class
<
T
>
clazz
){
return
getApplicationContext
().
getBean
(
name
,
clazz
);
}
...
...
src/main/java/com/tykj/workflowcore/model_layer/service/impl/ModelImpl.java
浏览文件 @
f5a40a4d
...
...
@@ -128,7 +128,7 @@ public class ModelImpl implements ModelService {
List
<
ColumnVO
>
dataList
=
tableVO
.
getDataList
();
TableInfo
tableInfo
=
new
TableInfo
();
tableInfo
.
setName
(
tableVO
.
getModelName
()
+
"_"
);
tableInfo
.
setName
(
tableVO
.
getModelName
());
tableInfo
.
setCnName
(
tableVO
.
getModelTitle
());
tableInfo
.
setXml
(
xmlMapping
);
tableInfo
.
setModelType
(
tableVO
.
getModelType
());
...
...
@@ -249,7 +249,7 @@ public class ModelImpl implements ModelService {
TableVO
tableVO
=
new
TableVO
();
String
className
=
getClassName
(
aClass
.
toString
());
//入表真实名称
String
realName
=
className
.
toLowerCase
()
+
"_model_test"
;
String
realName
=
className
.
toLowerCase
();
tableVO
.
setModelName
(
realName
);
//获得类中文描述
if
(
aClass
.
isAnnotationPresent
(
ApiModel
.
class
))
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论