package com.td.WaDa.game.complayerland.scheduled;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

//    private static String JOB_GROUP_NAME = "JOBGROUP_ComPlayerDisaster";
//    private static String TRIGGER_GROUP_NAME = "TRIGGERGROUP_ComPlayerDisaster";

    //private static String WeekTrigger = "0 0/1 * * * ?";
    //private static String DayTrigger = "0/5 * * * * ?";
    //每周日1点
    private static String WeekTrigger = "0 0 1 ? * SUN";
    //每天6点
    private static String DayTrigger = "0 0 6 * * ? *";

    @Bean
    public JobDetail syncDisasterWeekDetail() {
        JobDetail jobDetail = JobBuilder.newJob(ComPlayerDisasterWeekTask.class)
//                .withIdentity("syncUserJobDetail", JOB_GROUP_NAME)
                .storeDurably() //即使没有Trigger关联时，也不需要删除该JobDetail
                .build();
        return jobDetail;
    }

    @Bean
    public Trigger syncDisasterWeekTrigger() {
        //每隔5秒执行一次
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(WeekTrigger);

        //创建触发器
        Trigger trigger = TriggerBuilder.newTrigger()
                .forJob(syncDisasterWeekDetail())
//                .withIdentity("syncUserJobTrigger", TRIGGER_GROUP_NAME)
                .withSchedule(cronScheduleBuilder)
                .build();
        return trigger;
    }


    @Bean
    public JobDetail syncDisasterDayJobDetail() {
        JobDetail jobDetail = JobBuilder.newJob(ComPlayerDisasterDayTask.class)
//                .withIdentity("syncDisasterDayJobDetail", JOB_GROUP_NAME)
                .storeDurably()
                .build();
        return jobDetail;
    }

    @Bean
    public Trigger syncDisasterDayTrigger() {
        //每隔5秒执行一次
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(DayTrigger);

        //创建触发器
        Trigger trigger = TriggerBuilder.newTrigger()
                .forJob(syncDisasterDayJobDetail())
//                .withIdentity("syncDisasterDayTrigger", TRIGGER_GROUP_NAME)
                .withSchedule(cronScheduleBuilder)
                .build();
        return trigger;
    }
}
