提交 618b62d9 编写于 作者: ibizdev's avatar ibizdev

ibiz4j 部署微服务接口

上级 c70c5deb
......@@ -37,6 +37,11 @@
git clone -b master $para2 ibzwf/
export NODE_OPTIONS=--max-old-space-size=4096
cd ibzwf/
mvn clean package -Papi
cd ibzwf-provider/ibzwf-provider-api
mvn -Papi docker:build
mvn -Papi docker:push
docker -H $para1 stack deploy --compose-file=src/main/docker/ibzwf-provider-api.yaml ibzlab-rt --with-registry-auth
</command>
</hudson.tasks.Shell>
</builders>
......
......@@ -31,6 +31,10 @@ zuul:
path: /v7/login
serviceId: ibzuaa-api
stripPrefix: false
uaa:
path: /uaa/**
serviceId: ibzuaa-api
stripPrefix: false
oucore:
path: /ibzorganizations/**
serviceId: ibzou-api
......
......@@ -8,6 +8,10 @@ zuul:
path: /v7/login
serviceId: ibzuaa-api
stripPrefix: false
uaa:
path: /uaa/**
serviceId: ibzuaa-api
stripPrefix: false
oucore:
path: /ibzorganizations/**
serviceId: ibzou-api
......
......@@ -31,7 +31,7 @@ public class WFGroupSearchContext extends QueryWrapperContext<WFGroup> {
public void setN_groupname_like(String n_groupname_like) {
this.n_groupname_like = n_groupname_like;
if(!ObjectUtils.isEmpty(this.n_groupname_like)){
this.getSelectCond().like("groupname", n_groupname_like);
this.getSearchCond().like("groupname", n_groupname_like);
}
}
......@@ -42,7 +42,7 @@ public class WFGroupSearchContext extends QueryWrapperContext<WFGroup> {
{
this.query=query;
if(!StringUtils.isEmpty(query)){
this.getSelectCond().and( wrapper ->
this.getSearchCond().and( wrapper ->
wrapper.like("groupname", query)
);
}
......
......@@ -31,49 +31,49 @@ public class WFMemberSearchContext extends QueryWrapperContext<WFMember> {
public void setN_membername_like(String n_membername_like) {
this.n_membername_like = n_membername_like;
if(!ObjectUtils.isEmpty(this.n_membername_like)){
this.getSelectCond().like("membername", n_membername_like);
this.getSearchCond().like("membername", n_membername_like);
}
}
private String n_groupid_eq;//[组标识]
public void setN_groupid_eq(String n_groupid_eq) {
this.n_groupid_eq = n_groupid_eq;
if(!ObjectUtils.isEmpty(this.n_groupid_eq)){
this.getSelectCond().eq("groupid", n_groupid_eq);
this.getSearchCond().eq("groupid", n_groupid_eq);
}
}
private String n_groupname_eq;//[用户组]
public void setN_groupname_eq(String n_groupname_eq) {
this.n_groupname_eq = n_groupname_eq;
if(!ObjectUtils.isEmpty(this.n_groupname_eq)){
this.getSelectCond().eq("groupname", n_groupname_eq);
this.getSearchCond().eq("groupname", n_groupname_eq);
}
}
private String n_groupname_like;//[用户组]
public void setN_groupname_like(String n_groupname_like) {
this.n_groupname_like = n_groupname_like;
if(!ObjectUtils.isEmpty(this.n_groupname_like)){
this.getSelectCond().like("groupname", n_groupname_like);
this.getSearchCond().like("groupname", n_groupname_like);
}
}
private String n_userid_eq;//[用户标识]
public void setN_userid_eq(String n_userid_eq) {
this.n_userid_eq = n_userid_eq;
if(!ObjectUtils.isEmpty(this.n_userid_eq)){
this.getSelectCond().eq("userid", n_userid_eq);
this.getSearchCond().eq("userid", n_userid_eq);
}
}
private String n_personname_eq;//[用户]
public void setN_personname_eq(String n_personname_eq) {
this.n_personname_eq = n_personname_eq;
if(!ObjectUtils.isEmpty(this.n_personname_eq)){
this.getSelectCond().eq("personname", n_personname_eq);
this.getSearchCond().eq("personname", n_personname_eq);
}
}
private String n_personname_like;//[用户]
public void setN_personname_like(String n_personname_like) {
this.n_personname_like = n_personname_like;
if(!ObjectUtils.isEmpty(this.n_personname_like)){
this.getSelectCond().like("personname", n_personname_like);
this.getSearchCond().like("personname", n_personname_like);
}
}
......@@ -84,7 +84,7 @@ public class WFMemberSearchContext extends QueryWrapperContext<WFMember> {
{
this.query=query;
if(!StringUtils.isEmpty(query)){
this.getSelectCond().and( wrapper ->
this.getSearchCond().and( wrapper ->
wrapper.like("membername", query)
);
}
......
......@@ -31,14 +31,14 @@ public class WFProcessDefinitionSearchContext extends QueryWrapperContext<WFProc
public void setN_definitionname_like(String n_definitionname_like) {
this.n_definitionname_like = n_definitionname_like;
if(!ObjectUtils.isEmpty(this.n_definitionname_like)){
this.getSelectCond().like("definitionname", n_definitionname_like);
this.getSearchCond().like("definitionname", n_definitionname_like);
}
}
private String n_deploykey_like;//[DeployKey]
public void setN_deploykey_like(String n_deploykey_like) {
this.n_deploykey_like = n_deploykey_like;
if(!ObjectUtils.isEmpty(this.n_deploykey_like)){
this.getSelectCond().like("deploykey", n_deploykey_like);
this.getSearchCond().like("deploykey", n_deploykey_like);
}
}
......@@ -49,7 +49,7 @@ public class WFProcessDefinitionSearchContext extends QueryWrapperContext<WFProc
{
this.query=query;
if(!StringUtils.isEmpty(query)){
this.getSelectCond().and( wrapper ->
this.getSearchCond().and( wrapper ->
wrapper.like("definitionname", query)
);
}
......
......@@ -31,7 +31,7 @@ public class WFSystemSearchContext extends QueryWrapperContext<WFSystem> {
public void setN_pssystemname_like(String n_pssystemname_like) {
this.n_pssystemname_like = n_pssystemname_like;
if(!ObjectUtils.isEmpty(this.n_pssystemname_like)){
this.getSelectCond().like("pssystemname", n_pssystemname_like);
this.getSearchCond().like("pssystemname", n_pssystemname_like);
}
}
......@@ -42,7 +42,7 @@ public class WFSystemSearchContext extends QueryWrapperContext<WFSystem> {
{
this.query=query;
if(!StringUtils.isEmpty(query)){
this.getSelectCond().and( wrapper ->
this.getSearchCond().and( wrapper ->
wrapper.like("pssystemname", query)
);
}
......
......@@ -31,7 +31,7 @@ public class WFUserSearchContext extends QueryWrapperContext<WFUser> {
public void setN_personname_like(String n_personname_like) {
this.n_personname_like = n_personname_like;
if(!ObjectUtils.isEmpty(this.n_personname_like)){
this.getSelectCond().like("personname", n_personname_like);
this.getSearchCond().like("personname", n_personname_like);
}
}
......@@ -42,7 +42,7 @@ public class WFUserSearchContext extends QueryWrapperContext<WFUser> {
{
this.query=query;
if(!StringUtils.isEmpty(query)){
this.getSelectCond().and( wrapper ->
this.getSearchCond().and( wrapper ->
wrapper.like("personname", query)
);
}
......
......@@ -9,6 +9,6 @@ CMD echo "The application will start in ${IBIZ_SLEEP}s..." && \
sleep ${IBIZ_SLEEP} && \
java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /ibzwf-provider-api.jar
EXPOSE 8081
EXPOSE 40003
ADD ibzwf-provider-api.jar /ibzwf-provider-api.jar
......@@ -3,9 +3,21 @@ services:
ibzwf-provider-api:
image: registry.cn-shanghai.aliyuncs.com/ibizsys/ibzwf-provider-api:latest
ports:
- "8081:8081"
- "40003:40003"
networks:
- agent_network
environment:
- SPRING_CLOUD_NACOS_DISCOVERY_IP=172.16.180.237
- SERVER_PORT=40003
- SPRING_CLOUD_NACOS_DISCOVERY_SERVER-ADDR=172.16.102.211:8848
- SPRING_REDIS_HOST=172.16.100.243
- SPRING_REDIS_PORT=6379
- SPRING_REDIS_DATABASE=0
- SPRING_DATASOURCE_USERNAME=a_A_5d9d78509
- SPRING_DATASOURCE_PASSWORD=@6dEfb3@
- SPRING_DATASOURCE_URL=jdbc:mysql://172.16.180.232:3306/a_A_5d9d78509?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true
- SPRING_DATASOURCE_DRIVER-CLASS-NAME=com.mysql.jdbc.Driver
- SPRING_DATASOURCE_DEFAULTSCHEMA=a_A_5d9d78509
deploy:
resources:
limits:
......
......@@ -17,6 +17,7 @@ import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.spring.web.readers.operation.OperationParameterReader;
import springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import java.lang.reflect.Field;
import java.util.ArrayList;
......@@ -24,6 +25,7 @@ import java.util.List;
@Configuration
@EnableSwagger2
@ConditionalOnExpression("${swagger.enable:false}")
public class SwaggerConfiguration {
@Bean
......
......@@ -5,6 +5,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mongodb.QueryBuilder;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
@Slf4j
@Data
......@@ -14,4 +18,163 @@ public class QueryBuildContext extends SearchContextBase implements ISearchConte
@JSONField(serialize = false)
private QueryBuilder selectCond=new QueryBuilder();
public QueryBuilder getSearchCond(){
return this.selectCond;
}
/**
* 填充自定义查询条件
* @return
*/
public QueryBuilder getSelectCond() {
if(!ObjectUtils.isEmpty(filter)){
QueryBuilder queryBuilder=parseQueryFilter(filter);
if(!ObjectUtils.isEmpty(queryBuilder)){
selectCond.and(queryBuilder.get());
}
}
return selectCond;
}
/**
* 解析自定义查询条件
* @param queryFilter
* @return
*/
private QueryBuilder parseQueryFilter(QueryFilter queryFilter){
if( ObjectUtils.isEmpty(queryFilter.get$and()) && ObjectUtils.isEmpty(queryFilter.get$or()) && ObjectUtils.isEmpty(queryFilter.any()))
return null;
QueryBuilder rsBuilder=QueryBuilder.start();
QueryBuilder fieldBuilder=parseFieldMap(queryFilter.any());
QueryBuilder orBuilder=parseOrQueryFilter(queryFilter.get$or());
QueryBuilder andBuilder=parseAndQueryFilter(queryFilter.get$and());
if(!ObjectUtils.isEmpty(fieldBuilder)){
rsBuilder.and(fieldBuilder.get());
}
if(!ObjectUtils.isEmpty(orBuilder)){
rsBuilder.and(orBuilder.get());
}
if(!ObjectUtils.isEmpty(andBuilder)){
rsBuilder.and(andBuilder.get());
}
return rsBuilder;
}
/**
* 解析自定义条件[or]
* @param queryFilters
* @return
*/
private QueryBuilder parseOrQueryFilter(List<QueryFilter> queryFilters) {
QueryBuilder orBuilder =new QueryBuilder();
if(queryFilters==null || queryFilters.size()==0){
return null;
}
for(QueryFilter queryFilter: queryFilters){
QueryBuilder queryBuilder=parseQueryFilter(queryFilter);
if(!ObjectUtils.isEmpty(queryBuilder)){
orBuilder.or(queryBuilder.get());
}
}
return orBuilder;
}
/**
* 解析自定义条件[and]
* @param queryFilters
* @return
*/
private QueryBuilder parseAndQueryFilter(List<QueryFilter> queryFilters) {
QueryBuilder orBuilder =new QueryBuilder();
if(queryFilters==null || queryFilters.size()==0){
return null;
}
for(QueryFilter queryFilter: queryFilters){
QueryBuilder queryBuilder=parseQueryFilter(queryFilter);
if(!ObjectUtils.isEmpty(queryBuilder)){
orBuilder.and(queryBuilder.get());
}
}
return orBuilder;
}
/**
* 解析自定义条件[字段条件]
* @param fieldMap
* @return
*/
private QueryBuilder parseFieldMap(Map<String , QueryFilter.SegmentCond> fieldMap) {
if(fieldMap.size()==0)
return null;
QueryBuilder fieldBuilders=QueryBuilder.start();
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,QueryBuilder 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(QueryBuilder.start().and(fieldName).is(value).get());
break;
case "$ne":
fieldBuilder.and(QueryBuilder.start().not().and(fieldName).is(value).get());
break;
case "$gt":
fieldBuilder.and(QueryBuilder.start().and(fieldName).greaterThan(value).get());
break;
case "$gte":
fieldBuilder.and(QueryBuilder.start().and(fieldName).greaterThanEquals(value).get());
break;
case "$lt":
fieldBuilder.and(QueryBuilder.start().and(fieldName).lessThan(value).get());
break;
case "$lte":
fieldBuilder.and(QueryBuilder.start().and(fieldName).lessThanEquals(value).get());
break;
case "$null":
fieldBuilder.and(QueryBuilder.start().and(fieldName).exists(null).get());
break;
case "$notNull":
fieldBuilder.and(QueryBuilder.start().and(fieldName).exists(true).and(fieldName).notEquals("").and(fieldName).notEquals(null).get());
break;
case "$in":
fieldBuilder.and(QueryBuilder.start().and(fieldName).in(value).get());
break;
case "$notIn":
fieldBuilder.and(QueryBuilder.start().and(fieldName).not().in(value).get());
break;
case "$like":
Pattern likePattern = Pattern.compile("^.*" + value + ".*$", Pattern.CASE_INSENSITIVE);
fieldBuilder.and(QueryBuilder.start().and(fieldName).regex(likePattern).get());
break;
case "$startsWith":
Pattern startsWithPattern = Pattern.compile(value + ".*$", Pattern.CASE_INSENSITIVE);
fieldBuilder.and(QueryBuilder.start().and(fieldName).regex(startsWithPattern).get());
break;
case "$endsWith":
Pattern endsWithPattern = Pattern.compile("^.*" + value + "$", Pattern.CASE_INSENSITIVE);
fieldBuilder.and(QueryBuilder.start().and(fieldName).regex(endsWithPattern).get());
break;
case "$exists":
break;
case "$notExists":
break;
}
}
}
}
package cn.ibizlab.util.filter;
import com.fasterxml.jackson.annotation.*;
import org.springframework.data.annotation.Transient;
import java.util.*;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class QueryFilter {
public static QueryFilter createQuery()
{
QueryFilter queryFilter=new QueryFilter();
return queryFilter;
}
public QueryFilter eq(String column,Object value) {
return op(column,SegmentCond.eq(value));
}
public QueryFilter ne(String column,Object value) {
return op(column,SegmentCond.ne(value));
}
public QueryFilter gt(String column,Object value) {
return op(column,SegmentCond.gt(value));
}
public QueryFilter ge(String column,Object value) {
return op(column,SegmentCond.ge(value));
}
public QueryFilter lt(String column,Object value) {
return op(column,SegmentCond.lt(value));
}
public QueryFilter le(String column,Object value) {
return op(column,SegmentCond.le(value));
}
public QueryFilter isnull(String column) {
return op(column,SegmentCond.isnull());
}
public QueryFilter isnotnull(String column) {
return op(column,SegmentCond.isnotnull());
}
public QueryFilter in(String column,Collection value) {
return op(column,SegmentCond.in(value));
}
public QueryFilter notin(String column,Collection value) {
return op(column,SegmentCond.notin(value));
}
public QueryFilter like(String column,String value) {
return op(column,SegmentCond.like(value));
}
public QueryFilter startsWith(String column,String value) {
return op(column,SegmentCond.startsWith(value));
}
public QueryFilter endsWith(String column,String value) {
return op(column,SegmentCond.endsWith(value));
}
public QueryFilter between(String column,Object from,Object to) {
return op(column,SegmentCond.between(from,to));
}
@JsonIgnore
@Transient
private Map<String,SegmentCond> map;
private Map<String,SegmentCond> getMap()
{
if(map==null)
map=new LinkedHashMap<>();
return map;
}
@JsonAnyGetter
public Map<String , SegmentCond> any() {
return getMap();
}
@JsonAnySetter
public void set(String column, SegmentCond value) {
getMap().put(column,value);
}
@JsonProperty(index = 999)
private List<QueryFilter> $or;
public List<QueryFilter> get$or() {
return $or;
}
public void set$or(List<QueryFilter> $or) {
this.$or = $or;
}
public QueryFilter or(QueryFilter... ors)
{
if ($or == null) {
$or = new ArrayList();
}
Collections.addAll($or, ors);
return this;
}
@JsonProperty(index = 999)
private List<QueryFilter> $and;
public List<QueryFilter> get$and() {
return $and;
}
public void set$and(List<QueryFilter> $and) {
this.$and = $and;
}
public QueryFilter and(QueryFilter... ands)
{
if ($and == null) {
$and = new ArrayList();
}
Collections.addAll($and, ands);
return this;
}
@Override
public String toString() {
return "QueryFilter{" +
"map=" + map +
", $or=" + $or +
'}';
}
private QueryFilter op(String column, SegmentCond segmentCond) {
if(this.getMap().containsKey(column))
((SegmentCond)this.getMap().get(column)).getMap().putAll(segmentCond.getMap());
else
this.getMap().put(column,segmentCond);
return this;
}
public static class SegmentCond {
@JsonIgnore
@Transient
private Map<String,Object> map;
@Override
public String toString() {
return "SegmentCond{" +
"map=" + map +
'}';
}
private Map<String,Object> getMap()
{
if(map==null)
map=new LinkedHashMap<>();
return map;
}
@JsonAnyGetter
public Map<String , Object> any() {
return getMap();
}
@JsonAnySetter
public void set(String column, Object value) {
getMap().put(column,value);
}
public static SegmentCond eq(Object value) {
return op(Segment.EQ,value);
}
public static SegmentCond ne(Object value) {
return op(Segment.NE,value);
}
public static SegmentCond gt(Object value) {
return op(Segment.GT,value);
}
public static SegmentCond ge(Object value) {
return op(Segment.GE,value);
}
public static SegmentCond lt(Object value) {
return op(Segment.LT,value);
}
public static SegmentCond le(Object value) {
return op(Segment.LE,value);
}
public static SegmentCond isnull() {
return op(Segment.IS_NULL,true);
}
public static SegmentCond isnotnull() {
return op(Segment.IS_NOT_NULL,true);
}
public static SegmentCond in(Collection value) {
return op(Segment.IN,value);
}
public static SegmentCond notin(Collection value) {
return op(Segment.NOTIN,value);
}
public static SegmentCond like(String value) {
return op(Segment.LIKE,value);
}
public static SegmentCond startsWith(String value) {
return op(Segment.LEFTLIKE,value);
}
public static SegmentCond endsWith(String value) {
return op(Segment.RIGHTLIKE,value);
}
public static SegmentCond between(Object from,Object to) {
return op(Segment.GE,from).op(Segment.LT,to);
}
private static SegmentCond op(Segment segment,Object value) {
SegmentCond segmentCond=new SegmentCond();
segmentCond.getMap().put(segment.keyword,value);
return segmentCond;
}
}
public enum Segment {
AND("$and"),
OR("$or"),
EQ("$eq"),
NE("$ne"),
GT("$gt"),
GE("$gte"),
LT("$lt"),
LE("$lte"),
IS_NULL("$null"),
IS_NOT_NULL("$notNull"),
IN("$in"),
NOTIN("$notIn"),
LIKE("$like"),
LEFTLIKE("$startsWith"),
RIGHTLIKE("$endsWith"),
EXISTS("$exists"),
NOTEXISTS("$notExists");
private final String keyword;
Segment(final String keyword) {
this.keyword = keyword;
}
}
/*
SQL: (field1>1 and field2='3' and (field3 like "a" or (field4 is not null and field5 in ['11','12']) )
JAVA: QueryFilter filter=QueryFilter.createQuery()
.gt("field1",1)
.eq("field2",'3')
.or(QueryFilter.createQuery().like("field3","a")
,QueryFilter.createQuery().isnotnull("field4").in("field5",Arrays.asList("11","12")));
JSON: {
"$or":[
{
"field3":{"$like":"a"}
},
{
"field4":{ "$notNull":true},
"field5":{"$in":["11","12"]}
}],
"field1":{"$gt":1},
"field2":{"$eq":"3" }
}
*/
}
......@@ -10,11 +10,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Sort;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.*;
import java.util.function.Consumer;
@Slf4j
@Data
......@@ -73,4 +71,150 @@ public class QueryWrapperContext<T> extends SearchContextBase implements ISearch
return page;
}
public QueryWrapper<T> getSearchCond(){
return this.selectCond;
}
/**
* 填充自定义查询条件
* @return
*/
public QueryWrapper<T> getSelectCond() {
if(!ObjectUtils.isEmpty(filter)){
Consumer queryWrapper = parseQueryFilter(filter);
if(!ObjectUtils.isEmpty(queryWrapper)){
selectCond.and(queryWrapper);
}
}
return selectCond;
}
/**
* 解析自定义查询条件
* @param queryFilter
* @return
*/
private Consumer<QueryWrapper<T>> parseQueryFilter(QueryFilter queryFilter){
if(queryFilter.any().size()==0 && queryFilter.get$or()==null && queryFilter.get$and()==null)
return null;
Consumer<QueryWrapper<T>> consumer = queryWrapper -> {
Consumer fieldConsumer=parseFieldMap(queryFilter.any());
Consumer orConsumer=parseOrQueryFilter(queryFilter.get$or());
Consumer andConsumer=parseAndQueryFilter(queryFilter.get$and());
if(!ObjectUtils.isEmpty(fieldConsumer)){
queryWrapper.and(fieldConsumer);
}
if(!ObjectUtils.isEmpty(orConsumer)){
queryWrapper.and(orConsumer);
}
if(!ObjectUtils.isEmpty(andConsumer)){
queryWrapper.and(andConsumer);
}
};
return consumer;
}
/**
* 解析自定义条件[or]
* @param queryFilters
* @return
*/
private Consumer<QueryWrapper<T>> parseOrQueryFilter(List<QueryFilter> queryFilters) {
if(queryFilters==null || queryFilters.size()==0)
return null;
Consumer<QueryWrapper<T>> consumer = queryWrapper -> {
for(QueryFilter queryFilter: queryFilters){
Consumer tempQueryWrapper=parseQueryFilter(queryFilter);
queryWrapper.or(tempQueryWrapper);
}
};
return consumer;
}
/**
* 解析自定义条件[and]
* @param queryFilters
* @return
*/
private Consumer<QueryWrapper<T>> parseAndQueryFilter(List<QueryFilter> queryFilters) {
if(queryFilters==null || queryFilters.size()==0)
return null;
Consumer<QueryWrapper<T>> consumer = queryWrapper -> {
for(QueryFilter queryFilter: queryFilters){
Consumer tempQueryWrapper=parseQueryFilter(queryFilter);
queryWrapper.and(tempQueryWrapper);
}
};
return consumer;
}
/**
* 解析自定义条件[字段条件]
* @param fieldMap
* @return
*/
private Consumer<QueryWrapper<T>> parseFieldMap(Map<String , QueryFilter.SegmentCond> fieldMap) {
if(fieldMap.size()==0)
return null;
Consumer<QueryWrapper<T>> consumer = queryWrapper -> {
for(Map.Entry<String, QueryFilter.SegmentCond> field: fieldMap.entrySet()){
String fieldName=field.getKey();
QueryFilter.SegmentCond segmentCond=field.getValue();
Map<String , Object> segmentCondMap = segmentCond.any();
for(Map.Entry<String , Object> fieldCond: segmentCondMap.entrySet()){
Object value=fieldCond.getValue();
switch (fieldCond.getKey()){
case "$eq":
queryWrapper.eq(fieldName,value);
break;
case "$ne":
queryWrapper.ne(fieldName,value);
break;
case "$gt":
queryWrapper.gt(fieldName,value);
break;
case "$gte":
queryWrapper.ge(fieldName,value);
break;
case "$lt":
queryWrapper.lt(fieldName,value);
break;
case "$lte":
queryWrapper.le(fieldName,value);
break;
case "$null":
queryWrapper.isNull(fieldName);
break;
case "$notNull":
queryWrapper.isNotNull(fieldName);
break;
case "$in":
queryWrapper.in(fieldName,(Collection)value);
break;
case "$notIn":
queryWrapper.notIn(fieldName,(Collection)value);
break;
case "$like":
queryWrapper.like(fieldName,value);
break;
case "$startsWith":
queryWrapper.likeRight(fieldName,value);
break;
case "$endsWith":
queryWrapper.likeLeft(fieldName,value);
break;
case "$exists":
break;
case "$notExists":
break;
}
}
}
};
return consumer;
}
}
......@@ -12,9 +12,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.util.StringUtils;
import org.springframework.util.ObjectUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Slf4j
@Data
......@@ -35,7 +33,11 @@ public class SearchContextBase implements ISearchContext{
*/
@JsonProperty("query")
public String query;
/**
* 条件表达式
*/
@JsonProperty("filter")
public QueryFilter filter;
/**
* 数据查询
*/
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册