Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdata
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdata
提交
4be78d7f
提交
4be78d7f
编写于
8月 20, 2021
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
提交
上级
b457b716
变更
13
展开全部
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
450 行增加
和
101 行删除
+450
-101
pom.xml
ibzdata-core/pom.xml
+1
-1
DOModel.java
...re/src/main/java/cn/ibizlab/core/data/domain/DOModel.java
+7
-3
DynamicModelService.java
...n/java/cn/ibizlab/core/data/lite/DynamicModelService.java
+47
-8
EntityModel.java
.../src/main/java/cn/ibizlab/core/data/lite/EntityModel.java
+75
-1
FieldModel.java
...e/src/main/java/cn/ibizlab/core/data/lite/FieldModel.java
+5
-0
MetaEntityModel.java
.../main/java/cn/ibizlab/core/data/lite/MetaEntityModel.java
+4
-2
MetaFieldModel.java
...c/main/java/cn/ibizlab/core/data/lite/MetaFieldModel.java
+4
-2
POSchema.java
...re/src/main/java/cn/ibizlab/core/data/model/POSchema.java
+118
-25
PojoOption.java
.../src/main/java/cn/ibizlab/core/data/model/PojoOption.java
+21
-2
PojoSchema.java
.../src/main/java/cn/ibizlab/core/data/model/PojoSchema.java
+5
-0
TransUtils.java
.../src/main/java/cn/ibizlab/core/data/model/TransUtils.java
+110
-47
DOModelServiceImpl.java
...cn/ibizlab/core/data/service/impl/DOModelServiceImpl.java
+47
-6
DTOModelServiceImpl.java
...n/ibizlab/core/data/service/impl/DTOModelServiceImpl.java
+6
-4
未找到文件。
ibzdata-core/pom.xml
浏览文件 @
4be78d7f
...
...
@@ -100,7 +100,7 @@
<dependency>
<groupId>
net.ibizsys.model
</groupId>
<artifactId>
ibizlab-model
</artifactId>
<version>
1.2.
4
</version>
<version>
1.2.
5
</version>
</dependency>
</dependencies>
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/domain/DOModel.java
浏览文件 @
4be78d7f
...
...
@@ -281,9 +281,13 @@ public class DOModel extends EntityBase implements Serializable {
}
public
DOModel
addPOSchema
(
String
name
,
POSchema
poSchema
)
{
if
(
poSchemas
==
null
)
poSchemas
=
new
LinkedHashMap
<>();
poSchemas
.
put
(
name
,
poSchema
);
if
(
poSchema
!=
null
)
{
if
(
poSchemas
==
null
)
poSchemas
=
new
LinkedHashMap
<>();
poSchemas
.
put
(
name
,
poSchema
.
build
());
}
return
this
;
}
public
POSchema
getPOSchema
(
String
name
)
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/lite/DynamicModelService.java
浏览文件 @
4be78d7f
...
...
@@ -4,6 +4,7 @@ import cn.ibizlab.util.errors.BadRequestAlertException;
import
com.alibaba.fastjson.JSON
;
import
net.ibizsys.model.IPSSystem
;
import
net.ibizsys.model.PSModelServiceImpl
;
import
net.ibizsys.model.database.IPSDEFDTColumn
;
import
net.ibizsys.model.database.IPSSysDBTable
;
import
net.ibizsys.model.dataentity.IPSDataEntity
;
import
net.ibizsys.model.dataentity.defield.IPSDEField
;
...
...
@@ -58,7 +59,7 @@ public class DynamicModelService {
IPSSystem
iPSSystem
=
null
;
String
strPSModelFolderPath
=
null
;
if
(
Files
.
exists
(
Paths
.
get
(
getModelPath
(),
system
,
"model"
,
"PSSYSTEM.json"
)))
{
strPSModelFolderPath
=
Paths
.
get
(
getModelPath
(),
system
,
"model"
,
"PSSYSTEM.json"
).
toString
();
strPSModelFolderPath
=
Paths
.
get
(
getModelPath
(),
system
,
"model"
).
toString
();
}
else
{
...
...
@@ -183,10 +184,24 @@ public class DynamicModelService {
}
entityModel
.
setEntity
(
metaEntityModel
);
List
<
String
>
dsTypes
=
new
ArrayList
<>();
if
(
dataEntity
.
getAllPSDEDBConfigs
()!=
null
)
{
dataEntity
.
getAllPSDEDBConfigs
().
forEach
(
item
->{
dsTypes
.
add
(
item
.
getDBType
().
toLowerCase
());
if
(!
entityModel
.
getTableName
().
equalsIgnoreCase
(
item
.
getTableName
()))
entityModel
.
getEntity
().
set
(
"table-"
+
item
.
getDBType
().
toLowerCase
(),
item
.
getTableName
());
});
}
if
(
dsTypes
.
size
()>
0
)
entityModel
.
getEntity
().
set
(
"ds_types"
,
String
.
join
(
","
,
dsTypes
));
Map
<
String
,
FieldModel
>
fieldMaps
=
new
LinkedHashMap
<>();
for
(
IPSDEField
defield:
dataEntity
.
getAllPSDEFields
())
{
FieldModel
fieldModel
=
new
FieldModel
();
MetaFieldModel
metaFieldModel
=
new
MetaFieldModel
();
metaFieldModel
.
setFieldId
(
defield
.
getId
()).
setFieldName
(
defield
.
getName
()).
setCodeName
(
defield
.
getCodeName
()).
setFieldLogicName
(
defield
.
getLogicName
())
...
...
@@ -203,7 +218,7 @@ public class DynamicModelService {
if
(!
metaFieldModel
.
getFieldName
().
equalsIgnoreCase
(
col
.
getColumnName
()))
metaFieldModel
.
set
(
"column-"
+
col
.
getDBType
().
toLowerCase
(),
col
.
getColumnName
());
if
(
StringUtils
.
isEmpty
(
metaFieldModel
)&&
defield
.
isFormulaDEField
()&&(!
StringUtils
.
isEmpty
(
col
.
getQueryCodeExp
())))
metaFieldModel
.
setExpression
(
col
.
getQueryCodeExp
().
replace
(
"`"
,
""
));
metaFieldModel
.
setExpression
(
col
.
getQueryCodeExp
().
replace
(
"`"
,
""
)
.
replace
(
"["
,
""
).
replace
(
"]"
,
""
)
);
});
}
...
...
@@ -233,7 +248,7 @@ public class DynamicModelService {
MetaRelationshipModel
metaRel
=
new
MetaRelationshipModel
();
metaRel
.
setId
(
der
.
getId
()).
setName
(
der
.
getName
()).
setRelationType
(
der
.
getDERType
()).
setCodeName
(
der
.
getCodeName
()).
setRefEntityId
(
der
.
getMajorPSDataEntity
().
getId
())
.
setRefEntityName
(
der
.
getMajorPSDataEntity
().
getName
()).
setEntityId
(
dataEntity
.
getId
()).
setName
(
dataEntity
.
getName
()).
setNestedName
(
der
.
getMinorCodeName
())
.
setRefEntityName
(
der
.
getMajorPSDataEntity
().
getName
()).
setEntityId
(
dataEntity
.
getId
()).
set
Entity
Name
(
dataEntity
.
getName
()).
setNestedName
(
der
.
getMinorCodeName
())
.
setSystemId
(
iPSSystem
.
getCodeName
());
if
(
der
instanceof
IPSDER1N
)
...
...
@@ -263,7 +278,7 @@ public class DynamicModelService {
MetaRelationshipModel
metaRel
=
new
MetaRelationshipModel
();
metaRel
.
setId
(
der
.
getId
()).
setName
(
der
.
getName
()).
setRelationType
(
der
.
getDERType
()).
setCodeName
(
der
.
getCodeName
()).
setRefEntityId
(
der
.
getMajorPSDataEntity
().
getId
())
.
setRefEntityName
(
der
.
getMajorPSDataEntity
().
getName
()).
setEntityId
(
dataEntity
.
getId
()).
setName
(
dataEntity
.
getName
()).
setNestedName
(
der
.
getMinorCodeName
())
.
setRefEntityName
(
der
.
getMajorPSDataEntity
().
getName
()).
setEntityId
(
dataEntity
.
getId
()).
set
Entity
Name
(
dataEntity
.
getName
()).
setNestedName
(
der
.
getMinorCodeName
())
.
setSystemId
(
iPSSystem
.
getCodeName
());
if
(
der
instanceof
IPSDER1N
)
...
...
@@ -287,7 +302,7 @@ public class DynamicModelService {
if
(
dataQuery
.
getAllPSDEDataQueryCodes
()!=
null
)
{
dataQuery
.
getAllPSDEDataQueryCodes
().
forEach
(
dq
->{
MetaDataSetModel
dsModel
=
new
MetaDataSetModel
().
setDatasetId
(
"
dq-"
+
dataQuery
.
getCodeName
()+
"-"
+
dq
.
getDBType
().
toLowerCase
())
MetaDataSetModel
dsModel
=
new
MetaDataSetModel
().
setDatasetId
(
entityModel
.
getEntityName
().
toLowerCase
()+
"-
dq-"
+
dataQuery
.
getCodeName
()+
"-"
+
dq
.
getDBType
().
toLowerCase
())
.
setDatasetName
(
dataQuery
.
getLogicName
()).
setCodeName
(
dataQuery
.
getCodeName
())
.
setEntityId
(
entityModel
.
getEntityId
()).
setEntityName
(
entityModel
.
getEntityName
()).
setDsCode
(
dq
.
getQueryCode
());
entityModel
.
addDataSet
(
dsModel
);
...
...
@@ -306,8 +321,12 @@ public class DynamicModelService {
try
{
if
(
dataSet
.
getPSDEDataQueries
()!=
null
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
dataSet
.
getPSDEDataQueries
().
forEach
(
dataQuery
->{
...
...
@@ -324,7 +343,7 @@ public class DynamicModelService {
code
=
map
.
get
(
dq
.
getDBType
());
code
=
code
+
"\r\n union all \r\n"
;
}
code
=
code
+
dq
.
getQueryCode
()
;
code
=
code
+
"<include refid=\""
+
entityModel
.
getEntityName
().
toLowerCase
()+
"_dq_"
+
dataQuery
.
getCodeName
()+
"_"
+
dq
.
getDBType
().
toLowerCase
()+
"\"/>"
;
map
.
put
(
dq
.
getDBType
(),
code
);
});
}
...
...
@@ -336,9 +355,27 @@ public class DynamicModelService {
for
(
Map
.
Entry
<
String
,
String
>
entry:
map
.
entrySet
())
{
MetaDataSetModel
dsModel
=
new
MetaDataSetModel
().
setDatasetId
(
"ds-"
+
dataSet
.
getCodeName
()+
"-"
+
entry
.
getKey
().
toLowerCase
())
String
sql
=
"select t1.* from (\r\n"
.
concat
(
entry
.
getValue
()).
concat
(
"\r\n) t1"
);
if
(
dataSet
.
getMajorSortPSDEField
()!=
null
)
{
IPSDEFDTColumn
column
=
dataSet
.
getMajorSortPSDEField
().
getPSDEFDTColumn
(
entry
.
getKey
(),
false
);
sql
=
sql
.
concat
(
" order by "
).
concat
(
column
==
null
?
dataSet
.
getMajorSortPSDEField
().
getName
():
column
.
getColumnName
());
if
(!
StringUtils
.
isEmpty
(
dataSet
.
getMajorSortDir
()))
sql
=
sql
.
concat
(
" "
).
concat
(
dataSet
.
getMajorSortDir
());
if
(
dataSet
.
getMinorSortPSDEField
()!=
null
)
{
IPSDEFDTColumn
subCol
=
dataSet
.
getMinorSortPSDEField
().
getPSDEFDTColumn
(
entry
.
getKey
(),
false
);
sql
=
sql
.
concat
(
","
).
concat
(
subCol
==
null
?
dataSet
.
getMinorSortPSDEField
().
getName
():
subCol
.
getColumnName
());
if
(!
StringUtils
.
isEmpty
(
dataSet
.
getMinorSortDir
()))
sql
=
sql
.
concat
(
" "
).
concat
(
dataSet
.
getMinorSortDir
());
}
}
MetaDataSetModel
dsModel
=
new
MetaDataSetModel
().
setDatasetId
(
entityModel
.
getEntityName
().
toLowerCase
()+
"-ds-"
+
dataSet
.
getCodeName
()+
"-"
+
entry
.
getKey
().
toLowerCase
())
.
setDatasetName
(
dataSet
.
getLogicName
()).
setCodeName
(
dataSet
.
getCodeName
())
.
setEntityId
(
entityModel
.
getEntityId
()).
setEntityName
(
entityModel
.
getEntityName
()).
setDsCode
(
entry
.
getValue
()
);
.
setEntityId
(
entityModel
.
getEntityId
()).
setEntityName
(
entityModel
.
getEntityName
()).
setDsCode
(
sql
);
entityModel
.
addDataSet
(
dsModel
);
}
...
...
@@ -348,6 +385,8 @@ public class DynamicModelService {
}
});
}
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/lite/EntityModel.java
浏览文件 @
4be78d7f
...
...
@@ -277,6 +277,35 @@ public class EntityModel {
return
null
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getDefaultQueryScript
()
{
if
(
this
.
getDataSets
()!=
null
)
{
for
(
MetaDataSetModel
set:
this
.
getDataSets
()){
if
(
StringUtils
.
isEmpty
(
set
.
getDsCode
()))
continue
;
if
(
"view"
.
equalsIgnoreCase
(
set
.
getDatasetId
())||
set
.
getDatasetId
().
startsWith
(
"dq-view-"
)||
set
.
getDatasetId
().
startsWith
(
getEntityName
().
toLowerCase
()+
"-dq-view-"
))
{
return
set
.
getDsCode
().
replace
(
"`"
,
""
).
replace
(
"["
,
""
).
replace
(
"]"
,
""
);
}
}
for
(
MetaDataSetModel
set:
this
.
getDataSets
()){
if
(
StringUtils
.
isEmpty
(
set
.
getDsCode
()))
continue
;
if
(
"default"
.
equalsIgnoreCase
(
set
.
getDatasetId
())||
set
.
getDatasetId
().
startsWith
(
"dq-default-"
)||
set
.
getDatasetId
().
startsWith
(
getEntityName
().
toLowerCase
()+
"-dq-default-"
))
{
return
set
.
getDsCode
().
replace
(
"`"
,
""
).
replace
(
"["
,
""
).
replace
(
"]"
,
""
);
}
}
}
return
""
;
}
public
String
getSqlSegment
(
String
dataSet
)
{
...
...
@@ -298,6 +327,35 @@ public class EntityModel {
{
return
"select count(1) from "
+
this
.
getTableName
()+
" "
;
}
else
if
(
this
.
getDataSets
()!=
null
)
{
for
(
MetaDataSetModel
set:
this
.
getDataSets
()){
if
(
StringUtils
.
isEmpty
(
set
.
getDsCode
()))
continue
;
if
(
dataSet
.
equalsIgnoreCase
(
set
.
getDatasetId
())||
set
.
getDatasetId
().
indexOf
(
"ds-"
+
dataSet
.
toLowerCase
()+
"-"
)>=
0
||
set
.
getDatasetId
().
startsWith
(
getEntityName
().
toLowerCase
()+
"-ds-"
+
dataSet
.
toLowerCase
()+
"-"
))
{
return
set
.
getDsCode
().
replace
(
"`"
,
""
).
replace
(
"["
,
""
).
replace
(
"]"
,
""
);
}
}
for
(
MetaDataSetModel
set:
this
.
getDataSets
()){
if
(
StringUtils
.
isEmpty
(
set
.
getDsCode
()))
continue
;
if
(
dataSet
.
equalsIgnoreCase
(
set
.
getDatasetId
())||
set
.
getDatasetId
().
indexOf
(
"dq-"
+
dataSet
.
toLowerCase
()+
"-"
)>=
0
||
set
.
getDatasetId
().
startsWith
(
getEntityName
().
toLowerCase
()+
"-dq-"
+
dataSet
.
toLowerCase
()+
"-"
))
{
return
set
.
getDsCode
().
replace
(
"`"
,
""
).
replace
(
"["
,
""
).
replace
(
"]"
,
""
);
}
}
}
if
(
dataSet
.
equalsIgnoreCase
(
"VIEW"
)||
dataSet
.
equalsIgnoreCase
(
"DEFAULT"
))
{
return
""
;
}
else
{
String
columnSet
=
""
;
...
...
@@ -417,8 +475,24 @@ public class EntityModel {
public
String
getExtParams
(
String
key
)
{
return
Setting
.
getValue
(
this
.
getEntity
().
getExtParams
(),
key
);
return
DataObject
.
getStringValue
(
entity
.
get
(
key
),
""
);
}
public
String
getTableName
(
String
dsType
)
{
return
DataObject
.
getStringValue
(
entity
.
get
(
"table-"
+
dsType
.
toLowerCase
()),
getTableName
());
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
List
<
String
>
getDsTypes
()
{
List
<
String
>
dsTypes
=
new
ArrayList
<>();
String
strDsTypes
=
DataObject
.
getStringValue
(
entity
.
get
(
"ds_types"
),
""
);
for
(
String
dsType:
strDsTypes
.
split
(
","
))
dsTypes
.
add
(
dsType
);
return
dsTypes
;
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/lite/FieldModel.java
浏览文件 @
4be78d7f
package
cn
.
ibizlab
.
core
.
data
.
lite
;
import
cn.ibizlab.util.helper.DataObject
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
...
...
@@ -103,5 +104,9 @@ public class FieldModel {
return
"string"
;
}
public
String
getColumnName
(
String
dsType
)
{
return
DataObject
.
getStringValue
(
field
.
get
(
"column-"
+
dsType
.
toLowerCase
()),
getColumnName
());
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/lite/MetaEntityModel.java
浏览文件 @
4be78d7f
...
...
@@ -142,8 +142,10 @@ public class MetaEntityModel{
extensionparams
.
put
(
key
,
value
);
List
<
Setting
>
settingList
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
Object
>
entry:
extensionparams
.
entrySet
())
settingList
.
add
(
new
Setting
().
setProperty
(
key
).
setValue
(
DataObject
.
getStringValue
(
value
,
""
)));
for
(
Map
.
Entry
<
String
,
Object
>
entry:
extensionparams
.
entrySet
())
{
if
(!
entry
.
getKey
().
equalsIgnoreCase
(
"param"
))
settingList
.
add
(
new
Setting
().
setProperty
(
entry
.
getKey
()).
setValue
(
DataObject
.
getStringValue
(
entry
.
getValue
(),
""
)));
}
return
setExtParams
(
JSON
.
toJSONString
(
settingList
));
}
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/lite/MetaFieldModel.java
浏览文件 @
4be78d7f
...
...
@@ -293,8 +293,10 @@ public class MetaFieldModel {
extensionparams
.
put
(
key
,
value
);
List
<
Setting
>
settingList
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
String
,
Object
>
entry:
extensionparams
.
entrySet
())
settingList
.
add
(
new
Setting
().
setProperty
(
key
).
setValue
(
DataObject
.
getStringValue
(
value
,
""
)));
for
(
Map
.
Entry
<
String
,
Object
>
entry:
extensionparams
.
entrySet
())
{
if
(!
entry
.
getKey
().
equalsIgnoreCase
(
"param"
))
settingList
.
add
(
new
Setting
().
setProperty
(
entry
.
getKey
()).
setValue
(
DataObject
.
getStringValue
(
entry
.
getValue
(),
""
)));
}
return
setExtParams
(
JSON
.
toJSONString
(
settingList
));
}
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/model/POSchema.java
浏览文件 @
4be78d7f
package
cn
.
ibizlab
.
core
.
data
.
model
;
import
cn.ibizlab.core.data.dto.BaseData
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
...
...
@@ -12,6 +15,10 @@ import lombok.experimental.Accessors;
import
org.apache.ibatis.mapping.VendorDatabaseIdProvider
;
import
org.springframework.util.StringUtils
;
import
java.io.File
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.StandardOpenOption
;
import
java.util.*
;
@Getter
...
...
@@ -22,15 +29,21 @@ import java.util.*;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
POSchema
{
@JSONField
(
ordinal
=
1
)
private
String
name
;
@JSONField
(
ordinal
=
2
)
private
String
remarks
;
@JSONField
(
ordinal
=
3
)
private
String
dsType
;
@JSONField
(
ordinal
=
4
)
private
String
defaultDataSource
;
@JSONField
(
ordinal
=
5
)
private
String
logicVal
;
@JSONField
(
ordinal
=
6
)
private
String
logicDelVal
;
public
String
getLogicVal
()
{
...
...
@@ -45,8 +58,10 @@ public class POSchema {
return
logicDelVal
;
}
@JSONField
(
ordinal
=
7
)
private
List
<
Column
>
columns
;
@JSONField
(
ordinal
=
8
)
private
List
<
Column
>
transients
;
public
POSchema
setColumns
(
List
<
Column
>
columns
)
...
...
@@ -81,6 +96,7 @@ public class POSchema {
return
this
;
}
@JSONField
(
ordinal
=
9
)
private
List
<
ForeignKeyConstraint
>
foreignKeyConstraints
;
public
POSchema
addForeignKeyConstraint
(
ForeignKeyConstraint
foreignKeyConstraint
)
...
...
@@ -120,6 +136,7 @@ public class POSchema {
return
columnMaps
;
}
@JSONField
(
ordinal
=
10
)
public
boolean
needTrans
=
false
;
public
void
refreshColumnMaps
()
...
...
@@ -174,7 +191,7 @@ public class POSchema {
if
(
column
.
isLastModify
())
this
.
setLastModifyColumn
(
column
);
}
if
((!
StringUtils
.
isEmpty
(
column
.
getAlias
()))&&
column
.
getAlias
().
equalsIgnoreCase
(
column
.
getName
(
)))
if
((!
StringUtils
.
isEmpty
(
column
.
getAlias
()))&&
(!
column
.
getAlias
().
equalsIgnoreCase
(
column
.
getName
()
)))
{
needTrans
=
true
;
columnMaps
.
put
(
column
.
getAlias
().
toLowerCase
(),
column
);
...
...
@@ -300,6 +317,12 @@ public class POSchema {
private
String
alias
;
private
String
predefined
;
public
Column
setAlias
(
String
alias
)
{
if
((!
StringUtils
.
isEmpty
(
name
))&&(!
name
.
equalsIgnoreCase
(
alias
)))
this
.
alias
=
alias
;
return
this
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
...
...
@@ -447,21 +470,38 @@ public class POSchema {
@Accessors
(
chain
=
true
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_EMPTY
)
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
static
class
S
crip
t
{
public
static
class
S
egmen
t
{
private
String
name
;
private
String
vendorProvider
;
private
String
declare
;
private
String
body
;
private
Map
params
;
public
Segment
setVendorProvider
(
String
vendorProvider
)
{
if
(!
StringUtils
.
isEmpty
(
vendorProvider
))
this
.
vendorProvider
=
provider
.
get
(
vendorProvider
.
toLowerCase
());
return
this
;
}
}
public
List
<
Script
>
scripts
;
@JSONField
(
ordinal
=
11
)
public
List
<
Segment
>
segments
;
public
POSchema
addSegment
(
Segment
segment
)
{
if
(
segments
==
null
)
segments
=
new
ArrayList
<>();
segments
.
add
(
segment
);
return
this
;
}
private
static
Map
<
String
,
String
>
provider
=
new
HashMap
<
String
,
String
>(){{
put
(
"oracle"
,
"oracle"
);
put
(
"mysql"
,
"mysql"
);
put
(
"mysql5"
,
"mysql"
);
put
(
"postgresql"
,
"postgresql"
);
put
(
"mppdb"
,
"postgresql"
);
put
(
"dm"
,
"oracle"
);
...
...
@@ -472,39 +512,60 @@ public class POSchema {
public
S
cript
getScrip
t
(
String
name
,
String
type
)
public
S
egment
getSegmen
t
(
String
name
,
String
type
)
{
if
(
s
crip
ts
!=
null
)
if
(
s
egmen
ts
!=
null
)
{
String
vendorProvider
=
"mysql"
;
if
((!
StringUtils
.
isEmpty
(
type
))&&
provider
.
containsKey
(
type
.
toLowerCase
()))
vendorProvider
=
provider
.
get
(
type
.
toLowerCase
());
for
(
Script
script:
scripts
)
String
vendorProvider
=
StringUtils
.
isEmpty
(
type
)?
""
:
provider
.
get
(
type
.
toLowerCase
());
for
(
Segment
script:
segments
)
{
if
(
name
.
equalsIgnoreCase
(
script
.
getName
())&&((
script
.
getVendorProvider
().
indexOf
(
vendorProvider
)>=
0
)
||
StringUtils
.
isEmpty
(
script
.
getVendorProvider
())))
if
(
script
.
getName
().
toLowerCase
().
indexOf
(
name
.
toLowerCase
())>=
0
&&(
StringUtils
.
isEmpty
(
vendorProvider
)||
script
.
getVendorProvider
().
indexOf
(
vendorProvider
)>=
0
||
StringUtils
.
isEmpty
(
script
.
getVendorProvider
())))
return
script
;
}
}
else
{
scrip
ts
=
new
ArrayList
<>();
segmen
ts
=
new
ArrayList
<>();
}
return
getDefaultQueryScript
()
;
return
null
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Script
defaultQueryScript
;
@JSONField
(
ordinal
=
12
)
public
Segment
defaultQueryScript
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Script
getDefaultQueryScript
()
public
POSchema
setDefaultQueryScript
(
String
sql
)
{
defaultQueryScript
=
new
Segment
().
setName
(
"default_query_script"
).
setVendorProvider
(
""
).
setBody
(
sql
);
return
this
;
}
public
Segment
getDefaultQueryScript
()
{
if
(
defaultQueryScript
==
null
)
{
defaultQueryScript
=
new
Script
();
defaultQueryScript
.
setName
(
"default"
);
defaultQueryScript
.
setVendorProvider
(
"mysql,oracle,postgresql"
);
Segment
segment
=
this
.
getSegment
(
"dq-view-"
,
this
.
getDsType
());
if
(
segment
==
null
)
segment
=
this
.
getSegment
(
"dq-default-"
,
this
.
getDsType
());
if
(
segment
!=
null
)
{
setDefaultQueryScript
(
segment
.
getBody
());
return
defaultQueryScript
;
}
else
if
(!
StringUtils
.
isEmpty
(
this
.
getDsType
()))
{
segment
=
this
.
getSegment
(
"dq-view-"
,
""
);
if
(
segment
==
null
)
segment
=
this
.
getSegment
(
"dq-default-"
,
""
);
if
(
segment
!=
null
)
{
setDefaultQueryScript
(
segment
.
getBody
().
replace
(
"`"
,
""
).
replace
(
"["
,
""
).
replace
(
"]"
,
""
));
return
defaultQueryScript
;
}
}
defaultQueryScript
=
new
Segment
();
defaultQueryScript
.
setName
(
"default_query_script"
);
defaultQueryScript
.
setVendorProvider
(
""
);
String
sql
=
"select "
;
String
cols
=
""
;
...
...
@@ -514,18 +575,18 @@ public class POSchema {
{
if
(!
StringUtils
.
isEmpty
(
cols
))
cols
+=
","
;
cols
+=(
"t."
+
key
+
" as "
+
baseColumnMap
.
get
(
key
));
cols
+=(
"t
1
."
+
key
+
" as "
+
baseColumnMap
.
get
(
key
));
}
}
else
cols
=
"*"
;
cols
=
"
t1.
*"
;
sql
+=
(
cols
+
" from "
+
name
+
" t "
);
sql
+=
(
cols
+
" from "
+
name
+
" t
1
"
);
if
(
isLogicValid
())
{
sql
+=
" where t."
+
this
.
getLogicValidCond
();
sql
+=
" where t
1
."
+
this
.
getLogicValidCond
();
}
defaultQueryScript
.
setBody
(
sql
);
...
...
@@ -574,4 +635,36 @@ public class POSchema {
}
}
public
POSchema
writeTo
(
Path
path
)
{
return
writeTo
(
this
,
path
);
}
public
static
POSchema
fromPath
(
Path
path
)
{
try
{
if
(!
Files
.
exists
(
path
))
throw
new
BadRequestAlertException
(
"读取文件失败"
,
"POSchema"
,
path
.
toString
());
return
JSON
.
parseObject
(
Files
.
readAllBytes
(
path
),
POSchema
.
class
);
}
catch
(
Exception
e
)
{
throw
new
BadRequestAlertException
(
"解析文件失败"
,
"POSchema"
,
path
.
toString
());
}
}
public
static
POSchema
writeTo
(
POSchema
poSchema
,
Path
path
)
{
try
{
File
dir
=
path
.
getParent
().
toFile
();
if
(!
dir
.
exists
())
dir
.
mkdirs
();
Files
.
write
(
path
,
JSON
.
toJSONBytes
(
poSchema
),
StandardOpenOption
.
CREATE
);
}
catch
(
Exception
e
)
{
throw
new
BadRequestAlertException
(
"保存文件失败"
,
"POSchema"
,
path
.
toString
());
}
return
poSchema
;
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/model/PojoOption.java
浏览文件 @
4be78d7f
package
cn
.
ibizlab
.
core
.
data
.
model
;
import
cn.ibizlab.core.data.dto.DataObj
;
import
cn.ibizlab.util.helper.DataObject
;
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
org.springframework.util.StringUtils
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
@JsonInclude
(
JsonInclude
.
Include
.
NON_EMPTY
)
...
...
@@ -55,12 +58,28 @@ public class PojoOption extends DataObj
return
this
.
getStringValue
(
"ds_name"
,
this
.
getSystem
()+
"-master"
);
}
public
List
<
String
>
getDsTypes
(){
List
<
String
>
dsTypes
=
new
ArrayList
<>();
String
strDsTypes
=
this
.
getStringValue
(
"ds_types"
);
for
(
String
dsType:
strDsTypes
.
split
(
","
))
dsTypes
.
add
(
dsType
);
return
dsTypes
;
}
public
PojoOption
setDsTypes
(
String
dsTypes
){
return
this
.
set
(
"ds_types"
,
dsTypes
);
}
public
String
getDefaultQueryScript
()
{
return
this
.
getStringValue
(
"default_query_script"
);
}
public
Boolean
isLogicValid
()
{
return
this
.
getBooleanValue
(
"logic
V
alid"
);
return
this
.
getBooleanValue
(
"logic
_v
alid"
);
}
public
PojoOption
setLogicValid
(
Boolean
logicValid
)
{
return
this
.
set
(
"logic
V
alid"
,
logicValid
);
return
this
.
set
(
"logic
_v
alid"
,
logicValid
);
}
public
String
getLogicVal
()
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/model/PojoSchema.java
浏览文件 @
4be78d7f
...
...
@@ -13,6 +13,7 @@ import lombok.Setter;
import
lombok.experimental.Accessors
;
import
org.springframework.util.StringUtils
;
import
java.io.File
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.nio.file.Files
;
...
...
@@ -326,6 +327,10 @@ public class PojoSchema {
public
static
PojoSchema
writeTo
(
PojoSchema
pojoSchema
,
Path
path
)
{
try
{
File
dir
=
path
.
getParent
().
toFile
();
if
(!
dir
.
exists
())
dir
.
mkdirs
();
Files
.
write
(
path
,
JSON
.
toJSONBytes
(
pojoSchema
),
StandardOpenOption
.
CREATE
);
}
catch
(
Exception
e
)
{
throw
new
BadRequestAlertException
(
"保存文件失败"
,
"PojoSchema"
,
path
.
toString
());
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/model/TransUtils.java
浏览文件 @
4be78d7f
此差异已折叠。
点击以展开。
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/DOModelServiceImpl.java
浏览文件 @
4be78d7f
package
cn
.
ibizlab
.
core
.
data
.
service
.
impl
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Collection
;
import
java.nio.file.StandardOpenOption
;
import
java.util.*
;
import
cn.ibizlab.core.data.lite.EntityModel
;
import
cn.ibizlab.core.data.lite.LiteStorage
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.model.PojoSchema
;
import
cn.ibizlab.core.data.model.TransUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
...
...
@@ -71,18 +74,56 @@ public class DOModelServiceImpl implements IDOModelService {
String
entity
=
args
[
2
];
Path
storePath
=
Paths
.
get
(
LiteStorage
.
MODEL_PATH
,
system
,
"repo"
,
"domain"
,
entity
+
".json"
);
Path
storePath
=
Paths
.
get
(
LiteStorage
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"domain"
,
entity
+
".json"
);
if
(!
Files
.
exists
(
storePath
))
{
EntityModel
entityModel
=
LiteStorage
.
getEntityModel
(
system
,
entity
);
if
(
entityModel
!=
null
)
{
schema
=
TransUtils
.
EntityModelModel2Schema
(
entityModel
);
if
(
schema
!=
null
)
{
for
(
String
dsType:
entityModel
.
getDsTypes
())
{
POSchema
poSchema
=
TransUtils
.
EntityModelModel2PO
(
entityModel
,
dsType
);
if
(
poSchema
!=
null
)
{
doModel
.
addPOSchema
(
dsType
,
poSchema
);
}
}
if
(
doModel
.
getPoSchemas
()!=
null
)
{
Path
poPath
=
Paths
.
get
(
LiteStorage
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"repository"
,
entity
+
".json"
);
try
{
File
dir
=
poPath
.
getParent
().
toFile
();
if
(!
dir
.
exists
())
dir
.
mkdirs
();
Files
.
write
(
poPath
,
JSON
.
toJSONBytes
(
doModel
.
getPoSchemas
()),
StandardOpenOption
.
CREATE
);
}
catch
(
Exception
e
)
{
throw
new
BadRequestAlertException
(
"保存文件失败"
,
"POSchemas"
,
poPath
.
toString
());
}
}
schema
.
writeTo
(
storePath
);
}
}
}
else
{
schema
=
PojoSchema
.
fromPath
(
storePath
);
Path
poPath
=
Paths
.
get
(
LiteStorage
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"repository"
,
entity
+
".json"
);
if
(
Files
.
exists
(
poPath
))
{
try
{
LinkedHashMap
map
=
JSON
.
parseObject
(
Files
.
readAllBytes
(
poPath
),
LinkedHashMap
.
class
);
map
.
keySet
().
forEach
(
dsType
->{
doModel
.
addPOSchema
(
dsType
.
toString
(),
JSON
.
parseObject
(
JSON
.
toJSONString
(
map
.
get
(
dsType
)),
POSchema
.
class
));
});
}
catch
(
IOException
e
)
{
}
}
}
else
schema
=
PojoSchema
.
fromPath
(
storePath
);
if
(
schema
!=
null
)
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/DTOModelServiceImpl.java
浏览文件 @
4be78d7f
...
...
@@ -68,12 +68,14 @@ public class DTOModelServiceImpl implements IDTOModelService {
String
system
=
args
[
0
];
String
dto
=
args
[
2
];
Path
storePath
=
Paths
.
get
(
LiteStorage
.
MODEL_PATH
,
system
,
"repo"
,
"dto"
,
dto
+
".json"
);
String
entity
=
dto
;
if
(
entity
.
endsWith
(
"DTO"
))
entity
=
entity
.
substring
(
0
,
entity
.
length
()-
3
);
Path
storePath
=
Paths
.
get
(
LiteStorage
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"dto"
,
dto
+
".json"
);
if
(!
Files
.
exists
(
storePath
))
{
String
entity
=
dto
;
if
(
entity
.
endsWith
(
"DTO"
))
entity
=
entity
.
substring
(
0
,
entity
.
length
()-
3
);
EntityModel
entityModel
=
LiteStorage
.
getEntityModel
(
system
,
entity
);
if
(
entityModel
!=
null
)
{
schema
=
TransUtils
.
EntityModelModel2Schema
(
entityModel
);
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录