Commit 3f83569edc5a9c5f4e4ef5f055ab253d8c41b488

Authored by YunaiV
1 parent 98f9e44b

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

yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/config/SimpleTypeHandlerConfig.java deleted
1 -package cn.iocoder.yudao.module.iot.framework.mybatis.config;  
2 -  
3 -import cn.iocoder.yudao.module.iot.framework.mybatis.handler.SimpleObjectTypeHandler;  
4 -import jakarta.annotation.PostConstruct;  
5 -import jakarta.annotation.Resource;  
6 -import lombok.extern.slf4j.Slf4j;  
7 -import org.apache.ibatis.session.SqlSessionFactory;  
8 -import org.apache.ibatis.type.TypeHandlerRegistry;  
9 -import org.springframework.context.annotation.Configuration;  
10 -  
11 -/**  
12 - * 简单类型处理器配置  
13 - * 注册自定义的类型处理器,避免 JSON 解析错误  
14 - *  
15 - * @author 芋道源码  
16 - */  
17 -@Slf4j  
18 -@Configuration  
19 -public class SimpleTypeHandlerConfig {  
20 -  
21 - @Resource  
22 - private SqlSessionFactory sqlSessionFactory;  
23 -  
24 - @PostConstruct  
25 - public void registerTypeHandlers() {  
26 - TypeHandlerRegistry registry = sqlSessionFactory.getConfiguration().getTypeHandlerRegistry();  
27 -  
28 - // 注册简单的 Object 类型处理器,避免 JSON 解析问题  
29 - registry.register(java.lang.Object.class, new SimpleObjectTypeHandler());  
30 -  
31 - log.info("简单类型处理器注册完成,避免 JSON 解析错误");  
32 - }  
33 -}  
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/mybatis/handler/SimpleObjectTypeHandler.java deleted
1 -package cn.iocoder.yudao.module.iot.framework.mybatis.handler;  
2 -  
3 -import org.apache.ibatis.type.BaseTypeHandler;  
4 -import org.apache.ibatis.type.JdbcType;  
5 -  
6 -import java.sql.CallableStatement;  
7 -import java.sql.PreparedStatement;  
8 -import java.sql.ResultSet;  
9 -import java.sql.SQLException;  
10 -  
11 -/**  
12 - * 简单的 Object 类型处理器  
13 - * 直接返回字符串,避免 JSON 解析问题  
14 - *  
15 - * @author 芋道源码  
16 - */  
17 -public class SimpleObjectTypeHandler extends BaseTypeHandler<Object> {  
18 -  
19 - @Override  
20 - public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType)  
21 - throws SQLException {  
22 - ps.setString(i, parameter.toString());  
23 - }  
24 -  
25 - @Override  
26 - public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {  
27 - return rs.getString(columnName); // 直接返回字符串  
28 - }  
29 -  
30 - @Override  
31 - public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException {  
32 - return rs.getString(columnIndex); // 直接返回字符串  
33 - }  
34 -  
35 - @Override  
36 - public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {  
37 - return cs.getString(columnIndex); // 直接返回字符串  
38 - }  
39 -}  
40 \ No newline at end of file 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/IotDevicePropertyMapper.xml
@@ -66,20 +66,13 @@ @@ -66,20 +66,13 @@
66 DESCRIBE product_property_${productId} 66 DESCRIBE product_property_${productId}
67 </select> 67 </select>
68 68
69 - <resultMap id="IotDevicePropertyRespVOMap"  
70 - type="cn.iocoder.yudao.module.iot.controller.admin.device.vo.property.IotDevicePropertyRespVO">  
71 - <result property="value" column="value"  
72 - typeHandler="cn.iocoder.yudao.module.iot.framework.mybatis.handler.SimpleObjectTypeHandler"/>  
73 - <result property="updateTime" column="update_time" javaType="java.lang.Long"/>  
74 - </resultMap>  
75 -  
76 <select id="selectListByHistory" 69 <select id="selectListByHistory"
77 - resultMap="IotDevicePropertyRespVOMap"> 70 + resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.property.IotDevicePropertyRespVO">
78 SELECT ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} AS `value`, ts AS update_time 71 SELECT ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} AS `value`, ts AS update_time
79 FROM device_property_${reqVO.deviceId} 72 FROM device_property_${reqVO.deviceId}
80 WHERE ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} IS NOT NULL 73 WHERE ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} IS NOT NULL
81 AND ts BETWEEN ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[0])} 74 AND ts BETWEEN ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[0])}
82 - AND ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[1])} 75 + AND ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[1])}
83 ORDER BY ts DESC 76 ORDER BY ts DESC
84 </select> 77 </select>
85 78