Commit b319485ca60539fd2f343920c3f97d09cd13d8ee

Authored by YunaiV
1 parent 8089f3a3

【功能优化】IoT:清理通用 TDengine 封装,使用 SQL 查询

Showing 15 changed files with 5 additions and 951 deletions
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/FieldParser.java deleted
1   -package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine;
2   -
3   -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelProperty;
4   -import cn.iocoder.yudao.module.iot.controller.admin.thingmodel.model.ThingModelRespVO;
5   -
6   -import java.util.HashMap;
7   -import java.util.List;
8   -
9   -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
10   -
11   -/**
12   - * FieldParser 类用于解析和转换物模型字段到 TDengine 字段
13   - */
14   -public class FieldParser {
15   -
16   - /**
17   - * 物模型到td数据类型映射
18   - */
19   - @Deprecated
20   - private static final HashMap<String, String> TYPE_MAPPING = new HashMap<>() {
21   - {
22   - put("INT", "INT");
23   - put("FLOAT", "FLOAT");
24   - put("DOUBLE", "DOUBLE");
25   - put("BOOL", "BOOL");
26   - put("ENUM", "NCHAR");
27   - put("TEXT", "NCHAR");
28   - put("DATE", "NCHAR");
29   - }
30   - };
31   -
32   - /**
33   - * 将物模型字段转换为td字段
34   - *
35   - * @param property 物模型属性
36   - * @return TdField对象
37   - */
38   - public static TdFieldDO parse(ThingModelProperty property) {
39   - // 将物模型字段类型映射为 td 字段类型
40   - String fieldName = property.getIdentifier().toLowerCase();
41   - String fType = TYPE_MAPPING.get(property.getDataType().toUpperCase());
42   - // 如果字段类型为NCHAR,默认长度为64
43   - int dataLength = 0;
44   - if ("NCHAR".equals(fType)) {
45   - dataLength = 64;
46   - }
47   - return new TdFieldDO(fieldName, fType, dataLength);
48   - }
49   -
50   - /**
51   - * 从物模型中获取字段列表
52   - *
53   - * @param thingModel 物模型响应对象
54   - * @return 字段列表
55   - */
56   - public static List<TdFieldDO> parse(ThingModelRespVO thingModel) {
57   - return convertList(thingModel.getModel().getProperties(), FieldParser::parse);
58   - }
59   -
60   - /**
61   - * 将从库中查出来的字段信息转换为 TDengine 字段对象
62   - *
63   - * @param rows 从库中查出的字段信息列表
64   - * @return 转换后的 TDengine 字段对象列表
65   - */
66   - public static List<TdFieldDO> parse(List<List<Object>> rows) {
67   - return convertList(rows, row -> {
68   - String type = row.get(1).toString().toUpperCase();
69   - // TODO @puhui999:"NCHAR" 最好枚举下
70   - int dataLength = "NCHAR".equals(type) ? Integer.parseInt(row.get(2).toString()) : -1;
71   - return new TdFieldDO(row.get(0).toString(), type, dataLength);
72   - });
73   - }
74   -
75   - /**
76   - * 获取字段字义
77   - */
78   - @Deprecated
79   - public static String getFieldDefine(TdFieldDO field) {
80   - return "`" + field.getFieldName() + "`" + " "
81   - + (field.getDataLength() > 0 ? String.format("%s(%d)", field.getDataType(), field.getDataLength())
82   - : field.getDataType());
83   - }
84   -
85   -}
86 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/SelectDO.java deleted
1   -package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine;
2   -
3   -import lombok.Data;
4   -
5   -// TODO @haohao:类似这个,其实可以参考 mybatis plus,querywrapper,搞个 TdEngineQueryWrapper。这样看起来会更好懂。
6   -/**
7   - * 查询DO
8   - */
9   -@Data
10   -@Deprecated
11   -public class SelectDO {
12   -
13   - // TODO @haoha:database 是个单词
14   - /**
15   - * 数据库名称
16   - */
17   - private String dataBaseName;
18   -
19   - /**
20   - * 超级表名称
21   - */
22   - private String tableName;
23   -
24   - /**
25   - * 查询字段
26   - */
27   - private String fieldName;
28   -
29   - /**
30   - * 开始时间
31   - */
32   - private Long startTime;
33   -
34   - /**
35   - * 结束时间
36   - */
37   - private Long endTime;
38   -
39   - /**
40   - * 查询类型
41   - */
42   - private String type;
43   -
44   - /**
45   - * 设备ID
46   - */
47   - private String deviceId;
48   -}
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/TagsSelectDO.java deleted
1   -package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine;
2   -
3   -import lombok.Data;
4   -
5   -/**
6   - * tags查询DO
7   - */
8   -@Data
9   -@Deprecated
10   -public class TagsSelectDO {
11   -
12   - /**
13   - * 数据库名称
14   - */
15   - private String dataBaseName;
16   -
17   - /**
18   - * 超级表名称
19   - */
20   - private String stableName;
21   -
22   - /**
23   - * tags名称
24   - */
25   - private String tagsName;
26   -
27   - /**
28   - * tags值
29   - */
30   - private Long startTime;
31   -
32   - /**
33   - * tags值
34   - */
35   - private Long endTime;
36   -
37   -}
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/TdFieldDO.java deleted
1   -package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine;
2   -
3   -import lombok.AllArgsConstructor;
4   -import lombok.Builder;
5   -import lombok.Data;
6   -import lombok.NoArgsConstructor;
7   -
8   -// TODO 芋艿:看看是不是后续简化掉。
9   -/**
10   - * TD 引擎的字段
11   - */
12   -@Data
13   -@NoArgsConstructor
14   -@AllArgsConstructor
15   -@Builder
16   -@Deprecated
17   -public class TdFieldDO {
18   -
19   - /**
20   - * 字段名称
21   - */
22   - private String fieldName;
23   -
24   - /**
25   - * 字段类型
26   - */
27   - private String dataType;
28   -
29   - /**
30   - * 字段长度
31   - */
32   - private Integer dataLength = 0;
33   -
34   - /**
35   - * 字段值
36   - */
37   - private Object fieldValue;
38   -
39   - public TdFieldDO(String fieldName, String dataType, Integer dataLength) {
40   - this.fieldName = fieldName;
41   - this.dataType = dataType;
42   - this.dataLength = dataLength;
43   - }
44   -
45   - public TdFieldDO(String fieldName, Object fieldValue) {
46   - this.fieldName = fieldName;
47   - this.fieldValue = fieldValue;
48   - }
49   -}
50 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/TdResponse.java deleted
1   -package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine;
2   -
3   -import lombok.AllArgsConstructor;
4   -import lombok.Data;
5   -import lombok.NoArgsConstructor;
6   -
7   -import java.util.List;
8   -
9   -/**
10   - * TdResponse 类用于处理 TDengine 的响应
11   - */
12   -@Data
13   -@NoArgsConstructor
14   -@AllArgsConstructor
15   -@Deprecated
16   -public class TdResponse {
17   -
18   - public static final int CODE_SUCCESS = 0;
19   - public static final int CODE_TB_NOT_EXIST = 866;
20   -
21   - /**
22   - * 状态
23   - */
24   - private String status;
25   -
26   - /**
27   - * 错误码
28   - */
29   - private int code;
30   -
31   - /**
32   - * 错误信息
33   - */
34   - private String desc;
35   -
36   - /**
37   - * 列信息
38   - * [["time","TIMESTAMP",8,""],["powerstate","TINYINT",1,""],["brightness","INT",4,""],["deviceid","NCHAR",32,"TAG"]]
39   - */
40   - private List data;
41   -
42   -}
43 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/TdRestApi.java deleted
1   -package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine;
2   -
3   -import cn.hutool.http.HttpRequest;
4   -import cn.hutool.http.HttpResponse;
5   -import cn.hutool.json.JSONUtil;
6   -import lombok.extern.slf4j.Slf4j;
7   -import org.springframework.beans.factory.annotation.Value;
8   -import org.springframework.stereotype.Service;
9   -
10   -// TODO @haohao:有部分非实体的部分,是不是可以搞到 iot 的 framework 包下,搞个 tdengine 包,作为框架级的封装,放在 dataobject,感觉不是很合理哈。【可以微信讨论下】
11   -/**
12   - * TdRestApi 类用于处理 TDengine 的 REST API 请求
13   - */
14   -@Slf4j
15   -@Service
16   -@Deprecated // TODO 芋艿:貌似没用到
17   -public class TdRestApi {
18   -
19   - @Value("${spring.datasource.dynamic.datasource.tdengine.url}")
20   - private String url;
21   -
22   - @Value("${spring.datasource.dynamic.datasource.tdengine.username}")
23   - private String username;
24   -
25   - @Value("${spring.datasource.dynamic.datasource.tdengine.password}")
26   - private String password;
27   -
28   - /**
29   - * 获取 REST API URL
30   - */
31   - private String getRestApiUrl() {
32   - String restUrl = url.replace("jdbc:TAOS-RS://", "")
33   - .replaceAll("\\?.*", "");
34   - int idx = restUrl.lastIndexOf("/");
35   - return String.format("%s/rest/sql/%s", restUrl.substring(0, idx), restUrl.substring(idx + 1));
36   - }
37   -
38   -
39   - /**
40   - * 新建td api请求对象
41   - */
42   - public HttpRequest newApiRequest(String sql) {
43   - return HttpRequest
44   - .post(getRestApiUrl())
45   - .body(sql)
46   - .basicAuth(username, password);
47   - }
48   -
49   - /**
50   - * 执行sql
51   - */
52   - public TdResponse execSql(String sql) {
53   - log.info("exec td sql:{}", sql);
54   - HttpRequest request = newApiRequest(sql);
55   - HttpResponse response = request.execute();
56   - return JSONUtil.toBean(response.body(), TdResponse.class);
57   - }
58   -
59   -}
60 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/TdTableDO.java deleted
1   -package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine;
2   -
3   -import lombok.AllArgsConstructor;
4   -import lombok.Builder;
5   -import lombok.Data;
6   -import lombok.NoArgsConstructor;
7   -
8   -import java.util.List;
9   -
10   -@Deprecated
11   -/**
12   - * TD 引擎的数据库
13   - */
14   -@Data
15   -@Builder
16   -@NoArgsConstructor
17   -@AllArgsConstructor
18   -public class TdTableDO {
19   -
20   - /**
21   - * 数据库名称
22   - */
23   - private String dataBaseName;
24   -
25   - // TODO @haohao:superTableName 和 tableName 是不是合并。因为每个 mapper 操作的时候,有且只会使用到其中一个。
26   - /**
27   - * 超级表名称
28   - */
29   - private String superTableName;
30   -
31   - /**
32   - * 表名称
33   - */
34   - private String tableName;
35   -
36   - private String productKey;
37   -
38   - private String deviceKey;
39   -
40   - /**
41   - * COLUMN 字段
42   - */
43   - private TdFieldDO column;
44   -
45   - /**
46   - * TAG 字段
47   - */
48   - private TdFieldDO tag;
49   -
50   - /**
51   - * COLUMN 字段 - 列表
52   - */
53   - private List<TdFieldDO> columns;
54   -
55   - /**
56   - * TAG 字段 - 列表
57   - */
58   - private List<TdFieldDO> tags;
59   -
60   - public TdTableDO(String dataBaseName, String superTableName, List<TdFieldDO> columns, List<TdFieldDO> tags) {
61   - this.dataBaseName = dataBaseName;
62   - this.superTableName = superTableName;
63   - this.columns = columns;
64   - this.tags = tags;
65   - }
66   -
67   - public TdTableDO(String dataBaseName, String superTableName) {
68   - this.dataBaseName = dataBaseName;
69   - this.superTableName = superTableName;
70   - }
71   -}
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/dataobject/tdengine/ThingModelMessageDO.java deleted
1   -package cn.iocoder.yudao.module.iot.dal.dataobject.tdengine;
2   -
3   -import lombok.AllArgsConstructor;
4   -import lombok.Builder;
5   -import lombok.Data;
6   -import lombok.NoArgsConstructor;
7   -
8   -// TODO @芋艿:纠结下字段
9   -@Deprecated // TODO @super:看看啥时候删除下哈。
10   -/**
11   - * TD 物模型消息日志的数据库
12   - */
13   -@Data
14   -@Builder
15   -@NoArgsConstructor
16   -@AllArgsConstructor
17   -public class ThingModelMessageDO {
18   -
19   -
20   -
21   - /**
22   - * 消息 ID
23   - */
24   - private String id;
25   -
26   - /**
27   - * 系统扩展参数
28   - *
29   - * 例如:设备状态、系统时间、固件版本等系统级信息
30   - */
31   - private Object system;
32   -
33   - /**
34   - * 请求方法
35   - *
36   - * 例如:thing.event.property.post
37   - */
38   - private String method;
39   -
40   - /**
41   - * 请求参数
42   - */
43   - private Object params;
44   -
45   - /**
46   - * 属性上报时间戳
47   - */
48   - private Long time;
49   -
50   - /**
51   - * 设备信息
52   - */
53   - private String productKey;
54   -
55   -
56   - /**
57   - * 设备 key
58   - */
59   - private String deviceKey;
60   -
61   -}
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/IotDevicePropertyDataMapper.java
... ... @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.util.ObjectUtil;
5 5 import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
6 6 import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO;
7   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO;
8 7 import cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField;
9 8 import cn.iocoder.yudao.module.iot.framework.tdengine.core.annotation.TDengineDS;
10 9 import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
... ... @@ -78,27 +77,6 @@ public interface IotDevicePropertyDataMapper {
78 77 void alterProductPropertySTableDropField(@Param("productKey") String productKey,
79 78 @Param("field") TDengineTableField field);
80 79  
81   - //TODO:先参考一下老逻辑,后续改进
82   - /**
83   - * 插入数据 - 指定列插入数据
84   - *
85   - * @param table 数据
86   - * productKey 产品 key
87   - * deviceKey 设备 key
88   - * columns 列
89   - */
90   - void insertDevicePropertyData(TdTableDO table);
91   -
92   - //TODO:先参考一下老逻辑,后续改进
93   - /**
94   - * 查看超级表 - 获取超级表的结构信息
95   - * SQL:DESCRIBE [db_name.]stb_name;
96   - *
97   - * @param superTable 超级表信息
98   - * productKey 产品 key
99   - */
100   - List<Map<String, Object>> describeSuperTable(TdTableDO superTable);
101   -
102 80 /**
103 81 * 获取历史数据列表
104 82 *
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdEngineDDLMapper.java deleted
1   -package cn.iocoder.yudao.module.iot.dal.tdengine;
2   -
3   -import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
4   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO;
5   -import com.baomidou.dynamic.datasource.annotation.DS;
6   -import org.apache.ibatis.annotations.Mapper;
7   -import org.apache.ibatis.annotations.Param;
8   -
9   -import java.util.List;
10   -import java.util.Map;
11   -
12   -/**
13   - * 专门处理 DDL(数据定义语言)操作,包含所有的数据库和表的定义操作,例如创建数据库、创建超级表、创建子表等
14   - */
15   -@Mapper
16   -@DS("tdengine")
17   -public interface TdEngineDDLMapper {
18   -
19   - /**
20   - * 创建数据库
21   - * SQL:CREATE DATABASE [IF NOT EXISTS] db_name [database_options];
22   - *
23   - * @param dataBaseName 数据库名称
24   - */
25   - @TenantIgnore
26   - void createDatabase(@Param("dataBaseName") String dataBaseName);
27   -
28   - /**
29   - * 创建超级表
30   - * SQL:CREATE STABLE [IF NOT EXISTS] stb_name (create_definition [, create_definition] ...) TAGS (create_definition [, create_definition] ...) [table_options];
31   - *
32   - * @param superTable 超级表信息
33   - * dataBaseName 数据库名称
34   - * superTableName 超级表名称
35   - * columns 列信息
36   - * tags 标签信息
37   - */
38   - @TenantIgnore
39   - void createSuperTable(TdTableDO superTable);
40   -
41   - /**
42   - * 查看超级表 - 显示当前数据库下的所有超级表信息
43   - * SQL:SHOW STABLES [LIKE tb_name_wildcard];
44   - *
45   - * @param superTable 超级表信息
46   - * dataBaseName 数据库名称
47   - * superTableName 超级表名称
48   - */
49   - @TenantIgnore
50   - List<Map<String, Object>> showSuperTables(TdTableDO superTable);
51   -
52   - /**
53   - * 查看超级表 - 获取超级表的结构信息
54   - * SQL:DESCRIBE [db_name.]stb_name;
55   - *
56   - * @param superTable 超级表信息
57   - * dataBaseName 数据库名称
58   - * superTableName 超级表名称
59   - */
60   - @TenantIgnore
61   - List<Map<String, Object>> describeSuperTable(TdTableDO superTable);
62   -
63   - /**
64   - * 修改超级表 - 增加列
65   - * SQL:ALTER STABLE stb_name ADD COLUMN col_name column_type;
66   - *
67   - * @param superTable 超级表信息
68   - * dataBaseName 数据库名称
69   - * superTableName 超级表名称
70   - * column 列信息
71   - */
72   - @TenantIgnore
73   - void addColumnForSuperTable(TdTableDO superTable);
74   -
75   - /**
76   - * 修改超级表 - 删除列
77   - * SQL:ALTER STABLE stb_name DROP COLUMN col_name;
78   - *
79   - * @param superTable 超级表信息
80   - * dataBaseName 数据库名称
81   - * superTableName 超级表名称
82   - * column 列信息
83   - */
84   - @TenantIgnore
85   - void dropColumnForSuperTable(TdTableDO superTable);
86   -
87   - /**
88   - * 修改超级表 - 修改列宽
89   - * SQL:ALTER STABLE stb_name MODIFY COLUMN col_name data_type(length);
90   - *
91   - * @param superTable 超级表信息
92   - * dataBaseName 数据库名称
93   - * superTableName 超级表名称
94   - * column 列信息
95   - */
96   - @TenantIgnore
97   - void modifyColumnWidthForSuperTable(TdTableDO superTable);
98   -
99   - /**
100   - * 修改超级表 - 为超级表添加标签
101   - *
102   - * @param superTable 超级表信息
103   - * dataBaseName 数据库名称
104   - * superTableName 超级表名称
105   - * tag 标签信息
106   - */
107   - @TenantIgnore
108   - void addTagForSuperTable(TdTableDO superTable);
109   -
110   - /**
111   - * 修改超级表 - 为超级表删除标签
112   - *
113   - * @param superTable 超级表信息
114   - * dataBaseName 数据库名称
115   - * superTableName 超级表名称
116   - * tag 标签信息
117   - */
118   - @TenantIgnore
119   - void dropTagForSuperTable(TdTableDO superTable);
120   -
121   - /**
122   - * 创建子表 - 创建子表
123   - * SQL:CREATE TABLE [IF NOT EXISTS] tb_name USING stb_name TAGS (tag_value1, ...);
124   - *
125   - * @param table 表信息
126   - * dataBaseName 数据库名称
127   - * superTableName 超级表名称
128   - * tableName 子表名称
129   - * tags TAG 字段
130   - */
131   - @TenantIgnore
132   - void createTable(TdTableDO table);
133   -
134   - /**
135   - * 创建子表 - 创建子表并指定标签的值
136   - * SQL:CREATE TABLE [IF NOT EXISTS] tb_name USING stb_name (tag_name1, ...) TAGS (tag_value1, ...);
137   - *
138   - * @param table 表信息
139   - * dataBaseName 数据库名称
140   - * superTableName 超级表名称
141   - * tableName 子表名称
142   - * tags TAG 字段
143   - */
144   - @TenantIgnore
145   - void createTableWithTags(TdTableDO table);
146   -
147   -}
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/tdengine/TdEngineDMLMapper.java deleted
1   -package cn.iocoder.yudao.module.iot.dal.tdengine;
2   -
3   -import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
4   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectDO;
5   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO;
6   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TagsSelectDO;
7   -import cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TdTableDO;
8   -import com.baomidou.dynamic.datasource.annotation.DS;
9   -import org.apache.ibatis.annotations.Mapper;
10   -
11   -import java.util.List;
12   -import java.util.Map;
13   -
14   -/**
15   - * 专门处理 TD Engine 的 DML(数据操作语言)操作,处理所有的数据查询和写入操作,如插入数据、查询数据等
16   - */
17   -@Mapper
18   -@DS("tdengine")
19   -public interface TdEngineDMLMapper {
20   -
21   - /**
22   - * 插入数据 - 指定列插入数据
23   - *
24   - * @param table 数据
25   - * dataBaseName 数据库名
26   - * tableName 表名
27   - * columns 列
28   - */
29   - @TenantIgnore
30   - void insertData(TdTableDO table);
31   -
32   - /**
33   - * 根据时间戳查询数据
34   - *
35   - * @param selectDO 查询条件
36   - * @return 查询结果列表
37   - */
38   - @TenantIgnore
39   - List<Map<String, Object>> selectByTimestamp(SelectDO selectDO);
40   -
41   - /**
42   - * 根据时间戳获取数据条数
43   - *
44   - * @param selectDO 查询条件
45   - * @return 数据条数
46   - */
47   - @TenantIgnore
48   - Map<String, Long> selectCountByTimestamp(SelectDO selectDO);
49   -
50   - /**
51   - * 获取最新数据
52   - *
53   - * @param selectDO 查询条件
54   - * @return 最新数据
55   - */
56   - @TenantIgnore
57   - Map<String, Object> selectOneLastData(SelectDO selectDO);
58   -
59   - /**
60   - * 获取历史数据列表
61   - *
62   - * @param selectVisualDO 查询条件
63   - * @return 历史数据列表
64   - */
65   - @TenantIgnore
66   - List<Map<String, Object>> selectHistoryDataList(SelectVisualDO selectVisualDO);
67   -
68   - /**
69   - * 获取实时数据列表
70   - *
71   - * @param selectVisualDO 查询条件
72   - * @return 实时数据列表
73   - */
74   - @TenantIgnore
75   - List<Map<String, Object>> selectRealtimeDataList(SelectVisualDO selectVisualDO);
76   -
77   - /**
78   - * 获取聚合数据列表
79   - *
80   - * @param selectVisualDO 查询条件
81   - * @return 聚合数据列表
82   - */
83   - @TenantIgnore
84   - List<Map<String, Object>> selectAggregateDataList(SelectVisualDO selectVisualDO);
85   -
86   - /**
87   - * 根据标签获取最新数据列表
88   - *
89   - * @param tagsSelectDO 查询条件
90   - * @return 最新数据列表
91   - */
92   - @TenantIgnore
93   - List<Map<String, Object>> selectLastDataListByTags(TagsSelectDO tagsSelectDO);
94   -
95   - /**
96   - * 获取历史数据条数
97   - *
98   - * @param selectVisualDO 查询条件
99   - * @return 数据条数
100   - */
101   - @TenantIgnore
102   - Long selectHistoryCount(SelectVisualDO selectVisualDO);
103   -}
104 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitConfiguration.java renamed to yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/tdengine/config/TDengineTableInitRunner.java
... ... @@ -5,17 +5,17 @@ import lombok.RequiredArgsConstructor;
5 5 import lombok.extern.slf4j.Slf4j;
6 6 import org.springframework.boot.ApplicationArguments;
7 7 import org.springframework.boot.ApplicationRunner;
8   -import org.springframework.context.annotation.Configuration;
  8 +import org.springframework.stereotype.Component;
9 9  
10 10 /**
11 11 * TDengine 表初始化的 Configuration
12 12 *
13 13 * @author alwayssuper
14 14 */
15   -@Configuration
16   -@Slf4j
  15 +@Component
17 16 @RequiredArgsConstructor
18   -public class TDengineTableInitConfiguration implements ApplicationRunner {
  17 +@Slf4j
  18 +public class TDengineTableInitRunner implements ApplicationRunner {
19 19  
20 20 private final IotDeviceLogService deviceLogService;
21 21  
... ... @@ -26,7 +26,7 @@ public class TDengineTableInitConfiguration implements ApplicationRunner {
26 26 deviceLogService.defineDeviceLog();
27 27 } catch (Exception ex) {
28 28 // 初始化失败时打印错误日志并退出系统
29   - log.error("[TDengine] 初始化设备日志表结构失败,系统无法正常运行,即将退出", ex);
  29 + log.error("[run][TDengine初始化设备日志表结构失败,系统无法正常运行,即将退出]", ex);
30 30 System.exit(1);
31 31 }
32 32 }
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/tdengine/TdEngineDDLMapper.xml deleted
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!DOCTYPE mapper
3   - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
4   - "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5   -<mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper">
6   -
7   - <!-- 创建数据库 -->
8   - <update id="createDatabase" parameterType="String">
9   - CREATE DATABASE IF NOT EXISTS ${dataBaseName}
10   - </update>
11   -
12   - <!-- 创建超级表 -->
13   - <update id="createSuperTable">
14   - CREATE STABLE IF NOT EXISTS ${dataBaseName}.${superTableName}
15   - <foreach item="item" collection="columns" separator=","
16   - open="(" close=")">
17   - ${item.fieldName} ${item.dataType}
18   - <if test="item.dataLength > 0">
19   - (${item.dataLength})
20   - </if>
21   - </foreach>
22   - TAGS
23   - <foreach item="item" collection="tags" separator=","
24   - open="(" close=")">
25   - ${item.fieldName} ${item.dataType}
26   - <if test="item.dataLength > 0">
27   - (${item.dataLength})
28   - </if>
29   - </foreach>
30   - </update>
31   -
32   - <!-- 查看超级表 -->
33   - <select id="showSuperTables" resultType="java.util.Map">
34   - SHOW ${dataBaseName}.STABLES LIKE '${superTableName}'
35   - </select>
36   -
37   - <!-- 描述超级表结构 -->
38   - <select id="describeSuperTable" resultType="java.util.Map">
39   - DESCRIBE ${dataBaseName}.${superTableName}
40   - </select>
41   -
42   - <!-- 为超级表添加列 -->
43   - <update id="addColumnForSuperTable">
44   - ALTER STABLE ${dataBaseName}.${superTableName} ADD COLUMN ${column.fieldName} ${column.dataType}
45   - <if test="column.dataLength > 0">
46   - (${column.dataLength})
47   - </if>
48   - </update>
49   -
50   - <!-- 为超级表删除列 -->
51   - <update id="dropColumnForSuperTable">
52   - ALTER STABLE ${dataBaseName}.${superTableName} DROP COLUMN ${column.fieldName}
53   - </update>
54   -
55   - <!-- 修改列宽 -->
56   - <update id="modifyColumnWidthForSuperTable">
57   - ALTER STABLE ${dataBaseName}.${superTableName} MODIFY COLUMN ${column.fieldName} ${column.dataType}
58   - <if test="column.dataLength > 0">
59   - (${column.dataLength})
60   - </if>
61   - </update>
62   -
63   - <!-- 为超级表添加标签 -->
64   - <update id="addTagForSuperTable">
65   - ALTER STABLE ${dataBaseName}.${superTableName} ADD TAG ${tag.fieldName} ${tag.dataType}
66   - <if test="tag.dataLength > 0">
67   - (${tag.dataLength})
68   - </if>
69   - </update>
70   -
71   - <!-- 为超级表删除标签 -->
72   - <update id="dropTagForSuperTable">
73   - ALTER STABLE ${dataBaseName}.${superTableName} DROP TAG ${tag.fieldName}
74   - </update>
75   -
76   - <!-- 创建子表 -->
77   - <update id="createTable">
78   - CREATE TABLE IF NOT EXISTS ${dataBaseName}.${tableName}
79   - USING ${dataBaseName}.${superTableName}
80   - TAGS
81   - <foreach item="item" collection="tags" separator=","
82   - open="(" close=")">
83   - #{item.fieldValue}
84   - </foreach>
85   - </update>
86   -
87   - <!-- 创建子表,带有 TAGS -->
88   - <update id="createTableWithTags">
89   - CREATE TABLE IF NOT EXISTS ${dataBaseName}.${tableName}
90   - USING ${dataBaseName}.${superTableName}
91   - <foreach item="item" collection="tags" separator="," open="(" close=")">
92   - #{item.fieldName}
93   - </foreach>
94   - TAGS
95   - <foreach item="item" collection="tags" separator=","
96   - open="(" close=")">
97   - #{item.fieldValue}
98   - </foreach>
99   - </update>
100   -
101   -</mapper>
102 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/tdengine/TdEngineDMLMapper.xml deleted
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!DOCTYPE mapper
3   - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
4   - "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5   -<mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper">
6   -
7   - <!-- 插入数据 -->
8   - <insert id="insertData">
9   - INSERT INTO ${dataBaseName}.${tableName}
10   - <foreach item="item" collection="columns" separator=","
11   - open="(" close=")">
12   - ${item.fieldName}
13   - </foreach>
14   - VALUES
15   - <foreach item="item" collection="columns" separator=","
16   - open="(" close=")">
17   - #{item.fieldValue}
18   - </foreach>
19   - </insert>
20   -
21   - <!-- 根据时间戳查询数据 -->
22   - <select id="selectByTimestamp" parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectDO"
23   - resultType="Map">
24   - SELECT * FROM ${dataBaseName}.${tableName}
25   - WHERE ${fieldName} BETWEEN #{startTime} AND #{endTime}
26   - </select>
27   -
28   - <!-- 获取时间范围内的数据条数 -->
29   - <select id="selectCountByTimestamp" parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectDO"
30   - resultType="java.util.Map">
31   - SELECT COUNT(0) AS count
32   - FROM ${dataBaseName}.${tableName}
33   - WHERE ${fieldName} BETWEEN #{startTime} AND #{endTime}
34   - </select>
35   -
36   - <!-- 获取最新数据 -->
37   - <select id="selectOneLastData" resultType="java.util.Map">
38   - SELECT LAST(time), *
39   - FROM ${tableName}
40   - WHERE device_id = #{deviceId}
41   - </select>
42   -
43   - <!-- 根据标签获取最新数据 -->
44   - <select id="selectLastDataListByTags" parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TagsSelectDO"
45   - resultType="java.util.Map">
46   - SELECT LAST(*)
47   - FROM ${dataBaseName}.${stableName}
48   - GROUP BY ${tagsName}
49   - </select>
50   -
51   - <!-- 获取历史数据 -->
52   - <select id="selectHistoryDataList" resultType="java.util.Map"
53   - parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO">
54   - SELECT ${fieldName} AS data, time
55   - FROM ${dataBaseName}.${tableName}
56   - WHERE time BETWEEN #{startTime} AND #{endTime}
57   - AND ${fieldName} IS NOT NULL
58   - ORDER BY time DESC
59   - LIMIT #{params.rows} OFFSET #{params.page}
60   - </select>
61   -
62   - <!-- 获取实时数据 -->
63   - <select id="selectRealtimeDataList" resultType="java.util.Map"
64   - parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO">
65   - SELECT ${fieldName}, time
66   - FROM ${dataBaseName}.${tableName}
67   - </select>
68   -
69   - <!-- 获取聚合数据 -->
70   - <select id="selectAggregateDataList" resultType="java.util.Map"
71   - parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO">
72   - SELECT ${aggregate}(${fieldName})
73   - FROM ${dataBaseName}.${tableName}
74   - WHERE ts BETWEEN #{startTime} AND #{endTime} INTERVAL (${interval})
75   - LIMIT #{num}
76   - </select>
77   -
78   - <!-- 获取历史数据条数 -->
79   - <select id="selectHistoryCount" resultType="java.lang.Long">
80   - SELECT COUNT(time)
81   - FROM ${dataBaseName}.${tableName}
82   - WHERE time BETWEEN #{startTime} AND #{endTime}
83   - AND ${fieldName} IS NOT NULL
84   - </select>
85   -
86   -</mapper>
87 0 \ No newline at end of file
yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/tdengine/TdThinkModelMessageMapper.xml deleted
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!DOCTYPE mapper
3   - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
4   - "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5   -<mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.TdThingModelMessageMapper">
6   -
7   - <!-- 创建物模型消息日志超级表 -->
8   - <update id="createSuperTable">
9   - CREATE STABLE thing_model_message_${productKey}(
10   - ts TIMESTAMP,
11   - id NCHAR(64),
12   - sys NCHAR(2048),
13   - method NCHAR(255),
14   - params NCHAR(2048),
15   - device_name NCHAR(64)
16   - )TAGS (
17   - device_key NCHAR(50)
18   - )
19   - </update>
20   -
21   - <!-- 创建物模型消息日志子表,带有deviceKey的TAG -->
22   - <update id="createTableWithTag">
23   - CREATE STABLE ${deviceKey}
24   - USING thing_model_message_${productKey}(
25   - ts,
26   - id ,
27   - sys ,
28   - method ,
29   - params ,
30   - device_name
31   - )TAGS(
32   - #{device_key}
33   - )
34   - </update>
35   -</mapper>
36 0 \ No newline at end of file