定时任务清理推送日志

This commit is contained in:
zhugongping 2026-09-19 17:14:37 +08:00
parent 3ef98ab448
commit 65abbabb3a
7 changed files with 26 additions and 1 deletions

View File

@ -8,7 +8,7 @@ TARGET_PORT = 8888 # 请根据实际情况修改
# 元数组 modbus 指令
MODBUS_DATA_HEX = (
"7e80D920B9A6DB717e",
"7e80DCDC9891706E7e",
"0103204135317841ab8e39bf27bccd3f1fb19ac2b231bbc0b6f82040ae3207c3f9f80efa23",
"020320413b9fa441acd34dc0024a003fa2a59ac2af34a0c18e17ea413167dbc3f9c7fe6d40",
"0303204139565641ab21ddbff6af333fe26800c2aec626c18685244176ee82c3f9bd7568c8",

View File

@ -1,5 +1,6 @@
package com.fastbee.web.task;
import com.fastbee.iot.platform.service.IPlatformPushLogService;
import com.fastbee.iot.service.IAlertLogService;
import com.fastbee.iot.service.IEventLogService;
import com.fastbee.notify.service.INotifyLogService;
@ -38,6 +39,9 @@ public class LogCleanTask {
@Autowired
private INotifyLogService notifyLogService;
@Autowired
private IPlatformPushLogService platformPushLogService;
// 之后还有清理的表往下写
/**
@ -79,6 +83,8 @@ public class LogCleanTask {
notifyLogService.cleanNotifyLog(days);
//log.info("已清理 notify_log 表 {} 天前的数据", days);
platformPushLogService.cleanPushLog(days);
log.info("========== 日志清理任务执行完成 ==========");
} catch (Exception e) {
log.error("日志清理任务执行失败", e);

View File

@ -4,6 +4,7 @@ import com.fastbee.common.annotation.Log;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.enums.BusinessType;
import com.fastbee.iot.platform.service.IPlatformPushLogService;
import com.fastbee.iot.service.IAlertLogService;
import com.fastbee.iot.service.IEventLogService;
import com.fastbee.notify.service.INotifyLogService;
@ -48,6 +49,9 @@ public class LogCleanController extends BaseController {
@Autowired
private INotifyLogService notifyLogService;
@Autowired
private IPlatformPushLogService platformPushLogService;
/**
* 清理日志数据
*
@ -86,6 +90,8 @@ public class LogCleanController extends BaseController {
// 清理通知日志
notifyLogService.cleanNotifyLog(days);
platformPushLogService.cleanPushLog(days);
logger.info("日志清理完成,保留最近 {} 天的记录", days);
return success(String.format("日志清理完成,已删除 %d 天前的历史数据", days));
} catch (Exception e) {

View File

@ -14,4 +14,5 @@ public interface PlatformPushLogMapper extends BaseMapperX<PlatformPushLog> {
void cleanPushLog();
void deletePushLogBeforeDays(int days);
}

View File

@ -23,4 +23,5 @@ public interface IPlatformPushLogService extends IService<PlatformPushLog> {
*/
void cleanPushLog();
void cleanPushLog(int days);
}

View File

@ -121,4 +121,9 @@ public class PlatformPushLogServiceImpl extends ServiceImpl<PlatformPushLogMappe
pushLogMapper.cleanPushLog();
}
@Override
public void cleanPushLog(int days) {
pushLogMapper.deletePushLogBeforeDays(days);
}
}

View File

@ -35,4 +35,10 @@
<update id="cleanPushLog">
truncate table platform_push_log
</update>
<delete id="deletePushLogBeforeDays">
DELETE FROM platform_push_log
WHERE create_time &lt; DATE_SUB(NOW(), INTERVAL #{days} DAY)
</delete>
</mapper>