refactor: 优化查询条件转换
This commit is contained in:
parent
88e0dd4667
commit
d4645ad089
|
|
@ -14,6 +14,7 @@ import org.hswebframework.web.exception.BusinessException;
|
|||
import org.jetlinks.community.tdengine.TDEngineUtils;
|
||||
import org.jetlinks.community.tdengine.term.TDengineQueryConditionBuilder;
|
||||
import org.jetlinks.community.things.data.ThingsDataConstants;
|
||||
import org.jetlinks.community.things.utils.ThingsDatabaseUtils;
|
||||
import org.jetlinks.core.metadata.Converter;
|
||||
import org.jetlinks.core.metadata.DataType;
|
||||
import org.jetlinks.community.Interval;
|
||||
|
|
@ -100,11 +101,7 @@ class TDengineThingDataHelper implements Disposable {
|
|||
.getColumn(metric, term.getColumn())
|
||||
.ifPresent(meta -> {
|
||||
DataType type = meta.getValueType();
|
||||
if (isArrayTerm(type, term)) {
|
||||
term.setValue(tryConvertList(type, term));
|
||||
} else if (type instanceof Converter) {
|
||||
term.setValue(((Converter<?>) type).convert(term.getValue()));
|
||||
}
|
||||
ThingsDatabaseUtils.tryConvertTermValue(type, term);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import org.hswebframework.ezorm.rdb.codec.NumberValueCodec;
|
|||
import org.hswebframework.ezorm.rdb.metadata.RDBColumnMetadata;
|
||||
import org.jetlinks.community.ConfigMetadataConstants;
|
||||
import org.jetlinks.community.utils.ConverterUtils;
|
||||
import org.jetlinks.community.utils.TimeUtils;
|
||||
import org.jetlinks.core.metadata.Converter;
|
||||
import org.jetlinks.core.metadata.DataType;
|
||||
import org.jetlinks.core.metadata.PropertyMetadata;
|
||||
import org.jetlinks.core.metadata.types.*;
|
||||
|
|
@ -208,6 +210,33 @@ public class ThingsDatabaseUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void tryConvertTermValue(DataType type,
|
||||
Term term,
|
||||
BiFunction<DataType, Object, Object> tryConvertTermValue) {
|
||||
tryConvertTermValue(type,
|
||||
term,
|
||||
ThingsDatabaseUtils::isDoNotConvertValue,
|
||||
ThingsDatabaseUtils::maybeList,
|
||||
tryConvertTermValue);
|
||||
}
|
||||
|
||||
public static void tryConvertTermValue(DataType type,
|
||||
Term term) {
|
||||
tryConvertTermValue(type,
|
||||
term,
|
||||
ThingsDatabaseUtils::tryConvertTermValue);
|
||||
}
|
||||
|
||||
public static Object tryConvertTermValue(DataType type, Object value) {
|
||||
if (type instanceof DateTimeType) {
|
||||
return TimeUtils.convertToDate(value).getTime();
|
||||
} else if (type instanceof Converter) {
|
||||
return ((Converter<?>) type).convert(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
public static void tryConvertTermValue(DataType type,
|
||||
Term term,
|
||||
BiPredicate<DataType, Term> isDoNotConvertValue,
|
||||
|
|
|
|||
Loading…
Reference in New Issue