Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
workflow
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
2
议题
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄夏豪
workflow
Commits
a5d1214f
提交
a5d1214f
authored
4月 26, 2021
作者:
ww1xhqc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[数据模型] 修复扫描时多出id字段bug
上级
9b13f021
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
117 行增加
和
59 行删除
+117
-59
ModelImpl.java
...tykj/workflowcore/model_layer/service/impl/ModelImpl.java
+80
-50
ClassTypeLength.java
.../tykj/workflowcore/model_layer/utils/ClassTypeLength.java
+1
-1
CreateTableUtil.java
.../tykj/workflowcore/model_layer/utils/CreateTableUtil.java
+34
-2
WorkflowCoreApplicationTests.java
...a/com/tykj/workflowcore/WorkflowCoreApplicationTests.java
+2
-6
没有找到文件。
src/main/java/com/tykj/workflowcore/model_layer/service/impl/ModelImpl.java
浏览文件 @
a5d1214f
...
...
@@ -2,6 +2,7 @@ package com.tykj.workflowcore.model_layer.service.impl;
import
com.github.wenhao.jpa.PredicateBuilder
;
import
com.github.wenhao.jpa.Specifications
;
import
com.google.common.base.Strings
;
import
com.tykj.workflowcore.base.result.ApiException
;
import
com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan
;
import
com.tykj.workflowcore.model_layer.dao.ColumnInfoDao
;
...
...
@@ -104,13 +105,13 @@ public class ModelImpl implements ModelService {
return
tableInfoDao
.
findAll
(
and
.
build
());
}
private
PredicateBuilder
<
TableInfo
>
createPredicateBySearchTableInfoVo
(
SearchTableInfoVo
searchTableInfoVo
){
private
PredicateBuilder
<
TableInfo
>
createPredicateBySearchTableInfoVo
(
SearchTableInfoVo
searchTableInfoVo
)
{
PredicateBuilder
<
TableInfo
>
and
=
Specifications
.
and
();
if
(
searchTableInfoVo
!=
null
)
{
if
(
searchTableInfoVo
!=
null
)
{
and
.
like
(
searchTableInfoVo
.
getModelName
()
!=
null
&&
StringUtils
.
isNotEmpty
(
searchTableInfoVo
.
getModelName
()),
"modelName"
,
"%"
+
searchTableInfoVo
.
getModelName
()
+
"%"
);
and
.
like
(
searchTableInfoVo
.
getModelTitle
()
!=
null
&&
StringUtils
.
isNotEmpty
(
searchTableInfoVo
.
getModelTitle
()),
"modelTitle"
,
"%"
+
searchTableInfoVo
.
getModelTitle
()
+
"%"
);
and
.
in
(
searchTableInfoVo
.
getModelType
()
!=
null
&&
searchTableInfoVo
.
getModelType
().
length
>
0
,
"modelType"
,
searchTableInfoVo
.
getModelType
());
and
.
in
(
searchTableInfoVo
.
getIds
()
!=
null
&&
searchTableInfoVo
.
getIds
().
length
>
0
,
"id"
,
searchTableInfoVo
.
getIds
());
and
.
in
(
searchTableInfoVo
.
getModelType
()
!=
null
&&
searchTableInfoVo
.
getModelType
().
length
>
0
,
"modelType"
,
searchTableInfoVo
.
getModelType
());
and
.
in
(
searchTableInfoVo
.
getIds
()
!=
null
&&
searchTableInfoVo
.
getIds
().
length
>
0
,
"id"
,
searchTableInfoVo
.
getIds
());
}
return
and
;
}
...
...
@@ -307,10 +308,10 @@ public class ModelImpl implements ModelService {
if
(
aClass
.
isAnnotationPresent
(
ApiModel
.
class
))
{
ApiModel
annotation
=
aClass
.
getAnnotation
(
ApiModel
.
class
);
StringBuilder
apiModelDocument
=
new
StringBuilder
();
if
(
annotation
.
value
()
!=
null
&&
!
""
.
equals
(
annotation
.
value
()))
{
if
(
!
Strings
.
isNullOrEmpty
(
annotation
.
value
()))
{
apiModelDocument
.
append
(
annotation
.
value
()
+
"|"
);
}
if
(
annotation
.
description
()
!=
null
&&
!
""
.
equals
(
annotation
.
description
()))
{
if
(
!
Strings
.
isNullOrEmpty
(
annotation
.
description
()))
{
apiModelDocument
.
append
(
annotation
.
description
()
+
"|"
);
}
tableVO
.
setModelTitle
(
apiModelDocument
.
toString
());
...
...
@@ -322,8 +323,11 @@ public class ModelImpl implements ModelService {
java
.
lang
.
reflect
.
Type
genericType
;
List
<
ColumnVO
>
list
=
new
ArrayList
<>();
ColumnVO
primaryColumn
=
new
ColumnVO
();
;
List
<
ColumnVO
>
otherColumns
=
new
ArrayList
<>();
for
(
Field
declaredField
:
declaredFields
)
{
ColumnVO
columnVO
=
new
ColumnVO
();
//
ColumnVO columnVO = new ColumnVO();
if
(
declaredField
.
isAnnotationPresent
(
Transient
.
class
))
{
continue
;
}
...
...
@@ -331,31 +335,58 @@ public class ModelImpl implements ModelService {
genericType
=
declaredField
.
getGenericType
();
//是否主键
if
(
declaredField
.
isAnnotationPresent
(
javax
.
persistence
.
Id
.
class
))
{
columnVO
.
setPrimaryKey
(
0
);
}
columnVO
.
setFieldType
(
getTypeName
(
genericType
.
toString
()));
columnVO
.
setFieldName
(
getClassName
(
declaredField
.
toString
()));
columnVO
.
setFieldLength
(
setLength
(
genericType
.
toString
()));
//获得属性中文描述
if
(
declaredField
.
isAnnotationPresent
(
ApiModelProperty
.
class
))
{
ApiModelProperty
annotation
=
declaredField
.
getAnnotation
(
ApiModelProperty
.
class
);
StringBuilder
apiModelPropertyDocument
=
new
StringBuilder
();
if
(
annotation
.
value
()
!=
null
&&
!
""
.
equals
(
annotation
.
value
()))
{
apiModelPropertyDocument
.
append
(
annotation
.
value
()
+
"|"
);
}
if
(
annotation
.
example
()
!=
null
&&
!
""
.
equals
(
annotation
.
example
()))
{
apiModelPropertyDocument
.
append
(
annotation
.
example
()
+
"|"
);
primaryColumn
.
setPrimaryKey
(
0
);
primaryColumn
.
setFieldType
(
getTypeName
(
genericType
.
toString
()));
primaryColumn
.
setFieldName
(
getClassName
(
declaredField
.
toString
()));
// primaryColumn.setFieldLength(setLength(genericType.toString()));
//获得属性中文描述
if
(
declaredField
.
isAnnotationPresent
(
ApiModelProperty
.
class
))
{
ApiModelProperty
annotation
=
declaredField
.
getAnnotation
(
ApiModelProperty
.
class
);
StringBuilder
apiModelPropertyDocument
=
new
StringBuilder
();
if
(!
Strings
.
isNullOrEmpty
(
annotation
.
value
()))
{
apiModelPropertyDocument
.
append
(
annotation
.
value
()
+
"|"
);
}
if
(!
Strings
.
isNullOrEmpty
(
annotation
.
example
()))
{
apiModelPropertyDocument
.
append
(
annotation
.
example
()
+
"|"
);
}
primaryColumn
.
setFieldTitle
(
apiModelPropertyDocument
.
toString
());
}
else
{
primaryColumn
.
setFieldTitle
(
"(无描述)"
);
}
columnVO
.
setFieldTitle
(
apiModelPropertyDocument
.
toString
());
}
else
{
columnVO
.
setFieldTitle
(
"(无描述)"
);
ColumnVO
otherColumn
=
new
ColumnVO
();
otherColumn
.
setFieldType
(
getTypeName
(
genericType
.
toString
()));
otherColumn
.
setFieldName
(
getClassName
(
declaredField
.
toString
()));
// otherColumn.setFieldLength(setLength(genericType.toString()));
otherColumns
.
add
(
otherColumn
);
//获得属性中文描述
if
(
declaredField
.
isAnnotationPresent
(
ApiModelProperty
.
class
))
{
ApiModelProperty
annotation
=
declaredField
.
getAnnotation
(
ApiModelProperty
.
class
);
StringBuilder
apiModelPropertyDocument
=
new
StringBuilder
();
if
(!
Strings
.
isNullOrEmpty
(
annotation
.
value
()))
{
apiModelPropertyDocument
.
append
(
annotation
.
value
()
+
"|"
);
}
if
(!
Strings
.
isNullOrEmpty
(
annotation
.
example
()))
{
apiModelPropertyDocument
.
append
(
annotation
.
example
()
+
"|"
);
}
otherColumn
.
setFieldTitle
(
apiModelPropertyDocument
.
toString
());
}
else
{
otherColumn
.
setFieldTitle
(
"(无描述)"
);
}
}
list
.
add
(
columnVO
);
// columnVO.setFieldType(getTypeName(genericType.toString()));
// columnVO.setFieldName(getClassName(declaredField.toString()));
// columnVO.setFieldLength(setLength(genericType.toString()));
}
list
.
add
(
primaryColumn
);
list
.
addAll
(
otherColumns
);
tableVO
.
setDataList
(
list
);
String
xml
=
createTable
(
tableVO
);
//扫描的xml
String
xml
=
createTable
(
tableVO
.
getModelName
(),
primaryColumn
,
otherColumns
);
tableInfo
.
setModelName
(
tableVO
.
getModelName
());
tableInfo
.
setModelTitle
(
tableVO
.
getModelTitle
());
tableInfo
.
setXml
(
xml
);
...
...
@@ -363,21 +394,20 @@ public class ModelImpl implements ModelService {
//判断是否存在
if
(
checkRepeat
(
realName
))
{
tableInfo
=
tableInfoDao
.
save
(
tableInfo
);
List
<
ColumnVO
>
dataList
=
tableVO
.
getDataList
();
for
(
ColumnVO
columnVO
:
dataList
)
{
ColumnInfo
columnInfo
=
new
ColumnInfo
();
columnInfo
.
setFieldName
(
columnVO
.
getFieldName
());
columnInfo
.
setFieldType
(
columnVO
.
getFieldType
());
columnInfo
.
setFieldLength
(
columnVO
.
getFieldLength
());
columnInfo
.
setFieldTitle
(
columnVO
.
getFieldTitle
());
columnInfo
.
setPrimaryKey
(
columnVO
.
getPrimaryKey
());
columnInfo
.
setDbName
(
realName
);
columnInfo
.
setDbId
(
tableInfo
.
getId
());
columnInfoDao
.
save
(
columnInfo
);
}
}
else
{
tableInfo
=
tableInfoDao
.
findByModelName
(
tableInfo
.
getModelName
());
log
.
info
(
"{}已存在"
,
realName
);
}
List
<
ColumnVO
>
dataList
=
tableVO
.
getDataList
();
for
(
ColumnVO
columnVO
:
dataList
)
{
ColumnInfo
columnInfo
=
new
ColumnInfo
();
columnInfo
.
setFieldName
(
columnVO
.
getFieldName
());
columnInfo
.
setFieldType
(
columnVO
.
getFieldType
());
columnInfo
.
setFieldLength
(
columnVO
.
getFieldLength
());
columnInfo
.
setFieldTitle
(
columnVO
.
getFieldTitle
());
columnInfo
.
setPrimaryKey
(
columnVO
.
getPrimaryKey
());
columnInfo
.
setDbName
(
realName
);
columnInfo
.
setDbId
(
tableInfo
.
getId
());
columnInfoDao
.
save
(
columnInfo
);
log
.
warn
(
"{}已存在"
,
realName
);
}
}
}
...
...
@@ -469,14 +499,14 @@ public class ModelImpl implements ModelService {
.
collect
(
Collectors
.
toList
());
//根据ColumnInfo集合得出表实际改动的sql语句集合
List
<
String
>
sqls
=
getTableSqls
(
tableInfo
.
getModelName
(),
originalColumnInfos
,
currentColumnInfos
);
//执行sql语句
for
(
String
sql
:
sqls
)
{
System
.
out
.
println
(
sql
);
jdbcTemplate
.
execute
(
sql
);
//根据ColumnInfo集合得出表实际改动的sql语句集合
List
<
String
>
sqls
=
getTableSqls
(
tableInfo
.
getModelName
(),
originalColumnInfos
,
currentColumnInfos
);
//执行sql语句
for
(
String
sql
:
sqls
)
{
System
.
out
.
println
(
sql
);
jdbcTemplate
.
execute
(
sql
);
}
}
//重新保存字段信息
List
<
ColumnInfo
>
columnsForAdd
=
getColumnsForAdd
(
originalColumnInfos
,
currentColumnInfos
);
...
...
@@ -493,7 +523,7 @@ public class ModelImpl implements ModelService {
}
}
if
(
modelType
.
equals
(
ModelType
.
BASICS_EXTENSION
))
{
if
(
modelType
.
equals
(
ModelType
.
BASICS_EXTENSION
))
{
columnInfoDao
.
deleteAllByDbId
(
updateTableInfoVO
.
getDbId
());
List
<
ColumnInfo
>
dataList
=
updateTableInfoVO
.
getTableVO
().
getDataList
().
stream
()
.
map
(
columnVO
->
columnInfo
(
tableInfo
.
getId
(),
tableInfo
.
getModelName
(),
columnVO
))
...
...
@@ -599,7 +629,7 @@ public class ModelImpl implements ModelService {
}
else
{
TableInfo
tableInfo
=
byId
.
get
();
Integer
modelType
=
tableInfo
.
getModelType
();
if
(
modelType
.
equals
(
ModelType
.
BUSINESS
)
||
modelType
.
equals
(
ModelType
.
BASICS_EXTENSION
))
{
if
(
modelType
.
equals
(
ModelType
.
BUSINESS
)
||
modelType
.
equals
(
ModelType
.
BASICS_EXTENSION
))
{
tableInfoDao
.
deleteById
(
delTableVO
.
getId
());
List
<
ColumnInfo
>
allByDbId
=
columnInfoDao
.
findAllByDbId
(
delTableVO
.
getId
());
columnInfoDao
.
deleteInBatch
(
allByDbId
);
...
...
src/main/java/com/tykj/workflowcore/model_layer/utils/ClassTypeLength.java
浏览文件 @
a5d1214f
...
...
@@ -23,7 +23,7 @@ public class ClassTypeLength {
}
else
if
(
Double
.
equals
(
genericType
))
{
length
=
10
;
}
else
{
length
=
0
;
length
=
1
;
}
return
length
;
}
...
...
src/main/java/com/tykj/workflowcore/model_layer/utils/CreateTableUtil.java
浏览文件 @
a5d1214f
...
...
@@ -59,12 +59,13 @@ public class CreateTableUtil {
" <class entity-name=\""
+
tableVO
.
getModelName
()
+
"\" table=\""
+
tableVO
.
getModelName
()
+
"\">\n"
;
xmlMapping
+=
" <id name=\"id\" type=\"java.lang.Integer\" length=\"11\" unsaved-value=\"null\" >\n"
+
" <generator class=\"identity\" />\n"
+
" </id>"
;
for
(
ColumnVO
columnVO
:
dataList
)
{
xmlMapping
+=
" <property type=\""
+
columnVO
.
getFieldType
()
+
"\" name=\""
+
columnVO
.
getFieldName
()
+
"\" length=\""
+
columnVO
.
getFieldLength
()
+
"
\n
<property type=\""
+
columnVO
.
getFieldType
()
+
"\" name=\""
+
columnVO
.
getFieldName
()
+
"\" length=\""
+
columnVO
.
getFieldLength
()
+
"\" column=\""
+
columnVO
.
getFieldName
()
+
"\"/>\n"
;
}
...
...
@@ -74,6 +75,37 @@ public class CreateTableUtil {
}
public
static
String
createTable
(
String
entityName
,
ColumnVO
primaryColumn
,
List
<
ColumnVO
>
dataList
)
{
// 1sql-type="text" string 转为text文本,2长度超过会自动转换
// List<ColumnVO> dataList = tableVO.getDataList();
String
xmlMapping
=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+
"<!DOCTYPE hibernate-mapping PUBLIC\n"
+
" \"-//Hibernate/Hibernate Mapping DTD 3.0//EN\"\n"
+
" \"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd\">\n"
+
"<hibernate-mapping>\n"
+
" <class entity-name=\""
+
entityName
+
"\" table=\""
+
entityName
+
"\">\n"
;
xmlMapping
+=
" <id name=\""
+
primaryColumn
.
getFieldName
()+
"\" type=\""
+
primaryColumn
.
getFieldType
()+
"\" unsaved-value=\"null\" >\n"
+
" </id>"
;
for
(
ColumnVO
columnVO
:
dataList
)
{
xmlMapping
+=
"\n <property type=\""
+
columnVO
.
getFieldType
()
+
"\" name=\""
+
columnVO
.
getFieldName
()
+
"\" column=\""
+
columnVO
.
getFieldName
()
+
"\"/>\n"
;
// xmlMapping +=
// "\n <property type=\"" + columnVO.getFieldType() + "\" name=\"" + columnVO.getFieldName() + "\" length=\"" + columnVO.getFieldLength() +
// "\" column=\"" + columnVO.getFieldName() + "\"/>\n";
}
xmlMapping
+=
" </class>\n"
+
"</hibernate-mapping>"
;
return
xmlMapping
;
}
public
static
String
getClassName
(
String
aClass
)
{
...
...
src/main/test/java/com/tykj/workflowcore/WorkflowCoreApplicationTests.java
浏览文件 @
a5d1214f
...
...
@@ -517,17 +517,13 @@ class WorkflowCoreApplicationTests {
@Test
public
void
complex
()
{
ArrayList
<
QueryCondition
>
queryConditions
=
Lists
.
newArrayList
(
new
QueryCondition
(
"
i
d"
,
"="
,
"1"
)
new
QueryCondition
(
"
testI
d"
,
"="
,
"1"
)
// new QueryCondition("type", "=", "'1'")
);
List
<
Map
<
String
,
Object
>>
list
=
modelService
.
complexQuery
(
"
nw_history
"
,
queryConditions
);
List
<
Map
<
String
,
Object
>>
list
=
modelService
.
complexQuery
(
"
TestScan
"
,
queryConditions
);
for
(
Map
<
String
,
Object
>
map
:
list
)
{
System
.
out
.
println
(
map
);
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论