-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(场景联动): 添加设备数据执行动作,扩展数组条件,优化国际化 (#605)
- Loading branch information
Showing
53 changed files
with
2,332 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...omponent/src/main/java/org/jetlinks/community/configuration/DataTypeJSONDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.jetlinks.community.configuration; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import org.apache.commons.beanutils.BeanUtilsBean; | ||
import org.jetlinks.core.metadata.DataType; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @author zhangji 2025/1/23 | ||
* @since 2.3 | ||
*/ | ||
public class DataTypeJSONDeserializer extends JsonDeserializer<DataType> { | ||
@Override | ||
public DataType deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { | ||
|
||
Map<String,Object> map= ctxt.readValue(parser, Map.class); | ||
|
||
return (DataType) BeanUtilsBean.getInstance().getConvertUtils().convert(map, DataType.class); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ponent/src/main/java/org/jetlinks/community/reactorql/aggregation/AggregationSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.jetlinks.community.reactorql.aggregation; | ||
|
||
import org.hswebframework.ezorm.rdb.operator.builder.fragments.SqlFragments; | ||
import org.hswebframework.ezorm.rdb.operator.dml.FunctionColumn; | ||
import org.jetlinks.community.spi.Provider; | ||
import org.reactivestreams.Publisher; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* 聚合函数支持. | ||
* | ||
* @author zhangji 2025/1/22 | ||
* @since 2.3 | ||
*/ | ||
public interface AggregationSupport extends Function<Publisher<?>, Mono<?>> { | ||
|
||
Provider<AggregationSupport> supports = Provider.create(AggregationSupport.class); | ||
|
||
String getId(); | ||
|
||
String getName(); | ||
|
||
SqlFragments createSql(FunctionColumn column); | ||
|
||
|
||
static AggregationSupport getNow(String id) { | ||
return AggregationSupport.supports | ||
.get(id.toUpperCase()) | ||
.orElseGet(() -> AggregationSupport.supports | ||
.get(id.toLowerCase()) | ||
.orElseGet(() -> AggregationSupport.supports.getNow(id))); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...c/main/java/org/jetlinks/community/reactorql/aggregation/InternalAggregationSupports.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.jetlinks.community.reactorql.aggregation; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.hswebframework.ezorm.rdb.operator.builder.fragments.BatchSqlFragments; | ||
import org.hswebframework.ezorm.rdb.operator.builder.fragments.SqlFragments; | ||
import org.hswebframework.ezorm.rdb.operator.dml.FunctionColumn; | ||
import org.jetlinks.reactor.ql.supports.agg.MapAggFeature; | ||
import org.jetlinks.reactor.ql.utils.CastUtils; | ||
import org.reactivestreams.Publisher; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
import reactor.math.MathFlux; | ||
|
||
import java.util.Comparator; | ||
import java.util.function.Function; | ||
|
||
import static org.jetlinks.reactor.ql.supports.DefaultReactorQLMetadata.addGlobal; | ||
|
||
/** | ||
* | ||
* @author zhangji 2025/1/22 | ||
* @since 2.3 | ||
*/ | ||
@AllArgsConstructor | ||
public enum InternalAggregationSupports implements AggregationSupport { | ||
COUNT("总数", Flux::count, 0), | ||
//去重计数 | ||
DISTINCT_COUNT("总数(去重)", flux -> flux.distinct().count(), 0) { | ||
@Override | ||
public SqlFragments createSql(FunctionColumn column) { | ||
return new BatchSqlFragments().addSql("count(distinct ", column.getColumn(), ")"); | ||
} | ||
}, | ||
MIN("最小值", | ||
numberFlux -> MathFlux.min(numberFlux.map(CastUtils::castNumber), Comparator.comparing(Number::doubleValue)), null), | ||
MAX("最大值", numberFlux -> MathFlux.max(numberFlux.map(CastUtils::castNumber), Comparator.comparing(Number::doubleValue)), null), | ||
AVG("平均值", numberFlux -> MathFlux.averageDouble(numberFlux.map(CastUtils::castNumber), Number::doubleValue), null), | ||
SUM("总和", numberFlux -> MathFlux.sumDouble(numberFlux.map(CastUtils::castNumber), Number::doubleValue), 0), | ||
|
||
FIRST("第一个值", numberFlux -> numberFlux.take(1).singleOrEmpty(), null), | ||
LAST("最后一个值", numberFlux -> numberFlux.takeLast(1).singleOrEmpty(), null), | ||
|
||
// MEDIAN("中位数", numberFlux -> Mono.empty(), null),//中位数 | ||
// SPREAD("极差", numberFlux -> Mono.empty(), null),//差值 | ||
// STDDEV("标准差", numberFlux -> Mono.empty(), null),//标准差 | ||
; | ||
|
||
static { | ||
for (InternalAggregationSupports value : values()) { | ||
addGlobal(new MapAggFeature(value.getId(), value::apply)); | ||
AggregationSupport.supports.register(value.getId(), value); | ||
} | ||
} | ||
|
||
public static void register(){ | ||
|
||
} | ||
|
||
@Getter | ||
private final String name; | ||
|
||
private final Function<Flux<?>, Mono<?>> computer; | ||
@Getter | ||
private final Object defaultValue; | ||
|
||
@Override | ||
public SqlFragments createSql(FunctionColumn column) { | ||
return new BatchSqlFragments() | ||
.addSql(name() + "(").addSql(column.getColumn()).addSql(")"); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return name(); | ||
} | ||
|
||
@Override | ||
public Mono<?> apply(Publisher<?> publisher) { | ||
return computer.apply(Flux.from(publisher)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ommon-component/src/main/java/org/jetlinks/community/reactorql/function/FunctionInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.jetlinks.community.reactorql.function; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.jetlinks.core.metadata.DataType; | ||
import org.jetlinks.core.metadata.PropertyMetadata; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
* @author zhangji 2025/1/22 | ||
* @since 2.3 | ||
*/ | ||
@Getter | ||
@Setter | ||
public class FunctionInfo { | ||
private String id; | ||
|
||
private String name; | ||
|
||
private DataType outputType; | ||
|
||
private List<PropertyMetadata> args; | ||
} |
72 changes: 72 additions & 0 deletions
72
...on-component/src/main/java/org/jetlinks/community/reactorql/function/FunctionSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.jetlinks.community.reactorql.function; | ||
|
||
import org.hswebframework.ezorm.rdb.operator.builder.fragments.SqlFragments; | ||
import org.jetlinks.core.metadata.DataType; | ||
import org.jetlinks.community.spi.Provider; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* 函数支持,用于定义在可以在ReactorQL中使用的函数. | ||
* | ||
* @author zhangji 2025/1/22 | ||
* @since 2.3 | ||
*/ | ||
public interface FunctionSupport { | ||
|
||
Provider<FunctionSupport> supports = Provider.create(FunctionSupport.class); | ||
|
||
String getId(); | ||
|
||
String getName(); | ||
|
||
/** | ||
* 是否支持列的数据类型 | ||
* | ||
* @param type 数据类型 | ||
* @return 是否支持 | ||
*/ | ||
boolean isSupported(DataType type); | ||
|
||
/** | ||
* 获取输出数据类型 | ||
* | ||
* @return 输出数据类型 | ||
*/ | ||
DataType getOutputType(); | ||
|
||
/** | ||
* 创建SQL函数片段 | ||
* | ||
* @param column 列名 | ||
* @param args 参数 | ||
* @return SQL函数片段 | ||
*/ | ||
SqlFragments createSql(String column, Map<String, Object> args); | ||
|
||
/** | ||
* 查找支持的函数 | ||
* | ||
* @param type 数据类型 | ||
* @return 函数信息 | ||
*/ | ||
static List<FunctionInfo> lookup(DataType type) { | ||
return supports | ||
.getAll() | ||
.stream() | ||
.filter(support -> support.isSupported(type)) | ||
.map(FunctionSupport::toInfo) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
|
||
default FunctionInfo toInfo() { | ||
FunctionInfo info = new FunctionInfo(); | ||
info.setId(getId()); | ||
info.setOutputType(getOutputType()); | ||
info.setName(getName()); | ||
return info; | ||
} | ||
} |
Oops, something went wrong.