Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdata
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdata
提交
578ff47f
提交
578ff47f
编写于
8月 26, 2021
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
剥离模型初始化
上级
7429b1c3
变更
6
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
102 行增加
和
83 行删除
+102
-83
LiteStorage.java
.../src/main/java/cn/ibizlab/core/data/lite/LiteStorage.java
+13
-22
ModelService.java
.../main/java/cn/ibizlab/core/data/service/ModelService.java
+35
-4
BaseDataService.java
...va/cn/ibizlab/core/data/service/impl/BaseDataService.java
+2
-0
DOModelServiceImpl.java
...cn/ibizlab/core/data/service/impl/DOModelServiceImpl.java
+28
-43
DSSettingServiceImpl.java
.../ibizlab/core/data/service/impl/DSSettingServiceImpl.java
+4
-4
DTOModelServiceImpl.java
...n/ibizlab/core/data/service/impl/DTOModelServiceImpl.java
+20
-10
未找到文件。
ibzdata-core/src/main/java/cn/ibizlab/core/data/lite/LiteStorage.java
浏览文件 @
578ff47f
package
cn
.
ibizlab
.
core
.
data
.
lite
;
import
cn.ibizlab.core.data.service.ModelService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Lazy
;
...
...
@@ -14,6 +15,7 @@ public class LiteStorage {
private
static
LiteModelFeignClient
liteModelFeignClient
;
private
static
DynamicModelService
dynamicModelService
;
private
static
ModelService
globalModelService
;
...
...
@@ -39,21 +41,15 @@ public class LiteStorage {
return
liteModelFeignClient
;
}
public
static
EntityModel
getEntityModel
(
String
system
,
String
entity
)
public
static
void
setModelService
(
ModelService
globalModelService
)
{
if
(
LiteStorage
.
globalModelService
==
null
)
LiteStorage
.
globalModelService
=
globalModelService
;
}
EntityModel
entityModel
=
null
;
try
{
entityModel
=
getDynamicModelService
().
getDynamicEntity
(
system
,
entity
);
}
catch
(
Exception
exception
)
{
}
if
(
entityModel
==
null
)
entityModel
=
getLiteModelService
().
getProxyEntityModel
(
system
,
entity
);
return
entityModel
;
public
static
ModelService
getModelService
()
{
return
globalModelService
;
}
...
...
@@ -64,22 +60,17 @@ public class LiteStorage {
@Lazy
private
DynamicModelService
dynamicService
;
@Autowired
private
ModelService
modelService
;
@Value
(
"${ibiz.model.path:/app/file/model/}"
)
private
String
modelPath
;
public
String
getModelPath
()
{
if
(
modelPath
.
equals
(
File
.
separator
))
return
modelPath
.
substring
(
0
,
modelPath
.
length
()-
1
);
return
modelPath
;
}
@PostConstruct
public
void
init
(){
LiteStorage
.
setLiteModelService
(
liteService
);
LiteStorage
.
setDynamicModelService
(
dynamicService
);
LiteStorage
.
MODEL_PATH
=
getModelPath
();
LiteStorage
.
setModelService
(
modelService
);
LiteStorage
.
MODEL_PATH
=
modelService
.
getModelPath
();
}
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/ModelService.java
浏览文件 @
578ff47f
...
...
@@ -2,6 +2,7 @@ package cn.ibizlab.core.data.service;
import
cn.ibizlab.core.data.domain.DOModel
;
import
cn.ibizlab.core.data.lite.*
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.model.PojoSchema
;
import
cn.ibizlab.core.data.model.TransUtils
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
...
...
@@ -16,6 +17,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
javax.annotation.PostConstruct
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.charset.StandardCharsets
;
...
...
@@ -30,6 +32,8 @@ import java.util.Map;
@Slf4j
public
class
ModelService
{
public
static
String
MODEL_PATH
;
@Value
(
"${ibiz.model.path:/app/file/model/}"
)
private
String
modelPath
;
...
...
@@ -55,10 +59,7 @@ public class ModelService {
private
ModelService
proxy
;
public
DOModel
getDOModel
(
String
system
,
String
entity
)
{
return
doModelService
.
get
(
system
+
".domain."
+
entity
);
}
...
...
@@ -196,6 +197,36 @@ public class ModelService {
return
entityModel
;
}
public
DOModel
loadDOModel
(
String
system
,
String
entity
)
{
EntityModel
entityModel
=
proxy
.
getEntityModel
(
system
,
entity
);
DOModel
doModel
=
new
DOModel
();
if
(
entityModel
!=
null
)
{
PojoSchema
schema
=
TransUtils
.
EntityModelModel2Schema
(
entityModel
);
if
(
schema
!=
null
)
{
doModel
.
setSchema
(
schema
);
for
(
String
dsType
:
entityModel
.
getDsTypes
())
{
POSchema
poSchema
=
TransUtils
.
EntityModelModel2PO
(
entityModel
,
dsType
);
if
(
poSchema
!=
null
)
{
doModel
.
addPOSchema
(
dsType
,
poSchema
);
}
}
}
}
return
doModel
;
}
public
DOModel
getDOModel
(
String
system
,
String
entity
)
{
return
doModelService
.
get
(
system
+
".domain."
+
entity
);
}
@PostConstruct
public
void
init
()
{
MODEL_PATH
=
this
.
getModelPath
();
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/BaseDataService.java
浏览文件 @
578ff47f
...
...
@@ -3,6 +3,7 @@ package cn.ibizlab.core.data.service.impl;
import
cn.ibizlab.core.data.domain.DOModel
;
import
cn.ibizlab.core.data.dto.*
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.service.IDOModelService
;
import
cn.ibizlab.core.data.service.IDSSettingService
;
import
cn.ibizlab.core.data.service.IDataService
;
import
cn.ibizlab.core.data.service.ModelService
;
...
...
@@ -44,6 +45,7 @@ public class BaseDataService implements IDataService {
@Autowired
private
IDSSettingService
dsSettingService
;
public
IDataService
getProxyService
(
String
datasource
)
{
DSLink
dsLink
=
dsSettingService
.
getDataSource
(
datasource
);
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/DOModelServiceImpl.java
浏览文件 @
578ff47f
...
...
@@ -9,11 +9,8 @@ import java.nio.file.Paths;
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
cn.ibizlab.core.data.service.ModelService
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.TypeReference
;
...
...
@@ -72,14 +69,14 @@ public class DOModelServiceImpl implements IDOModelService {
@Cacheable
(
value
=
"domodel"
,
key
=
"'row:'+#p0"
)
@Override
public
DOModel
get
(
String
key
)
{
DOModel
doModel
=
n
ew
DOModel
()
;
DOModel
doModel
=
n
ull
;
PojoSchema
schema
=
null
;
String
[]
args
=
key
.
split
(
"[.]"
);
String
system
=
args
[
0
];
String
entity
=
args
[
2
];
Path
storePath
=
Paths
.
get
(
LiteStorag
e
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"domain"
,
entity
+
".json"
);
Path
storePath
=
Paths
.
get
(
ModelServic
e
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"domain"
,
entity
+
".json"
);
if
(!
Files
.
exists
(
storePath
))
{
try
{
...
...
@@ -91,7 +88,7 @@ public class DOModelServiceImpl implements IDOModelService {
args
=
entityId
.
split
(
"[.]"
);
system
=
args
[
0
];
entity
=
args
[
2
];
storePath
=
Paths
.
get
(
LiteStorag
e
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"domain"
,
entity
+
".json"
);
storePath
=
Paths
.
get
(
ModelServic
e
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"domain"
,
entity
+
".json"
);
}
}
catch
(
Exception
exception
)
{
throw
new
BadRequestAlertException
(
"获取模型失败"
,
"DOModel"
,
key
);
...
...
@@ -100,56 +97,44 @@ public class DOModelServiceImpl implements IDOModelService {
if
(!
Files
.
exists
(
storePath
))
{
EntityModel
entityModel
=
modelService
.
getEntity
Model
(
system
,
entity
);
if
(
entityModel
!=
null
)
{
schema
=
TransUtils
.
EntityModelModel2Schema
(
entityModel
);
if
(
schema
!=
null
)
doModel
=
modelService
.
loadDO
Model
(
system
,
entity
);
schema
=
doModel
.
getSchema
();
if
(
schema
!=
null
)
{
if
(
doModel
.
getPoSchemas
()
!=
null
)
{
for
(
String
dsType:
entityModel
.
getDsTypes
())
{
POSchema
poSchema
=
TransUtils
.
EntityModelModel2PO
(
entityModel
,
dsType
);
if
(
poSchema
!=
null
)
{
doModel
.
addPOSchema
(
dsType
,
poSchema
);
}
Path
poPath
=
Paths
.
get
(
ModelService
.
MODEL_PATH
,
doModel
.
getSystemId
(),
"repo"
,
doModel
.
getName
(),
"repository"
,
doModel
.
getName
()+
".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
());
}
if
(
doModel
.
getPoSchemas
()!=
null
)
{
Path
poPath
=
Paths
.
get
(
LiteStorage
.
MODEL_PATH
,
entityModel
.
getSystemId
(),
"repo"
,
entityModel
.
getEntityName
(),
"repository"
,
entityModel
.
getEntityName
()+
".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
(
Paths
.
get
(
LiteStorage
.
MODEL_PATH
,
entityModel
.
getSystemId
(),
"repo"
,
entityModel
.
getEntityName
(),
"domain"
,
entityModel
.
getEntityName
()+
".json"
));
}
schema
.
writeTo
(
Paths
.
get
(
ModelService
.
MODEL_PATH
,
doModel
.
getSystemId
(),
"repo"
,
doModel
.
getName
(),
"domain"
,
doModel
.
getName
()+
".json"
));
}
}
else
{
doModel
=
new
DOModel
();
schema
=
PojoSchema
.
fromPath
(
storePath
);
Path
poPath
=
Paths
.
get
(
LiteStorage
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"repository"
,
entity
+
".json"
);
if
(
Files
.
exists
(
poPath
))
{
try
{
doModel
.
setPoSchemas
(
JSON
.
parseObject
(
new
String
(
Files
.
readAllBytes
(
poPath
),
StandardCharsets
.
UTF_8
),
new
TypeReference
<
LinkedHashMap
<
String
,
POSchema
>>(){}
));
}
catch
(
IOException
e
)
{
if
(
schema
!=
null
)
{
doModel
.
setSchema
(
schema
);
Path
poPath
=
Paths
.
get
(
ModelService
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"repository"
,
entity
+
".json"
);
if
(
Files
.
exists
(
poPath
))
{
try
{
doModel
.
setPoSchemas
(
JSON
.
parseObject
(
new
String
(
Files
.
readAllBytes
(
poPath
),
StandardCharsets
.
UTF_8
),
new
TypeReference
<
LinkedHashMap
<
String
,
POSchema
>>()
{
}));
}
catch
(
IOException
e
)
{
}
}
}
}
if
(
schema
!=
null
)
doModel
.
setSchema
(
schema
);
else
if
(
schema
==
null
)
throw
new
BadRequestAlertException
(
"未找到对应的模型"
,
"DOModel"
,
key
);
return
doModel
;
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/DSSettingServiceImpl.java
浏览文件 @
578ff47f
...
...
@@ -7,8 +7,8 @@ import java.nio.file.Paths;
import
java.nio.file.StandardOpenOption
;
import
java.util.*
;
import
cn.ibizlab.core.data.lite.LiteStorage
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.service.ModelService
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.TypeReference
;
import
com.baomidou.dynamic.datasource.DynamicRoutingDataSource
;
...
...
@@ -47,7 +47,7 @@ public class DSSettingServiceImpl implements IDSSettingService {
public
Map
<
String
,
DSLink
>
getAllConfigs
()
{
Path
path
=
Paths
.
get
(
LiteStorag
e
.
MODEL_PATH
,
"DATASOURCE.json"
);
Path
path
=
Paths
.
get
(
ModelServic
e
.
MODEL_PATH
,
"DATASOURCE.json"
);
try
{
Map
<
String
,
DSLink
>
all
=
new
LinkedHashMap
<>();
...
...
@@ -151,7 +151,7 @@ public class DSSettingServiceImpl implements IDSSettingService {
et
.
setDSLinkConfig
(
config
);
}
});
Path
path
=
Paths
.
get
(
LiteStorag
e
.
MODEL_PATH
,
"DATASOURCE.json"
);
Path
path
=
Paths
.
get
(
ModelServic
e
.
MODEL_PATH
,
"DATASOURCE.json"
);
try
{
Files
.
write
(
path
,
JSON
.
toJSONBytes
(
newConfigs
));
}
catch
(
Exception
e
)
{
...
...
@@ -229,7 +229,7 @@ public class DSSettingServiceImpl implements IDSSettingService {
newConfigs
.
put
(
config
.
getName
(),
et
.
getDSLinkConfig
());
}
});
Path
path
=
Paths
.
get
(
LiteStorag
e
.
MODEL_PATH
,
"DATASOURCE.json"
);
Path
path
=
Paths
.
get
(
ModelServic
e
.
MODEL_PATH
,
"DATASOURCE.json"
);
try
{
Files
.
write
(
path
,
JSON
.
toJSONBytes
(
newConfigs
));
}
catch
(
Exception
e
)
{
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/DTOModelServiceImpl.java
浏览文件 @
578ff47f
...
...
@@ -7,16 +7,15 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.Collection
;
import
cn.ibizlab.core.data.lite.EntityModel
;
import
cn.ibizlab.core.data.lite.LiteStorage
;
import
cn.ibizlab.core.data.domain.DOModel
;
import
cn.ibizlab.core.data.model.PojoSchema
;
import
cn.ibizlab.core.data.
model.TransUtils
;
import
cn.ibizlab.core.data.
service.ModelService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageImpl
;
import
org.springframework.beans.factory.annotation.Value
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
org.springframework.transaction.annotation.Transactional
;
import
cn.ibizlab.core.data.domain.DTOModel
;
...
...
@@ -31,8 +30,8 @@ import cn.ibizlab.core.data.service.IDTOModelService;
@Service
public
class
DTOModelServiceImpl
implements
IDTOModelService
{
@
Value
(
"${ibiz.model.path:/app/file/model/}"
)
private
String
modelPath
;
@
Autowired
private
ModelService
modelService
;
@Override
public
boolean
create
(
DTOModel
et
)
{
...
...
@@ -72,13 +71,24 @@ public class DTOModelServiceImpl implements IDTOModelService {
if
(
entity
.
endsWith
(
"DTO"
))
entity
=
entity
.
substring
(
0
,
entity
.
length
()-
3
);
Path
storePath
=
Paths
.
get
(
LiteStorage
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"dto"
,
dto
+
".json"
);
Path
storePath
=
Paths
.
get
(
ModelService
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"dto"
,
dto
+
".json"
);
if
(!
Files
.
exists
(
storePath
))
{
DOModel
doModel
=
modelService
.
getDOModel
(
system
,
entity
);
schema
=
doModel
.
getSchema
().
copy
();
system
=
doModel
.
getSystemId
();
dto
=
dto
.
replace
(
entity
,
doModel
.
getName
());
entity
=
doModel
.
getName
();
key
=
system
.
concat
(
".dto."
).
concat
(
dto
);
storePath
=
Paths
.
get
(
ModelService
.
MODEL_PATH
,
system
,
"repo"
,
entity
,
"dto"
,
dto
+
".json"
);
}
EntityModel
entityModel
=
LiteStorage
.
getEntityModel
(
system
,
entity
);
if
(
entityModel
!=
null
)
{
schema
=
TransUtils
.
EntityModelModel2Schema
(
entityModel
);
if
(!
Files
.
exists
(
storePath
))
{
if
(
schema
!=
null
)
{
schema
.
setName
(
dto
);
schema
.
setId
(
key
);
if
(
schema
!=
null
)
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录