Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdata
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdata
提交
c2e78922
提交
c2e78922
编写于
3年前
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
es实现
上级
3fdab763
变更
10
展开全部
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
927 行增加
和
86 行删除
+927
-86
FilterData.java
...re/src/main/java/cn/ibizlab/core/data/dto/FilterData.java
+80
-2
EsDataRepository.java
...ava/cn/ibizlab/core/data/repository/EsDataRepository.java
+317
-0
MongoDataRepository.java
.../cn/ibizlab/core/data/repository/MongoDataRepository.java
+19
-15
PersistentResource.java
...in/java/cn/ibizlab/core/data/rest/PersistentResource.java
+34
-23
ModelService.java
.../main/java/cn/ibizlab/core/data/service/ModelService.java
+41
-0
BaseDataServiceImpl.java
...n/ibizlab/core/data/service/impl/BaseDataServiceImpl.java
+8
-11
DbPersistentServiceImpl.java
...izlab/core/data/service/impl/DbPersistentServiceImpl.java
+3
-4
EsPersistentServiceImpl.java
...izlab/core/data/service/impl/EsPersistentServiceImpl.java
+229
-0
MongoPersistentServiceImpl.java
...ab/core/data/service/impl/MongoPersistentServiceImpl.java
+6
-31
EsQueryContext.java
.../src/main/java/cn/ibizlab/util/filter/EsQueryContext.java
+190
-0
未找到文件。
ibzdata-core/src/main/java/cn/ibizlab/core/data/dto/FilterData.java
浏览文件 @
c2e78922
...
...
@@ -2,11 +2,10 @@ 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
;
import
cn.ibizlab.core.data.filter.QueryWrapperContext
;
import
cn.ibizlab.util.filter.EsQueryContext
;
import
cn.ibizlab.util.helper.DataObject
;
import
cn.ibizlab.util.security.AuthenticationUser
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.OrderItem
;
...
...
@@ -17,6 +16,8 @@ import com.mongodb.QueryBuilder;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.elasticsearch.core.query.Criteria
;
import
org.springframework.data.elasticsearch.core.query.CriteriaQuery
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
...
...
@@ -384,6 +385,83 @@ public class FilterData<T> extends BaseData
return
queryBuilder
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
CriteriaQuery
esCriteriaQuery
=
null
;
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
CriteriaQuery
getEsQuery
()
{
if
(
esCriteriaQuery
==
null
)
{
esCriteriaQuery
=
new
EsQueryContext
().
getSelectCond
();
}
if
(
this
.
getPOSchema
()!=
null
)
{
if
(!
StringUtils
.
isEmpty
(
this
.
getQuery
()))
{
if
(!
ObjectUtils
.
isEmpty
(
this
.
getPOSchema
().
getQuickSearch
()))
{
Criteria
critera
=
new
Criteria
();
for
(
String
column:
this
.
getPOSchema
().
getQuickSearch
().
keySet
())
critera
.
or
(
column
).
contains
(
this
.
getQuery
());
esCriteriaQuery
.
getCriteria
().
and
(
critera
);
}
}
if
(!
ObjectUtils
.
isEmpty
(
this
.
getPOSchema
().
getSearchMap
()))
{
for
(
Map
.
Entry
<
String
,
POSchema
.
Column
>
search:
this
.
getPOSchema
().
getSearchMap
().
entrySet
())
{
String
key
=
search
.
getKey
().
toLowerCase
();
String
name
=
search
.
getValue
().
getName
().
toLowerCase
();
if
(
this
.
keySet
().
contains
(
key
))
{
POSchema
.
Column
column
=
search
.
getValue
();
Object
obj
=
column
.
isDateTime
()?
this
.
getTimestampValue
(
key
,
null
):
this
.
get
(
key
);
if
(!
ObjectUtils
.
isEmpty
(
obj
))
{
if
(
key
.
endsWith
(
"_like"
))
{
esCriteriaQuery
.
getCriteria
().
and
(
name
).
contains
(
obj
.
toString
());
}
else
if
(
key
.
endsWith
(
"_leftlike"
)){
esCriteriaQuery
.
getCriteria
().
and
(
name
).
startsWith
(
obj
.
toString
());
}
else
if
(
key
.
endsWith
(
"_rightlike"
)){
esCriteriaQuery
.
getCriteria
().
and
(
name
).
endsWith
(
obj
.
toString
());
}
else
if
(
key
.
endsWith
(
"_eq"
))
esCriteriaQuery
.
getCriteria
().
and
(
name
).
is
(
obj
);
else
if
(
key
.
endsWith
(
"_noteq"
))
esCriteriaQuery
.
getCriteria
().
not
().
and
(
name
).
is
(
obj
);
else
if
(
key
.
endsWith
(
"_gt"
))
esCriteriaQuery
.
getCriteria
().
and
(
name
).
greaterThan
(
obj
);
else
if
(
key
.
endsWith
(
"_gtandeq"
))
esCriteriaQuery
.
getCriteria
().
and
(
name
).
greaterThanEqual
(
obj
);
else
if
(
key
.
endsWith
(
"_lt"
))
esCriteriaQuery
.
getCriteria
().
and
(
name
).
lessThan
(
obj
);
else
if
(
key
.
endsWith
(
"_ltandeq"
))
esCriteriaQuery
.
getCriteria
().
and
(
name
).
lessThanEqual
(
obj
);
else
if
(
key
.
endsWith
(
"_isnotnull"
)&&
DataObject
.
getIntegerValue
(
obj
,
1
)==
1
)
esCriteriaQuery
.
getCriteria
().
not
().
and
(
name
).
is
(
null
);
else
if
(
key
.
endsWith
(
"_isnull"
)&&
DataObject
.
getIntegerValue
(
obj
,
1
)==
1
)
esCriteriaQuery
.
getCriteria
().
and
(
name
).
is
(
null
);
else
if
(
key
.
endsWith
(
"_in"
))
esCriteriaQuery
.
getCriteria
().
and
(
name
).
in
(
DataObject
.
getStringValue
(
obj
,
""
).
split
(
";|,"
));
else
if
(
key
.
endsWith
(
"_notin"
))
esCriteriaQuery
.
getCriteria
().
and
(
name
).
notIn
(
DataObject
.
getStringValue
(
obj
,
""
).
split
(
";|,"
));
}
}
}
}
}
return
esCriteriaQuery
;
}
public
String
getSql
(
String
codename
)
{
Assert
.
notNull
(
getPOSchema
(),
"未找到查询片段"
);
...
...
This diff is collapsed.
Click to expand it.
ibzdata-core/src/main/java/cn/ibizlab/core/data/repository/EsDataRepository.java
0 → 100644
浏览文件 @
c2e78922
package
cn
.
ibizlab
.
core
.
data
.
repository
;
import
cn.ibizlab.core.data.dto.BaseData
;
import
cn.ibizlab.core.data.dto.FilterData
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.elasticsearch.DynamicEsContextHolder
;
import
lombok.extern.slf4j.Slf4j
;
import
org.elasticsearch.index.query.IdsQueryBuilder
;
import
org.elasticsearch.index.query.QueryBuilders
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.data.domain.*
;
import
org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate
;
import
org.springframework.data.elasticsearch.core.query.*
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.Assert
;
import
reactor.core.publisher.Flux
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@Component
public
class
EsDataRepository
{
@Autowired
@Lazy
private
ReactiveElasticsearchTemplate
esTemplate
;
final
private
String
TYPE
=
"_doc"
;
/**
* 反射获取泛型类型
*
* @return
*/
protected
Class
<
BaseData
>
getEntityClass
()
{
return
getEntityClass
();
}
/**
* 将查询条件对象转换为query
*
* @param object
* @return
* @author Jason
*/
private
Query
getQueryByObject
(
BaseData
object
)
{
Criteria
query
=
new
Criteria
();
Map
<
String
,
Object
>
dataMap
=
(
Map
)
object
;
Criteria
criteria
=
new
Criteria
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
dataMap
.
entrySet
())
{
criteria
.
and
(
entry
.
getKey
()).
is
(
entry
.
getValue
());
}
return
new
CriteriaQuery
(
query
);
}
public
Query
getKeyQuery
(
BaseData
data
)
{
Assert
.
notNull
(
data
.
getKey
(),
"未找到主键"
);
return
new
CriteriaQuery
(
new
Criteria
().
and
(
"_id"
).
is
(
data
.
getKey
()));
}
public
Query
getKeyQuery
(
List
list
)
{
List
<
String
>
ids
=
new
ArrayList
<>();
if
(
list
.
get
(
0
)
instanceof
BaseData
)
{
list
.
forEach
(
item
->
{
BaseData
data
=
(
BaseData
)
item
;
Serializable
key
=
data
.
getKey
();
Assert
.
notNull
(
key
,
"未找到主键"
);
ids
.
add
(
key
.
toString
());
});
}
else
{
ids
.
addAll
(
list
);
}
return
new
CriteriaQuery
(
new
Criteria
().
and
(
"_id"
).
in
(
ids
));
}
public
IdsQueryBuilder
getKeyQueryBuilder
(
List
list
)
{
IdsQueryBuilder
ids
=
QueryBuilders
.
idsQuery
();
if
(
list
.
get
(
0
)
instanceof
BaseData
)
{
list
.
forEach
(
item
->
{
BaseData
data
=
(
BaseData
)
item
;
Serializable
key
=
data
.
getKey
();
Assert
.
notNull
(
key
,
"未找到主键"
);
ids
.
addIds
(
key
.
toString
());
});
}
else
{
list
.
forEach
(
key
->
ids
.
addIds
(
key
.
toString
()));
}
return
ids
;
}
public
void
insertData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
{
DynamicEsContextHolder
.
push
(
ds
);
data
.
setAll
(
this
.
esTemplate
.
save
(
data
,
schema
.
getName
(),
TYPE
).
block
());
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
void
insertBathData
(
String
ds
,
POSchema
schema
,
List
<
BaseData
>
list
){
try
{
DynamicEsContextHolder
.
push
(
ds
);
this
.
esTemplate
.
save
(
Flux
.
fromIterable
(
list
),
schema
.
getName
(),
TYPE
).
block
();
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
void
updateData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
{
DynamicEsContextHolder
.
push
(
ds
);
data
.
setAll
(
this
.
esTemplate
.
save
(
data
,
schema
.
getName
(),
TYPE
).
block
());
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
void
updateBathData
(
String
ds
,
POSchema
schema
,
List
<
BaseData
>
list
){
try
{
DynamicEsContextHolder
.
push
(
ds
);
this
.
esTemplate
.
save
(
Flux
.
fromIterable
(
list
),
schema
.
getName
(),
TYPE
).
block
();
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
void
removeData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
{
Assert
.
notNull
(
data
.
getKey
(),
"未找到主键"
);
DynamicEsContextHolder
.
push
(
ds
);
this
.
esTemplate
.
deleteById
(
data
.
getKey
().
toString
(),
getEntityClass
(),
schema
.
getName
(),
TYPE
).
block
();
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
void
removeBathData
(
String
ds
,
POSchema
schema
,
List
list
){
try
{
DynamicEsContextHolder
.
push
(
ds
);
esTemplate
.
deleteBy
(
getKeyQuery
(
list
),
getEntityClass
(),
schema
.
getName
(),
TYPE
).
block
();
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
void
saveData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
{
DynamicEsContextHolder
.
push
(
ds
);
data
.
setAll
(
this
.
esTemplate
.
save
(
data
,
schema
.
getName
(),
TYPE
).
block
());;
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
void
saveBatchData
(
String
ds
,
POSchema
schema
,
List
<
BaseData
>
list
){
try
{
DynamicEsContextHolder
.
push
(
ds
);
this
.
esTemplate
.
save
(
Flux
.
fromIterable
(
list
),
schema
.
getName
(),
TYPE
).
block
();
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
long
countData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
{
DynamicEsContextHolder
.
push
(
ds
);
return
esTemplate
.
count
(
getQueryByObject
(
data
),
getEntityClass
(),
schema
.
getName
(),
TYPE
).
block
();
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
List
<
BaseData
>
getData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
{
Assert
.
notNull
(
data
.
getKey
(),
"未找到主键"
);
DynamicEsContextHolder
.
push
(
ds
);
return
esTemplate
.
find
(
getKeyQuery
(
data
),
getEntityClass
(),
schema
.
getName
(),
TYPE
).
collectList
().
block
();
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
List
<
BaseData
>
getBatchData
(
String
ds
,
POSchema
schema
,
List
<
BaseData
>
list
){
try
{
DynamicEsContextHolder
.
push
(
ds
);
return
esTemplate
.
find
(
getKeyQuery
(
list
),
getEntityClass
(),
schema
.
getName
(),
TYPE
).
collectList
().
block
();
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
List
<
BaseData
>
getBatchKey
(
String
ds
,
POSchema
schema
,
List
<
BaseData
>
list
){
try
{
NativeSearchQuery
query
=
new
NativeSearchQueryBuilder
()
.
withQuery
(
getKeyQueryBuilder
(
list
)).
withSourceFilter
(
new
SourceFilter
()
{
@Override
public
String
[]
getIncludes
()
{
return
new
String
[]{
"_id"
};
}
@Override
public
String
[]
getExcludes
()
{
return
new
String
[]{
""
};
}
}).
build
();
DynamicEsContextHolder
.
push
(
ds
);
return
esTemplate
.
find
(
query
,
getEntityClass
(),
schema
.
getName
(),
TYPE
).
collectList
().
block
();
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
List
<
BaseData
>
selectData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
{
DynamicEsContextHolder
.
push
(
ds
);
return
esTemplate
.
find
(
getQueryByObject
(
data
),
getEntityClass
(),
schema
.
getName
(),
TYPE
).
collectList
().
block
();
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
Page
<
BaseData
>
selectData
(
String
ds
,
POSchema
schema
,
BaseData
data
,
Pageable
page
){
try
{
if
(
page
==
null
)
page
=
PageRequest
.
of
(
0
,
20
,
Sort
.
unsorted
());
Query
query
=
getQueryByObject
(
data
);
DynamicEsContextHolder
.
push
(
ds
);
long
total
=
esTemplate
.
count
(
query
,
getEntityClass
(),
schema
.
getName
()).
block
();
List
<
BaseData
>
list
=(
total
==
0
)?
new
ArrayList
<>():
esTemplate
.
find
(
query
.
setPageable
(
page
),
getEntityClass
(),
schema
.
getName
()).
collectList
().
block
();
return
new
PageImpl
<
BaseData
>(
list
,
page
,
total
);
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
List
<
BaseData
>
queryData
(
String
ds
,
POSchema
schema
,
String
sql
,
FilterData
context
){
try
{
DynamicEsContextHolder
.
push
(
ds
);
return
esTemplate
.
find
(
context
.
getEsQuery
(),
getEntityClass
(),
schema
.
getName
(),
TYPE
).
collectList
().
block
();
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
public
Page
<
BaseData
>
queryData
(
String
ds
,
POSchema
schema
,
String
sql
,
FilterData
context
,
Pageable
page
){
try
{
if
(
page
==
null
)
page
=
context
.
getPageable
();
else
context
.
setPageable
(
page
);
DynamicEsContextHolder
.
push
(
ds
);
Query
query
=
context
.
getEsQuery
();
long
total
=
esTemplate
.
count
(
query
,
getEntityClass
(),
schema
.
getName
(),
TYPE
).
block
();
List
<
BaseData
>
list
=(
total
==
0
)?
new
ArrayList
<>():
esTemplate
.
find
(
query
.
setPageable
(
page
),
getEntityClass
(),
schema
.
getName
(),
TYPE
).
collectList
().
block
();
return
new
PageImpl
<
BaseData
>(
list
,
page
,
total
);
}
finally
{
DynamicEsContextHolder
.
poll
();
}
}
}
This diff is collapsed.
Click to expand it.
ibzdata-core/src/main/java/cn/ibizlab/core/data/repository/MongoDataRepository.java
浏览文件 @
c2e78922
...
...
@@ -12,12 +12,12 @@ import com.mongodb.BasicDBObject;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
org.castor.core.util.Assert
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.data.domain.*
;
import
org.springframework.data.mongodb.core.BulkOperations
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.query.BasicQuery
;
import
org.springframework.data.mongodb.core.query.Criteria
;
...
...
@@ -25,6 +25,7 @@ import org.springframework.data.mongodb.core.query.Query;
import
org.springframework.data.mongodb.core.query.Update
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
...
...
@@ -117,13 +118,12 @@ public class MongoDataRepository {
}
public
int
insertData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
public
void
insertData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
{
DynamicMongoContextHolder
.
push
(
ds
);
this
.
mongoTemplate
.
save
(
data
,
schema
.
getName
());
return
1
;
}
finally
{
DynamicMongoContextHolder
.
poll
();
...
...
@@ -142,14 +142,14 @@ public class MongoDataRepository {
}
}
public
int
updateData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
public
long
updateData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
{
Query
query
=
getKeyQuery
(
data
);
Update
update
=
getUpdateByObject
(
data
);
DynamicMongoContextHolder
.
push
(
ds
);
return
(
int
)
this
.
mongoTemplate
.
updateFirst
(
query
,
update
,
schema
.
getName
()).
getModifiedCount
();
return
this
.
mongoTemplate
.
updateFirst
(
query
,
update
,
schema
.
getName
()).
getModifiedCount
();
}
finally
{
DynamicMongoContextHolder
.
poll
();
...
...
@@ -160,47 +160,49 @@ public class MongoDataRepository {
try
{
DynamicMongoContextHolder
.
push
(
ds
);
BulkOperations
ops
=
mongoTemplate
.
bulkOps
(
BulkOperations
.
BulkMode
.
UNORDERED
,
schema
.
getName
());
list
.
forEach
(
data
->
{
Query
query
=
getKeyQuery
(
data
);
Update
update
=
getUpdateByObject
(
data
);
this
.
mongoTemplate
.
updateFirst
(
query
,
update
,
schema
.
getName
()
);
ops
.
updateOne
(
query
,
update
);
});
ops
.
execute
();
}
finally
{
DynamicMongoContextHolder
.
poll
();
}
}
public
int
removeData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
public
long
removeData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
{
DynamicMongoContextHolder
.
push
(
ds
);
return
(
int
)
this
.
mongoTemplate
.
remove
(
getKeyQuery
(
data
),
schema
.
getName
()).
getDeletedCount
();
return
this
.
mongoTemplate
.
remove
(
getKeyQuery
(
data
),
schema
.
getName
()).
getDeletedCount
();
}
finally
{
DynamicMongoContextHolder
.
poll
();
}
}
public
int
removeBathData
(
String
ds
,
POSchema
schema
,
List
list
){
public
long
removeBathData
(
String
ds
,
POSchema
schema
,
List
list
){
try
{
DynamicMongoContextHolder
.
push
(
ds
);
return
(
int
)
mongoTemplate
.
remove
(
getKeyQuery
(
list
),
schema
.
getName
()).
getDeletedCount
();
return
mongoTemplate
.
remove
(
getKeyQuery
(
list
),
schema
.
getName
()).
getDeletedCount
();
}
finally
{
DynamicMongoContextHolder
.
poll
();
}
}
public
int
saveData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
public
long
saveData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
{
Query
query
=
getKeyQuery
(
data
);
Update
update
=
getUpdateByObject
(
data
);
DynamicMongoContextHolder
.
push
(
ds
);
return
(
int
)
this
.
mongoTemplate
.
upsert
(
query
,
update
,
schema
.
getName
()).
getModifiedCount
();
return
this
.
mongoTemplate
.
upsert
(
query
,
update
,
schema
.
getName
()).
getModifiedCount
();
}
finally
{
DynamicMongoContextHolder
.
poll
();
...
...
@@ -211,11 +213,13 @@ public class MongoDataRepository {
try
{
DynamicMongoContextHolder
.
push
(
ds
);
BulkOperations
ops
=
mongoTemplate
.
bulkOps
(
BulkOperations
.
BulkMode
.
UNORDERED
,
schema
.
getName
());
list
.
forEach
(
data
->
{
Query
query
=
getKeyQuery
(
data
);
Update
update
=
getUpdateByObject
(
data
);
mongoTemplate
.
upsert
(
query
,
update
,
schema
.
getName
()
);
ops
.
upsert
(
query
,
update
);
});
ops
.
execute
();
}
finally
{
DynamicMongoContextHolder
.
poll
();
...
...
@@ -301,7 +305,7 @@ public class MongoDataRepository {
DynamicMongoContextHolder
.
push
(
ds
);
long
total
=
mongoTemplate
.
count
(
query
,
BaseData
.
class
,
schema
.
getName
());
List
<
BaseData
>
list
=
mongoTemplate
.
find
(
query
.
with
(
page
),
BaseData
.
class
,
schema
.
getName
());
List
<
BaseData
>
list
=
(
total
==
0
)?
new
ArrayList
<>():
mongoTemplate
.
find
(
query
.
with
(
page
),
BaseData
.
class
,
schema
.
getName
());
return
new
PageImpl
<
BaseData
>(
list
,
page
,
total
);
}
finally
{
...
...
@@ -332,7 +336,7 @@ public class MongoDataRepository {
DynamicMongoContextHolder
.
push
(
ds
);
long
total
=
mongoTemplate
.
count
(
query
,
BaseData
.
class
,
schema
.
getName
());
List
<
BaseData
>
list
=
mongoTemplate
.
find
(
query
.
with
(
page
),
BaseData
.
class
,
schema
.
getName
());
List
<
BaseData
>
list
=
(
total
==
0
)?
new
ArrayList
<>():
mongoTemplate
.
find
(
query
.
with
(
page
),
BaseData
.
class
,
schema
.
getName
());
return
new
PageImpl
<
BaseData
>(
list
,
page
,
total
);
}
finally
{
...
...
This diff is collapsed.
Click to expand it.
ibzdata-core/src/main/java/cn/ibizlab/core/data/rest/PersistentResource.java
浏览文件 @
c2e78922
此差异已折叠。
点击以展开。
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/ModelService.java
浏览文件 @
c2e78922
...
...
@@ -6,6 +6,9 @@ import cn.ibizlab.core.data.model.DSLink;
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.impl.DbPersistentServiceImpl
;
import
cn.ibizlab.core.data.service.impl.EsPersistentServiceImpl
;
import
cn.ibizlab.core.data.service.impl.MongoPersistentServiceImpl
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.helper.DataObject
;
import
cn.ibizlab.util.helper.Inflector
;
...
...
@@ -66,6 +69,44 @@ public class ModelService {
@Lazy
private
ModelService
proxy
;
@Autowired
@Lazy
private
DbPersistentServiceImpl
dbProxyService
;
@Autowired
@Lazy
private
MongoPersistentServiceImpl
mongoProxyService
;
@Autowired
@Lazy
private
EsPersistentServiceImpl
esProxyService
;
@Autowired
@Lazy
private
IDSSettingService
dsSettingService
;
public
IPersistentService
getProxyService
(
String
datasource
)
{
return
getProxyService
(
getDSLink
(
datasource
));
}
public
IPersistentService
getProxyService
(
DSLink
link
)
{
if
(
link
.
isMongodb
())
return
mongoProxyService
;
else
if
(
link
.
isElasticSearch
())
return
esProxyService
;
else
if
(
link
.
isCassandra
())
return
dbProxyService
;
else
return
dbProxyService
;
}
public
DSLink
getDSLink
(
String
datasource
)
{
return
dsSettingService
.
getDataSource
(
datasource
);
}
@Cacheable
(
value
=
"syspssystem"
,
key
=
"'row:sys-dst-sys-local'"
)
...
...
This diff is collapsed.
Click to expand it.
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/BaseDataServiceImpl.java
浏览文件 @
c2e78922
...
...
@@ -35,6 +35,7 @@ public class BaseDataServiceImpl implements IDataService {
@Autowired
@Lazy
private
DbPersistentServiceImpl
dbProxyService
;
@Autowired
...
...
@@ -42,22 +43,18 @@ public class BaseDataServiceImpl implements IDataService {
private
MongoPersistentServiceImpl
mongoProxyService
;
@Autowired
private
ModelService
modelService
;
@Lazy
private
EsPersistentServiceImpl
esProxyService
;
@Autowired
private
IDSSettingService
dsSettingService
;
@Lazy
private
ModelService
modelService
;
public
IPersistentService
getProxyService
(
DSLink
link
)
{
if
(
link
.
isMongodb
())
return
mongoProxyService
;
else
if
(
link
.
isElasticSearch
())
return
dbProxyService
;
else
if
(
link
.
isCassandra
())
return
dbProxyService
;
else
return
dbProxyService
;
return
modelService
.
getProxyService
(
link
);
}
@Override
...
...
@@ -68,7 +65,7 @@ public class BaseDataServiceImpl implements IDataService {
@Override
public
DSLink
getDSLink
(
String
datasource
)
{
return
dsSettingService
.
getDataSource
(
datasource
);
return
modelService
.
getDSLink
(
datasource
);
}
@Override
...
...
This diff is collapsed.
Click to expand it.
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/DbPersistentServiceImpl.java
浏览文件 @
c2e78922
...
...
@@ -5,13 +5,13 @@ import cn.ibizlab.core.data.dto.FilterData;
import
cn.ibizlab.core.data.mapper.DbDataMapper
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.service.IDSSettingService
;
import
cn.ibizlab.core.data.service.IPersistentService
;
import
cn.ibizlab.core.data.service.ModelService
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageImpl
;
...
...
@@ -37,6 +37,7 @@ public class DbPersistentServiceImpl implements IPersistentService {
@Autowired
private
DbDataMapper
repository
;
@Autowired
@Lazy
private
ModelService
modelService
;
@Override
...
...
@@ -336,11 +337,9 @@ public class DbPersistentServiceImpl implements IPersistentService {
return
new
PageImpl
<
BaseData
>(
pages
.
getRecords
(),
pageable
,
pages
.
getTotal
());
}
@Autowired
private
IDSSettingService
dsSettingService
;
@Override
public
DSLink
getDSLink
(
String
datasource
)
{
return
dsSettingService
.
getDataSource
(
datasource
);
return
modelService
.
getDSLink
(
datasource
);
}
@Override
...
...
This diff is collapsed.
Click to expand it.
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/EsPersistentServiceImpl.java
0 → 100644
浏览文件 @
c2e78922
package
cn
.
ibizlab
.
core
.
data
.
service
.
impl
;
import
cn.ibizlab.core.data.dto.BaseData
;
import
cn.ibizlab.core.data.dto.FilterData
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.repository.EsDataRepository
;
import
cn.ibizlab.core.data.service.IPersistentService
;
import
cn.ibizlab.core.data.service.ModelService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ObjectUtils
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
@Service
@Slf4j
public
class
EsPersistentServiceImpl
implements
IPersistentService
{
@Autowired
private
EsDataRepository
repository
;
@Autowired
@Lazy
private
ModelService
modelService
;
@Override
public
BaseData
create
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
)
{
repository
.
insertData
(
link
.
getName
(),
poSchema
,
et
);
if
(
bGet
)
et
.
setAll
(
getByMap
(
link
,
poSchema
,
et
));
return
et
;
}
@Override
public
List
<
BaseData
>
createBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
repository
.
insertBathData
(
link
.
getName
(),
poSchema
,
list
);
if
(
bGet
)
return
getByMapBatch
(
link
,
poSchema
,
list
);
return
list
;
}
@Override
public
BaseData
update
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
)
{
repository
.
updateData
(
link
.
getName
(),
poSchema
,
et
);
if
(
bGet
)
et
.
setAll
(
getByMap
(
link
,
poSchema
,
et
));
return
et
;
}
@Override
public
List
<
BaseData
>
updateBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
repository
.
updateBathData
(
link
.
getName
(),
poSchema
,
list
);
if
(
bGet
)
return
getByMapBatch
(
link
,
poSchema
,
list
);
return
list
;
}
@Override
public
boolean
remove
(
DSLink
link
,
POSchema
poSchema
,
Serializable
key
)
{
BaseData
et
=
poSchema
.
newData
(
key
);
Assert
.
notNull
(
et
,
"未找到主键"
);
repository
.
removeData
(
link
.
getName
(),
poSchema
,
et
);
return
true
;
}
@Override
public
boolean
removeBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
Serializable
>
idList
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
idList
.
forEach
(
key
->{
BaseData
et
=
poSchema
.
newData
(
key
);
Assert
.
notNull
(
et
,
"未找到主键"
);
batch
.
add
(
et
);
});
if
(
batch
.
size
()>
0
)
{
repository
.
removeBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
return
true
;
}
@Override
public
boolean
removeByMap
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
repository
.
removeData
(
link
.
getName
(),
poSchema
,
et
);
return
true
;
}
@Override
public
boolean
removeByMapBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
)
{
repository
.
removeBathData
(
link
.
getName
(),
poSchema
,
list
);
return
true
;
}
@Override
public
BaseData
get
(
DSLink
link
,
POSchema
poSchema
,
Serializable
key
)
{
BaseData
et
=
poSchema
.
newData
(
key
);
Assert
.
notNull
(
et
,
"未找到主键"
);
List
<
BaseData
>
list
=
repository
.
getData
(
link
.
getName
(),
poSchema
,
et
);
if
(
ObjectUtils
.
isEmpty
(
list
)||
list
.
size
()>
1
)
throw
new
IllegalArgumentException
(
"未找到数据"
+
poSchema
.
getName
()+
":"
+
key
);
return
list
.
get
(
0
);
}
@Override
public
List
<
BaseData
>
getBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
Serializable
>
idList
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
idList
.
forEach
(
key
->{
BaseData
et
=
poSchema
.
newData
(
key
);
Assert
.
notNull
(
et
,
"未找到主键"
);
batch
.
add
(
et
);
});
return
repository
.
getBatchData
(
link
.
getName
(),
poSchema
,
batch
);
}
@Override
public
BaseData
getByMap
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
List
<
BaseData
>
list
=
repository
.
getData
(
link
.
getName
(),
poSchema
,
et
);
if
(
ObjectUtils
.
isEmpty
(
list
)||
list
.
size
()>
1
)
throw
new
IllegalArgumentException
(
"未找到数据"
+
poSchema
.
getName
()+
":"
+
et
.
getKey
());
return
list
.
get
(
0
);
}
@Override
public
List
<
BaseData
>
getByMapBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
)
{
return
repository
.
getBatchData
(
link
.
getName
(),
poSchema
,
list
);
}
@Override
public
List
<
BaseData
>
getBatchKey
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
)
{
return
repository
.
getBatchKey
(
link
.
getName
(),
poSchema
,
list
);
}
@Override
public
Long
count
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
return
repository
.
countData
(
link
.
getName
(),
poSchema
,
et
);
}
@Override
public
boolean
checkKey
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
Long
cnt
=
repository
.
countData
(
link
.
getName
(),
poSchema
,
et
);
return
cnt
==
1
;
}
@Override
public
BaseData
save
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
)
{
if
(
checkKey
(
link
,
poSchema
,
et
))
return
update
(
link
,
poSchema
,
et
,
bGet
);
else
return
create
(
link
,
poSchema
,
et
,
bGet
);
}
@Override
public
List
<
BaseData
>
saveBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
repository
.
saveBatchData
(
link
.
getName
(),
poSchema
,
list
);
if
(
bGet
)
return
getByMapBatch
(
link
,
poSchema
,
list
);
return
list
;
}
@Override
public
List
<
BaseData
>
select
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
return
repository
.
selectData
(
link
.
getName
(),
poSchema
,
et
);
}
@Override
public
Page
<
BaseData
>
select
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
Pageable
pageable
)
{
Page
<
BaseData
>
pages
=
repository
.
selectData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
),
pageable
);
return
pages
;
}
@Override
public
List
<
BaseData
>
query
(
DSLink
link
,
POSchema
poSchema
,
String
dataQuery
,
FilterData
context
)
{
context
.
setPOSchema
(
poSchema
);
return
repository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
);
}
@Override
public
Page
<
BaseData
>
query
(
DSLink
link
,
POSchema
poSchema
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
)
{
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
Page
<
BaseData
>
pages
=
repository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
,
pageable
);
return
pages
;
}
@Override
public
List
<
BaseData
>
selectRaw
(
DSLink
link
,
POSchema
poSchema
,
String
sql
,
FilterData
context
)
{
return
repository
.
queryData
(
link
.
getName
(),
poSchema
,
sql
,
context
);
}
@Override
public
boolean
execRaw
(
DSLink
link
,
POSchema
poSchema
,
String
sql
,
BaseData
param
)
{
throw
new
IllegalArgumentException
(
String
.
format
(
"没有实现方法execRaw,%1$s,%2$s"
,
poSchema
.
getName
(),
sql
));
}
@Override
public
List
<
BaseData
>
fetch
(
DSLink
link
,
POSchema
poSchema
,
String
dataSet
,
FilterData
context
)
{
context
.
setPOSchema
(
poSchema
);
return
repository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
);
}
@Override
public
Page
<
BaseData
>
fetch
(
DSLink
link
,
POSchema
poSchema
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
)
{
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
Page
<
BaseData
>
pages
=
repository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
,
pageable
);
return
pages
;
}
@Override
public
DSLink
getDSLink
(
String
datasource
)
{
return
modelService
.
getDSLink
(
datasource
);
}
@Override
public
POSchema
getSchema
(
DSLink
link
,
String
system
,
String
table
)
{
return
modelService
.
getPOSchema
(
system
,
table
,
link
.
getType
());
}
}
This diff is collapsed.
Click to expand it.
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/MongoPersistentServiceImpl.java
浏览文件 @
c2e78922
...
...
@@ -5,12 +5,11 @@ import cn.ibizlab.core.data.dto.FilterData;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.repository.MongoDataRepository
;
import
cn.ibizlab.core.data.service.IDSSettingService
;
import
cn.ibizlab.core.data.service.IPersistentService
;
import
cn.ibizlab.core.data.service.ModelService
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
...
...
@@ -31,6 +30,7 @@ public class MongoPersistentServiceImpl implements IPersistentService {
@Autowired
private
MongoDataRepository
repository
;
@Autowired
@Lazy
private
ModelService
modelService
;
@Override
...
...
@@ -158,32 +158,9 @@ public class MongoPersistentServiceImpl implements IPersistentService {
@Override
public
List
<
BaseData
>
saveBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
List
<
BaseData
>
rt
=
this
.
getBatchKey
(
link
,
poSchema
,
list
);
Map
<
Serializable
,
Integer
>
keys
=
new
LinkedHashMap
<>();
rt
.
forEach
(
et
->{
Serializable
key
=
poSchema
.
getKeyValue
(
et
,
false
);
if
(!
ObjectUtils
.
isEmpty
(
key
))
keys
.
put
(
key
,
1
);
});
List
<
BaseData
>
create
=
new
ArrayList
<>();
List
<
BaseData
>
update
=
new
ArrayList
<>();
list
.
forEach
(
et
->
{
Serializable
key
=
poSchema
.
getKeyValue
(
et
,
false
);
if
(
keys
.
containsKey
(
key
))
update
.
add
(
et
);
else
create
.
add
(
et
);
});
List
rtList
=
new
ArrayList
<>();
if
(
update
.
size
()>
0
)
rtList
.
addAll
(
this
.
updateBatch
(
link
,
poSchema
,
update
,
bGet
));
if
(
create
.
size
()>
0
)
rtList
.
addAll
(
this
.
createBatch
(
link
,
poSchema
,
create
,
bGet
));
return
rtList
;
repository
.
saveBatchData
(
link
.
getName
(),
poSchema
,
list
);
if
(
bGet
)
return
getByMapBatch
(
link
,
poSchema
,
list
);
return
list
;
}
@Override
...
...
@@ -242,11 +219,9 @@ public class MongoPersistentServiceImpl implements IPersistentService {
return
pages
;
}
@Autowired
private
IDSSettingService
dsSettingService
;
@Override
public
DSLink
getDSLink
(
String
datasource
)
{
return
dsSettingService
.
getDataSource
(
datasource
);
return
modelService
.
getDSLink
(
datasource
);
}
@Override
...
...
This diff is collapsed.
Click to expand it.
ibzdata-core/src/main/java/cn/ibizlab/util/filter/EsQueryContext.java
0 → 100644
浏览文件 @
c2e78922
package
cn
.
ibizlab
.
util
.
filter
;
import
cn.ibizlab.core.data.filter.QueryFilter
;
import
cn.ibizlab.core.data.filter.SearchContextBase
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.elasticsearch.core.query.Criteria
;
import
org.springframework.data.elasticsearch.core.query.CriteriaQuery
;
import
org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder
;
import
org.springframework.util.ObjectUtils
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.regex.Pattern
;
@Slf4j
@Data
public
class
EsQueryContext
extends
SearchContextBase
{
@JsonIgnore
@JSONField
(
serialize
=
false
)
private
CriteriaQuery
selectCond
=
null
;
public
CriteriaQuery
getSearchCond
(){
return
this
.
selectCond
;
}
/**
* 填充自定义查询条件
* @return
*/
public
CriteriaQuery
getSelectCond
()
{
if
(
selectCond
==
null
&&(!
ObjectUtils
.
isEmpty
(
filter
))){
Criteria
queryBuilder
=
parseQueryFilter
(
filter
);
if
(!
ObjectUtils
.
isEmpty
(
queryBuilder
)){
selectCond
=
new
CriteriaQuery
(
queryBuilder
);
}
}
else
if
(
selectCond
==
null
)
{
selectCond
=
new
CriteriaQuery
(
new
Criteria
());
}
return
selectCond
;
}
/**
* 解析自定义查询条件
* @param queryFilter
* @return
*/
private
Criteria
parseQueryFilter
(
QueryFilter
queryFilter
){
if
(
ObjectUtils
.
isEmpty
(
queryFilter
.
get
$and
())
&&
ObjectUtils
.
isEmpty
(
queryFilter
.
get
$or
())
&&
ObjectUtils
.
isEmpty
(
queryFilter
.
any
()))
{
return
null
;
}
Criteria
rsBuilder
=
new
Criteria
();
Criteria
fieldBuilder
=
parseFieldMap
(
queryFilter
.
any
());
Criteria
orBuilder
=
parseOrQueryFilter
(
queryFilter
.
get
$or
());
Criteria
andBuilder
=
parseAndQueryFilter
(
queryFilter
.
get
$and
());
if
(!
ObjectUtils
.
isEmpty
(
fieldBuilder
)){
rsBuilder
.
and
(
fieldBuilder
);
}
if
(!
ObjectUtils
.
isEmpty
(
orBuilder
)){
rsBuilder
.
and
(
orBuilder
);
}
if
(!
ObjectUtils
.
isEmpty
(
andBuilder
)){
rsBuilder
.
and
(
andBuilder
);
}
return
rsBuilder
;
}
/**
* 解析自定义条件[or]
* @param queryFilters
* @return
*/
private
Criteria
parseOrQueryFilter
(
List
<
QueryFilter
>
queryFilters
)
{
Criteria
orBuilder
=
new
Criteria
();
if
(
queryFilters
==
null
||
queryFilters
.
size
()==
0
){
return
null
;
}
for
(
QueryFilter
queryFilter:
queryFilters
){
Criteria
queryBuilder
=
parseQueryFilter
(
queryFilter
);
if
(!
ObjectUtils
.
isEmpty
(
queryBuilder
)){
orBuilder
.
or
(
queryBuilder
);
}
}
return
orBuilder
;
}
/**
* 解析自定义条件[and]
* @param queryFilters
* @return
*/
private
Criteria
parseAndQueryFilter
(
List
<
QueryFilter
>
queryFilters
)
{
Criteria
orBuilder
=
new
Criteria
();
if
(
queryFilters
==
null
||
queryFilters
.
size
()==
0
){
return
null
;
}
for
(
QueryFilter
queryFilter:
queryFilters
){
Criteria
queryBuilder
=
parseQueryFilter
(
queryFilter
);
if
(!
ObjectUtils
.
isEmpty
(
queryBuilder
)){
orBuilder
.
and
(
queryBuilder
);
}
}
return
orBuilder
;
}
/**
* 解析自定义条件[字段条件]
* @param fieldMap
* @return
*/
private
Criteria
parseFieldMap
(
Map
<
String
,
QueryFilter
.
SegmentCond
>
fieldMap
)
{
if
(
fieldMap
.
size
()==
0
)
{
return
null
;
}
Criteria
fieldBuilders
=
new
Criteria
();
for
(
Map
.
Entry
<
String
,
QueryFilter
.
SegmentCond
>
entry:
fieldMap
.
entrySet
()){
getSegmentCondSql
(
entry
.
getKey
(),
entry
.
getValue
(),
fieldBuilders
);
}
return
fieldBuilders
;
}
/**
* 解析自定义条件[字段条件]
* @param fieldName
* @param segmentCond
* @param fieldBuilder
*/
private
void
getSegmentCondSql
(
String
fieldName
,
QueryFilter
.
SegmentCond
segmentCond
,
Criteria
fieldBuilder
)
{
Map
<
String
,
Object
>
segmentCondMap
=
segmentCond
.
any
();
for
(
Map
.
Entry
<
String
,
Object
>
entry:
segmentCondMap
.
entrySet
()){
Object
value
=
entry
.
getValue
();
switch
(
entry
.
getKey
()){
case
"$eq"
:
fieldBuilder
.
and
(
fieldName
).
is
(
value
);
break
;
case
"$ne"
:
fieldBuilder
.
not
().
and
(
fieldName
).
is
(
value
);
break
;
case
"$gt"
:
fieldBuilder
.
and
(
fieldName
).
greaterThan
(
value
);
break
;
case
"$gte"
:
fieldBuilder
.
and
(
fieldName
).
greaterThanEqual
(
value
);
break
;
case
"$lt"
:
fieldBuilder
.
and
(
fieldName
).
lessThan
(
value
);
break
;
case
"$lte"
:
fieldBuilder
.
and
(
fieldName
).
lessThanEqual
(
value
);
break
;
case
"$null"
:
fieldBuilder
.
and
(
fieldName
).
is
(
null
);
break
;
case
"$notNull"
:
fieldBuilder
.
not
().
and
(
fieldName
).
is
(
null
);
break
;
case
"$in"
:
fieldBuilder
.
and
(
fieldName
).
in
(
value
);
break
;
case
"$notIn"
:
fieldBuilder
.
and
(
fieldName
).
notIn
(
value
);
break
;
case
"$like"
:
if
(!
ObjectUtils
.
isEmpty
(
value
))
fieldBuilder
.
and
(
fieldName
).
contains
(
value
.
toString
());
break
;
case
"$startsWith"
:
if
(!
ObjectUtils
.
isEmpty
(
value
))
fieldBuilder
.
and
(
fieldName
).
startsWith
(
value
.
toString
());
break
;
case
"$endsWith"
:
if
(!
ObjectUtils
.
isEmpty
(
value
))
fieldBuilder
.
and
(
fieldName
).
endsWith
(
value
.
toString
());
break
;
case
"$exists"
:
break
;
case
"$notExists"
:
break
;
}
}
}
}
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录