|
|
@ -366,4 +366,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
) t2 ON t1.monitorId = t2.monitorId AND t1.objid = t2.max_objid
|
|
|
|
) t2 ON t1.monitorId = t2.monitorId AND t1.objid = t2.max_objid
|
|
|
|
</select>
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 高性能采样查询:TiDB原生优化,无索引依赖 -->
|
|
|
|
|
|
|
|
<select id="selectRecordIotenvInstantListFromTablesWithSampling" resultMap="RecordIotenvInstantResult">
|
|
|
|
|
|
|
|
<!-- 使用分段+聚合的高效算法,避免复杂窗口函数 -->
|
|
|
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
|
|
t1.objid, t1.monitorId, t1.temperature, t1.humidity, t1.illuminance, t1.noise, t1.concentration,
|
|
|
|
|
|
|
|
t1.vibration_speed, t1.vibration_displacement, t1.vibration_acceleration, t1.vibration_temp,
|
|
|
|
|
|
|
|
t1.collectTime, t1.recodeTime
|
|
|
|
|
|
|
|
FROM ${tableName} t1
|
|
|
|
|
|
|
|
INNER JOIN (
|
|
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
|
|
monitorId,
|
|
|
|
|
|
|
|
FLOOR(UNIX_TIMESTAMP(recodeTime) / (#{recordIotenvInstant.samplingInterval} * 60)) as time_slot,
|
|
|
|
|
|
|
|
MAX(recodeTime) as max_time
|
|
|
|
|
|
|
|
FROM ${tableName}
|
|
|
|
|
|
|
|
<where>
|
|
|
|
|
|
|
|
<if test="recordIotenvInstant.monitorId != null and recordIotenvInstant.monitorId != ''">
|
|
|
|
|
|
|
|
AND monitorId = #{recordIotenvInstant.monitorId}
|
|
|
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
<if test="recordIotenvInstant.params.beginRecordTime != null and recordIotenvInstant.params.endRecordTime != null">
|
|
|
|
|
|
|
|
AND recodeTime >= #{recordIotenvInstant.params.beginRecordTime}
|
|
|
|
|
|
|
|
AND recodeTime <= #{recordIotenvInstant.params.endRecordTime}
|
|
|
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
<if test="recordIotenvInstant.monitorIds != null and recordIotenvInstant.monitorIds.length > 0">
|
|
|
|
|
|
|
|
AND monitorId IN
|
|
|
|
|
|
|
|
<foreach collection="recordIotenvInstant.monitorIds" item="monitorId" open="(" separator="," close=")">
|
|
|
|
|
|
|
|
#{monitorId}
|
|
|
|
|
|
|
|
</foreach>
|
|
|
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
AND (temperature IS NULL OR temperature BETWEEN 0 AND 80)
|
|
|
|
|
|
|
|
AND (humidity IS NULL OR humidity BETWEEN 0 AND 80)
|
|
|
|
|
|
|
|
AND (noise IS NULL OR noise BETWEEN 0 AND 80)
|
|
|
|
|
|
|
|
</where>
|
|
|
|
|
|
|
|
GROUP BY monitorId, time_slot
|
|
|
|
|
|
|
|
) t2 ON t1.monitorId = t2.monitorId AND t1.recodeTime = t2.max_time
|
|
|
|
|
|
|
|
</foreach>
|
|
|
|
|
|
|
|
ORDER BY monitorId ASC, recodeTime ASC
|
|
|
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
</mapper>
|
|
|
|
</mapper>
|