|
|
|
@ -151,26 +151,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
AND recodeTime BETWEEN #{recordIotenvInstant.params.beginRecordTime} AND #{recordIotenvInstant.params.endRecordTime}
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
|
|
<!-- <if test="recordIotenvInstant.monitorIds != null and recordIotenvInstant.monitorIds.length > 0">
|
|
|
|
|
<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>-->
|
|
|
|
|
</if>
|
|
|
|
|
|
|
|
|
|
</where>
|
|
|
|
|
</foreach>
|
|
|
|
|
ORDER BY recodeTime ASC
|
|
|
|
|
ORDER BY recodeTime desc
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 检查表是否存在 -->
|
|
|
|
|
<select id="checkTableExists" parameterType="java.util.Map" resultType="java.lang.Integer">
|
|
|
|
|
SELECT COUNT(1) FROM information_schema.tables
|
|
|
|
|
WHERE table_schema = DATABASE() AND table_name = #{tableName}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 使用 UNION ALL 从多个表查询物联网数据列表 ,具有分页功能-->
|
|
|
|
|
<select id="selectFromTablesWithPage" resultMap="RecordIotenvInstantResult">
|
|
|
|
|
<!-- (待测试limit)测试一: 使用 UNION ALL 从多个表查询物联网数据列表 ,具有分页功能(可能会在查询完所有数据后才limit,需测试)-->
|
|
|
|
|
<!-- <select id="selectFromTablesWithPage" resultMap="RecordIotenvInstantResult">
|
|
|
|
|
select * from (
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
SELECT objid, monitorId, temperature, humidity, illuminance, noise, concentration,
|
|
|
|
|
vibration_speed, vibration_displacement, vibration_acceleration, vibration_temp,
|
|
|
|
@ -203,11 +199,62 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
|
|
|
|
|
</where>
|
|
|
|
|
</foreach>
|
|
|
|
|
ORDER BY recodeTime ASC
|
|
|
|
|
)AS combined_data
|
|
|
|
|
ORDER BY recodeTime desc
|
|
|
|
|
LIMIT #{offset}, #{pageSize}
|
|
|
|
|
</select>
|
|
|
|
|
</select> -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 测试二: 使用 UNION ALL 从多个表查询物联网数据列表 ,具有分页功能-->
|
|
|
|
|
<select id="selectFromTablesWithPage" resultMap="RecordIotenvInstantResult">
|
|
|
|
|
SELECT * FROM (
|
|
|
|
|
SELECT *, ROW_NUMBER() OVER (ORDER BY recodeTime DESC) as row_num
|
|
|
|
|
FROM (
|
|
|
|
|
<foreach collection="tableNames" item="tableName" separator=" UNION ALL ">
|
|
|
|
|
(SELECT objid, monitorId, temperature, humidity, illuminance, noise, concentration,
|
|
|
|
|
vibration_speed, vibration_displacement, vibration_acceleration, vibration_temp,
|
|
|
|
|
collectTime, recodeTime
|
|
|
|
|
FROM ${tableName}
|
|
|
|
|
<where>
|
|
|
|
|
<if test="recordIotenvInstant.monitorId != null and recordIotenvInstant.monitorId != ''"> and monitorId = #{recordIotenvInstant.monitorId}</if>
|
|
|
|
|
<if test="recordIotenvInstant.temperature != null "> and temperature = #{recordIotenvInstant.temperature}</if>
|
|
|
|
|
<if test="recordIotenvInstant.humidity != null "> and humidity = #{recordIotenvInstant.humidity}</if>
|
|
|
|
|
<if test="recordIotenvInstant.illuminance != null "> and illuminance = #{recordIotenvInstant.illuminance}</if>
|
|
|
|
|
<if test="recordIotenvInstant.noise != null "> and noise = #{recordIotenvInstant.noise}</if>
|
|
|
|
|
<if test="recordIotenvInstant.concentration != null "> and concentration = #{recordIotenvInstant.concentration}</if>
|
|
|
|
|
<if test="recordIotenvInstant.vibrationSpeed != null "> and vibration_speed = #{recordIotenvInstant.vibrationSpeed}</if>
|
|
|
|
|
<if test="recordIotenvInstant.vibrationDisplacement != null "> and vibration_displacement = #{recordIotenvInstant.vibrationDisplacement}</if>
|
|
|
|
|
<if test="recordIotenvInstant.vibrationAcceleration != null "> and vibration_acceleration = #{recordIotenvInstant.vibrationAcceleration}</if>
|
|
|
|
|
<if test="recordIotenvInstant.vibrationTemp != null "> and vibration_temp = #{recordIotenvInstant.vibrationTemp}</if>
|
|
|
|
|
<if test="recordIotenvInstant.collectTime != null "> and collectTime = #{recordIotenvInstant.collectTime}</if>
|
|
|
|
|
<if test="recordIotenvInstant.recodeTime != null "> and recodeTime = #{recordIotenvInstant.recodeTime}</if>
|
|
|
|
|
|
|
|
|
|
<if test="recordIotenvInstant.params.beginRecordTime!= null and recordIotenvInstant.params.endRecordTime != null">
|
|
|
|
|
AND recodeTime BETWEEN #{recordIotenvInstant.params.beginRecordTime} AND #{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>
|
|
|
|
|
|
|
|
|
|
</where>
|
|
|
|
|
ORDER BY objid DESC)
|
|
|
|
|
</foreach>
|
|
|
|
|
) AS all_data
|
|
|
|
|
) AS paged_data
|
|
|
|
|
WHERE row_num > #{offset} AND row_num <= (#{offset} + #{pageSize})
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 检查表是否存在 -->
|
|
|
|
|
<select id="checkTableExists" parameterType="java.util.Map" resultType="java.lang.Integer">
|
|
|
|
|
SELECT COUNT(1) FROM information_schema.tables
|
|
|
|
|
WHERE table_schema = DATABASE() AND table_name = #{tableName}
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 统计多表查询的总记录数 -->
|
|
|
|
|
<select id="countFromTables" resultType="java.lang.Integer">
|
|
|
|
|
SELECT COUNT(*) FROM (
|
|
|
|
@ -231,6 +278,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
<if test="recordIotenvInstant.params.beginRecordTime!= null and recordIotenvInstant.params.endRecordTime != null">
|
|
|
|
|
AND recodeTime BETWEEN #{recordIotenvInstant.params.beginRecordTime} AND #{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>
|
|
|
|
|
|
|
|
|
|
</where>
|
|
|
|
|
</foreach>
|
|
|
|
|
) AS total_count
|
|
|
|
|