Commit 569d6514816e373c9fa2ec66295707a2b7a7c89e

Authored by YunaiV
1 parent e66c6993

【功能完善】IoT:增加 device config 配置

yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceRespVO.java
... ... @@ -83,6 +83,9 @@ public class IotDeviceRespVO {
83 83 @ExcelProperty("认证类型(如一机一密、动态注册)")
84 84 private String authType;
85 85  
  86 + @Schema(description = "设备配置", example = "{\"abc\": \"efg\"}")
  87 + private String config;
  88 +
86 89 @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
87 90 @ExcelProperty("创建时间")
88 91 private LocalDateTime createTime;
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/device/IotDeviceSaveReqVO.java
... ... @@ -38,4 +38,7 @@ public class IotDeviceSaveReqVO {
38 38 @Schema(description = "网关设备 ID", example = "16380")
39 39 private Long gatewayId;
40 40  
  41 + @Schema(description = "设备配置", example = "{\"abc\": \"efg\"}")
  42 + private String config;
  43 +
41 44 }
42 45 \ No newline at end of file
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDevicePropertyMapper.java
... ... @@ -32,7 +32,6 @@ public interface IotDevicePropertyMapper {
32 32 default void alterProductPropertySTable(String productKey,
33 33 List<TDengineTableField> oldFields,
34 34 List<TDengineTableField> newFields) {
35   - // TODO @芋艿:需要处理 device_key,重新发布的时候
36 35 oldFields.removeIf(field -> StrUtil.equalsAny(field.getField(),
37 36 TDengineTableField.FIELD_TS, "report_time", "device_key"));
38 37 List<TDengineTableField> addFields = newFields.stream().filter( // 新增的字段
... ...
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-emqx/src/main/java/cn/iocoder/yudao/module/iot/plugin/emqx/upstream/router/IotDeviceWebhookVertxHandler.java
... ... @@ -17,9 +17,8 @@ import java.util.Collections;
17 17  
18 18 /**
19 19 * IoT Emqx Webhook 事件处理的 Vert.x Handler
20   - * <a href=
21   - * "https://docs.emqx.com/zh/emqx/latest/data-integration/webhook.html">EMQX
22   - * Webhook</a>
  20 + *
  21 + * <a href="https://docs.emqx.com/zh/emqx/latest/data-integration/webhook.html">EMQXWebhook</a>
23 22 *
24 23 * @author haohao
25 24 */
... ... @@ -69,12 +68,11 @@ public class IotDeviceWebhookVertxHandler implements Handler&lt;RoutingContext&gt; {
69 68 * @param username 用户名
70 69 */
71 70 private void handleClientConnected(String clientId, String username) {
  71 + // 解析产品标识和设备名称
72 72 if (StrUtil.isEmpty(username) || "undefined".equals(username)) {
73 73 log.warn("[handleClientConnected][客户端连接事件,但用户名为空] clientId={}", clientId);
74 74 return;
75 75 }
76   -
77   - // 解析产品标识和设备名称
78 76 String[] parts = parseUsername(username);
79 77 if (parts == null) {
80 78 return;
... ... @@ -87,7 +85,6 @@ public class IotDeviceWebhookVertxHandler implements Handler&lt;RoutingContext&gt; {
87 85 updateReqDTO.setState(IotDeviceStateEnum.ONLINE.getState());
88 86 updateReqDTO.setProcessId(IotPluginCommonUtils.getProcessId());
89 87 updateReqDTO.setReportTime(LocalDateTime.now());
90   -
91 88 CommonResult<Boolean> result = deviceUpstreamApi.updateDeviceState(updateReqDTO);
92 89 if (result.getCode() != 0 || !result.getData()) {
93 90 log.error("[handleClientConnected][更新设备状态为在线失败] clientId={}, username={}, code={}, msg={}",
... ... @@ -104,12 +101,11 @@ public class IotDeviceWebhookVertxHandler implements Handler&lt;RoutingContext&gt; {
104 101 * @param username 用户名
105 102 */
106 103 private void handleClientDisconnected(String clientId, String username) {
  104 + // 解析产品标识和设备名称
107 105 if (StrUtil.isEmpty(username) || "undefined".equals(username)) {
108 106 log.warn("[handleClientDisconnected][客户端断开连接事件,但用户名为空] clientId={}", clientId);
109 107 return;
110 108 }
111   -
112   - // 解析产品标识和设备名称
113 109 String[] parts = parseUsername(username);
114 110 if (parts == null) {
115 111 return;
... ... @@ -122,7 +118,6 @@ public class IotDeviceWebhookVertxHandler implements Handler&lt;RoutingContext&gt; {
122 118 offlineReqDTO.setState(IotDeviceStateEnum.OFFLINE.getState());
123 119 offlineReqDTO.setProcessId(IotPluginCommonUtils.getProcessId());
124 120 offlineReqDTO.setReportTime(LocalDateTime.now());
125   -
126 121 CommonResult<Boolean> offlineResult = deviceUpstreamApi.updateDeviceState(offlineReqDTO);
127 122 if (offlineResult.getCode() != 0 || !offlineResult.getData()) {
128 123 log.error("[handleClientDisconnected][更新设备状态为离线失败] clientId={}, username={}, code={}, msg={}",
... ... @@ -136,19 +131,18 @@ public class IotDeviceWebhookVertxHandler implements Handler&lt;RoutingContext&gt; {
136 131 * 解析用户名,格式为 deviceName&productKey
137 132 *
138 133 * @param username 用户名
139   - * @return 解析结果,[0]为deviceName,[1]为productKey,解析失败返回null
  134 + * @return 解析结果,[0] 为 deviceName,[1] 为productKey,解析失败返回 null
140 135 */
141 136 private String[] parseUsername(String username) {
142 137 if (StrUtil.isEmpty(username)) {
143 138 return null;
144 139 }
145   -
146 140 String[] parts = username.split("&");
147 141 if (parts.length != 2) {
148   - log.warn("[parseUsername][用户名格式不正确,无法解析产品标识和设备名称] username={}", username);
  142 + log.warn("[parseUsername][用户名格式({})不正确,无法解析产品标识和设备名称]", username);
149 143 return null;
150 144 }
151   -
152 145 return parts;
153 146 }
  147 +
154 148 }
155 149 \ No newline at end of file
... ...
yudao-server/pom.xml
... ... @@ -46,11 +46,11 @@
46 46 <!-- <version>${revision}</version>-->
47 47 <!-- </dependency>-->
48 48 <!-- 工作流。默认注释,保证编译速度 -->
49   -<!-- <dependency>-->
50   -<!-- <groupId>cn.iocoder.boot</groupId>-->
51   -<!-- <artifactId>yudao-module-bpm-biz</artifactId>-->
52   -<!-- <version>${revision}</version>-->
53   -<!-- </dependency>-->
  49 + <dependency>
  50 + <groupId>cn.iocoder.boot</groupId>
  51 + <artifactId>yudao-module-bpm-biz</artifactId>
  52 + <version>${revision}</version>
  53 + </dependency>
54 54 <!-- 支付服务。默认注释,保证编译速度 -->
55 55 <!-- <dependency>-->
56 56 <!-- <groupId>cn.iocoder.boot</groupId>-->
... ...