|
@@ -0,0 +1,50 @@
|
|
|
|
|
+package com.fs.app.task;
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
|
|
+import com.fs.gtPush.domain.UniPushLog;
|
|
|
|
|
+import com.fs.gtPush.mapper.PushLogMapper;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Date;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @description: App定时任务
|
|
|
|
|
+ * @author: Xgb
|
|
|
|
|
+ * @createDate: 2026/5/13
|
|
|
|
|
+ * @version: 1.0
|
|
|
|
|
+ */
|
|
|
|
|
+@Component("appTask")
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class AppTask {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PushLogMapper pushLogMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Scheduled(cron = "0 0 2 * * ?")
|
|
|
|
|
+ public void deleteUniPushLog() {
|
|
|
|
|
+ Date expireDate = DateUtils.addDays(new Date(), -30);
|
|
|
|
|
+ int batchSize = 1000;
|
|
|
|
|
+ int totalDelete = 0;
|
|
|
|
|
+ int deleted;
|
|
|
|
|
+ do {
|
|
|
|
|
+ LambdaQueryWrapper<UniPushLog> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.lt(UniPushLog::getCreateTime, expireDate);
|
|
|
|
|
+ wrapper.last("LIMIT " + batchSize);
|
|
|
|
|
+ deleted = pushLogMapper.delete(wrapper);
|
|
|
|
|
+ totalDelete += deleted;
|
|
|
|
|
+ if (deleted > 0) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(200);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } while (deleted == batchSize);
|
|
|
|
|
+ log.info("定时删除uni_push_log记录,保留最近30天数据,共删除 {} 条", totalDelete);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|