diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/iot/config/YudaoIotProperties.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/iot/config/YudaoIotProperties.java
new file mode 100644
index 0000000000..07473c0293
--- /dev/null
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/iot/config/YudaoIotProperties.java
@@ -0,0 +1,28 @@
+package cn.iocoder.yudao.module.iot.framework.iot.config;
+
+import lombok.Data;
+import org.springframework.stereotype.Component;
+
+import java.time.Duration;
+
+/**
+ * 芋道 IoT 全局配置类
+ *
+ * @author 芋道源码
+ */
+@Component
+@Data
+public class YudaoIotProperties {
+
+ /**
+ * 设备连接超时时间
+ */
+ private Duration keepAliveTime = Duration.ofMinutes(10);
+ /**
+ * 设备连接超时时间的因子
+ *
+ * 因为设备可能会有网络抖动,所以需要乘以一个因子,避免误判
+ */
+ private double keepAliveFactor = 1.5D;
+
+}
diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/iot/package-info.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/iot/package-info.java
new file mode 100644
index 0000000000..0930a1409c
--- /dev/null
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/iot/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * iot 模块的【全局】拓展封装
+ */
+package cn.iocoder.yudao.module.iot.framework.iot;
\ No newline at end of file
diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/device/IotDeviceOfflineCheckJob.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/device/IotDeviceOfflineCheckJob.java
index b14beafe23..6bd27a679a 100644
--- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/device/IotDeviceOfflineCheckJob.java
+++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/job/device/IotDeviceOfflineCheckJob.java
@@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.iot.core.enums.IotDeviceStateEnum;
import cn.iocoder.yudao.module.iot.core.mq.message.IotDeviceMessage;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
+import cn.iocoder.yudao.module.iot.framework.iot.config.YudaoIotProperties;
import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
import cn.iocoder.yudao.module.iot.service.device.message.IotDeviceMessageService;
import cn.iocoder.yudao.module.iot.service.device.property.IotDevicePropertyService;
@@ -24,17 +25,14 @@ import java.util.Set;
*
* 检测逻辑:设备最后一条 {@link IotDeviceMessage} 消息超过一定时间,则认为设备离线
*
+ * @see 阿里云 IoT —— 设备离线分析
* @author 芋道源码
*/
@Component
public class IotDeviceOfflineCheckJob implements JobHandler {
- /**
- * 设备离线超时时间
- *
- * TODO 芋艿:暂定 10 分钟,后续看看要不要基于设备或者全局有配置文件
- */
- public static final Duration OFFLINE_TIMEOUT = Duration.ofMinutes(10);
+ @Resource
+ private YudaoIotProperties iotProperties;
@Resource
private IotDeviceService deviceService;
@@ -52,8 +50,7 @@ public class IotDeviceOfflineCheckJob implements JobHandler {
return JsonUtils.toJsonString(Collections.emptyList());
}
// 1.2 获取超时的设备集合
- Set timeoutDeviceIds = devicePropertyService.getDeviceIdListByReportTime(
- LocalDateTime.now().minus(OFFLINE_TIMEOUT));
+ Set timeoutDeviceIds = devicePropertyService.getDeviceIdListByReportTime(getTimeoutTime());
// 2. 下线设备
List offlineDevices = CollUtil.newArrayList();
@@ -68,4 +65,9 @@ public class IotDeviceOfflineCheckJob implements JobHandler {
return JsonUtils.toJsonString(offlineDevices);
}
+ private LocalDateTime getTimeoutTime() {
+ return LocalDateTime.now().minus(Duration.ofNanos(
+ (long) (iotProperties.getKeepAliveTime().toNanos() * iotProperties.getKeepAliveFactor())));
+ }
+
}
diff --git a/yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/enums/IotDeviceMessageMethodEnum.java b/yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/enums/IotDeviceMessageMethodEnum.java
index cb343e33ec..fddf155a08 100644
--- a/yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/enums/IotDeviceMessageMethodEnum.java
+++ b/yudao-module-iot/yudao-module-iot-core/src/main/java/cn/iocoder/yudao/module/iot/core/enums/IotDeviceMessageMethodEnum.java
@@ -21,6 +21,8 @@ public enum IotDeviceMessageMethodEnum implements ArrayValuable {
STATE_UPDATE("thing.state.update", "设备状态更新", true),
+ // TODO 芋艿:要不要加个 ping 消息;
+
// ========== 设备属性 ==========
// 可参考:https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services
diff --git a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/modbus/package-info.java b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/modbus/package-info.java
deleted file mode 100644
index 5e4835da78..0000000000
--- a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/modbus/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package cn.iocoder.yudao.module.iot.gateway.codec.modbus;
\ No newline at end of file
diff --git a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/simple/package-info.java b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/simple/package-info.java
new file mode 100644
index 0000000000..5bd676ad1a
--- /dev/null
+++ b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/codec/simple/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * TODO @芋艿:实现一个 alink 的 xml 版本
+ */
+package cn.iocoder.yudao.module.iot.gateway.codec.simple;
\ No newline at end of file