diff --git a/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml b/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml index 149158d..d2a5bc1 100644 --- a/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml +++ b/os-ems/src/main/resources/mapper/ems/record/RecordIotenvInstantMapper.xml @@ -130,40 +130,56 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" SELECT COUNT(*) FROM ( - SELECT objid - FROM ${tableName} + SELECT t.objid + FROM ${tableName} t + LEFT JOIN ems_base_monitor_info ebmi ON t.monitorId = ebmi.monitor_code - and monitorId = #{recordIotenvInstant.monitorId} - and temperature = #{recordIotenvInstant.temperature} - and humidity = #{recordIotenvInstant.humidity} - and illuminance = #{recordIotenvInstant.illuminance} - and noise = #{recordIotenvInstant.noise} - and concentration = #{recordIotenvInstant.concentration} - and vibration_speed = #{recordIotenvInstant.vibrationSpeed} - and vibration_displacement = #{recordIotenvInstant.vibrationDisplacement} - and vibration_acceleration = #{recordIotenvInstant.vibrationAcceleration} - and vibration_temp = #{recordIotenvInstant.vibrationTemp} - and collectTime = #{recordIotenvInstant.collectTime} - and recodeTime = #{recordIotenvInstant.recodeTime} + and t.monitorId = #{recordIotenvInstant.monitorId} + and t.temperature = #{recordIotenvInstant.temperature} + and t.humidity = #{recordIotenvInstant.humidity} + and t.illuminance = #{recordIotenvInstant.illuminance} + and t.noise = #{recordIotenvInstant.noise} + and t.concentration = #{recordIotenvInstant.concentration} + and t.vibration_speed = #{recordIotenvInstant.vibrationSpeed} + and t.vibration_displacement = #{recordIotenvInstant.vibrationDisplacement} + and t.vibration_acceleration = #{recordIotenvInstant.vibrationAcceleration} + and t.vibration_temp = #{recordIotenvInstant.vibrationTemp} + and t.collectTime = #{recordIotenvInstant.collectTime} + and t.recodeTime = #{recordIotenvInstant.recodeTime} - AND recodeTime BETWEEN #{recordIotenvInstant.params.beginRecordTime} AND #{recordIotenvInstant.params.endRecordTime} + AND t.recodeTime BETWEEN #{recordIotenvInstant.params.beginRecordTime} AND #{recordIotenvInstant.params.endRecordTime} - AND monitorId IN + AND t.monitorId IN #{monitorId} @@ -305,9 +337,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - AND (temperature IS NULL OR temperature BETWEEN 1 AND 79) - AND (humidity IS NULL OR humidity BETWEEN 1 AND 79) - AND (noise IS NULL OR noise BETWEEN 1 AND 79) + 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 ( + -- 温度设备(type=5):过滤温度为0的数据 + (ebmi.monitor_type = 5 AND t.temperature > 0) OR + -- 温湿度设备(type=6):过滤温度和湿度都为0的数据 + (ebmi.monitor_type = 6 AND (t.temperature > 0 OR t.humidity > 0)) OR + -- 噪声设备(type=7):过滤噪声为0的数据 + (ebmi.monitor_type = 7 AND t.noise > 0) OR + -- 振动设备(type=10):过滤振动相关字段都为0的数据 + (ebmi.monitor_type = 10 AND (t.vibration_speed > 0 OR t.vibration_displacement > 0 OR t.vibration_acceleration > 0 OR t.vibration_temp > 0)) OR + -- 其他类型设备或无设备信息:保留所有有效数据 + (ebmi.monitor_type NOT IN (5, 6, 7, 10) OR ebmi.monitor_type IS NULL) + ) @@ -375,31 +422,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" t1.vibration_speed, t1.vibration_displacement, t1.vibration_acceleration, t1.vibration_temp, t1.collectTime, t1.recodeTime FROM ${tableName} t1 + LEFT JOIN ems_base_monitor_info ebmi ON t1.monitorId = ebmi.monitor_code INNER JOIN ( SELECT - monitorId, - FLOOR(UNIX_TIMESTAMP(recodeTime) / (#{recordIotenvInstant.samplingInterval} * 60)) as time_slot, - MAX(recodeTime) as max_time - FROM ${tableName} + t.monitorId, + FLOOR(UNIX_TIMESTAMP(t.recodeTime) / (#{recordIotenvInstant.samplingInterval} * 60)) 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 monitorId = #{recordIotenvInstant.monitorId} + AND t.monitorId = #{recordIotenvInstant.monitorId} - AND recodeTime >= #{recordIotenvInstant.params.beginRecordTime} - AND recodeTime <= #{recordIotenvInstant.params.endRecordTime} + AND t.recodeTime >= #{recordIotenvInstant.params.beginRecordTime} + AND t.recodeTime <= #{recordIotenvInstant.params.endRecordTime} - AND monitorId IN + AND t.monitorId IN #{monitorId} - AND (temperature IS NULL OR temperature BETWEEN 1 AND 79) - AND (humidity IS NULL OR humidity BETWEEN 1 AND 79) - AND (noise IS NULL OR noise BETWEEN 1 AND 79) + 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 ( + -- 温度设备(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 monitorId, time_slot + GROUP BY t.monitorId, time_slot ) t2 ON t1.monitorId = t2.monitorId AND t1.recodeTime = t2.max_time ORDER BY monitorId ASC, recodeTime ASC