Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdata
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdata
提交
277ba0e5
提交
277ba0e5
编写于
8月 29, 2021
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持多级地址栏参数,mongodb实现
上级
294a10fa
变更
11
展开全部
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
1129 行增加
和
180 行删除
+1129
-180
DOModel.java
...re/src/main/java/cn/ibizlab/core/data/domain/DOModel.java
+26
-25
BaseData.java
...core/src/main/java/cn/ibizlab/core/data/dto/BaseData.java
+96
-2
FilterData.java
...re/src/main/java/cn/ibizlab/core/data/dto/FilterData.java
+25
-63
RequestData.java
...e/src/main/java/cn/ibizlab/core/data/dto/RequestData.java
+6
-0
DSLink.java
...core/src/main/java/cn/ibizlab/core/data/model/DSLink.java
+11
-0
DynamicMongoContextHolder.java
.../ibizlab/core/data/mongodb/DynamicMongoContextHolder.java
+72
-0
DynamicMongoTemplate.java
...va/cn/ibizlab/core/data/mongodb/DynamicMongoTemplate.java
+20
-0
MongoDataRepository.java
...ava/cn/ibizlab/core/data/mongodb/MongoDataRepository.java
+524
-0
DataResource.java
...src/main/java/cn/ibizlab/core/data/rest/DataResource.java
+330
-86
DSSettingServiceImpl.java
.../ibizlab/core/data/service/impl/DSSettingServiceImpl.java
+16
-4
MongoDataServiceImpl.java
.../ibizlab/core/data/service/impl/MongoDataServiceImpl.java
+3
-0
未找到文件。
ibzdata-core/src/main/java/cn/ibizlab/core/data/domain/DOModel.java
浏览文件 @
277ba0e5
...
...
@@ -175,18 +175,18 @@ public class DOModel implements Serializable {
Map
<
String
,
PojoSchema
>
keyMap
=
this
.
getKeyMap
();
if
(
keyMap
!=
null
)
{
if
(
keyMap
.
size
()==
1
)
PojoSchema
keyProperty
=
this
.
getKeyProperty
();
String
keyPropertyName
=
keyProperty
.
getName
().
toLowerCase
();
Object
key
=
data
.
get
(
keyPropertyName
);
if
(
ObjectUtils
.
isEmpty
(
key
))
{
PojoSchema
keyProperty
=
this
.
getKeyProperty
();
String
keyPropertyName
=
keyProperty
.
getName
().
toLowerCase
();
Object
key
=
data
.
get
(
keyPropertyName
);
if
(
ObjectUtils
.
isEmpty
(
key
))
{
key
=
data
.
getKey
();
if
(!
ObjectUtils
.
isEmpty
(
key
))
data
.
set
(
keyPropertyName
,
key
);
}
if
(
ObjectUtils
.
isEmpty
(
key
))
key
=
data
.
getKey
();
if
(!
ObjectUtils
.
isEmpty
(
key
))
data
.
set
(
keyPropertyName
,
key
);
}
if
(
ObjectUtils
.
isEmpty
(
key
))
{
if
(
keyMap
.
size
()==
1
)
{
if
(
genKeyWhenNotExists
)
{
...
...
@@ -213,28 +213,28 @@ public class DOModel implements Serializable {
}
data
.
set
(
keyPropertyName
,
key
);
data
.
setKey
(
key
);
}
else
return
null
;
}
return
(
Serializable
)
key
;
}
else
if
(
keyMap
.
size
()>
1
)
{
String
key
=
""
;
for
(
PojoSchema
keySchema:
keyMap
.
values
())
else
if
(
keyMap
.
size
()>
1
)
{
if
(
ObjectUtils
.
isEmpty
(
data
.
get
(
keySchema
.
getName
().
toLowerCase
())))
return
null
;
if
(!
StringUtils
.
isEmpty
(
key
))
key
+=
"||"
;
else
key
+=
data
.
getStringValue
(
keySchema
.
getName
().
toLowerCase
());
for
(
PojoSchema
keySchema:
keyMap
.
values
())
{
if
(
ObjectUtils
.
isEmpty
(
data
.
get
(
keySchema
.
getName
().
toLowerCase
())))
return
null
;
if
(!
StringUtils
.
isEmpty
(
key
))
key
+=
"||"
;
else
key
+=
data
.
getStringValue
(
keySchema
.
getName
().
toLowerCase
());
}
data
.
setKey
(
key
);
}
return
key
;
}
return
(
Serializable
)
key
;
}
return
null
;
}
...
...
@@ -246,6 +246,7 @@ public class DOModel implements Serializable {
public
BaseData
setKeyValue
(
BaseData
data
,
Object
keyValue
)
{
Map
<
String
,
PojoSchema
>
keyMap
=
this
.
getKeyMap
();
data
.
setKey
(
keyValue
);
if
(
keyMap
!=
null
)
{
if
(
keyMap
.
size
()==
1
)
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/dto/BaseData.java
浏览文件 @
277ba0e5
...
...
@@ -4,13 +4,16 @@ import cn.ibizlab.core.data.domain.DOModel;
import
cn.ibizlab.core.data.domain.DTOModel
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.model.PojoSchema
;
import
cn.ibizlab.util.security.AuthenticationUser
;
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.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.Serializable
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
@JsonInclude
(
JsonInclude
.
Include
.
ALWAYS
)
...
...
@@ -119,14 +122,105 @@ public class BaseData extends DataObj
return
_pojoschema
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
BaseData
getParams
()
{
BaseData
param
=
null
;
Object
obj
=
this
.
get
(
"params"
);
if
(
obj
!=
null
)
{
if
(
obj
instanceof
BaseData
)
param
=(
BaseData
)
obj
;
else
if
(
obj
instanceof
Map
)
{
param
=
new
BaseData
().
setAll
((
Map
)
obj
);
this
.
set
(
"params"
,
param
);
}
}
else
{
return
this
;
}
return
param
;
}
public
BaseData
setParams
(
BaseData
params
)
{
return
this
.
set
(
"params"
,
params
);
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
BaseData
getDatacontext
()
{
return
getParams
();
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
BaseData
getWebcontext
()
{
return
getParams
();
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
BaseData
sessioncontext
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
BaseData
getSessioncontext
()
{
if
(
sessioncontext
==
null
)
sessioncontext
=
new
BaseData
().
setAll
(
AuthenticationUser
.
getAuthenticationUser
().
getSessionParams
());
return
sessioncontext
;
}
@Override
public
Object
get
(
Object
key
)
{
if
(
key
==
null
)
return
null
;
if
(
key
.
toString
().
equalsIgnoreCase
(
"datacontext"
))
return
getDatacontext
();
else
if
(
key
.
toString
().
equalsIgnoreCase
(
"webcontext"
))
return
getWebcontext
();
else
if
(
key
.
toString
().
equalsIgnoreCase
(
"sessioncontext"
))
return
getSessioncontext
();
return
super
.
get
(
key
);
}
public
BaseData
setKey
(
Object
key
)
{
return
this
.
set
(
"_
key
"
,
key
);
return
this
.
set
(
"_
id
"
,
key
);
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Serializable
getKey
()
{
return
getSerializableValue
(
"_key"
);
return
getSerializableValue
(
"_id"
);
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
Map
<
String
,
BaseData
>
parentDatas
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
Map
<
String
,
BaseData
>
getParentData
()
{
return
parentDatas
;
}
public
BaseData
addParent
(
String
entity
,
String
key
)
{
if
(
StringUtils
.
isEmpty
(
entity
)||
StringUtils
.
isEmpty
(
key
))
return
this
;
if
(
parentDatas
==
null
)
parentDatas
=
new
LinkedHashMap
<>();
parentDatas
.
put
(
entity
,
new
BaseData
().
setKey
(
key
));
return
this
;
}
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/dto/FilterData.java
浏览文件 @
277ba0e5
package
cn
.
ibizlab
.
core
.
data
.
dto
;
import
cn.ibizlab.core.data.filter.QueryBuildContext
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.core.data.filter.QueryFilter
;
...
...
@@ -11,6 +12,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.mongodb.QueryBuilder
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Sort
;
...
...
@@ -129,72 +131,12 @@ public class FilterData<T> extends BaseData
return
this
;
}
public
BaseData
getParams
(
)
public
FilterData
addParent
(
String
entity
,
String
key
)
{
BaseData
param
=
null
;
Object
obj
=
this
.
get
(
"params"
);
if
(
obj
!=
null
)
{
if
(
obj
instanceof
BaseData
)
param
=(
BaseData
)
obj
;
else
if
(
obj
instanceof
Map
)
{
param
=
new
BaseData
().
setAll
((
Map
)
obj
);
this
.
set
(
"params"
,
param
);
}
}
else
{
return
this
;
}
return
param
;
}
public
FilterData
setParams
(
BaseData
params
)
{
return
this
.
set
(
"params"
,
params
);
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
BaseData
getDatacontext
()
{
return
getParams
();
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
BaseData
getWebcontext
()
{
return
getParams
();
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
BaseData
sessioncontext
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
BaseData
getSessioncontext
()
{
if
(
sessioncontext
==
null
)
sessioncontext
=
new
BaseData
().
setAll
(
AuthenticationUser
.
getAuthenticationUser
().
getSessionParams
());
return
sessioncontext
;
}
@Override
public
Object
get
(
Object
key
)
{
if
(
key
==
null
)
return
null
;
if
(
key
.
toString
().
equalsIgnoreCase
(
"datacontext"
))
return
getDatacontext
();
else
if
(
key
.
toString
().
equalsIgnoreCase
(
"webcontext"
))
return
getWebcontext
();
else
if
(
key
.
toString
().
equalsIgnoreCase
(
"sessioncontext"
))
return
getSessioncontext
();
return
super
.
get
(
key
);
super
.
addParent
(
entity
,
key
);
return
this
;
}
public
String
getUserTaskId
()
{
return
this
.
getStringValue
(
"userTaskId"
,
this
.
getParams
().
getStringValue
(
"userTaskId"
));
}
...
...
@@ -354,6 +296,26 @@ public class FilterData<T> extends BaseData
return
searchCond
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
QueryBuilder
queryBuilder
=
null
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
QueryBuilder
getQueryBuilder
()
{
if
(
queryBuilder
==
null
)
{
if
(!
ObjectUtils
.
isEmpty
(
filter
)){
QueryBuildContext
context
=
new
QueryBuildContext
();
context
.
setFilter
(
this
.
getFilter
());
queryBuilder
=
context
.
getSelectCond
();
}
else
queryBuilder
=
new
QueryBuilder
();
}
return
queryBuilder
;
}
public
String
getSql
(
String
codename
)
{
if
(
getPOSchema
()==
null
)
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/dto/RequestData.java
浏览文件 @
277ba0e5
...
...
@@ -124,4 +124,10 @@ public class RequestData<T> extends BaseData
}
public
RequestData
addParent
(
String
entity
,
String
key
)
{
getBaseData
().
addParent
(
entity
,
key
);
return
this
;
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/model/DSLink.java
浏览文件 @
277ba0e5
...
...
@@ -70,6 +70,17 @@ public class DSLink
return
this
;
}
@JSONField
(
serialize
=
false
)
@JsonIgnore
public
Object
source
;
public
DSLink
setSource
(
Object
source
)
{
this
.
source
=
source
;
return
this
;
}
private
static
DSLink
defaultLink
;
public
static
DSLink
getDefaultLink
()
{
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/mongodb/DynamicMongoContextHolder.java
0 → 100644
浏览文件 @
277ba0e5
package
cn
.
ibizlab
.
core
.
data
.
mongodb
;
import
cn.ibizlab.core.data.model.DSLink
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.data.mongodb.MongoDbFactory
;
import
org.springframework.data.mongodb.core.SimpleMongoClientDbFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
javax.annotation.PostConstruct
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
@Component
public
class
DynamicMongoContextHolder
{
private
static
final
Map
<
String
,
MongoDbFactory
>
MONGO_CLIENT_DB_FACTORY_MAP
=
new
HashMap
<>();
private
static
final
ThreadLocal
<
MongoDbFactory
>
MONGO_DB_FACTORY_THREAD_LOCAL
=
new
ThreadLocal
<>();
public
static
MongoDbFactory
getMongoDbFactory
()
{
return
MONGO_DB_FACTORY_THREAD_LOCAL
.
get
();
}
public
static
void
push
(
String
name
)
{
MONGO_DB_FACTORY_THREAD_LOCAL
.
set
(
MONGO_CLIENT_DB_FACTORY_MAP
.
get
(
name
));
}
public
static
void
poll
()
{
MONGO_DB_FACTORY_THREAD_LOCAL
.
remove
();
}
public
static
synchronized
void
addFactory
(
String
ds
,
DSLink
link
)
{
addFactory
(
ds
,
link
.
getUrl
());
}
public
static
synchronized
void
addFactory
(
String
ds
,
String
uri
)
{
MONGO_CLIENT_DB_FACTORY_MAP
.
put
(
ds
,
new
SimpleMongoClientDbFactory
(
uri
));
}
public
static
synchronized
void
removeFactory
(
String
ds
)
{
MONGO_CLIENT_DB_FACTORY_MAP
.
remove
(
ds
);
}
@Value
(
"${spring.data.mongodb.uri}"
)
private
String
uri
;
@PostConstruct
public
void
init
()
{
if
(!
StringUtils
.
isEmpty
(
uri
))
{
addFactory
(
"master"
,
uri
);
}
}
@Bean
(
name
=
"mongoTemplate"
)
public
DynamicMongoTemplate
dynamicMongoTemplate
()
{
Iterator
<
MongoDbFactory
>
iterator
=
MONGO_CLIENT_DB_FACTORY_MAP
.
values
().
iterator
();
return
new
DynamicMongoTemplate
(
iterator
.
next
());
}
@Bean
(
name
=
"mongoDbFactory"
)
public
MongoDbFactory
mongoDbFactory
()
{
Iterator
<
MongoDbFactory
>
iterator
=
MONGO_CLIENT_DB_FACTORY_MAP
.
values
().
iterator
();
return
iterator
.
next
();
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/mongodb/DynamicMongoTemplate.java
0 → 100644
浏览文件 @
277ba0e5
package
cn
.
ibizlab
.
core
.
data
.
mongodb
;
import
com.mongodb.client.MongoDatabase
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.mongodb.MongoDbFactory
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
@Slf4j
public
class
DynamicMongoTemplate
extends
MongoTemplate
{
public
DynamicMongoTemplate
(
MongoDbFactory
mongoDbFactory
)
{
super
(
mongoDbFactory
);
}
@Override
protected
MongoDatabase
doGetDatabase
()
{
MongoDbFactory
mongoDbFactory
=
DynamicMongoContextHolder
.
getMongoDbFactory
();
return
mongoDbFactory
==
null
?
super
.
doGetDatabase
()
:
mongoDbFactory
.
getDb
();
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/mongodb/MongoDataRepository.java
0 → 100644
浏览文件 @
277ba0e5
此差异已折叠。
点击以展开。
ibzdata-core/src/main/java/cn/ibizlab/core/data/rest/DataResource.java
浏览文件 @
277ba0e5
此差异已折叠。
点击以展开。
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/DSSettingServiceImpl.java
浏览文件 @
277ba0e5
...
...
@@ -8,6 +8,7 @@ import java.nio.file.StandardOpenOption;
import
java.util.*
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.mongodb.DynamicMongoContextHolder
;
import
cn.ibizlab.core.data.service.ModelService
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.TypeReference
;
...
...
@@ -111,6 +112,8 @@ public class DSSettingServiceImpl implements IDSSettingService {
DynamicRoutingDataSource
ds
=
(
DynamicRoutingDataSource
)
dataSource
;
ds
.
removeDataSource
(
et
.
getDsId
());
}
else
if
(
et
.
isMongodb
())
DynamicMongoContextHolder
.
removeFactory
(
et
.
getDsId
());
check
.
remove
(
et
.
getDsId
());
}
if
(!
et
.
getDsId
().
equals
(
et
.
getDsId
().
toLowerCase
()))
...
...
@@ -279,22 +282,29 @@ public class DSSettingServiceImpl implements IDSSettingService {
{
synchronized
(
lock
)
{
DSLink
dsLink
=
dstDataSource
.
getDSLinkConfig
();
if
(
dstDataSource
.
isDatabase
())
{
DataSourceProperty
dataSourceProperty
=
dstDataSource
.
getDataSourceProperty
();
DynamicRoutingDataSource
ds
=
dataSource
;
DataSource
dataSource
=
druidDataSourceCreator
.
createDataSource
(
dataSourceProperty
);
ds
.
addDataSource
(
dstDataSource
.
getDsId
(),
dataSource
);
dsLink
.
setSource
(
dataSource
);
}
check
.
put
(
dstDataSource
.
getDsId
(),
dstDataSource
.
getDSLinkConfig
());
else
if
(
dstDataSource
.
isMongodb
())
{
DynamicMongoContextHolder
.
addFactory
(
dstDataSource
.
getDsId
(),
dsLink
);
}
check
.
put
(
dstDataSource
.
getDsId
(),
dsLink
);
if
(!
dstDataSource
.
getDsId
().
equals
(
dstDataSource
.
getDsId
().
toLowerCase
()))
check
.
put
(
dstDataSource
.
getDsId
().
toLowerCase
(),
ds
tDataSource
.
getDSLinkConfig
()
);
check
.
put
(
dstDataSource
.
getDsId
().
toLowerCase
(),
ds
Link
);
if
(!
ObjectUtils
.
isEmpty
(
dstDataSource
.
getUsings
()))
{
dstDataSource
.
getUsings
().
forEach
(
using
->{
check
.
put
(
using
,
ds
tDataSource
.
getDSLinkConfig
()
);
check
.
put
(
using
,
ds
Link
);
if
(!
using
.
equals
(
using
.
toLowerCase
()))
check
.
put
(
using
.
toLowerCase
(),
ds
tDataSource
.
getDSLinkConfig
()
);
check
.
put
(
using
.
toLowerCase
(),
ds
Link
);
});
}
}
...
...
@@ -337,6 +347,8 @@ public class DSSettingServiceImpl implements IDSSettingService {
return
new
PageImpl
<
DSSetting
>(
list
,
context
.
getPageable
(),
list
.
size
());
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/MongoDataServiceImpl.java
浏览文件 @
277ba0e5
...
...
@@ -22,6 +22,8 @@ import java.util.List;
public
class
MongoDataServiceImpl
implements
IDataService
{
@Override
public
ResponseData
call
(
DOModel
model
,
String
scope
,
String
datasource
,
String
method
,
RequestData
requestData
)
{
...
...
@@ -31,6 +33,7 @@ public class MongoDataServiceImpl implements IDataService
@Override
public
boolean
create
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
return
false
;
}
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录