Skip to content

Commit

Permalink
feat(设备管理): 新增在reactorQL中获取设备属性上报时间 (#592)
Browse files Browse the repository at this point in the history
Co-authored-by: fighter-wang <11291691+fighter-wang@user.noreply.gitee.com>
  • Loading branch information
fighter-wang and fighter-wang authored Dec 9, 2024
1 parent b890f4e commit 9c26d7d
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.jetlinks.community.device.function;

import org.jetlinks.core.message.DeviceDataManager;
import org.jetlinks.reactor.ql.supports.map.FunctionMapFeature;
import org.jetlinks.reactor.ql.utils.CastUtils;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

/**
* 在reactorQL中获取设备属性上报时间
* <pre>{@code
* select device.property_time.recent(deviceId,'temperature',timestamp) recent from ...
*
* select * from ... where device.property_time.recent(deviceId,'temperature',timestamp) = 'xxx'
* }</pre>
*
* @author zhouhao
* @since 2.2
*/
@Component
public class DevicePropertyTimeFunction extends FunctionMapFeature {
public DevicePropertyTimeFunction(DeviceDataManager dataManager) {
super("device.property_time.recent", 3, 2, flux -> flux
.collectList()
.flatMap(args -> {
if (args.size() < 2) {
return Mono.empty();
}
String deviceId = String.valueOf(args.get(0));
String property = String.valueOf(args.get(1));
long timestamp = args.size() > 2
? CastUtils.castNumber(args.get(2))
.longValue()
: System.currentTimeMillis();

return dataManager
.getLastProperty(deviceId, property, timestamp)
.map(DeviceDataManager.PropertyValue::getTimestamp);
}));
}
}

0 comments on commit 9c26d7d

Please sign in to comment.