Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzlite
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzlite
提交
125a5084
提交
125a5084
编写于
12月 28, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化初始化模型逻辑
上级
8c790a3a
变更
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
129 行增加
和
126 行删除
+129
-126
MetaEntityExService.java
.../ibizlab/core/extensions/service/MetaEntityExService.java
+129
-126
未找到文件。
ibzlite-core/src/main/java/cn/ibizlab/core/extensions/service/MetaEntityExService.java
浏览文件 @
125a5084
package
cn
.
ibizlab
.
core
.
extensions
.
service
;
package
cn
.
ibizlab
.
core
.
extensions
.
service
;
import
cn.ibizlab.core.lite.domain.MetaEntity
;
import
cn.ibizlab.core.lite.domain.MetaField
;
import
cn.ibizlab.core.lite.domain.MetaModel
;
import
cn.ibizlab.core.lite.domain.MetaModel
;
import
cn.ibizlab.core.lite.domain.MetaRelationship
;
import
cn.ibizlab.core.lite.domain.MetaRelationship
;
import
cn.ibizlab.core.lite.extensions.model.DataModel
;
import
cn.ibizlab.core.lite.extensions.model.DataModel
;
import
cn.ibizlab.core.lite.extensions.model.LayerMapping
;
import
cn.ibizlab.core.lite.extensions.model.LayerMapping
;
import
cn.ibizlab.core.lite.extensions.model.Property
;
import
cn.ibizlab.core.lite.extensions.model.Property
;
import
cn.ibizlab.core.lite.extensions.model.PropertyMapping
;
import
cn.ibizlab.core.lite.extensions.model.PropertyMapping
;
import
cn.ibizlab.core.lite.extensions.service.LiteModelService
;
import
cn.ibizlab.core.lite.service.IMetaModelService
;
import
cn.ibizlab.core.lite.service.IMetaModelService
;
import
cn.ibizlab.core.lite.service.IMetaRelationshipService
;
import
cn.ibizlab.core.lite.service.impl.MetaEntityServiceImpl
;
import
cn.ibizlab.core.lite.service.impl.MetaEntityServiceImpl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
liquibase.pro.packaged.D
;
import
liquibase.pro.packaged.M
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
cn.ibizlab.core.lite.domain.MetaEntity
;
import
cn.ibizlab.core.lite.extensions.service.LiteModelService
;
import
org.bouncycastle.pqc.crypto.rainbow.Layer
;
import
org.springframework.security.core.parameters.P
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.util.
*
;
import
java.util.
LinkedHashSet
;
import
java.util.
stream.Collectors
;
import
java.util.
List
;
/**
/**
* 实体[实体] 自定义服务对象
* 实体[实体] 自定义服务对象
...
@@ -38,6 +32,8 @@ import java.util.stream.Collectors;
...
@@ -38,6 +32,8 @@ import java.util.stream.Collectors;
@Service
(
"MetaEntityExService"
)
@Service
(
"MetaEntityExService"
)
public
class
MetaEntityExService
extends
MetaEntityServiceImpl
{
public
class
MetaEntityExService
extends
MetaEntityServiceImpl
{
private
final
int
loop
=
2
;
@Override
@Override
protected
Class
currentModelClass
()
{
protected
Class
currentModelClass
()
{
return
com
.
baomidou
.
mybatisplus
.
core
.
toolkit
.
ReflectionKit
.
getSuperClassGenericType
(
this
.
getClass
().
getSuperclass
(),
1
);
return
com
.
baomidou
.
mybatisplus
.
core
.
toolkit
.
ReflectionKit
.
getSuperClassGenericType
(
this
.
getClass
().
getSuperclass
(),
1
);
...
@@ -45,6 +41,7 @@ public class MetaEntityExService extends MetaEntityServiceImpl {
...
@@ -45,6 +41,7 @@ public class MetaEntityExService extends MetaEntityServiceImpl {
/**
/**
* [GetDefaultModel:GetDefaultModel] 行为扩展
* [GetDefaultModel:GetDefaultModel] 行为扩展
*
* @param et
* @param et
* @return
* @return
*/
*/
...
@@ -58,156 +55,162 @@ public class MetaEntityExService extends MetaEntityServiceImpl {
...
@@ -58,156 +55,162 @@ public class MetaEntityExService extends MetaEntityServiceImpl {
@Lazy
@Lazy
private
LiteModelService
liteModelService
;
private
LiteModelService
liteModelService
;
@Autowired
@Lazy
private
IMetaRelationshipService
metaRelationshipService
;
@Autowired
@Autowired
@Lazy
@Lazy
private
IMetaModelService
metaModelService
;
private
IMetaModelService
metaModelService
;
@Override
@Override
public
boolean
update
(
MetaEntity
et
)
public
boolean
update
(
MetaEntity
et
)
{
{
if
(!
super
.
update
(
et
))
if
(!
super
.
update
(
et
))
return
false
;
return
false
;
liteModelService
.
resetEntityModel
(
et
.
getSystemId
(),
et
.
getEntityName
());
liteModelService
.
resetEntityModel
(
et
.
getSystemId
(),
et
.
getEntityName
());
return
true
;
return
true
;
}
}
@Override
@Override
public
MetaEntity
initModels
(
MetaEntity
et
)
{
public
MetaEntity
initModels
(
MetaEntity
et
)
{
todoBaseModel
(
baseMapper
.
selectById
(
et
.
getEntityId
()));
et
=
get
(
et
.
getEntityId
());
DataModel
dm
=
getDataModel
(
et
,
loop
,
null
);
String
json
=
JSON
.
toJSONString
(
dm
);
JSONObject
modelCfg
=
JSON
.
parseObject
(
json
);
modelCfg
.
remove
(
"dataModelId"
);
MetaModel
model
=
new
MetaModel
();
model
.
setId
(
et
.
getEntityId
());
model
.
setName
(
et
.
getEntityName
());
model
.
setCodeName
(
et
.
getCodeName
());
model
.
setSystemId
(
et
.
getSystemId
());
model
.
setConfig
(
modelCfg
.
toJSONString
());
metaModelService
.
save
(
model
);
return
et
;
return
et
;
}
}
/**
/**
* 根据所选实体执行生成主模型
* 获取实体模型结构
*
* @param et 实体
* @param et 所选实体
* @param loop 关系嵌套层级(默认只取2层),如:order --> orderDetail
* @return 执行结果
* @param parent 父关系
* @return
*/
*/
@Transactional
private
DataModel
getDataModel
(
MetaEntity
et
,
int
loop
,
MetaRelationship
parent
)
{
public
Boolean
todoBaseModel
(
MetaEntity
et
)
{
DataModel
model
=
new
DataModel
();
DataModel
dm
=
new
DataModel
();
model
.
setDataModelName
(
et
.
getEntityName
());
dm
.
setDataModelName
(
et
.
getEntityName
());
if
(
loop
>
0
)
{
dm
.
setObjectProperties
(
findParRelation
(
et
));
loop
--;
dm
.
setNestedDataModels
(
assembleModel
(
et
));
model
.
setObjectProperties
(
getParentModel
(
et
));
//获取主
model
.
setNestedDataModels
(
getNestedModel
(
et
,
loop
));
//获取从
String
json
=
JSON
.
toJSONString
(
dm
);
}
JSONObject
jsonObject
=
JSON
.
parseObject
(
json
);
if
(!
ObjectUtils
.
isEmpty
(
parent
))
{
jsonObject
.
remove
(
"dataModelId"
);
model
.
setLayerMappings
(
getMapping
(
et
,
parent
));
//获取关系
}
MetaModel
mm
=
new
MetaModel
();
return
model
;
mm
.
setName
(
et
.
getTableName
()
+
"_模型:"
+
UUID
.
randomUUID
().
toString
().
substring
(
0
,
5
).
toUpperCase
());
mm
.
setCodeName
(
et
.
getTableName
());
mm
.
setConfig
(
jsonObject
.
toJSONString
());
mm
.
setSystemId
(
et
.
getSystemId
());
return
metaModelService
.
create
(
mm
);
}
}
/**
/**
*
通过传入一个实体对象,生成对应的主从关系
*
获取子关系模型
*
*
@param et
* @param
et 实体对象
* @param
loop
* @return
主从关系组
* @return
*/
*/
public
LinkedHashSet
<
Property
>
findParRelation
(
MetaEntity
et
)
{
private
LinkedHashSet
<
DataModel
>
getNestedModel
(
MetaEntity
et
,
int
loop
)
{
Property
property
;
LinkedHashSet
<
DataModel
>
models
=
new
LinkedHashSet
<>();
Property
temp
;
//主关系
MetaEntity
parEntity
;
List
<
MetaRelationship
>
subList
=
et
.
getSubEntitys
();
PropertyMapping
propertyMapping
;
if
(!
ObjectUtils
.
isEmpty
(
subList
))
{
LinkedHashSet
<
PropertyMapping
>
propertyMappingSet
;
for
(
MetaRelationship
relation
:
subList
)
{
LinkedHashSet
<
Property
>
parPropertyList
=
new
LinkedHashSet
<>();
DataModel
model
=
null
;
MetaEntity
subEntity
=
relation
.
getEntity
();
// 查询所有从关系
if
(!
ObjectUtils
.
isEmpty
(
subEntity
))
{
List
<
MetaRelationship
>
parList
=
metaRelationshipService
.
selectByEntityId
(
et
.
getEntityId
());
model
=
getDataModel
(
subEntity
,
loop
,
relation
);
if
(!
ObjectUtils
.
isEmpty
(
parList
))
{
models
.
add
(
model
);
List
<
String
>
refIds
=
parList
.
stream
().
map
(
MetaRelationship:
:
getRefEntityId
).
collect
(
Collectors
.
toList
());
}
for
(
int
i
=
0
;
i
<
refIds
.
size
();
i
++)
{
models
.
add
(
model
);
parEntity
=
baseMapper
.
selectById
(
refIds
.
get
(
i
));
}
}
return
models
;
}
/**
* 获取父关系模型
* @param et
* @return
*/
public
LinkedHashSet
<
Property
>
getParentModel
(
MetaEntity
et
)
{
LinkedHashSet
<
Property
>
properties
=
new
LinkedHashSet
<>();
List
<
MetaField
>
fields
=
et
.
getFields
();
List
<
MetaRelationship
>
parentList
=
et
.
getParentEntitys
();
if
(!
ObjectUtils
.
isEmpty
(
parentList
))
{
Property
master
=
new
Property
();
master
.
setPropertyName
(
et
.
getEntityName
());
master
.
setSystem
(
et
.
getSystemId
());
master
.
setPropertyEntity
(
et
.
getEntityName
());
properties
.
add
(
master
);
for
(
MetaRelationship
relation
:
parentList
)
{
MetaField
fkField
=
getForeignkey
(
fields
,
relation
);
if
(
fkField
==
null
)
{
log
.
error
(
"未能找到实体关系{}对应的外键属性"
,
relation
.
getName
());
continue
;
}
// 存储对象参数集合
// 存储对象参数集合
property
=
new
Property
();
Property
property
=
new
Property
();
propertyMapping
=
new
PropertyMapping
();
property
.
setPropertyName
(
relation
.
getRefEntityName
()
==
null
?
""
:
relation
.
getRefEntityName
());
property
.
setPropertyName
(
parEntity
.
getEntityName
()
==
null
?
""
:
parEntity
.
getEntityName
());
property
.
setSystem
(
et
.
getSystemId
()
==
null
?
""
:
et
.
getSystemId
());
property
.
setSystem
(
parEntity
.
getSystemId
()
==
null
?
""
:
parEntity
.
getSystemId
());
property
.
setPropertyEntity
(
relation
.
getRefEntityName
()
==
null
?
""
:
relation
.
getRefEntityName
());
property
.
setPropertyEntity
(
parEntity
.
getTableName
()
==
null
?
""
:
parEntity
.
getTableName
());
// 对应存储相同实体id关系
// 对应存储相同实体id关系
propertyMapping
.
setSelfPropertyColumn
(
parList
.
get
(
i
).
getCodeName
()
==
null
?
""
:
parList
.
get
(
i
).
getCodeName
());
PropertyMapping
mapping
=
new
PropertyMapping
();
propertyMapping
.
setJoinPropertyName
(
parList
.
get
(
i
).
getEntityName
()
==
null
?
""
:
parList
.
get
(
i
).
getEntityName
());
mapping
.
setSelfPropertyColumn
(
fkField
.
getRefFieldName
()
==
null
?
""
:
fkField
.
getRefFieldName
());
propertyMapping
.
setJoinPropertyColumn
(
parList
.
get
(
i
).
getCodeName
()
==
null
?
""
:
parList
.
get
(
i
).
getCodeName
());
mapping
.
setJoinPropertyName
(
relation
.
getEntityName
()
==
null
?
""
:
relation
.
getEntityName
());
mapping
.
setJoinPropertyColumn
(
fkField
.
getFieldName
()
==
null
?
""
:
fkField
.
getFieldName
());
// 添加主实体在集合头部
if
(
i
==
0
)
{
property
.
setPropertyMappings
(
new
LinkedHashSet
<
PropertyMapping
>()
{{
temp
=
new
Property
();
add
(
mapping
);
temp
.
setPropertyName
(
et
.
getEntityName
());
}});
temp
.
setSystem
(
et
.
getSystemId
());
properties
.
add
(
property
);
temp
.
setPropertyEntity
(
et
.
getTableName
());
parPropertyList
.
add
(
temp
);
}
propertyMappingSet
=
new
LinkedHashSet
<>();
parPropertyList
.
add
(
property
);
propertyMappingSet
.
add
(
propertyMapping
);
property
.
setPropertyMappings
(
propertyMappingSet
);
}
}
}
}
return
p
arPropertyList
;
return
p
roperties
;
}
}
/**
/**
*
传入一个对象,返回一个数据模型Set集合
*
获取父关系映射
*
*
@param et
* @param
et 实体对象
* @param
relation
* @return
数据模型
* @return
*/
*/
public
DataModel
findSubEntityRelation
(
MetaEntity
et
,
String
son
,
String
parent
)
{
private
LinkedHashSet
<
LayerMapping
>
getMapping
(
MetaEntity
et
,
MetaRelationship
relation
)
{
DataModel
dm
=
new
DataModel
();
LinkedHashSet
<
LayerMapping
>
mappings
=
new
LinkedHashSet
<>();
LinkedHashSet
<
LayerMapping
>
layerMappings
=
new
LinkedHashSet
<>();
List
<
MetaField
>
fields
=
et
.
getFields
();
LayerMapping
layerMapping
=
new
LayerMapping
();
if
(!
ObjectUtils
.
isEmpty
(
fields
))
{
layerMapping
.
setSelfPropertyColumn
(
son
);
MetaField
fkField
=
getForeignkey
(
fields
,
relation
);
layerMapping
.
setParentPropertyColumn
(
parent
);
if
(
fkField
==
null
)
{
layerMappings
.
add
(
layerMapping
);
log
.
error
(
"未能找到实体关系{}对应的外键属性"
,
relation
.
getName
());
return
mappings
;
dm
.
setDataModelName
(
et
.
getEntityName
());
}
dm
.
setObjectProperties
(
findParRelation
(
et
));
LayerMapping
mapping
=
new
LayerMapping
();
mapping
.
setSelfPropertyColumn
(
fkField
.
getFieldName
());
// 添加递归在此
mapping
.
setParentPropertyColumn
(
fkField
.
getRefFieldName
());
dm
.
setNestedDataModels
(
null
);
mappings
.
add
(
mapping
);
dm
.
setLayerMappings
(
layerMappings
);
}
return
mappings
;
return
dm
;
}
}
/**
/**
*
组合成一个主从模型
*
获取外键属性
*
*
* @return 数据模型Set集合
* @param fields
* @param relation
* @return
*/
*/
public
LinkedHashSet
<
DataModel
>
assembleModel
(
MetaEntity
et
)
{
private
MetaField
getForeignkey
(
List
<
MetaField
>
fields
,
MetaRelationship
relation
)
{
List
<
MetaEntity
>
subEntityList
;
for
(
MetaField
field
:
fields
)
{
LinkedHashSet
<
DataModel
>
dataModels
=
new
LinkedHashSet
<>();
String
relationName
=
field
.
getRelationName
();
if
(!
StringUtils
.
isEmpty
(
relationName
)
&&
relationName
.
equalsIgnoreCase
(
relation
.
getName
())
&&
"PICKUP"
.
equalsIgnoreCase
(
field
.
getFieldType
()))
{
List
<
MetaRelationship
>
subList
=
metaRelationshipService
.
selectByRefEntityId
(
et
.
getEntityId
());
return
field
;
if
(!
ObjectUtils
.
isEmpty
(
subList
))
{
List
<
String
>
ids
=
subList
.
stream
().
map
(
MetaRelationship:
:
getEntityId
).
collect
(
Collectors
.
toList
());
subEntityList
=
baseMapper
.
selectBatchIds
(
ids
);
for
(
MetaEntity
metaEntity
:
subEntityList
)
{
for
(
int
i
=
0
;
i
<
subList
.
size
();
i
++)
{
if
(
metaEntity
.
getEntityId
().
equals
(
subList
.
get
(
i
).
getEntityId
()))
{
dataModels
.
add
(
findSubEntityRelation
(
metaEntity
,
subList
.
get
(
i
).
getCodeName
(),
et
.
getCodeName
()));
}
}
}
}
}
}
return
dataModels
;
return
null
;
}
}
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录