Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdst
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
1
议题
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdst
提交
2aa2dc28
提交
2aa2dc28
编写于
1月 05, 2021
作者:
tangyaolong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【dst模型初始化导入导出】第三版
上级
156edbc8
变更
3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
203 行增加
和
73 行删除
+203
-73
MetaModelExService.java
...n/ibizlab/core/extensions/service/MetaModelExService.java
+75
-62
RelationshipModel.java
...bizlab/core/lite/extensions/domain/RelationshipModel.java
+3
-0
LiteModelService.java
...bizlab/core/lite/extensions/service/LiteModelService.java
+125
-11
未找到文件。
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/service/MetaModelExService.java
浏览文件 @
2aa2dc28
...
...
@@ -8,6 +8,8 @@ import cn.ibizlab.core.analysis.service.IDAMetricService;
import
cn.ibizlab.core.extensions.domain.AssembleModel
;
import
cn.ibizlab.core.lite.domain.*
;
import
cn.ibizlab.core.lite.extensions.domain.EntityModel
;
import
cn.ibizlab.core.lite.extensions.domain.FieldModel
;
import
cn.ibizlab.core.lite.extensions.domain.RelationshipModel
;
import
cn.ibizlab.core.lite.extensions.model.DataModel
;
import
cn.ibizlab.core.lite.extensions.model.Property
;
import
cn.ibizlab.core.lite.extensions.service.LiteModelService
;
...
...
@@ -34,6 +36,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.nio.charset.StandardCharsets
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
...
...
@@ -73,15 +76,15 @@ public class MetaModelExService extends MetaModelServiceImpl {
@Autowired
@Lazy
private
IMetaDataSetService
metaD
ataSetService
;
private
IMetaDataSetService
d
ataSetService
;
@Autowired
@Lazy
private
IMetaRelationshipService
metaR
elationshipService
;
private
IMetaRelationshipService
r
elationshipService
;
@Autowired
@Lazy
private
IMetaFieldService
metaF
ieldService
;
private
IMetaFieldService
f
ieldService
;
@Value
(
"${ibiz.filePath:/app/file/}"
)
private
String
fileRoot
;
...
...
@@ -124,26 +127,58 @@ public class MetaModelExService extends MetaModelServiceImpl {
String
strModel
=
getModel
(
objFile
.
getString
(
"id"
));
List
<
AssembleModel
>
models
=
JSONObject
.
parseArray
(
strModel
,
AssembleModel
.
class
);
for
(
AssembleModel
model
:
models
)
{
//
前置铺垫实体模型,防止外键冲突
//
基础数据导入
if
(
model
.
getEntityModels
()
!=
null
)
{
LinkedHashSet
<
MetaEntity
>
metaEntities
=
new
LinkedHashSet
<>();
LinkedHashSet
<
MetaEntity
>
entities
=
new
LinkedHashSet
<>();
LinkedHashSet
<
MetaRelationship
>
p_relations
=
new
LinkedHashSet
<>();
LinkedHashSet
<
MetaRelationship
>
s_relations
=
new
LinkedHashSet
<>();
LinkedHashSet
<
MetaField
>
fields
=
new
LinkedHashSet
<>();
LinkedHashSet
<
MetaDataSet
>
dataSets
=
new
LinkedHashSet
<>();
model
.
getEntityModels
().
forEach
(
item
->
{
metaEntities
.
add
(
item
.
getEntity
());
if
(!
ObjectUtils
.
isEmpty
(
item
.
getReferences
())){
for
(
RelationshipModel
relationModel
:
item
.
getReferences
()){
if
(!
ObjectUtils
.
isEmpty
(
relationModel
.
getRelation
())){
p_relations
.
add
(
relationModel
.
getRelation
());
}
}
}
if
(!
ObjectUtils
.
isEmpty
(
item
.
getNesteds
())){
for
(
RelationshipModel
relationModel
:
item
.
getNesteds
()){
if
(!
ObjectUtils
.
isEmpty
(
relationModel
.
getRelation
())){
s_relations
.
add
(
relationModel
.
getRelation
());
}
}
}
if
(!
ObjectUtils
.
isEmpty
(
item
.
getFields
())){
List
<
FieldModel
>
fieldModels
=
item
.
getFields
();
for
(
FieldModel
fieldModel
:
fieldModels
){
if
(!
ObjectUtils
.
isEmpty
(
fieldModel
.
getField
())){
fields
.
add
(
fieldModel
.
getField
());
}
}
}
if
(!
ObjectUtils
.
isEmpty
(
item
.
getDataSets
())){
dataSets
.
addAll
(
item
.
getDataSets
());
}
entities
.
add
(
item
.
getEntity
());
});
metaEntityService
.
saveBatch
(
metaEntities
);
}
if
(
model
.
getMetaDataSets
().
size
()
>
0
)
{
metaDataSetService
.
saveBatch
(
model
.
getMetaDataSets
());
}
if
(
model
.
getNesteds
().
size
()
>
0
)
{
metaRelationshipService
.
saveBatch
(
model
.
getNesteds
());
}
if
(
model
.
getReferences
().
size
()
>
0
)
{
metaRelationshipService
.
saveBatch
(
model
.
getReferences
());
}
if
(
model
.
getMetaFields
().
size
()
>
0
)
{
metaFieldService
.
saveBatch
(
model
.
getMetaFields
());
if
(
entities
.
size
()>
0
){
metaEntityService
.
saveBatch
(
entities
);
}
if
(
p_relations
.
size
()>
0
){
relationshipService
.
saveBatch
(
p_relations
);
}
if
(
s_relations
.
size
()>
0
){
relationshipService
.
saveBatch
(
s_relations
);
}
if
(
dataSets
.
size
()>
0
){
dataSetService
.
saveBatch
(
dataSets
);
}
if
(
fields
.
size
()>
0
){
fieldService
.
saveBatch
(
fields
);
}
}
//核心数据导入
if
(
model
.
getMetaModel
()
!=
null
)
{
metaModelService
.
save
(
model
.
getMetaModel
());
}
...
...
@@ -179,9 +214,10 @@ public class MetaModelExService extends MetaModelServiceImpl {
models
.
add
(
getModel
(
metaModel
));
}
String
strModel
=
JSON
.
toJSONString
(
models
);
File
modelFile
=
G
enerateModelFile
(
strModel
);
File
modelFile
=
g
enerateModelFile
(
strModel
);
HttpServletResponse
resp
=
((
ServletRequestAttributes
)
req
).
getResponse
();
resp
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
getFileName
(
modelFile
.
getName
()));
if
(
resp
!=
null
)
resp
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
getFileName
(
modelFile
.
getName
()));
sendResponse
(
resp
,
modelFile
);
return
true
;
}
...
...
@@ -198,15 +234,8 @@ public class MetaModelExService extends MetaModelServiceImpl {
AssembleModel
models
=
new
AssembleModel
();
List
<
DAMetric
>
metrics
=
new
ArrayList
<>();
LinkedHashSet
<
String
>
entities
=
new
LinkedHashSet
<>();
LinkedHashSet
<
MetaDataSet
>
metaDataSets
=
new
LinkedHashSet
<>();
LinkedHashSet
<
MetaRelationship
>
references
=
new
LinkedHashSet
<>();
LinkedHashSet
<
MetaRelationship
>
nesteds
=
new
LinkedHashSet
<>();
LinkedHashSet
<
MetaField
>
metaFields
=
new
LinkedHashSet
<>();
// 查询模型
MetaModel
metaModel
=
metaModelService
.
get
(
et
.
getId
());
models
.
setMetaModel
(
metaModel
);
// 查询模型对应的N个规则
for
(
RuleItem
ruleItem
:
metaModel
.
getRuleitems
())
{
...
...
@@ -247,11 +276,8 @@ public class MetaModelExService extends MetaModelServiceImpl {
}
}
// 将关联的数据集,上下级关系,字段一并存入
models
.
setEntityModels
(
getEntityModel
(
entities
,
modelId
,
metaDataSets
,
references
,
nesteds
,
metaFields
));
models
.
setMetaDataSets
(
metaDataSets
);
models
.
setReferences
(
references
);
models
.
setNesteds
(
nesteds
);
models
.
setMetaFields
(
metaFields
);
models
.
setEntityModels
(
getEntityModel
(
modelId
));
models
.
setMetaModel
(
metaModel
);
models
.
setRuleItems
(
metaModel
.
getRuleitems
());
models
.
setDaBuilds
(
metaModel
.
getBuilds
());
models
.
setMetrics
(
metrics
);
...
...
@@ -260,34 +286,21 @@ public class MetaModelExService extends MetaModelServiceImpl {
/**
* 传入一组实体模型名和模型id来返回实体模型集合
*
* @param entities 实体模型名组
* @param modelId 模型id
* @return 实体模型集合
*/
private
List
<
EntityModel
>
getEntityModel
(
LinkedHashSet
<
String
>
entities
,
String
modelId
,
LinkedHashSet
<
MetaDataSet
>
metaDataSets
,
LinkedHashSet
<
MetaRelationship
>
references
,
LinkedHashSet
<
MetaRelationship
>
nesteds
,
LinkedHashSet
<
MetaField
>
metaFields
)
{
private
List
<
EntityModel
>
getEntityModel
(
String
modelId
)
{
List
<
EntityModel
>
entityModels
=
new
ArrayList
<>();
DataModel
model
=
liteModelService
.
getDataModel
(
modelId
);
if
(
model
!=
null
)
{
for
(
String
entity
:
entities
)
{
metaDataSets
.
addAll
(
metaDataSetService
.
selectByEntityId
(
entity
));
references
.
addAll
(
metaRelationshipService
.
selectByEntityId
(
entity
));
nesteds
.
addAll
(
metaRelationshipService
.
selectByRefEntityId
(
entity
));
EntityModel
entityModel
=
null
;
Property
subModel
=
model
.
getObjectProperty
(
entity
);
if
(
subModel
!=
null
)
{
entityModel
=
subModel
.
getEntityModel
();
metaFields
.
addAll
(
metaFieldService
.
selectByEntityId
(
entityModel
.
getEntityId
()));
}
else
{
if
(
model
.
getNestedDataModel
(
entity
)
!=
null
)
{
entityModel
=
model
.
getNestedDataModel
(
entity
).
getFactEntityModel
();
}
}
if
(
entityModel
!=
null
)
{
entityModels
.
add
(
entityModel
);
}
}
DataModel
dataModel
=
liteModelService
.
getDataModel
(
modelId
);
List
<
Property
>
parents
=
dataModel
.
getParentProperty
();
LinkedHashSet
<
DataModel
>
childs
=
dataModel
.
getNestedDataModels
();
for
(
Property
parent
:
parents
){
EntityModel
model
=
parent
.
getEntityModel
();
entityModels
.
add
(
model
);
}
for
(
DataModel
child
:
childs
){
EntityModel
model
=
child
.
getFactEntityModel
();
entityModels
.
add
(
model
);
}
return
entityModels
;
}
...
...
@@ -300,7 +313,8 @@ public class MetaModelExService extends MetaModelServiceImpl {
*/
protected
String
getFileName
(
String
fileName
)
{
try
{
return
new
String
(
fileName
.
getBytes
(
"utf-8"
),
"iso8859-1"
);
//防止中文乱码
//防止中文乱码
return
new
String
(
fileName
.
getBytes
(
"utf-8"
),
"iso8859-1"
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -313,7 +327,7 @@ public class MetaModelExService extends MetaModelServiceImpl {
* @param strModel
* @return
*/
public
File
G
enerateModelFile
(
String
strModel
)
{
public
File
g
enerateModelFile
(
String
strModel
)
{
File
file
;
Date
now
=
new
Date
();
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyyMMddHHmmss"
);
...
...
@@ -366,8 +380,8 @@ public class MetaModelExService extends MetaModelServiceImpl {
}
else
{
throw
new
InternalServerErrorException
(
"文件未找到"
);
}
Reader
reader
=
new
InputStreamReader
(
new
FileInputStream
(
ModelFile
),
"utf-8"
);
int
ch
=
0
;
Reader
reader
=
new
InputStreamReader
(
new
FileInputStream
(
ModelFile
),
StandardCharsets
.
UTF_8
);
int
ch
;
while
((
ch
=
reader
.
read
())
!=
-
1
)
{
strModel
.
append
((
char
)
ch
);
}
...
...
@@ -415,5 +429,4 @@ public class MetaModelExService extends MetaModelServiceImpl {
}
}
}
}
ibzdst-core/src/main/java/cn/ibizlab/core/lite/extensions/domain/RelationshipModel.java
浏览文件 @
2aa2dc28
package
cn
.
ibizlab
.
core
.
lite
.
extensions
.
domain
;
import
cn.ibizlab.core.lite.domain.MetaRelationship
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
...
...
@@ -27,4 +28,6 @@ public class RelationshipModel {
private
String
entityId
;
private
MetaRelationship
relation
;
}
ibzdst-core/src/main/java/cn/ibizlab/core/lite/extensions/service/LiteModelService.java
浏览文件 @
2aa2dc28
package
cn
.
ibizlab
.
core
.
lite
.
extensions
.
service
;
import
cn.ibizlab.core.lite.domain.*
;
import
cn.ibizlab.core.extensions.domain.AssembleModel
;
import
cn.ibizlab.core.extensions.service.MetaModelExService
;
import
cn.ibizlab.core.lite.domain.DstApp
;
import
cn.ibizlab.core.lite.domain.DstSystem
;
import
cn.ibizlab.core.lite.domain.MetaEntity
;
import
cn.ibizlab.core.lite.domain.MetaModel
;
import
cn.ibizlab.core.lite.extensions.domain.EntityModel
;
import
cn.ibizlab.core.lite.extensions.domain.FieldModel
;
import
cn.ibizlab.core.lite.extensions.domain.RelationshipModel
;
import
cn.ibizlab.core.lite.extensions.model.DataModel
;
import
cn.ibizlab.core.lite.extensions.util.LiteStorage
;
import
cn.ibizlab.core.lite.filter.MetaEntitySearchContext
;
import
cn.ibizlab.core.lite.filter.MetaFieldSearchContext
;
import
cn.ibizlab.core.lite.service.*
;
import
cn.ibizlab.util.domain.FileItem
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.errors.InternalServerErrorException
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
Array
;
import
com.alibaba.fastjson.JSON
Object
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cache.annotation.Caching
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.DigestUtils
;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.
bind.annotation.PathVariab
le
;
import
org.springframework.web.
multipart.MultipartFi
le
;
import
javax.annotation.PostConstruct
;
import
java.
sql.Wrapper
;
import
java.
util.ArrayList
;
import
java.util.
LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.
io.*
;
import
java.
nio.file.Files
;
import
java.util.
*
;
import
static
cn
.
ibizlab
.
util
.
service
.
SimpleFileService
.
getExtensionName
;
@Service
public
class
LiteModelService
{
...
...
@@ -91,7 +99,7 @@ public class LiteModelService {
EntityModel
entityModel
=
new
EntityModel
();
entityModel
.
setEntity
(
entity
);
entityModel
.
setDataSets
(
metaDataSetService
.
selectByEntityId
(
entity
.
getEntityId
()
));
entityModel
.
setDataSets
(
metaDataSetService
.
selectByEntityId
(
entity
!=
null
?
entity
.
getEntityId
()
:
null
));
Map
<
String
,
RelationshipModel
>
parentSet
=
new
LinkedHashMap
();
List
<
RelationshipModel
>
references
=
new
ArrayList
<>();
...
...
@@ -100,6 +108,7 @@ public class LiteModelService {
RelationshipModel
model
=
new
RelationshipModel
();
MetaEntity
parentEntity
=
LiteStorage
.
getMetaEntity
(
item
.
getRefEntityId
());
if
(
parentEntity
!=
null
){
model
.
setRelation
(
item
);
model
.
setCodeName
(
item
.
getCodeName
());
model
.
setDataSourceName
(
parentEntity
.
getDsName
());
model
.
setEntityCodeName
(
parentEntity
.
getCodeName
());
...
...
@@ -120,6 +129,7 @@ public class LiteModelService {
RelationshipModel
model
=
new
RelationshipModel
();
MetaEntity
subEntity
=
LiteStorage
.
getMetaEntity
(
item
.
getEntityId
());
if
(
subEntity
!=
null
){
model
.
setRelation
(
item
);
model
.
setCodeName
(
StringUtils
.
isEmpty
(
item
.
getNestedName
())?
item
.
getCodeName
()+
"_"
+
item
.
getEntityName
():
item
.
getNestedName
());
model
.
setDataSourceName
(
subEntity
.
getDsName
());
model
.
setEntityCodeName
(
subEntity
.
getCodeName
());
...
...
@@ -195,6 +205,11 @@ public class LiteModelService {
@Lazy
private
IDstSystemService
dstSystemService
;
@Value
(
"${ibiz.filePath:/app/file/}"
)
private
String
fileRoot
;
@Autowired
private
MetaModelExService
metaModelExService
;
@Cacheable
(
value
=
"syspssystem"
,
key
=
"'row:all-dst-apps'"
)
public
LinkedHashMap
<
String
,
DstApp
>
getApps
()
{
...
...
@@ -247,4 +262,103 @@ public class LiteModelService {
return
list
;
}
public
FileItem
uploadFile
(
MultipartFile
multipartFile
)
{
FileItem
item
=
null
;
// 获取文件名
String
fileName
=
multipartFile
.
getOriginalFilename
();
// 获取文件后缀
String
extname
=
"."
+
getExtensionName
(
fileName
);
try
{
String
fileid
=
DigestUtils
.
md5DigestAsHex
(
multipartFile
.
getInputStream
());
String
fileFullPath
=
this
.
fileRoot
+
"ibizutil"
+
File
.
separator
+
File
.
separator
+
fileName
;
File
file
=
new
File
(
fileFullPath
);
File
parent
=
new
File
(
file
.
getParent
());
if
(!
parent
.
exists
())
{
parent
.
mkdirs
();
}
FileCopyUtils
.
copy
(
multipartFile
.
getInputStream
(),
Files
.
newOutputStream
(
file
.
toPath
()));
item
=
new
FileItem
(
fileid
,
fileName
,
fileid
,
fileName
,
(
int
)
multipartFile
.
getSize
(),
extname
);
}
catch
(
IOException
e
)
{
throw
new
InternalServerErrorException
(
"文件上传失败,"
+
e
);
}
return
item
;
}
public
String
saveFile
(
String
jsonObject
)
{
// 获取文件名
String
fileName
=
"packageModel_"
+
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
).
toUpperCase
();
// 获取文件后缀
String
extname
=
".json"
;
try
{
String
fileFullPath
=
this
.
fileRoot
+
"ibizutil"
+
File
.
separator
+
fileName
+
extname
;
File
file
=
new
File
(
fileFullPath
);
File
parent
=
new
File
(
file
.
getParent
());
if
(!
parent
.
exists
())
{
parent
.
mkdirs
();
}
writeFile
(
fileFullPath
,
jsonObject
);
}
catch
(
Exception
e
)
{
throw
new
InternalServerErrorException
(
"文件上传失败,"
+
e
);
}
return
fileName
+
extname
;
}
public
File
getFile
(
String
fileId
)
{
String
dirpath
=
this
.
fileRoot
+
"ibizutil"
+
File
.
separator
+
fileId
;
File
parent
=
new
File
(
dirpath
);
if
(
parent
.
exists
())
{
return
parent
;
}
throw
new
InternalServerErrorException
(
"文件未找到"
);
}
public
static
void
writeFile
(
String
filePath
,
String
sets
)
throws
IOException
{
FileWriter
fw
=
new
FileWriter
(
filePath
);
PrintWriter
out
=
new
PrintWriter
(
fw
);
out
.
write
(
sets
);
out
.
println
();
fw
.
close
();
out
.
close
();
}
public
String
exportFile
(
List
<
MetaModel
>
model
){
List
<
AssembleModel
>
temp
=
new
ArrayList
<>();
for
(
MetaModel
metaModel
:
model
)
{
temp
.
add
(
null
);
}
String
json
=
JSON
.
toJSONString
(
temp
);
String
fileName
=
this
.
saveFile
(
json
);
return
fileName
;
}
public
List
<
AssembleModel
>
translateFile
(
MultipartFile
file
){
BufferedReader
reader
=
null
;
String
ans
=
""
;
try
{
Reader
read
=
new
InputStreamReader
(
file
.
getInputStream
(),
"utf-8"
);
reader
=
new
BufferedReader
(
read
);
String
tmpString
=
null
;
while
((
tmpString
=
reader
.
readLine
())
!=
null
){
ans
+=
tmpString
;
}
if
(
StringUtils
.
isEmpty
(
ans
)){
throw
new
BadRequestAlertException
(
"文件内容为空"
,
""
,
""
);
}
List
<
AssembleModel
>
assembleModel
=
JSONObject
.
parseArray
(
ans
,
AssembleModel
.
class
);
return
assembleModel
;
}
catch
(
Exception
e
){
return
null
;
}
finally
{
if
(
reader
!=
null
){
try
{
reader
.
close
();
}
catch
(
IOException
ee
){
ee
.
printStackTrace
();
}
}
}
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录