|
|
@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalTime; |
|
|
@ -35,6 +36,7 @@ public class StatisticsServiceImpl implements StatisticsService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
// @Scheduled(cron = "0 4 * * * ?") // 每小时执行一次 |
|
|
|
@Transactional(rollbackFor = Exception.class) // 1. 开启事务 |
|
|
|
public void runHourlyTaskPart1() { |
|
|
|
LocalDate today = LocalDate.now(); //取当天日期 |
|
|
|
List<Statistics> list = statisticsMapper.listPart1All(today); |
|
|
@ -42,6 +44,8 @@ public class StatisticsServiceImpl implements StatisticsService { |
|
|
|
if (!list.isEmpty()) { |
|
|
|
statisticsMapper.batchInsertPart1(list); |
|
|
|
} |
|
|
|
// 2. 日志验证连接已归还 |
|
|
|
log.info("=== Part1 done, tx commit, connection will be closed by Spring ==="); |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
@ -49,6 +53,7 @@ public class StatisticsServiceImpl implements StatisticsService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
//@Scheduled(cron = "0 8 * * * ?") // 每小时执行一次 |
|
|
|
@Transactional(rollbackFor = Exception.class) // 1. 开启事务 |
|
|
|
public void runHourlyTaskPart2() { |
|
|
|
//设定起止时间 当天00:00:00至23:59:59 |
|
|
|
LocalDate today = LocalDate.now(); |
|
|
@ -61,6 +66,9 @@ public class StatisticsServiceImpl implements StatisticsService { |
|
|
|
if (!list.isEmpty()) { |
|
|
|
statisticsMapper.batchInsertPart2(list); |
|
|
|
} |
|
|
|
// 2. 日志验证连接已归还 |
|
|
|
log.info("=== Part1 done, tx commit, connection will be closed by Spring ==="); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
@ -69,6 +77,7 @@ public class StatisticsServiceImpl implements StatisticsService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
//@Scheduled(cron = "0 12 * * * ?") // 每小时执行一次 |
|
|
|
@Transactional(rollbackFor = Exception.class) // 1. 开启事务 |
|
|
|
public void runHourlyTaskYear() { |
|
|
|
LocalDate today = LocalDate.now(); |
|
|
|
LocalDate firstDay = today.withDayOfYear(1); |
|
|
@ -81,6 +90,9 @@ public class StatisticsServiceImpl implements StatisticsService { |
|
|
|
if (!list.isEmpty()) { |
|
|
|
statisticsMapper.batchInsertYear(list); |
|
|
|
} |
|
|
|
// 2. 日志验证连接已归还 |
|
|
|
log.info("=== Part1 done, tx commit, connection will be closed by Spring ==="); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@ -89,11 +101,15 @@ public class StatisticsServiceImpl implements StatisticsService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
//@Scheduled(cron = "0 30 0 * * ?") // 修改为每天 00:30 执行 |
|
|
|
@Transactional(rollbackFor = Exception.class) // 1. 开启事务 |
|
|
|
public void runDailyTaskPart2() { |
|
|
|
List<Statistics> list = statisticsMapper.listPart2RangeAll(); |
|
|
|
if (!list.isEmpty()) { |
|
|
|
statisticsMapper.batchInsertPart2(list); |
|
|
|
} |
|
|
|
// 2. 日志验证连接已归还 |
|
|
|
log.info("=== Part1 done, tx commit, connection will be closed by Spring ==="); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |