Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdata
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdata
提交
b413a71c
提交
b413a71c
编写于
8月 13, 2021
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
提交
上级
ac9d86f8
变更
3
展开全部
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
427 行增加
和
11 行删除
+427
-11
POSchema.java
...re/src/main/java/cn/ibizlab/core/data/model/POSchema.java
+339
-0
PojoSchema.java
.../src/main/java/cn/ibizlab/core/data/model/PojoSchema.java
+34
-2
TransUtils.java
.../src/main/java/cn/ibizlab/core/data/model/TransUtils.java
+54
-9
未找到文件。
ibzdata-core/src/main/java/cn/ibizlab/core/data/model/POSchema.java
0 → 100644
浏览文件 @
b413a71c
package
cn
.
ibizlab
.
core
.
data
.
model
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
org.apache.ibatis.mapping.VendorDatabaseIdProvider
;
import
org.springframework.util.StringUtils
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
@Getter
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_EMPTY
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
POSchema
{
private
String
name
;
private
String
remarks
;
private
String
dsType
;
private
List
<
Column
>
columns
;
private
List
<
ForeignKeyConstraint
>
foreignKeyConstraints
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
Map
<
String
,
Column
>
columnMaps
;
public
Map
<
String
,
Column
>
getColumnMaps
()
{
if
(
columns
!=
null
&&
columnMaps
==
null
)
{
columnMaps
=
new
LinkedHashMap
<>();
columns
.
forEach
(
column
->
{
columnMaps
.
put
(
column
.
getName
().
toLowerCase
(),
column
);
if
((!
StringUtils
.
isEmpty
(
column
.
getAlias
()))&&
column
.
getAlias
().
equalsIgnoreCase
(
column
.
getName
()))
columnMaps
.
put
(
column
.
getAlias
().
toLowerCase
(),
column
);
});
}
return
columnMaps
;
}
public
Column
getColumn
(
String
name
)
{
if
(
getColumnMaps
()!=
null
)
{
return
columnMaps
.
get
(
name
.
toLowerCase
());
}
return
null
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
Column
lastModifyColumn
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Column
getLastModifyField
()
{
if
(
columns
!=
null
&&
lastModifyColumn
==
null
)
for
(
Column
col:
columns
)
if
(
col
.
isLastModify
())
{
lastModifyColumn
=
col
;
return
lastModifyColumn
;
}
return
lastModifyColumn
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
Column
createTimeColumn
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Column
getCreateTimeColumn
()
{
if
(
columns
!=
null
&&
createTimeColumn
==
null
)
for
(
Column
col:
columns
)
if
(
col
.
isCreateTime
())
{
createTimeColumn
=
col
;
return
createTimeColumn
;
}
return
createTimeColumn
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
Column
tenantColumn
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Column
getTenantColumn
()
{
if
(
columns
!=
null
&&
tenantColumn
==
null
)
for
(
Column
col:
columns
)
if
(
col
.
isTenant
())
{
tenantColumn
=
col
;
return
tenantColumn
;
}
return
tenantColumn
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
boolean
logicValid
=
true
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
boolean
isLogicValid
()
{
if
(
logicValid
&&
logicValidColumn
==
null
)
{
if
(
columns
!=
null
)
{
for
(
Column
col:
columns
)
{
if
(
col
.
isLogicValid
())
{
logicValidColumn
=
col
;
return
logicValid
;
}
}
}
logicValid
=
false
;
}
return
logicValid
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
Column
logicValidColumn
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Column
getLogicValidColumn
()
{
if
(
logicValid
&&
logicValidColumn
==
null
)
{
if
(
columns
!=
null
)
{
for
(
Column
col:
columns
)
{
if
(
col
.
isLogicValid
())
{
logicValidColumn
=
col
;
return
logicValidColumn
;
}
}
}
logicValid
=
false
;
}
return
logicValidColumn
;
}
@Getter
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_EMPTY
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
Column
{
private
String
name
;
private
String
remarks
;
private
String
type
;
private
Integer
length
;
private
Integer
precision
;
private
String
defaultValue
;
private
Boolean
autoIncrement
;
private
String
alias
;
private
String
predefined
;
private
Boolean
tenant
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
boolean
isLogicValid
()
{
return
"LOGICVALID"
.
equals
(
this
.
getPredefined
());
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
boolean
isLastModify
()
{
return
"UPDATEDATE"
.
equals
(
this
.
getPredefined
());
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
boolean
isCreateTime
()
{
return
"CREATEDATE"
.
equals
(
this
.
getPredefined
());
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
boolean
isTenant
()
{
return
"TENANT"
.
equals
(
this
.
getPredefined
());
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
boolean
isText
()
{
return
this
.
getType
().
toUpperCase
().
indexOf
(
"TEXT"
)>=
0
||
this
.
getType
().
toUpperCase
().
indexOf
(
"CHAR"
)>=
0
;
}
private
Constraints
constraints
;
}
@Getter
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_EMPTY
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
Constraints
{
private
Boolean
nullable
;
private
Boolean
primaryKey
;
private
String
primaryKeyName
;
private
String
foreignKeyName
;
private
String
referencedTableName
;
private
String
referencedColumnNames
;
}
@Getter
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_EMPTY
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
ForeignKeyConstraint
{
private
String
baseColumnNames
;
private
String
baseTableName
;
private
String
constraintName
;
private
String
referencedTableName
;
private
String
referencedColumnNames
;
private
Boolean
validate
;
private
String
onUpdate
;
private
String
onDelete
;
}
@Getter
@Setter
@NoArgsConstructor
@Accessors
(
chain
=
true
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_EMPTY
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
Script
{
private
String
name
;
private
String
vendorProvider
;
private
String
declare
;
private
String
body
;
private
Map
params
;
}
public
List
<
Script
>
scripts
;
private
static
Map
<
String
,
String
>
provider
=
new
HashMap
<
String
,
String
>(){{
put
(
"oracle"
,
"oracle"
);
put
(
"mysql"
,
"mysql"
);
put
(
"postgresql"
,
"postgresql"
);
put
(
"mppdb"
,
"postgresql"
);
put
(
"dm"
,
"oracle"
);
put
(
"dameng"
,
"oracle"
);
put
(
"gbase"
,
"oracle"
);
put
(
"h2"
,
"mysql"
);
}};
public
Script
getScript
(
String
name
,
String
type
)
{
if
(
scripts
!=
null
)
{
String
vendorProvider
=
"mysql"
;
if
((!
StringUtils
.
isEmpty
(
type
))&&
provider
.
containsKey
(
type
.
toLowerCase
()))
vendorProvider
=
provider
.
get
(
type
.
toLowerCase
());
for
(
Script
script:
scripts
)
{
if
(
name
.
equalsIgnoreCase
(
script
.
getName
())&&(
vendorProvider
.
equals
(
script
.
getVendorProvider
())||
StringUtils
.
isEmpty
(
script
.
getVendorProvider
())))
return
script
;
}
}
return
getDefaultQueryScript
();
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Script
defaultQueryScript
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Script
getDefaultQueryScript
()
{
if
(
defaultQueryScript
==
null
)
{
defaultQueryScript
=
new
Script
();
defaultQueryScript
.
setName
(
"default"
);
String
sql
=
"select "
;
if
(
columns
!=
null
)
{
String
cols
=
""
;
for
(
Column
col:
columns
)
{
if
(!
StringUtils
.
isEmpty
(
cols
))
cols
+=
","
;
cols
+=(
col
.
getName
());
if
((!
StringUtils
.
isEmpty
(
col
.
getAlias
()))&&
col
.
getAlias
().
equalsIgnoreCase
(
col
.
getName
()))
cols
+=(
" as "
+
col
.
getAlias
());
}
sql
+=
cols
;
}
else
sql
+=
" * "
;
sql
+=
(
" from "
+
name
+
" t "
);
if
(
isLogicValid
())
{
String
defaultVal
=
this
.
getLogicValidColumn
().
getDefaultValue
();
if
(
StringUtils
.
isEmpty
(
defaultVal
))
defaultVal
=
"1"
;
sql
+=
" where t."
+
this
.
getLogicValidColumn
().
getName
()+
"="
;
if
(
this
.
getLogicValidColumn
().
isText
())
sql
+=(
"'"
+
defaultVal
+
"'"
);
else
sql
+=(
defaultVal
+
" "
);
}
defaultQueryScript
.
setBody
(
sql
);
}
return
defaultQueryScript
;
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/model/PojoSchema.java
浏览文件 @
b413a71c
...
@@ -122,7 +122,7 @@ public class PojoSchema {
...
@@ -122,7 +122,7 @@ public class PojoSchema {
public
Map
<
String
,
PojoSchema
>
getProperties
()
public
Map
<
String
,
PojoSchema
>
getProperties
()
{
{
if
(!
"object"
.
equals
(
this
.
type
))
if
(!
Type
.
object
.
getCode
()
.
equals
(
this
.
type
))
{
{
properties
=
null
;
properties
=
null
;
return
properties
;
return
properties
;
...
@@ -152,7 +152,7 @@ public class PojoSchema {
...
@@ -152,7 +152,7 @@ public class PojoSchema {
public
Set
<
String
>
getRequired
()
public
Set
<
String
>
getRequired
()
{
{
if
(!
"object"
.
equals
(
this
.
type
))
if
(!
Type
.
object
.
getCode
()
.
equals
(
this
.
type
))
{
{
required
=
null
;
required
=
null
;
return
required
;
return
required
;
...
@@ -231,4 +231,36 @@ public class PojoSchema {
...
@@ -231,4 +231,36 @@ public class PojoSchema {
System
.
out
.
println
(
JSON
.
toJSONString
(
schema
));
System
.
out
.
println
(
JSON
.
toJSONString
(
schema
));
}
}
public
static
enum
Type
{
string
(
"string"
,
"字符"
),
integer
(
"integer"
,
"整型"
),
number
(
"number"
,
"数值"
),
object
(
"object"
,
"对象"
),
array
(
"array"
,
"数组"
);
public
final
String
code
;
public
final
String
name
;
private
Type
(
String
code
,
String
name
)
{
this
.
code
=
code
;
this
.
name
=
name
;
}
public
String
getCode
()
{
return
code
;
}
public
String
getName
()
{
return
name
;
}
@Override
public
String
toString
()
{
return
"Type{"
+
"code='"
+
code
+
'\''
+
", name='"
+
name
+
'\''
+
'}'
;
}
}
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/model/TransUtils.java
浏览文件 @
b413a71c
此差异已折叠。
点击以展开。
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录