Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
workflow-core
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
workflow-core
Commits
ba353842
提交
ba353842
authored
3月 10, 2021
作者:
HASEE
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
model layer 优化(1)扫描所有主系统Entity
上级
d02b152d
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
94 行增加
和
128 行删除
+94
-128
ModelImpl.java
...tykj/workflowcore/model_layer/service/impl/ModelImpl.java
+94
-1
ClassScanUtil.java
...om/tykj/workflowcore/model_layer/utils/ClassScanUtil.java
+0
-60
CreatTableUtil.java
...m/tykj/workflowcore/model_layer/utils/CreatTableUtil.java
+0
-67
没有找到文件。
src/main/java/com/tykj/workflowcore/model_layer/service/impl/ModelImpl.java
浏览文件 @
ba353842
...
...
@@ -3,6 +3,7 @@ package com.tykj.workflowcore.model_layer.service.impl;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan
;
import
com.tykj.workflowcore.model_layer.dao.ColumnInfoDao
;
import
com.tykj.workflowcore.model_layer.dao.TableInfoDao
;
import
com.tykj.workflowcore.model_layer.model.ColumnInfo
;
...
...
@@ -11,6 +12,8 @@ import com.tykj.workflowcore.model_layer.model.TableInfo;
import
com.tykj.workflowcore.model_layer.model.TableVO
;
import
com.tykj.workflowcore.model_layer.service.ModelService
;
import
com.tykj.workflowcore.model_layer.utils.CreatTableUtil
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
org.hibernate.Session
;
import
org.hibernate.internal.SessionImpl
;
...
...
@@ -24,15 +27,20 @@ import org.springframework.data.jpa.domain.Specification;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.persistence.Entity
;
import
javax.persistence.EntityManagerFactory
;
import
javax.persistence.criteria.*
;
import
java.lang.reflect.Field
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
static
com
.
tykj
.
workflowcore
.
model_layer
.
utils
.
CreatTableUtil
.
CreatTable
;
import
static
com
.
tykj
.
workflowcore
.
model_layer
.
utils
.
CreatTableUtil
.
getClassName
;
/**
* @ClassName MoedelImpl
...
...
@@ -117,7 +125,7 @@ public class ModelImpl implements ModelService {
@Override
public
TableVO
NewTable
(
TableVO
tableVO
)
{
String
XML_MAPPING
=
CreatTable
Util
.
CreatTable
(
tableVO
);
String
XML_MAPPING
=
CreatTable
(
tableVO
);
CreatTableUtil
creatTableUtil
=
new
CreatTableUtil
();
Session
session
=
creatTableUtil
.
getSession
(
entityManagerFactory
,
XML_MAPPING
);
...
...
@@ -231,4 +239,89 @@ public class ModelImpl implements ModelService {
newSession
.
saveOrUpdate
(
tableName
,
map
);
newSession
.
close
();
}
public
void
SwaggerScan
(
Class
<?>
aClass
)
{
if
(!
aClass
.
isAnnotationPresent
(
WorkFlowCoreNoScan
.
class
))
{
if
(
aClass
.
isAnnotationPresent
(
Entity
.
class
))
{
TableInfo
tableInfo
=
new
TableInfo
();
// tableInfo.setId(id);
TableVO
tableVO
=
new
TableVO
();
String
className
=
getClassName
(
aClass
.
toString
());
tableVO
.
setModelName
(
className
.
toLowerCase
()
+
"_model_test"
);
if
(
aClass
.
isAnnotationPresent
(
ApiModel
.
class
))
{
ApiModel
annotation
=
aClass
.
getAnnotation
(
ApiModel
.
class
);
StringBuilder
APiModelDocument
=
new
StringBuilder
();
if
(
annotation
.
value
()
!=
null
&&
!
annotation
.
value
().
equals
(
""
))
{
APiModelDocument
.
append
(
annotation
.
value
()
+
"|"
);
}
if
(
annotation
.
description
()
!=
null
&&
!
annotation
.
description
().
equals
(
""
))
{
APiModelDocument
.
append
(
annotation
.
description
()
+
"|"
);
}
tableVO
.
setModelTitle
(
APiModelDocument
.
toString
());
}
else
{
tableVO
.
setModelTitle
(
""
);
}
Field
[]
declaredFields
=
aClass
.
getDeclaredFields
();
java
.
lang
.
reflect
.
Type
genericType
=
null
;
List
<
ColumnVO
>
list
=
new
ArrayList
<>();
for
(
Field
declaredField
:
declaredFields
)
{
ColumnVO
columnVO
=
new
ColumnVO
();
genericType
=
declaredField
.
getGenericType
();
columnVO
.
setFiledType
(
genericType
.
toString
());
columnVO
.
setFieldName
(
getClassName
(
declaredField
.
toString
()));
if
(
declaredField
.
isAnnotationPresent
(
ApiModelProperty
.
class
))
{
ApiModelProperty
annotation
=
declaredField
.
getAnnotation
(
ApiModelProperty
.
class
);
StringBuilder
ApiModelPropertyDocument
=
new
StringBuilder
();
if
(
annotation
.
value
()
!=
null
&&
!
annotation
.
value
().
equals
(
""
))
{
ApiModelPropertyDocument
.
append
(
annotation
.
value
()
+
"|"
);
}
if
(
annotation
.
example
()
!=
null
&&
!
annotation
.
example
().
equals
(
""
))
{
ApiModelPropertyDocument
.
append
(
annotation
.
example
()
+
"|"
);
}
columnVO
.
setFiledDescription
(
ApiModelPropertyDocument
.
toString
());
}
else
{
columnVO
.
setFiledDescription
(
"无描述"
);
}
list
.
add
(
columnVO
);
}
tableVO
.
setDataList
(
list
);
String
xml
=
CreatTable
(
tableVO
);
tableInfo
.
setName
(
tableVO
.
getModelName
());
tableInfo
.
setCnName
(
tableVO
.
getModelTitle
());
tableInfo
.
setXML
(
xml
);
tableInfo
=
tableInfoDao
.
save
(
tableInfo
);
List
<
ColumnVO
>
dataList
=
tableVO
.
getDataList
();
for
(
ColumnVO
columnVO
:
dataList
)
{
ColumnInfo
columnInfo
=
new
ColumnInfo
();
columnInfo
.
setName
(
columnVO
.
getFieldName
());
columnInfo
.
setType
(
columnVO
.
getFiledType
());
columnInfo
.
setLength
(
columnVO
.
getFiledLength
());
columnInfo
.
setCnName
(
columnVO
.
getFiledDescription
());
if
(
genericType
.
toString
().
equals
(
"class java.lang.String"
)){
columnInfo
.
setLength
(
65535
);
}
else
if
(
genericType
.
toString
().
equals
(
"class java.lang.Integer"
)){
columnInfo
.
setLength
(
11
);
}
else
{
columnInfo
.
setLength
(
0
);
}
columnInfo
.
setDbName
(
className
);
columnInfo
.
setDbId
(
tableInfo
.
getId
());
columnInfoDao
.
save
(
columnInfo
);
}
}
}
}
}
src/main/java/com/tykj/workflowcore/model_layer/utils/ClassScanUtil.java
deleted
100644 → 0
浏览文件 @
d02b152d
package
com
.
tykj
.
workflowcore
.
model_layer
.
utils
;
import
sun.net.www.protocol.jar.JarURLConnection
;
import
java.io.File
;
import
java.io.FileFilter
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.net.URLDecoder
;
import
java.util.*
;
import
java.util.jar.JarEntry
;
import
java.util.jar.JarFile
;
/**
* @ClassName ClassScan
* @Description TODO
* @Author WWW
* @Date 2021/2/22 13:44
* @Version 1.0
*/
public
class
ClassScanUtil
{
private
void
loadClassByPath
(
String
root
,
String
path
,
List
<
Class
<?>>
list
,
ClassLoader
load
)
{
File
f
=
new
File
(
path
);
if
(
root
==
null
)
root
=
f
.
getPath
();
//判断是否是class文件
if
(
f
.
isFile
()
&&
f
.
getName
().
matches
(
"^.*\\.class$"
))
{
try
{
String
classPath
=
f
.
getPath
();
//截取出className 将路径分割符替换为.(windows是\ linux、mac是/)
String
className
=
classPath
.
substring
(
root
.
length
()
+
1
,
classPath
.
length
()
-
6
).
replace
(
'/'
,
'.'
).
replace
(
'\\'
,
'.'
);
list
.
add
(
load
.
loadClass
(
className
));
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
else
{
File
[]
fs
=
f
.
listFiles
();
if
(
fs
==
null
)
return
;
for
(
File
file
:
fs
)
{
loadClassByPath
(
root
,
file
.
getPath
(),
list
,
load
);
}
}
}
public
List
<
Class
<?>>
loadClassByLoader
(
ClassLoader
load
)
{
List
<
Class
<?>>
classes
=
new
ArrayList
<>();
try
{
Enumeration
<
URL
>
urls
=
load
.
getResources
(
""
);
//放所有类型
while
(
urls
.
hasMoreElements
())
{
URL
url
=
urls
.
nextElement
();
//文件类型(其实是文件夹)
if
(
url
.
getProtocol
().
equals
(
"file"
))
{
loadClassByPath
(
null
,
url
.
getPath
(),
classes
,
load
);
}
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
classes
;
}
}
src/main/java/com/tykj/workflowcore/model_layer/utils/CreatTableUtil.java
浏览文件 @
ba353842
...
...
@@ -78,74 +78,7 @@ public class CreatTableUtil {
return
newSession
;
}
public
TableInfo
SwaggerScan
(
Class
<?>
aClass
)
{
TableInfo
tableInfo
=
null
;
if
(!
aClass
.
isAnnotationPresent
(
WorkFlowCoreNoScan
.
class
)){
if
(
aClass
.
isAnnotationPresent
(
Entity
.
class
))
{
tableInfo
=
new
TableInfo
();
TableVO
tableVO
=
new
TableVO
();
String
className
=
getClassName
(
aClass
.
toString
());
tableVO
.
setModelName
(
className
.
toLowerCase
()+
"_ModelTest"
);
if
(
aClass
.
isAnnotationPresent
(
ApiModel
.
class
))
{
ApiModel
annotation
=
aClass
.
getAnnotation
(
ApiModel
.
class
);
StringBuilder
APiModelDocument
=
new
StringBuilder
();
if
(
annotation
.
value
()
!=
null
&&
!
annotation
.
value
().
equals
(
""
))
{
APiModelDocument
.
append
(
annotation
.
value
()+
"|"
);
}
if
(
annotation
.
description
()
!=
null
&&
!
annotation
.
description
().
equals
(
""
))
{
APiModelDocument
.
append
(
annotation
.
description
()
+
"|"
);
}
tableVO
.
setModelTitle
(
APiModelDocument
.
toString
());
}
else
{
tableVO
.
setModelTitle
(
""
);
}
Field
[]
declaredFields
=
aClass
.
getDeclaredFields
();
List
<
ColumnVO
>
list
=
new
ArrayList
<>();
for
(
Field
declaredField
:
declaredFields
)
{
ColumnVO
columnVO
=
new
ColumnVO
();
Type
genericType
=
declaredField
.
getGenericType
();
columnVO
.
setFiledType
(
genericType
.
toString
());
columnVO
.
setFieldName
(
getClassName
(
declaredField
.
toString
()));
if
(
declaredField
.
isAnnotationPresent
(
ApiModelProperty
.
class
))
{
ApiModelProperty
annotation
=
declaredField
.
getAnnotation
(
ApiModelProperty
.
class
);
StringBuilder
ApiModelPropertyDocument
=
new
StringBuilder
();
if
(
annotation
.
value
()
!=
null
&&
!
annotation
.
value
().
equals
(
""
))
{
ApiModelPropertyDocument
.
append
(
annotation
.
value
()
+
"|"
);
}
if
(
annotation
.
example
()
!=
null
&&
!
annotation
.
example
().
equals
(
""
))
{
ApiModelPropertyDocument
.
append
(
annotation
.
example
()
+
"|"
);
}
columnVO
.
setFiledDescription
(
ApiModelPropertyDocument
.
toString
());
}
else
{
columnVO
.
setFiledDescription
(
"无描述"
);
}
list
.
add
(
columnVO
);
}
tableVO
.
setDataList
(
list
);
String
xml
=
CreatTable
(
tableVO
);
tableInfo
.
setName
(
tableVO
.
getModelName
());
tableInfo
.
setCnName
(
tableVO
.
getModelTitle
());
tableInfo
.
setXML
(
xml
);
}
}
return
tableInfo
;
}
public
static
String
getClassName
(
String
aClass
){
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论