Skip to content

Commit

Permalink
fix(场景联动): 修复场景联动使用指标值无法触发问题 (#562)
Browse files Browse the repository at this point in the history
Co-authored-by: fighter-wang <[email protected]>
  • Loading branch information
fighter-wang and fighter-wang authored Aug 29, 2024
1 parent 845206f commit bf5ba69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -106,14 +107,16 @@ protected void appendFunction(String column, PrepareSqlFragments fragments) {
};

private final String text;
private final boolean needValue;
private final Set<String> 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
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public Mono<PropertyMetric> getPropertyMetric(ThingId thingId, String property,
private Mono<PropertyMetric> 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
Expand Down

0 comments on commit bf5ba69

Please sign in to comment.