|
@@ -9,6 +9,7 @@ import org.elasticsearch.search.sort.SortOrder;
|
|
|
import org.hswebframework.ezorm.core.param.QueryParam;
|
|
import org.hswebframework.ezorm.core.param.QueryParam;
|
|
|
import org.hswebframework.ezorm.core.param.Sort;
|
|
import org.hswebframework.ezorm.core.param.Sort;
|
|
|
import org.hswebframework.ezorm.core.param.Term;
|
|
import org.hswebframework.ezorm.core.param.Term;
|
|
|
|
|
+import org.hswebframework.ezorm.core.param.TermType;
|
|
|
import org.jetlinks.community.elastic.search.index.ElasticSearchIndexMetadata;
|
|
import org.jetlinks.community.elastic.search.index.ElasticSearchIndexMetadata;
|
|
|
import org.jetlinks.community.elastic.search.parser.DefaultLinkTypeParser;
|
|
import org.jetlinks.community.elastic.search.parser.DefaultLinkTypeParser;
|
|
|
import org.jetlinks.community.utils.ConverterUtils;
|
|
import org.jetlinks.community.utils.ConverterUtils;
|
|
@@ -43,26 +44,61 @@ public class QueryParamTranslator {
|
|
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ private static boolean maybeList(Term term) {
|
|
|
|
|
+ switch (term.getTermType().toLowerCase()) {
|
|
|
|
|
+ case TermType.in:
|
|
|
|
|
+ case TermType.nin:
|
|
|
|
|
+ case TermType.btw:
|
|
|
|
|
+ case TermType.nbtw:
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private static boolean isDoNotConvertValue(Term term) {
|
|
|
|
|
+ switch (term.getTermType().toLowerCase()) {
|
|
|
|
|
+ case TermType.isnull:
|
|
|
|
|
+ case TermType.notnull:
|
|
|
|
|
+ case TermType.empty:
|
|
|
|
|
+ case TermType.nempty:
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private static Object convertValue(DataType type, Object val) {
|
|
|
|
|
+ if (type instanceof DateTimeType) {
|
|
|
|
|
+ return TimeUtils.convertToDate(val).getTime();
|
|
|
|
|
+ } else if (type instanceof Converter) {
|
|
|
|
|
+ return ((Converter<?>) type).convert(val);
|
|
|
|
|
+ }
|
|
|
|
|
+ return val;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static QueryBuilder createQueryBuilder(QueryParam queryParam, ElasticSearchIndexMetadata metadata) {
|
|
public static QueryBuilder createQueryBuilder(QueryParam queryParam, ElasticSearchIndexMetadata metadata) {
|
|
|
BoolQueryBuilder queryBuilders = QueryBuilders.boolQuery();
|
|
BoolQueryBuilder queryBuilders = QueryBuilders.boolQuery();
|
|
|
Consumer<Term> paramConverter = doNotingParamConverter;
|
|
Consumer<Term> paramConverter = doNotingParamConverter;
|
|
|
if (metadata != null) {
|
|
if (metadata != null) {
|
|
|
paramConverter = t -> {
|
|
paramConverter = t -> {
|
|
|
- if (ObjectUtils.isEmpty(t.getColumn())) {
|
|
|
|
|
|
|
+ if (ObjectUtils.isEmpty(t.getColumn()) || isDoNotConvertValue(t)) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
PropertyMetadata property = metadata.getProperty(t.getColumn());
|
|
PropertyMetadata property = metadata.getProperty(t.getColumn());
|
|
|
if (null != property) {
|
|
if (null != property) {
|
|
|
DataType type = property.getValueType();
|
|
DataType type = property.getValueType();
|
|
|
- t.setValue(
|
|
|
|
|
- ConverterUtils.tryConvertToList(t.getValue(), val -> {
|
|
|
|
|
- if (type instanceof DateTimeType) {
|
|
|
|
|
- return TimeUtils.convertToDate(val).getTime();
|
|
|
|
|
- } else if (type instanceof Converter) {
|
|
|
|
|
- return ((Converter<?>) type).convert(val);
|
|
|
|
|
- }
|
|
|
|
|
- return val;
|
|
|
|
|
- }));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ Object value;
|
|
|
|
|
+ if (maybeList(t)) {
|
|
|
|
|
+ value = ConverterUtils.tryConvertToList(t.getValue(), v -> convertValue(type, v));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ value = convertValue(type, t.getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (null != value) {
|
|
|
|
|
+ t.setValue(value);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.warn("Can not convert {} to {}", t.getValue(), type.getId());
|
|
|
|
|
+ }
|
|
|
converter.getOrDefault(type.getId(), defaultDataTypeConverter).accept(type, t);
|
|
converter.getOrDefault(type.getId(), defaultDataTypeConverter).accept(type, t);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
@@ -85,7 +121,7 @@ public class QueryParamTranslator {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return sourceBuilder.query(createQueryBuilder(queryParam,metadata));
|
|
|
|
|
|
|
+ return sourceBuilder.query(createQueryBuilder(queryParam, metadata));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|