From 341e72c0b180611abaa1aec496ca90d4186b27cc Mon Sep 17 00:00:00 2001 From: haohao <1036606149@qq.com> Date: Mon, 22 Sep 2025 23:10:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=80=90IoT=20=E7=89=A9=E8=81=94?= =?UTF-8?q?=E7=BD=91=E3=80=91=E6=96=B0=E5=A2=9E=E7=AE=80=E5=8D=95=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=A4=84=E7=90=86=E5=99=A8=E9=85=8D=E7=BD=AE=E5=92=8C?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=99=A8=EF=BC=8C=E4=BC=98=E5=8C=96=20JSON?= =?UTF-8?q?=20=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/SimpleTypeHandlerConfig.java | 33 ++++++++++++++++ .../handler/SimpleObjectTypeHandler.java | 39 +++++++++++++++++++ .../mapper/device/IotDevicePropertyMapper.xml | 9 ++++- .../mqtt/router/IotMqttUpstreamHandler.java | 20 ++++++---- .../src/main/resources/application.yaml | 1 - 5 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/config/SimpleTypeHandlerConfig.java create mode 100644 yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/handler/SimpleObjectTypeHandler.java diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/config/SimpleTypeHandlerConfig.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/config/SimpleTypeHandlerConfig.java new file mode 100644 index 0000000000..7360e488ff --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/config/SimpleTypeHandlerConfig.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.iot.framework.mybatis.config; + +import cn.iocoder.yudao.module.iot.framework.mybatis.handler.SimpleObjectTypeHandler; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.type.TypeHandlerRegistry; +import org.springframework.context.annotation.Configuration; + +/** + * 简单类型处理器配置 + * 注册自定义的类型处理器,避免 JSON 解析错误 + * + * @author 芋道源码 + */ +@Slf4j +@Configuration +public class SimpleTypeHandlerConfig { + + @Resource + private SqlSessionFactory sqlSessionFactory; + + @PostConstruct + public void registerTypeHandlers() { + TypeHandlerRegistry registry = sqlSessionFactory.getConfiguration().getTypeHandlerRegistry(); + + // 注册简单的 Object 类型处理器,避免 JSON 解析问题 + registry.register(java.lang.Object.class, new SimpleObjectTypeHandler()); + + log.info("简单类型处理器注册完成,避免 JSON 解析错误"); + } +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/handler/SimpleObjectTypeHandler.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/handler/SimpleObjectTypeHandler.java new file mode 100644 index 0000000000..c61bf94258 --- /dev/null +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/handler/SimpleObjectTypeHandler.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.iot.framework.mybatis.handler; + +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * 简单的 Object 类型处理器 + * 直接返回字符串,避免 JSON 解析问题 + * + * @author 芋道源码 + */ +public class SimpleObjectTypeHandler extends BaseTypeHandler { + + @Override + public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) + throws SQLException { + ps.setString(i, parameter.toString()); + } + + @Override + public Object getNullableResult(ResultSet rs, String columnName) throws SQLException { + return rs.getString(columnName); // 直接返回字符串 + } + + @Override + public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + return rs.getString(columnIndex); // 直接返回字符串 + } + + @Override + public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + return cs.getString(columnIndex); // 直接返回字符串 + } +} \ No newline at end of file diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml b/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml index fc2d3662fe..85149d67a1 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml @@ -66,8 +66,15 @@ DESCRIBE product_property_${productId} + + + + +