Compare commits

..

2 Commits

Author SHA1 Message Date
Gjm
f9538ffc9b fix(iot): 修复日志批量删除功能中的表名错误和性能优化
- 修正了事件日志删除SQL中的表名从 iot_event log 到 iot_event_log
- 将批量删除大小从5000调整为1000以提高性能稳定性
- 添加了批量删除过程中的进度日志记录功能
- 将删除批次间的休眠时间从100ms缩短到50ms
- 增加了中断处理的日志警告信息
- 完善了删除任务完成后的统计日志输出

Signed-off-by: Gjm <你的邮箱>
2026-05-18 15:13:30 +08:00
Gjm
5899b565c6 fix(iot): 修复日志批量删除功能中的表名错误和性能优化
- 修正了事件日志删除SQL中的表名从 iot_event log 到 iot_event_log
- 将批量删除大小从5000调整为1000以提高性能稳定性
- 添加了批量删除过程中的进度日志记录功能
- 将删除批次间的休眠时间从100ms缩短到50ms
- 增加了中断处理的日志警告信息
- 完善了删除任务完成后的统计日志输出

Signed-off-by: Gjm <你的邮箱>
2026-05-13 10:55:59 +08:00
3 changed files with 40 additions and 19 deletions

View File

@@ -1876,70 +1876,94 @@ public class DeviceServiceImpl implements IDeviceService {
private long deleteDeviceLogBatch(Date cutoffDate) {
long totalDeleted = 0;
int batchSize = 5000;
int batchSize = 1000;
int batchCount = 0;
while (true) {
int deleted = deviceMapper.deleteDeviceLogBatch(cutoffDate, batchSize);
totalDeleted += deleted;
batchCount++;
if (batchCount % 10 == 0) {
log.info("设备日志已删除{}批,累计删除:{}条", batchCount, totalDeleted);
}
if (deleted == 0) {
break;
}
try {
Thread.sleep(100);
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.warn("设备日志删除任务被中断");
break;
}
}
log.info("设备日志删除完成,共{}批,总计删除:{}条", batchCount, totalDeleted);
return totalDeleted;
}
private long deleteEventLogBatch(Date cutoffDate) {
long totalDeleted = 0;
int batchSize = 5000;
int batchSize = 1000;
int batchCount = 0;
while (true) {
int deleted = deviceMapper.deleteEventLogBatch(cutoffDate, batchSize);
totalDeleted += deleted;
batchCount++;
if (batchCount % 10 == 0) {
log.info("事件日志已删除{}批,累计删除:{}条", batchCount, totalDeleted);
}
if (deleted == 0) {
break;
}
try {
Thread.sleep(100);
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.warn("事件日志删除任务被中断");
break;
}
}
log.info("事件日志删除完成,共{}批,总计删除:{}条", batchCount, totalDeleted);
return totalDeleted;
}
private long deleteFunctionLogBatch(Date cutoffDate) {
long totalDeleted = 0;
int batchSize = 5000;
int batchSize = 1000;
int batchCount = 0;
while (true) {
int deleted = deviceMapper.deleteFunctionLogBatch(cutoffDate, batchSize);
totalDeleted += deleted;
batchCount++;
if (batchCount % 10 == 0) {
log.info("告警日志已删除{}批,累计删除:{}条", batchCount, totalDeleted);
}
if (deleted == 0) {
break;
}
try {
Thread.sleep(100);
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
log.warn("告警日志删除任务被中断");
break;
}
}
log.info("告警日志删除完成,共{}批,总计删除:{}条", batchCount, totalDeleted);
return totalDeleted;
}
}

View File

@@ -73,18 +73,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="deviceLogList" resultType="iot.lidee.iot.domain.DeviceLog">
SELECT
*
FROM (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY identity ORDER BY create_time DESC) AS rn
FROM
iot_device_log
WHERE
serial_number = #{serialNumber}
) t
WHERE rn = 1
SELECT l1.*
FROM iot_device_log l1
INNER JOIN (
SELECT identity, MAX(create_time) AS max_time
FROM iot_device_log
WHERE serial_number = #{serialNumber}
GROUP BY identity
) l2 ON l1.identity = l2.identity AND l1.create_time = l2.max_time
WHERE l1.serial_number = #{serialNumber};
</select>
</mapper>

View File

@@ -976,7 +976,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<delete id="deleteEventLogBatch">
DELETE FROM iot_event log
DELETE FROM iot_event_log
WHERE create_time &lt; #{cutoffDate}
LIMIT #{batchSize}
</delete>