From 7bda866ed5537738f8c6ee544bd680a7429ba210 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期一, 23 九月 2024 15:18:22 +0800
Subject: [PATCH] #

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/LogDataScheduler.java |   48 ++++++++++++++++++++++++++----------------------
 1 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/LogDataScheduler.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/LogDataScheduler.java
index 07edcc0..dd49e48 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/LogDataScheduler.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/scheduler/LogDataScheduler.java
@@ -1,11 +1,14 @@
 package com.zy.acs.manager.core.scheduler;
 
+import com.zy.acs.manager.system.service.ConfigService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Optional;
 
 /**
  * Created by vincent on 5/8/2024
@@ -15,31 +18,32 @@
 @SuppressWarnings("all")
 public class LogDataScheduler {
 
-    public static final Integer EXPIRED_DAYS = 7;
-
     @Autowired
     private JdbcTemplate jdbcTemplate;
+    @Autowired
+    private ConfigService configService;
 
     @Scheduled(cron = "0 0 1 * * ?")
     @Transactional
     public void syncLog() {
-        this.syncTaskLog();
-        this.syncActionLog();
-        this.syncSegmentLog();
-        this.syncJamLog();
-        this.syncTravelLog();
+        Integer dataExpiredDays = Optional.ofNullable(configService.getVal("dataExpiredDays", Integer.class)).orElse(7);
+        this.syncTaskLog(dataExpiredDays);
+        this.syncActionLog(dataExpiredDays);
+        this.syncSegmentLog(dataExpiredDays);
+        this.syncJamLog(dataExpiredDays);
+        this.syncTravelLog(dataExpiredDays);
     }
 
-    public void syncTaskLog(){
+    public void syncTaskLog(Integer dataExpiredDays){
         try {
             String insertSql = "INSERT INTO man_task_log " +
                     "SELECT * FROM man_task " +
-                    "WHERE create_time < NOW() - INTERVAL "+ EXPIRED_DAYS +" DAY";
+                    "WHERE create_time < NOW() - INTERVAL "+ dataExpiredDays +" DAY";
             int rowsInserted = jdbcTemplate.update(insertSql);
             log.info("Inserted {} rows into man_task_log", rowsInserted);
 
             String deleteSql = "DELETE FROM man_task " +
-                    "WHERE create_time < NOW() - INTERVAL "+ EXPIRED_DAYS +" DAY";
+                    "WHERE create_time < NOW() - INTERVAL "+ dataExpiredDays +" DAY";
             int rowsDeleted = jdbcTemplate.update(deleteSql);
             log.info("Deleted {} rows from man_task", rowsDeleted);
 
@@ -50,16 +54,16 @@
     }
 
 
-    public void syncActionLog(){
+    public void syncActionLog(Integer dataExpiredDays){
         try {
             String insertSql = "INSERT INTO man_action_log " +
                     "SELECT * FROM man_action " +
-                    "WHERE create_time < NOW() - INTERVAL "+ EXPIRED_DAYS +" DAY";
+                    "WHERE create_time < NOW() - INTERVAL "+ dataExpiredDays +" DAY";
             int rowsInserted = jdbcTemplate.update(insertSql);
             log.info("Inserted {} rows into man_action_log", rowsInserted);
 
             String deleteSql = "DELETE FROM man_action " +
-                    "WHERE create_time < NOW() - INTERVAL "+ EXPIRED_DAYS +" DAY";
+                    "WHERE create_time < NOW() - INTERVAL "+ dataExpiredDays +" DAY";
             int rowsDeleted = jdbcTemplate.update(deleteSql);
             log.info("Deleted {} rows from man_action", rowsDeleted);
 
@@ -69,16 +73,16 @@
         }
     }
 
-    public void syncSegmentLog(){
+    public void syncSegmentLog(Integer dataExpiredDays){
         try {
             String insertSql = "INSERT INTO man_segment_log " +
                     "SELECT * FROM man_segment " +
-                    "WHERE create_time < NOW() - INTERVAL "+ EXPIRED_DAYS +" DAY";
+                    "WHERE create_time < NOW() - INTERVAL "+ dataExpiredDays +" DAY";
             int rowsInserted = jdbcTemplate.update(insertSql);
             log.info("Inserted {} rows into man_segment_log", rowsInserted);
 
             String deleteSql = "DELETE FROM man_segment " +
-                    "WHERE create_time < NOW() - INTERVAL "+ EXPIRED_DAYS +" DAY";
+                    "WHERE create_time < NOW() - INTERVAL "+ dataExpiredDays +" DAY";
             int rowsDeleted = jdbcTemplate.update(deleteSql);
             log.info("Deleted {} rows from man_segment", rowsDeleted);
 
@@ -88,16 +92,16 @@
         }
     }
 
-    public void syncJamLog(){
+    public void syncJamLog(Integer dataExpiredDays){
         try {
             String insertSql = "INSERT INTO man_jam_log " +
                     "SELECT * FROM man_jam " +
-                    "WHERE create_time < NOW() - INTERVAL "+ EXPIRED_DAYS +" DAY";
+                    "WHERE create_time < NOW() - INTERVAL "+ dataExpiredDays +" DAY";
             int rowsInserted = jdbcTemplate.update(insertSql);
             log.info("Inserted {} rows into man_jam_log", rowsInserted);
 
             String deleteSql = "DELETE FROM man_jam " +
-                    "WHERE create_time < NOW() - INTERVAL "+ EXPIRED_DAYS +" DAY";
+                    "WHERE create_time < NOW() - INTERVAL "+ dataExpiredDays +" DAY";
             int rowsDeleted = jdbcTemplate.update(deleteSql);
             log.info("Deleted {} rows from man_jam", rowsDeleted);
 
@@ -107,16 +111,16 @@
         }
     }
 
-    public void syncTravelLog(){
+    public void syncTravelLog(Integer dataExpiredDays){
         try {
             String insertSql = "INSERT INTO man_travel_log " +
                     "SELECT * FROM man_travel " +
-                    "WHERE create_time < NOW() - INTERVAL "+ EXPIRED_DAYS +" DAY";
+                    "WHERE create_time < NOW() - INTERVAL "+ dataExpiredDays +" DAY";
             int rowsInserted = jdbcTemplate.update(insertSql);
             log.info("Inserted {} rows into man_travel_log", rowsInserted);
 
             String deleteSql = "DELETE FROM man_travel " +
-                    "WHERE create_time < NOW() - INTERVAL "+ EXPIRED_DAYS +" DAY";
+                    "WHERE create_time < NOW() - INTERVAL "+ dataExpiredDays +" DAY";
             int rowsDeleted = jdbcTemplate.update(deleteSql);
             log.info("Deleted {} rows from man_travel", rowsDeleted);
 

--
Gitblit v1.9.1