package com.upchina.app.schedule; import com.upchina.app.service.OrderSyncService; import com.upchina.common.config.cache.CacheKey; import com.upchina.common.service.CacheService; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.concurrent.TimeUnit; @Component public class AppTask { @Resource private CacheService cacheService; @Resource private OrderSyncService orderSyncService; /** * 拉取云端视频转码状态 */ @Scheduled(cron = "${cron.syncAppOrderRecent}") public void syncAppOrder() { cacheService.lock(CacheKey.LockKey.SYNC_APP_ORDER, 0, TimeUnit.SECONDS, 4, TimeUnit.MINUTES, () -> { LocalDateTime now = LocalDateTime.now(); LocalDateTime startTime = now.plusDays(-1); orderSyncService.syncAppOrder(startTime, now); } ); } @Scheduled(cron = "${cron.syncAppOrderHistory}") public void saveWatchSeconds() { cacheService.lock(CacheKey.LockKey.SYNC_APP_ORDER, 0, TimeUnit.SECONDS, 4, TimeUnit.MINUTES, () -> { LocalDateTime now = LocalDateTime.now(); LocalDateTime startTime = now.plusDays(-7); LocalDateTime endTime = now.plusDays(-1); orderSyncService.syncAppOrder(startTime, endTime); } ); } }