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); } 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> 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); } 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("生产日志移动任务结束"); } }