package com.red.circle.game.fruit.application.scheduler;

import com.red.circle.component.redis.annotation.TaskCacheLock;
import com.red.circle.game.fruit.application.command.InitGameDataExe;
import com.red.circle.game.fruit.application.service.UserRankingService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 游戏运转定时任务
 *
 * @author lisizhe 2023/11/30  15:21
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class FruitGameRunningTask {

  private final InitGameDataExe initGameDataExe;
  private final UserRankingService userRankingService;

  /**
   * 一天一次,每天23点00分执行，游戏数据初始化
   */
  @Scheduled(cron = "0 00 23 * * ?", zone = "Asia/Shanghai")
  @TaskCacheLock(key = "GAME_FRUIT_INIT_DATA", expireSecond = 60 * 60)
//  @Scheduled(cron = "0 1-59 * * * ?", zone = "Asia/Shanghai")
  public void initGameData() {
    initGameDataExe.execute();
  }

  /**
   * 每30s执行一次
   */
   @Scheduled(cron = "0 1-30 * * * ?", zone = "Asia/Shanghai")
   @TaskCacheLock(key = "GAME_FRUIT_TEST_BET", expireSecond = 20)
  public void testBet() {
    userRankingService.testBet();
  }

}
