From 4ccf639cd2f559af695282620501a86fb3953987 Mon Sep 17 00:00:00 2001 From: "zangch@mesnac.com" Date: Wed, 1 Apr 2026 16:56:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(RecordIotenvInstantMapper):=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=A7=92=E7=BA=A7=E5=9B=9E=E6=BA=AF=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96SQL=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ems/record/RecordIotenvInstantMapper.xml | 99 +++++++++++-------- 1 file changed, 58 insertions(+), 41 deletions(-) diff --git a/ruoyi-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml b/ruoyi-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml index b1b1724..70d4d93 100644 --- a/ruoyi-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml +++ b/ruoyi-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml @@ -508,49 +508,66 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" FROM ${tableName} t1 LEFT JOIN ems_base_monitor_info ebmi ON t1.monitorId = ebmi.monitor_code INNER JOIN ( - SELECT - t.monitorId, - CAST(DATEDIFF(MINUTE, '1970-01-01', t.recodeTime) / #{recordIotenvInstant.samplingInterval} AS BIGINT) as time_slot, - MAX(t.recodeTime) as max_time - FROM ${tableName} t - LEFT JOIN ems_base_monitor_info ebmi2 ON t.monitorId = ebmi2.monitor_code - - - AND t.monitorId = #{recordIotenvInstant.monitorId} - - - AND t.recodeTime >= #{recordIotenvInstant.params.beginRecordTime} - AND t.recodeTime <= #{recordIotenvInstant.params.endRecordTime} - - - AND t.monitorId IN - - #{monitorId} - - - AND (t.temperature IS NULL OR t.temperature BETWEEN 0 AND 79) - AND (t.humidity IS NULL OR t.humidity BETWEEN 0 AND 79) - AND (t.noise IS NULL OR t.noise BETWEEN 0 AND 79) + + SELECT monitorId, time_slot, MAX(recodeTime) AS max_time FROM ( + SELECT + t.monitorId, + CAST( + + + + DATEDIFF(SECOND, '1970-01-01', t.recodeTime) + + + DATEDIFF(HOUR, '1970-01-01', t.recodeTime) + + + DATEDIFF(MINUTE, '1970-01-01', t.recodeTime) + + + / #{recordIotenvInstant.samplingInterval} AS BIGINT + ) as time_slot, + t.recodeTime + FROM ${tableName} t + LEFT JOIN ems_base_monitor_info ebmi2 ON t.monitorId = ebmi2.monitor_code + + + AND t.monitorId = #{recordIotenvInstant.monitorId} + + + AND t.recodeTime >= #{recordIotenvInstant.params.beginRecordTime} + AND t.recodeTime <= #{recordIotenvInstant.params.endRecordTime} + + + AND t.monitorId IN + + #{monitorId} + + + AND (t.temperature IS NULL OR t.temperature BETWEEN 0 AND 79) + AND (t.humidity IS NULL OR t.humidity BETWEEN 0 AND 79) + AND (t.noise IS NULL OR t.noise BETWEEN 0 AND 79) - --- AND (ebmi2.is_ammeter IS NULL OR ebmi2.is_ammeter != '0') + +-- AND (ebmi2.is_ammeter IS NULL OR ebmi2.is_ammeter != '0') - - - AND ( - -- 温度设备(type=5):过滤温度为0的数据 - (ebmi2.monitor_type = 5 AND t.temperature > 0) OR - -- 温湿度设备(type=6):过滤温度和湿度都为0的数据 - (ebmi2.monitor_type = 6 AND (t.temperature > 0 OR t.humidity > 0)) OR - -- 噪声设备(type=7):过滤噪声为0的数据 - (ebmi2.monitor_type = 7 AND t.noise > 0) OR - -- 振动设备(type=10):过滤振动相关字段都为0的数据 - (ebmi2.monitor_type = 10 AND (t.vibration_speed > 0 OR t.vibration_displacement > 0 OR t.vibration_acceleration > 0 OR t.vibration_temp > 0)) OR - -- 其他类型设备或无设备信息:保留所有有效数据 - (ebmi2.monitor_type NOT IN (5, 6, 7, 10) OR ebmi2.monitor_type IS NULL) - ) - - GROUP BY t.monitorId, CAST(DATEDIFF(MINUTE, '1970-01-01', t.recodeTime) / #{recordIotenvInstant.samplingInterval} AS BIGINT) + + + AND ( + -- 温度设备(type=5):过滤温度为0的数据 + (ebmi2.monitor_type = 5 AND t.temperature > 0) OR + -- 温湿度设备(type=6):过滤温度和湿度都为0的数据 + (ebmi2.monitor_type = 6 AND (t.temperature > 0 OR t.humidity > 0)) OR + -- 噪声设备(type=7):过滤噪声为0的数据 + (ebmi2.monitor_type = 7 AND t.noise > 0) OR + -- 振动设备(type=10):过滤振动相关字段都为0的数据 + (ebmi2.monitor_type = 10 AND (t.vibration_speed > 0 OR t.vibration_displacement > 0 OR t.vibration_acceleration > 0 OR t.vibration_temp > 0)) OR + -- 其他类型设备或无设备信息:保留所有有效数据 + (ebmi2.monitor_type NOT IN (5, 6, 7, 10) OR ebmi2.monitor_type IS NULL) + ) + + ) sub + GROUP BY sub.monitorId, sub.time_slot ) t2 ON t1.monitorId = t2.monitorId AND t1.recodeTime = t2.max_time ORDER BY monitorId ASC, recodeTime ASC