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

This commit is contained in:
YunaiV 2025-03-13 08:17:31 +08:00
parent e66c69932f
commit 569d651481
5 changed files with 18 additions and 19 deletions

View File

@ -83,6 +83,9 @@ public class IotDeviceRespVO {
@ExcelProperty("认证类型(如一机一密、动态注册)") @ExcelProperty("认证类型(如一机一密、动态注册)")
private String authType; private String authType;
@Schema(description = "设备配置", example = "{\"abc\": \"efg\"}")
private String config;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间") @ExcelProperty("创建时间")
private LocalDateTime createTime; private LocalDateTime createTime;

View File

@ -38,4 +38,7 @@ public class IotDeviceSaveReqVO {
@Schema(description = "网关设备 ID", example = "16380") @Schema(description = "网关设备 ID", example = "16380")
private Long gatewayId; private Long gatewayId;
@Schema(description = "设备配置", example = "{\"abc\": \"efg\"}")
private String config;
} }

View File

@ -32,7 +32,6 @@ public interface IotDevicePropertyMapper {
default void alterProductPropertySTable(String productKey, default void alterProductPropertySTable(String productKey,
List<TDengineTableField> oldFields, List<TDengineTableField> oldFields,
List<TDengineTableField> newFields) { List<TDengineTableField> newFields) {
// TODO @芋艿需要处理 device_key重新发布的时候
oldFields.removeIf(field -> StrUtil.equalsAny(field.getField(), oldFields.removeIf(field -> StrUtil.equalsAny(field.getField(),
TDengineTableField.FIELD_TS, "report_time", "device_key")); TDengineTableField.FIELD_TS, "report_time", "device_key"));
List<TDengineTableField> addFields = newFields.stream().filter( // 新增的字段 List<TDengineTableField> addFields = newFields.stream().filter( // 新增的字段

View File

@ -17,9 +17,8 @@ import java.util.Collections;
/** /**
* IoT Emqx Webhook 事件处理的 Vert.x Handler * IoT Emqx Webhook 事件处理的 Vert.x Handler
* <a href= *
* "https://docs.emqx.com/zh/emqx/latest/data-integration/webhook.html">EMQX * <a href="https://docs.emqx.com/zh/emqx/latest/data-integration/webhook.html">EMQXWebhook</a>
* Webhook</a>
* *
* @author haohao * @author haohao
*/ */
@ -69,12 +68,11 @@ public class IotDeviceWebhookVertxHandler implements Handler<RoutingContext> {
* @param username 用户名 * @param username 用户名
*/ */
private void handleClientConnected(String clientId, String username) { private void handleClientConnected(String clientId, String username) {
// 解析产品标识和设备名称
if (StrUtil.isEmpty(username) || "undefined".equals(username)) { if (StrUtil.isEmpty(username) || "undefined".equals(username)) {
log.warn("[handleClientConnected][客户端连接事件,但用户名为空] clientId={}", clientId); log.warn("[handleClientConnected][客户端连接事件,但用户名为空] clientId={}", clientId);
return; return;
} }
// 解析产品标识和设备名称
String[] parts = parseUsername(username); String[] parts = parseUsername(username);
if (parts == null) { if (parts == null) {
return; return;
@ -87,7 +85,6 @@ public class IotDeviceWebhookVertxHandler implements Handler<RoutingContext> {
updateReqDTO.setState(IotDeviceStateEnum.ONLINE.getState()); updateReqDTO.setState(IotDeviceStateEnum.ONLINE.getState());
updateReqDTO.setProcessId(IotPluginCommonUtils.getProcessId()); updateReqDTO.setProcessId(IotPluginCommonUtils.getProcessId());
updateReqDTO.setReportTime(LocalDateTime.now()); updateReqDTO.setReportTime(LocalDateTime.now());
CommonResult<Boolean> result = deviceUpstreamApi.updateDeviceState(updateReqDTO); CommonResult<Boolean> result = deviceUpstreamApi.updateDeviceState(updateReqDTO);
if (result.getCode() != 0 || !result.getData()) { if (result.getCode() != 0 || !result.getData()) {
log.error("[handleClientConnected][更新设备状态为在线失败] clientId={}, username={}, code={}, msg={}", log.error("[handleClientConnected][更新设备状态为在线失败] clientId={}, username={}, code={}, msg={}",
@ -104,12 +101,11 @@ public class IotDeviceWebhookVertxHandler implements Handler<RoutingContext> {
* @param username 用户名 * @param username 用户名
*/ */
private void handleClientDisconnected(String clientId, String username) { private void handleClientDisconnected(String clientId, String username) {
// 解析产品标识和设备名称
if (StrUtil.isEmpty(username) || "undefined".equals(username)) { if (StrUtil.isEmpty(username) || "undefined".equals(username)) {
log.warn("[handleClientDisconnected][客户端断开连接事件,但用户名为空] clientId={}", clientId); log.warn("[handleClientDisconnected][客户端断开连接事件,但用户名为空] clientId={}", clientId);
return; return;
} }
// 解析产品标识和设备名称
String[] parts = parseUsername(username); String[] parts = parseUsername(username);
if (parts == null) { if (parts == null) {
return; return;
@ -122,7 +118,6 @@ public class IotDeviceWebhookVertxHandler implements Handler<RoutingContext> {
offlineReqDTO.setState(IotDeviceStateEnum.OFFLINE.getState()); offlineReqDTO.setState(IotDeviceStateEnum.OFFLINE.getState());
offlineReqDTO.setProcessId(IotPluginCommonUtils.getProcessId()); offlineReqDTO.setProcessId(IotPluginCommonUtils.getProcessId());
offlineReqDTO.setReportTime(LocalDateTime.now()); offlineReqDTO.setReportTime(LocalDateTime.now());
CommonResult<Boolean> offlineResult = deviceUpstreamApi.updateDeviceState(offlineReqDTO); CommonResult<Boolean> offlineResult = deviceUpstreamApi.updateDeviceState(offlineReqDTO);
if (offlineResult.getCode() != 0 || !offlineResult.getData()) { if (offlineResult.getCode() != 0 || !offlineResult.getData()) {
log.error("[handleClientDisconnected][更新设备状态为离线失败] clientId={}, username={}, code={}, msg={}", log.error("[handleClientDisconnected][更新设备状态为离线失败] clientId={}, username={}, code={}, msg={}",
@ -136,19 +131,18 @@ public class IotDeviceWebhookVertxHandler implements Handler<RoutingContext> {
* 解析用户名格式为 deviceName&productKey * 解析用户名格式为 deviceName&productKey
* *
* @param username 用户名 * @param username 用户名
* @return 解析结果[0]deviceName[1]为productKey解析失败返回null * @return 解析结果[0] deviceName[1] 为productKey解析失败返回 null
*/ */
private String[] parseUsername(String username) { private String[] parseUsername(String username) {
if (StrUtil.isEmpty(username)) { if (StrUtil.isEmpty(username)) {
return null; return null;
} }
String[] parts = username.split("&"); String[] parts = username.split("&");
if (parts.length != 2) { if (parts.length != 2) {
log.warn("[parseUsername][用户名格式不正确,无法解析产品标识和设备名称] username={}", username); log.warn("[parseUsername][用户名格式({})不正确,无法解析产品标识和设备名称]", username);
return null; return null;
} }
return parts; return parts;
} }
} }

View File

@ -46,11 +46,11 @@
<!-- <version>${revision}</version>--> <!-- <version>${revision}</version>-->
<!-- </dependency>--> <!-- </dependency>-->
<!-- 工作流。默认注释,保证编译速度 --> <!-- 工作流。默认注释,保证编译速度 -->
<!-- <dependency>--> <dependency>
<!-- <groupId>cn.iocoder.boot</groupId>--> <groupId>cn.iocoder.boot</groupId>
<!-- <artifactId>yudao-module-bpm-biz</artifactId>--> <artifactId>yudao-module-bpm-biz</artifactId>
<!-- <version>${revision}</version>--> <version>${revision}</version>
<!-- </dependency>--> </dependency>
<!-- 支付服务。默认注释,保证编译速度 --> <!-- 支付服务。默认注释,保证编译速度 -->
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>cn.iocoder.boot</groupId>--> <!-- <groupId>cn.iocoder.boot</groupId>-->