You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.7 KiB
111 lines
3.7 KiB
<?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.hand.mapper.TdengineMapper">
|
|
<!--
|
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
|
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
|
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
|
-->
|
|
|
|
|
|
<insert id="insertHandLogBatch">
|
|
|
|
INSERT INTO hand_original_log_${sn}
|
|
USING hand_original_log
|
|
TAGS(#{sn}, #{tenantId})
|
|
(ts, payload)
|
|
VALUES
|
|
<foreach collection="logList" item="log" separator=",">
|
|
(#{log.ts}, #{log.payload})
|
|
</foreach>
|
|
</insert>
|
|
|
|
<insert id="saveDataLogBatch">
|
|
INSERT INTO device_data_log_#{sn}
|
|
USING device_data_log
|
|
TAGS(#{sn}, #{tenantId})
|
|
(ts, battery, `value`, longitude, latitude, `name`,gas_type)
|
|
VALUES
|
|
<foreach collection="dataVoList" item="log" separator=",">
|
|
(#{log.ts}, #{log.battery}, #{log.value}, #{log.longitude}, #{log.latitude}, #{log.name}, #{log.gasType})
|
|
</foreach>
|
|
|
|
</insert>
|
|
|
|
<select id="selectPage" resultType="cn.iocoder.yudao.module.hand.vo.TdengineDataVo">
|
|
SELECT
|
|
ts, sn, battery, `value`, longitude, latitude, `name`,gas_type as gasType,tenantId
|
|
FROM
|
|
device_data_log
|
|
<where>
|
|
|
|
<if test="vo.sn != null and vo.sn != ''">
|
|
AND sn = #{vo.sn}
|
|
</if>
|
|
<if test="vo.tenantId != null">
|
|
AND tenant_id = #{vo.tenantId}
|
|
</if>
|
|
<if test="vo.startTime != null">
|
|
AND ts >= #{vo.startTime}
|
|
</if>
|
|
<!-- 条件3: 根据结束时间进行过滤 -->
|
|
<if test="vo.endTime != null">
|
|
AND ts <= #{vo.endTime}
|
|
</if>
|
|
</where>
|
|
ORDER BY
|
|
ts DESC
|
|
</select>
|
|
|
|
<select id="selectOriginalPage" resultType="cn.iocoder.yudao.module.hand.vo.HandOriginalLog">
|
|
SELECT
|
|
ts, sn, payload, tenantId
|
|
FROM
|
|
hand_original_log
|
|
<where>
|
|
|
|
<if test="vo.sn != null and vo.sn != ''">
|
|
AND sn = #{vo.sn}
|
|
</if>
|
|
<if test="vo.tenantId != null">
|
|
AND tenant_id = #{vo.tenantId}
|
|
</if>
|
|
<if test="vo.startTime != null">
|
|
AND ts >= #{vo.startTime}
|
|
</if>
|
|
<!-- 条件3: 根据结束时间进行过滤 -->
|
|
<if test="vo.endTime != null">
|
|
AND ts <= #{vo.endTime}
|
|
</if>
|
|
</where>
|
|
</select>
|
|
|
|
<select id="HistoricalSn" resultType="cn.iocoder.yudao.module.hand.vo.TdengineDataVo">
|
|
SELECT
|
|
_wstart as ts,
|
|
LAST(`value`) as `value`,
|
|
LAST(longitude) as longitude,
|
|
LAST(latitude) as latitude,
|
|
LAST(gas_type) as gasType
|
|
FROM
|
|
device_data_log
|
|
<where>
|
|
<if test="vo.sn != null and vo.sn != ''">
|
|
AND sn = #{vo.sn}
|
|
</if>
|
|
<if test="vo.tenantId != null">
|
|
AND tenantId = #{vo.tenantId}
|
|
</if>
|
|
<if test="vo.startTime != null">
|
|
AND ts >= #{vo.startTime}
|
|
</if>
|
|
<if test="vo.endTime != null">
|
|
AND ts <= #{vo.endTime}
|
|
</if>
|
|
</where>
|
|
INTERVAL(1m)
|
|
PARTITION BY sn, tenantId
|
|
ORDER BY ts DESC
|
|
</select>
|
|
</mapper>
|