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