Browse Source

feat: 【IoT 物联网】新增简单类型处理器配置和处理器,优化 JSON 解析问题(移除,已经解决)

YunaiV 8 months ago
parent
commit
3f83569edc

+ 0 - 33
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/config/SimpleTypeHandlerConfig.java

@@ -1,33 +0,0 @@
-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 解析错误");
-    }
-}

+ 0 - 39
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/handler/SimpleObjectTypeHandler.java

@@ -1,39 +0,0 @@
-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<Object> {
-
-    @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); // 直接返回字符串
-    }
-}

+ 2 - 9
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml

@@ -66,20 +66,13 @@
         DESCRIBE product_property_${productId}
     </select>
 
-    <resultMap id="IotDevicePropertyRespVOMap"
-               type="cn.iocoder.yudao.module.iot.controller.admin.device.vo.property.IotDevicePropertyRespVO">
-        <result property="value" column="value"
-                typeHandler="cn.iocoder.yudao.module.iot.framework.mybatis.handler.SimpleObjectTypeHandler"/>
-        <result property="updateTime" column="update_time" javaType="java.lang.Long"/>
-    </resultMap>
-
     <select id="selectListByHistory"
-            resultMap="IotDevicePropertyRespVOMap">
+            resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.property.IotDevicePropertyRespVO">
         SELECT ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} AS `value`, ts AS update_time
         FROM device_property_${reqVO.deviceId}
         WHERE ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} IS NOT NULL
           AND ts BETWEEN ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[0])}
-              AND ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[1])}
+            AND ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[1])}
         ORDER BY ts DESC
     </select>