mirror of
https://gitee.com/zhijiantianya/yudao-cloud.git
synced 2026-03-22 05:07:16 +08:00
fix:【iot 物联网】增强 jdk8 的兼容性
This commit is contained in:
@@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.iot.core.util.IotDeviceMessageUtils;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IoT 网关 HTTP 订阅者:接收下行给设备的消息
|
* IoT 网关 HTTP 订阅者:接收下行给设备的消息
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public class IotMqttConnectionManager {
|
|||||||
*/
|
*/
|
||||||
public IotMqttConnectionManager.ConnectionInfo getConnectionInfoByDeviceId(Long deviceId) {
|
public IotMqttConnectionManager.ConnectionInfo getConnectionInfoByDeviceId(Long deviceId) {
|
||||||
// 通过设备 ID 获取连接端点
|
// 通过设备 ID 获取连接端点
|
||||||
var endpoint = getDeviceEndpoint(deviceId);
|
MqttEndpoint endpoint = getDeviceEndpoint(deviceId);
|
||||||
if (endpoint == null) {
|
if (endpoint == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
|||||||
*/
|
*/
|
||||||
private final LoadingCache<Long, IotDeviceRespDTO> deviceCaches = buildAsyncReloadingCache(
|
private final LoadingCache<Long, IotDeviceRespDTO> deviceCaches = buildAsyncReloadingCache(
|
||||||
CACHE_EXPIRE,
|
CACHE_EXPIRE,
|
||||||
new CacheLoader<>() {
|
new CacheLoader<Long, IotDeviceRespDTO>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IotDeviceRespDTO load(Long id) {
|
public IotDeviceRespDTO load(Long id) {
|
||||||
@@ -51,7 +51,7 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
|||||||
*/
|
*/
|
||||||
private final LoadingCache<KeyValue<String, String>, IotDeviceRespDTO> deviceCaches2 = buildAsyncReloadingCache(
|
private final LoadingCache<KeyValue<String, String>, IotDeviceRespDTO> deviceCaches2 = buildAsyncReloadingCache(
|
||||||
CACHE_EXPIRE,
|
CACHE_EXPIRE,
|
||||||
new CacheLoader<>() {
|
new CacheLoader<KeyValue<String, String>, IotDeviceRespDTO>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IotDeviceRespDTO load(KeyValue<String, String> kv) {
|
public IotDeviceRespDTO load(KeyValue<String, String> kv) {
|
||||||
|
|||||||
@@ -40,19 +40,19 @@ public class IotDeviceApiImpl implements IotDeviceCommonApi {
|
|||||||
IotGatewayProperties.RpcProperties rpc = gatewayProperties.getRpc();
|
IotGatewayProperties.RpcProperties rpc = gatewayProperties.getRpc();
|
||||||
restTemplate = new RestTemplateBuilder()
|
restTemplate = new RestTemplateBuilder()
|
||||||
.rootUri(rpc.getUrl() + "/rpc-api/iot/device")
|
.rootUri(rpc.getUrl() + "/rpc-api/iot/device")
|
||||||
.readTimeout(rpc.getReadTimeout())
|
.setReadTimeout(rpc.getReadTimeout())
|
||||||
.connectTimeout(rpc.getConnectTimeout())
|
.setConnectTimeout(rpc.getConnectTimeout())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<Boolean> authDevice(IotDeviceAuthReqDTO authReqDTO) {
|
public CommonResult<Boolean> authDevice(IotDeviceAuthReqDTO authReqDTO) {
|
||||||
return doPost("/auth", authReqDTO, new ParameterizedTypeReference<>() { });
|
return doPost("/auth", authReqDTO, new ParameterizedTypeReference<CommonResult<Boolean>>() { });
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CommonResult<IotDeviceRespDTO> getDevice(IotDeviceGetReqDTO getReqDTO) {
|
public CommonResult<IotDeviceRespDTO> getDevice(IotDeviceGetReqDTO getReqDTO) {
|
||||||
return doPost("/get", getReqDTO, new ParameterizedTypeReference<>() { });
|
return doPost("/get", getReqDTO, new ParameterizedTypeReference<CommonResult<IotDeviceRespDTO>>() { });
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T, R> CommonResult<R> doPost(String url, T body,
|
private <T, R> CommonResult<R> doPost(String url, T body,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.iot.framework.web.config;
|
package cn.iocoder.yudao.module.iot.framework.web.config;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
|
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
|
||||||
import org.springdoc.core.models.GroupedOpenApi;
|
import org.springdoc.core.GroupedOpenApi;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|||||||
@@ -219,14 +219,14 @@ public class IotSceneRuleServiceImpl implements IotSceneRuleService {
|
|||||||
IotDeviceDO device = deviceService.getDeviceFromCache(message.getDeviceId());
|
IotDeviceDO device = deviceService.getDeviceFromCache(message.getDeviceId());
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
log.warn("[getMatchedSceneRuleListByMessage][设备({}) 不存在]", message.getDeviceId());
|
log.warn("[getMatchedSceneRuleListByMessage][设备({}) 不存在]", message.getDeviceId());
|
||||||
return List.of();
|
return ListUtil.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.2 通过 productId 获取产品信息
|
// 1.2 通过 productId 获取产品信息
|
||||||
IotProductDO product = productService.getProductFromCache(device.getProductId());
|
IotProductDO product = productService.getProductFromCache(device.getProductId());
|
||||||
if (product == null) {
|
if (product == null) {
|
||||||
log.warn("[getMatchedSceneRuleListByMessage][产品({}) 不存在]", device.getProductId());
|
log.warn("[getMatchedSceneRuleListByMessage][产品({}) 不存在]", device.getProductId());
|
||||||
return List.of();
|
return ListUtil.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1.3 获取匹配的规则场景
|
// 1.3 获取匹配的规则场景
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||||
|
|
||||||
@@ -48,17 +49,17 @@ public class IotSceneRuleMatcherManager {
|
|||||||
List<IotSceneRuleMatcher> allMatchers = matchers.stream()
|
List<IotSceneRuleMatcher> allMatchers = matchers.stream()
|
||||||
.filter(IotSceneRuleMatcher::isEnabled)
|
.filter(IotSceneRuleMatcher::isEnabled)
|
||||||
.sorted(Comparator.comparing(IotSceneRuleMatcher::getPriority))
|
.sorted(Comparator.comparing(IotSceneRuleMatcher::getPriority))
|
||||||
.toList();
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 分离触发器匹配器和条件匹配器
|
// 分离触发器匹配器和条件匹配器
|
||||||
List<IotSceneRuleTriggerMatcher> triggerMatchers = allMatchers.stream()
|
List<IotSceneRuleTriggerMatcher> triggerMatchers = allMatchers.stream()
|
||||||
.filter(matcher -> matcher instanceof IotSceneRuleTriggerMatcher)
|
.filter(matcher -> matcher instanceof IotSceneRuleTriggerMatcher)
|
||||||
.map(matcher -> (IotSceneRuleTriggerMatcher) matcher)
|
.map(matcher -> (IotSceneRuleTriggerMatcher) matcher)
|
||||||
.toList();
|
.collect(Collectors.toList());
|
||||||
List<IotSceneRuleConditionMatcher> conditionMatchers = allMatchers.stream()
|
List<IotSceneRuleConditionMatcher> conditionMatchers = allMatchers.stream()
|
||||||
.filter(matcher -> matcher instanceof IotSceneRuleConditionMatcher)
|
.filter(matcher -> matcher instanceof IotSceneRuleConditionMatcher)
|
||||||
.map(matcher -> (IotSceneRuleConditionMatcher) matcher)
|
.map(matcher -> (IotSceneRuleConditionMatcher) matcher)
|
||||||
.toList();
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 构建触发器匹配器映射表
|
// 构建触发器匹配器映射表
|
||||||
this.triggerMatchers = convertMap(triggerMatchers, IotSceneRuleTriggerMatcher::getSupportedTriggerType,
|
this.triggerMatchers = convertMap(triggerMatchers, IotSceneRuleTriggerMatcher::getSupportedTriggerType,
|
||||||
|
|||||||
Reference in New Issue
Block a user