From b5a3c0f6823d17d4acd97545cee3556a07f09865 Mon Sep 17 00:00:00 2001
From: 刘小明 <liuxm_a@163.com>
Date: 星期二, 03 九月 2024 10:56:23 +0800
Subject: [PATCH] 移动生产日志定时任务优化
---
pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoSta/StaDeviceProductionLogPastMapper.java | 2 ++
pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogPastMapper.xml | 4 ++++
pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/config/AppStartupRunner.java | 17 +++++++++++++++++
pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/task/LogMoveTask.java | 9 +++++----
4 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoSta/StaDeviceProductionLogPastMapper.java b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoSta/StaDeviceProductionLogPastMapper.java
index a59132e..f361f88 100644
--- a/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoSta/StaDeviceProductionLogPastMapper.java
+++ b/pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/daoSta/StaDeviceProductionLogPastMapper.java
@@ -17,5 +17,7 @@
StaDeviceProductionLogPast selectByPrimaryKey(Long id);
+ Long countLastDayLogs();
+
// void createNewTable(String newTableName);
}
diff --git a/pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogPastMapper.xml b/pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogPastMapper.xml
index c7ec6a1..18c924a 100644
--- a/pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogPastMapper.xml
+++ b/pms-parent/pms-global/src/main/resources/mapper/StaDeviceProductionLogPastMapper.xml
@@ -51,4 +51,8 @@
<delete id="deleteFromLogTable">
DELETE FROM sta_device_production_log WHERE DATE(out_time) != CURDATE();
</delete>
+
+ <select id="countLastDayLogs" resultType="_long">
+ SELECT COUNT(1) FROM sta_device_production_log WHERE DATE(out_time) != CURDATE();
+ </select>
</mapper>
diff --git a/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/config/AppStartupRunner.java b/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/config/AppStartupRunner.java
index cd9b256..6d8275a 100644
--- a/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/config/AppStartupRunner.java
+++ b/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/config/AppStartupRunner.java
@@ -1,15 +1,32 @@
package com.dy.pmsStation.config;
import com.dy.common.schedulerTask.SchedulerTaskSupport;
+import com.dy.pmsGlobal.daoSta.StaDeviceProductionLogPastMapper;
import com.dy.pmsStation.task.LogMoveTask;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
+@Slf4j
@Component
public class AppStartupRunner implements CommandLineRunner {
+
+ private StaDeviceProductionLogPastMapper pastMapper;
+ @Autowired
+ public void setPastMapper(StaDeviceProductionLogPastMapper pastMapper) {
+ this.pastMapper = pastMapper;
+ }
+
@Override
public void run(String... args) throws Exception {
+ //鏈嶅姟鍚姩鏃舵鏌ヤ笂娆′换鍔℃槸鍚﹀凡鎵ц
+ Long count = pastMapper.countLastDayLogs();
+ log.info("鏈Щ鍔ㄨ褰曟暟閲�:"+count);
+ if(count >0){
+ new LogMoveTask().execute(null);
+ }
SchedulerTaskSupport.addDailyJob("logMoveTask", "station", LogMoveTask.class,
null, 0, 5);
}
diff --git a/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/task/LogMoveTask.java b/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/task/LogMoveTask.java
index 2e20fd5..4a6d0a5 100644
--- a/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/task/LogMoveTask.java
+++ b/pms-parent/pms-web-station/src/main/java/com/dy/pmsStation/task/LogMoveTask.java
@@ -6,11 +6,9 @@
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
-import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
-@Component
public class LogMoveTask extends TaskJob {
@Override
@@ -18,8 +16,11 @@
public void execute(JobExecutionContext ctx) throws JobExecutionException {
log.info("鐢熶骇鏃ュ織绉诲姩浠诲姟寮�濮�");
StaDeviceProductionLogPastMapper pastMapper = SpringContextUtil.getBean(StaDeviceProductionLogPastMapper.class);
- pastMapper.insertIntoPastLogs();
- pastMapper.deleteFromLogTable();
+ Long count = pastMapper.countLastDayLogs();
+ if(count>0){
+ pastMapper.insertIntoPastLogs();
+ pastMapper.deleteFromLogTable();
+ }
log.info("鐢熶骇鏃ュ織绉诲姩浠诲姟缁撴潫");
}
}
--
Gitblit v1.8.0