2026-06-26 20b96473f2520590a0dca6b775b81e3ea06a77a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package cn.iocoder.yudao.module.iot.core.enums;
 
import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import cn.iocoder.yudao.framework.common.util.collection.SetUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
 
import java.util.Arrays;
import java.util.Set;
 
/**
 * IoT 设备消息的方法枚举
 *
 * @author haohao
 */
@Getter
@AllArgsConstructor
public enum IotDeviceMessageMethodEnum implements ArrayValuable<String> {
 
    // ========== 设备状态 ==========
 
    STATE_UPDATE("thing.state.update", "设备状态更新", true),
 
    // TODO 芋艿:要不要加个 ping 消息;
 
    // ========== 拓扑管理 ==========
    // 可参考:https://help.aliyun.com/zh/iot/user-guide/manage-topological-relationships
 
    TOPO_ADD("thing.topo.add", "添加拓扑关系", true),
    TOPO_DELETE("thing.topo.delete", "删除拓扑关系", true),
    TOPO_GET("thing.topo.get", "获取拓扑关系", true),
    TOPO_CHANGE("thing.topo.change", "拓扑关系变更通知", false),
 
    // ========== 设备注册 ==========
    // 可参考:https://help.aliyun.com/zh/iot/user-guide/unique-certificate-per-product-verification
 
    DEVICE_REGISTER("thing.auth.register", "设备动态注册", true),
    SUB_DEVICE_REGISTER("thing.auth.register.sub", "子设备动态注册", true),
 
    // ========== 设备属性 ==========
    // 可参考:https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services
 
    PROPERTY_POST("thing.property.post", "属性上报", true),
    PROPERTY_SET("thing.property.set", "属性设置", false),
 
    PROPERTY_PACK_POST("thing.event.property.pack.post", "批量上报(属性 + 事件 + 子设备)", true), // 网关独有
 
    // ========== 设备事件 ==========
    // 可参考:https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services
 
    EVENT_POST("thing.event.post", "事件上报", true),
 
    // ========== 设备服务调用 ==========
    // 可参考:https://help.aliyun.com/zh/iot/user-guide/device-properties-events-and-services
 
    SERVICE_INVOKE("thing.service.invoke", "服务调用", false),
 
    // ========== 设备配置 ==========
    // 可参考:https://help.aliyun.com/zh/iot/user-guide/remote-configuration-1
 
    CONFIG_PUSH("thing.config.push", "配置推送", false),
 
    // ========== OTA 固件 ==========
    // 可参考:https://help.aliyun.com/zh/iot/user-guide/perform-ota-updates
 
    OTA_UPGRADE("thing.ota.upgrade", "OTA 固件信息推送", false),
    OTA_PROGRESS("thing.ota.progress", "OTA 升级进度上报", true),
 
    ;
 
    public static final String[] ARRAYS = Arrays.stream(values()).map(IotDeviceMessageMethodEnum::getMethod)
            .toArray(String[]::new);
 
    /**
     * 不进行 reply 回复的方法集合
     */
    public static final Set<String> REPLY_DISABLED = SetUtils.asSet(
            STATE_UPDATE.getMethod(),
            OTA_PROGRESS.getMethod() // 参考阿里云,OTA 升级进度上报,不进行回复
    );
 
    private final String method;
 
    private final String name;
 
    private final Boolean upstream;
 
    @Override
    public String[] array() {
        return ARRAYS;
    }
 
    public static IotDeviceMessageMethodEnum of(String method) {
        return ArrayUtil.firstMatch(item -> item.getMethod().equals(method),
                IotDeviceMessageMethodEnum.values());
    }
 
    public static boolean isReplyDisabled(String method) {
        return REPLY_DISABLED.contains(method);
    }
 
}