87 lines
3.0 KiB
XML
87 lines
3.0 KiB
XML
<?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.IotDevicePropertyDataMapper">
|
|
|
|
<select id="getProductPropertySTableFieldList" resultType="cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField">
|
|
DESCRIBE product_property_${productKey}
|
|
</select>
|
|
|
|
<update id="createProductPropertySTable">
|
|
CREATE STABLE product_property_${productKey}
|
|
<foreach item="field" collection="fields" separator="," open="(" close=")">
|
|
${field.field} ${field.type}
|
|
<if test="field.length != null and field.length > 0">
|
|
(${field.length})
|
|
</if>
|
|
</foreach>
|
|
TAGS (
|
|
device_key NCHAR(50)
|
|
)
|
|
</update>
|
|
|
|
<update id="alterProductPropertySTableAddField">
|
|
ALTER STABLE product_property_${productKey}
|
|
ADD COLUMN ${field.field} ${field.type}
|
|
<if test="field.length != null and field.length > 0">
|
|
(${field.length})
|
|
</if>
|
|
</update>
|
|
|
|
<update id="alterProductPropertySTableModifyField">
|
|
ALTER STABLE product_property_${productKey}
|
|
MODIFY COLUMN ${field.field} ${field.type}
|
|
<if test="field.length != null and field.length > 0">
|
|
(${field.length})
|
|
</if>
|
|
</update>
|
|
|
|
<update id="alterProductPropertySTableDropField">
|
|
ALTER STABLE product_property_${productKey}
|
|
DROP COLUMN ${field.field}
|
|
</update>
|
|
|
|
<insert id="insertDevicePropertyData">
|
|
INSERT INTO device_property_${deviceKey}
|
|
USING product_property_${productKey}
|
|
TAGS ('${deviceKey}')
|
|
(ts
|
|
<foreach item="item" collection="columns" separator=",">
|
|
,${item.fieldName}
|
|
</foreach>
|
|
)
|
|
VALUES
|
|
(NOW
|
|
<foreach item="item" collection="columns" separator=",">
|
|
,#{item.fieldValue}
|
|
</foreach>
|
|
)
|
|
</insert>
|
|
|
|
<!-- 描述超级表结构 -->
|
|
<select id="describeSuperTable" resultType="java.util.Map">
|
|
DESCRIBE product_property_${productKey}
|
|
</select>
|
|
|
|
<!-- 获取历史数据 -->
|
|
<select id="selectHistoryDataList" resultType="java.util.Map"
|
|
parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO">
|
|
SELECT ${fieldName} AS data, ts AS time
|
|
FROM device_property_${deviceKey}
|
|
WHERE ts BETWEEN #{startTime} AND #{endTime}
|
|
AND ${fieldName} IS NOT NULL
|
|
ORDER BY ts DESC
|
|
LIMIT #{params.rows} OFFSET #{params.page}
|
|
</select>
|
|
|
|
<!-- 统计历史数据总数 -->
|
|
<select id="selectHistoryCount" resultType="java.lang.Long"
|
|
parameterType="cn.iocoder.yudao.module.iot.dal.dataobject.tdengine.SelectVisualDO">
|
|
SELECT COUNT(*)
|
|
FROM device_property_${deviceKey}
|
|
WHERE ts BETWEEN #{startTime} AND #{endTime}
|
|
AND ${fieldName} IS NOT NULL
|
|
</select>
|
|
|
|
</mapper> |