From bf5ba69bcb497eb60104d5dcda1aa3232b0e799f Mon Sep 17 00:00:00 2001 From: fighter-wang <118291973+fighter-wang@users.noreply.github.com> Date: Thu, 29 Aug 2024 15:50:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=9C=BA=E6=99=AF=E8=81=94=E5=8A=A8):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=BA=E6=99=AF=E8=81=94=E5=8A=A8=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E6=8C=87=E6=A0=87=E5=80=BC=E6=97=A0=E6=B3=95=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E9=97=AE=E9=A2=98=20(#562)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: fighter-wang <11291691+fighter-wang@user.noreply.gitee.com> --- .../reactorql/term/FixedTermTypeSupport.java | 26 +++++++++---------- .../metric/AbstractPropertyMetricManager.java | 3 +-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/jetlinks-components/common-component/src/main/java/org/jetlinks/community/reactorql/term/FixedTermTypeSupport.java b/jetlinks-components/common-component/src/main/java/org/jetlinks/community/reactorql/term/FixedTermTypeSupport.java index 21928e43e..e4f2ac672 100644 --- a/jetlinks-components/common-component/src/main/java/org/jetlinks/community/reactorql/term/FixedTermTypeSupport.java +++ b/jetlinks-components/common-component/src/main/java/org/jetlinks/community/reactorql/term/FixedTermTypeSupport.java @@ -1,5 +1,6 @@ package org.jetlinks.community.reactorql.term; +import com.google.common.collect.Sets; import lombok.Getter; import org.hswebframework.ezorm.core.param.Term; import org.hswebframework.ezorm.rdb.operator.builder.fragments.NativeSql; @@ -106,14 +107,16 @@ protected void appendFunction(String column, PrepareSqlFragments fragments) { }; private final String text; + private final boolean needValue; private final Set supportTypes; private final String function; - private FixedTermTypeSupport(String text, String function, String... supportTypes) { + FixedTermTypeSupport(String text, String function, String... supportTypes) { this.text = text; this.function = function; - this.supportTypes = new HashSet<>(Arrays.asList(supportTypes)); + this.needValue = true; + this.supportTypes = Sets.newHashSet(supportTypes); } @Override @@ -140,21 +143,18 @@ public SqlFragments createSql(String column, Object value, Term term) { PrepareSqlFragments fragments = PrepareSqlFragments.of(); appendFunction(column, fragments); - if (term.getOptions().contains(OPTIONS_NATIVE_SQL)) { - value = NativeSql.of(String.valueOf(value)); - } - - value = convertValue(value, term); - if (value instanceof NativeSql) { fragments .addSql(((NativeSql) value).getSql()) - .addParameter(((NativeSql) value).getParameters()); - } else { - fragments.addSql("?") - .addParameter(value); + .addParameter(((NativeSql) value).getParameters()) + .addSql(")"); + } else if (needValue) { + value = convertValue(value, term); + fragments + .addSql("?") + .addParameter(value) + .addSql(")"); } - fragments.addSql(")"); return fragments; } diff --git a/jetlinks-components/things-component/src/main/java/org/jetlinks/community/things/metric/AbstractPropertyMetricManager.java b/jetlinks-components/things-component/src/main/java/org/jetlinks/community/things/metric/AbstractPropertyMetricManager.java index aa6af027b..8fb363505 100644 --- a/jetlinks-components/things-component/src/main/java/org/jetlinks/community/things/metric/AbstractPropertyMetricManager.java +++ b/jetlinks-components/things-component/src/main/java/org/jetlinks/community/things/metric/AbstractPropertyMetricManager.java @@ -36,8 +36,7 @@ public Mono getPropertyMetric(ThingId thingId, String property, private Mono loadFromTemplate(ThingId thingId, String property, String metric) { return registry .getThing(thingId.getType(), thingId.getId()) - .flatMap(Thing::getTemplate) - .flatMap(ThingTemplate::getMetadata) + .flatMap(Thing::getMetadata) .flatMap(metadata -> Mono .justOrEmpty( metadata