feat(statistics): 添加当日数据Redis缓存并调整定时任务时间

- 在AppStatisticsServiceImpl中实现当日数据的Redis缓存机制
- 仅对实时查询且查询日期为当天的数据进行缓存
- 设置缓存时间为60秒以减少实时查询压力
- 将历史数据查询与实时数据查询分离
- 调整ScenicStatsTask定时任务执行时间
- 添加每日凌晨3点执行的任务配置
- 新增每天0点1分执行的统计任务调度
This commit is contained in:
2026-02-05 01:05:56 +08:00
parent 6c330764ea
commit a85d6b0ead
2 changed files with 11 additions and 1 deletions

View File

@@ -273,6 +273,15 @@ public class AppStatisticsServiceImpl implements AppStatisticsService {
vo.setPayOfOrderAmount(payOfOrderAmount.setScale(2, RoundingMode.HALF_UP));
vo.setRefundOfOrderNum(refundOfOrderNum);
vo.setRefundOfOrderAmount(refundOfOrderAmount.setScale(2, RoundingMode.HALF_UP));
// 仅对当天数据启用 Redis 缓存(短期缓存,减少实时查询压力)
// 历史数据已在 scenic_stats 表中持久化,不需要 Redis 缓存
if (!query.isRealtime() && query.getStartTime() != null) {
// 判断查询日期是否为今天
if (DateUtil.isSameDay(query.getStartTime(), new Date())) {
redisTemplate.opsForValue().set(redisKey, JacksonUtil.toJSONString(vo), 60, TimeUnit.SECONDS);
}
}
return ApiResponse.success(vo);
} finally {
lock.unlock();

View File

@@ -60,7 +60,8 @@ public class ScenicStatsTask {
});
}
}
@Scheduled(cron = "0 0 2 * * *")
@Scheduled(cron = "0 0 3 * * *")
@Scheduled(cron = "0 1 0 * * *")
public void countScenicStats() {
log.info("开始执行景区统计任务,统计前7天至昨天的数据");