【功能优化】IoT:清理通用 TDengine 封装,使用 SQL 查询
This commit is contained in:
@@ -1,101 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDDLMapper">
|
||||
|
||||
<!-- 创建数据库 -->
|
||||
<update id="createDatabase" parameterType="String">
|
||||
CREATE DATABASE IF NOT EXISTS ${dataBaseName}
|
||||
</update>
|
||||
|
||||
<!-- 创建超级表 -->
|
||||
<update id="createSuperTable">
|
||||
CREATE STABLE IF NOT EXISTS ${dataBaseName}.${superTableName}
|
||||
<foreach item="item" collection="columns" separator=","
|
||||
open="(" close=")">
|
||||
${item.fieldName} ${item.dataType}
|
||||
<if test="item.dataLength > 0">
|
||||
(${item.dataLength})
|
||||
</if>
|
||||
</foreach>
|
||||
TAGS
|
||||
<foreach item="item" collection="tags" separator=","
|
||||
open="(" close=")">
|
||||
${item.fieldName} ${item.dataType}
|
||||
<if test="item.dataLength > 0">
|
||||
(${item.dataLength})
|
||||
</if>
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 查看超级表 -->
|
||||
<select id="showSuperTables" resultType="java.util.Map">
|
||||
SHOW ${dataBaseName}.STABLES LIKE '${superTableName}'
|
||||
</select>
|
||||
|
||||
<!-- 描述超级表结构 -->
|
||||
<select id="describeSuperTable" resultType="java.util.Map">
|
||||
DESCRIBE ${dataBaseName}.${superTableName}
|
||||
</select>
|
||||
|
||||
<!-- 为超级表添加列 -->
|
||||
<update id="addColumnForSuperTable">
|
||||
ALTER STABLE ${dataBaseName}.${superTableName} ADD COLUMN ${column.fieldName} ${column.dataType}
|
||||
<if test="column.dataLength > 0">
|
||||
(${column.dataLength})
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<!-- 为超级表删除列 -->
|
||||
<update id="dropColumnForSuperTable">
|
||||
ALTER STABLE ${dataBaseName}.${superTableName} DROP COLUMN ${column.fieldName}
|
||||
</update>
|
||||
|
||||
<!-- 修改列宽 -->
|
||||
<update id="modifyColumnWidthForSuperTable">
|
||||
ALTER STABLE ${dataBaseName}.${superTableName} MODIFY COLUMN ${column.fieldName} ${column.dataType}
|
||||
<if test="column.dataLength > 0">
|
||||
(${column.dataLength})
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<!-- 为超级表添加标签 -->
|
||||
<update id="addTagForSuperTable">
|
||||
ALTER STABLE ${dataBaseName}.${superTableName} ADD TAG ${tag.fieldName} ${tag.dataType}
|
||||
<if test="tag.dataLength > 0">
|
||||
(${tag.dataLength})
|
||||
</if>
|
||||
</update>
|
||||
|
||||
<!-- 为超级表删除标签 -->
|
||||
<update id="dropTagForSuperTable">
|
||||
ALTER STABLE ${dataBaseName}.${superTableName} DROP TAG ${tag.fieldName}
|
||||
</update>
|
||||
|
||||
<!-- 创建子表 -->
|
||||
<update id="createTable">
|
||||
CREATE TABLE IF NOT EXISTS ${dataBaseName}.${tableName}
|
||||
USING ${dataBaseName}.${superTableName}
|
||||
TAGS
|
||||
<foreach item="item" collection="tags" separator=","
|
||||
open="(" close=")">
|
||||
#{item.fieldValue}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 创建子表,带有 TAGS -->
|
||||
<update id="createTableWithTags">
|
||||
CREATE TABLE IF NOT EXISTS ${dataBaseName}.${tableName}
|
||||
USING ${dataBaseName}.${superTableName}
|
||||
<foreach item="item" collection="tags" separator="," open="(" close=")">
|
||||
#{item.fieldName}
|
||||
</foreach>
|
||||
TAGS
|
||||
<foreach item="item" collection="tags" separator=","
|
||||
open="(" close=")">
|
||||
#{item.fieldValue}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
@@ -1,86 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.TdEngineDMLMapper">
|
||||
|
||||
<!-- 插入数据 -->
|
||||
<insert id="insertData">
|
||||
INSERT INTO ${dataBaseName}.${tableName}
|
||||
<foreach item="item" collection="columns" separator=","
|
||||
open="(" close=")">
|
||||
${item.fieldName}
|
||||
</foreach>
|
||||
VALUES
|
||||
<foreach item="item" collection="columns" separator=","
|
||||
open="(" close=")">
|
||||
#{item.fieldValue}
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<!-- 根据时间戳查询数据 -->
|
||||
<select id="selectByTimestamp" parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectDO"
|
||||
resultType="Map">
|
||||
SELECT * FROM ${dataBaseName}.${tableName}
|
||||
WHERE ${fieldName} BETWEEN #{startTime} AND #{endTime}
|
||||
</select>
|
||||
|
||||
<!-- 获取时间范围内的数据条数 -->
|
||||
<select id="selectCountByTimestamp" parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectDO"
|
||||
resultType="java.util.Map">
|
||||
SELECT COUNT(0) AS count
|
||||
FROM ${dataBaseName}.${tableName}
|
||||
WHERE ${fieldName} BETWEEN #{startTime} AND #{endTime}
|
||||
</select>
|
||||
|
||||
<!-- 获取最新数据 -->
|
||||
<select id="selectOneLastData" resultType="java.util.Map">
|
||||
SELECT LAST(time), *
|
||||
FROM ${tableName}
|
||||
WHERE device_id = #{deviceId}
|
||||
</select>
|
||||
|
||||
<!-- 根据标签获取最新数据 -->
|
||||
<select id="selectLastDataListByTags" parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.TagsSelectDO"
|
||||
resultType="java.util.Map">
|
||||
SELECT LAST(*)
|
||||
FROM ${dataBaseName}.${stableName}
|
||||
GROUP BY ${tagsName}
|
||||
</select>
|
||||
|
||||
<!-- 获取历史数据 -->
|
||||
<select id="selectHistoryDataList" resultType="java.util.Map"
|
||||
parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO">
|
||||
SELECT ${fieldName} AS data, time
|
||||
FROM ${dataBaseName}.${tableName}
|
||||
WHERE time BETWEEN #{startTime} AND #{endTime}
|
||||
AND ${fieldName} IS NOT NULL
|
||||
ORDER BY time DESC
|
||||
LIMIT #{params.rows} OFFSET #{params.page}
|
||||
</select>
|
||||
|
||||
<!-- 获取实时数据 -->
|
||||
<select id="selectRealtimeDataList" resultType="java.util.Map"
|
||||
parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO">
|
||||
SELECT ${fieldName}, time
|
||||
FROM ${dataBaseName}.${tableName}
|
||||
</select>
|
||||
|
||||
<!-- 获取聚合数据 -->
|
||||
<select id="selectAggregateDataList" resultType="java.util.Map"
|
||||
parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO">
|
||||
SELECT ${aggregate}(${fieldName})
|
||||
FROM ${dataBaseName}.${tableName}
|
||||
WHERE ts BETWEEN #{startTime} AND #{endTime} INTERVAL (${interval})
|
||||
LIMIT #{num}
|
||||
</select>
|
||||
|
||||
<!-- 获取历史数据条数 -->
|
||||
<select id="selectHistoryCount" resultType="java.lang.Long">
|
||||
SELECT COUNT(time)
|
||||
FROM ${dataBaseName}.${tableName}
|
||||
WHERE time BETWEEN #{startTime} AND #{endTime}
|
||||
AND ${fieldName} IS NOT NULL
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,35 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.iocoder.yudao.module.iot.dal.tdengine.TdThingModelMessageMapper">
|
||||
|
||||
<!-- 创建物模型消息日志超级表 -->
|
||||
<update id="createSuperTable">
|
||||
CREATE STABLE thing_model_message_${productKey}(
|
||||
ts TIMESTAMP,
|
||||
id NCHAR(64),
|
||||
sys NCHAR(2048),
|
||||
method NCHAR(255),
|
||||
params NCHAR(2048),
|
||||
device_name NCHAR(64)
|
||||
)TAGS (
|
||||
device_key NCHAR(50)
|
||||
)
|
||||
</update>
|
||||
|
||||
<!-- 创建物模型消息日志子表,带有deviceKey的TAG -->
|
||||
<update id="createTableWithTag">
|
||||
CREATE STABLE ${deviceKey}
|
||||
USING thing_model_message_${productKey}(
|
||||
ts,
|
||||
id ,
|
||||
sys ,
|
||||
method ,
|
||||
params ,
|
||||
device_name
|
||||
)TAGS(
|
||||
#{device_key}
|
||||
)
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user