package com.friday.custody.config;

import com.friday.custody.quartz.*;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {
    @Value("${custody.quartz.initHtscDataByScheduled.cron}")//"0 0 16 * * ?"
    private String initHtscDataByScheduledCron;
    @Value("${custody.quartz.updateDataDailyByScheduled.cron}")//" 0 0 7,19 * * ?"
    private String updateDataDailyByScheduledCron;
    @Value("${custody.quartz.updateDataCJDailyByScheduled.cron}")//" 0 0 7,19 * * ?"
    private String updateDataCJDailyByScheduledCron;
    @Value("${custody.quartz.PullRemoteDataFirstQueueJob.cron}")//"0 0/10 * * * ?"
    private String PullRemoteDataFirstQueueJobCron;
    @Value("${custody.quartz.updateData20min.cron}")//"0 0/20 * * * ?"
    private String updateData20minCorn;
    @Value("${custody.quartz.updateZhongXinDataDailyByScheduled.cron}")//"0 0 0,12 * * ?"
    private String updateZhongXinDataDailyCorn;
    @Value("${custody.quartz.updateSWDataDailyByScheduled.cron}")//"0 0 0,12 * * ?"
    private String updateSWDataDailyCorn;
    @Value("${custody.quartz.updateData1h.cron}")
    private String updateData1hCron;
    @Value("${custody.quartz.updateDataDicZxFndBasicInfoCyByScheduled.cron}")
    private String updateDataDicZxCron;
    @Value("${custody.quartz.updateDataZxByScheduled.cron}")
    private String updateDataZxCron;
    @Value("${custody.quartz.updateNetValueDataByScheduled.cron}")
    private String updateNetValueDataCron;
    @Value("${custody.quartz.updateZhongxTotalAssetByScheduled.cron}")
    private String updateZhongxTotalAssetCron;
    @Value("${custody.quartz.updateSWMgDataDailyByScheduled.cron}")
    private String updateSWMgDataDailyCron;
    @Value("${custody.quartz.updateTongyiCron.cron}")
    private String updateTongyiCron;
    @Value("${custody.quartz.updateGJDFCron.cron}")
    private String updateGJDFCron;
    @Value("${custody.quartz.syncZXData.cron}")
    private String syncZXDataCron;

    @Bean
    public JobDetail doInitHtscDataByScheduledJob() {
        return JobBuilder.newJob(InitHtscDataByScheduledJob.class).withIdentity("InitHtscDataByScheduledJob", "InitHtscDataByScheduledJob").storeDurably().build();
    }

    @Bean
    public Trigger doInitHtscDataByScheduledJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(initHtscDataByScheduledCron);
        return TriggerBuilder.newTrigger().forJob(doInitHtscDataByScheduledJob())
                .withIdentity("InitHtscDataByScheduledJob", "InitHtscDataByScheduledJob")
                .withSchedule(scheduleBuilder)
                .build();
    }


    @Bean
    public JobDetail doUpdateDataDailyByScheduledJob() {
        return JobBuilder.newJob(UpdateDataDailyByScheduledJob.class).withIdentity("UpdateDataDailyByScheduledJob", "UpdateDataDailyByScheduledJob").storeDurably().build();
    }

    @Bean
    public Trigger doUpdateDataDailyByScheduledJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateDataDailyByScheduledCron);
        return TriggerBuilder.newTrigger().forJob(doUpdateDataDailyByScheduledJob())
                .withIdentity("UpdateDataDailyByScheduledJob", "UpdateDataDailyByScheduledJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail doUpdateDataCJDailyByScheduledJob() {
        return JobBuilder.newJob(UpdateDataCJDailyByScheduledJob.class).withIdentity("UpdateDataCJDailyByScheduledJob", "UpdateDataCJDailyByScheduledJob").storeDurably().build();
    }

    @Bean
    public Trigger doUpdateDataCJDailyByScheduledJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateDataCJDailyByScheduledCron);
        return TriggerBuilder.newTrigger().forJob(doUpdateDataCJDailyByScheduledJob())
                .withIdentity("UpdateDataCJDailyByScheduledJob", "UpdateDataCJDailyByScheduledJob")
                .withSchedule(scheduleBuilder)
                .build();
    }


    @Bean
    public JobDetail doPullRemoteDataFirstQueueFJob() {
        return JobBuilder.newJob(PullRemoteDataFirstQueueJob.class).withIdentity("PullRemoteDataFirstQueueJob", "PullRemoteDataFirstQueueJob").storeDurably().build();
    }

    @Bean
    public Trigger doPullRemoteDataFirstQueueJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(PullRemoteDataFirstQueueJobCron);
        return TriggerBuilder.newTrigger().forJob(doPullRemoteDataFirstQueueFJob())
                .withIdentity("PullRemoteDataFirstQueueJob", "PullRemoteDataFirstQueueJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail doUpdateData20minJob() {
        return JobBuilder.newJob(UpdateData20minJob.class).withIdentity("UpdateData20minJob", "UpdateData20minJob").storeDurably().build();
    }

    @Bean
    public Trigger doUpdateData20minJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateData20minCorn);
        return TriggerBuilder.newTrigger().forJob(doUpdateData20minJob())
                .withIdentity("UpdateData20minJob", "UpdateData20minJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail doUpdateZhongXinDataDailyJob() {
        return JobBuilder.newJob(UpdateZhongxinDataDailyByScheduledJob.class).withIdentity("UpdateZhongXinDataDailyJob", "UpdateZhongXinDataDailyJob").storeDurably().build();
    }

    @Bean
    public Trigger doUpdateZhongXinDataDailyJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateZhongXinDataDailyCorn);
        return TriggerBuilder.newTrigger().forJob(doUpdateZhongXinDataDailyJob())
                .withIdentity("UpdateZhongXinDataDailyJob", "UpdateZhongXinDataDailyJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail doUpdateSWDataDailyJob() {
        return JobBuilder.newJob(UpdateSWDataDailyByScheduledJob.class).withIdentity("UpdateSWDataDailyJob", "UpdateSWDataDailyJob").storeDurably().build();
    }
    @Bean
    public Trigger doUpdateSWDataDailyJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateSWDataDailyCorn);
        return TriggerBuilder.newTrigger().forJob(doUpdateSWDataDailyJob())
                .withIdentity("UpdateSWDataDailyJob", "UpdateSWDataDailyJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail doUpdateData1hJob() {
        return JobBuilder.newJob(UpdateData1hJob.class).withIdentity("UpdateData1hJob", "UpdateData1hJob").storeDurably().build();
    }

    @Bean
    public Trigger doUpdateData1hJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateData1hCron);
        return TriggerBuilder.newTrigger().forJob(doUpdateData1hJob())
                .withIdentity("UpdateData1hJob", "UpdateData1hJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail doUpdateDataDicZxJob() {
        return JobBuilder.newJob(UpdateDataDicZxFndBasicInfoCyJob.class)
                .withIdentity("UpdateDataDicZxFndBasicInfoCyJob", "UpdateDataDicZxFndBasicInfoCyJob")
                .storeDurably().build();
    }
    @Bean
    public Trigger doUpdateDataDicZxJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateDataDicZxCron);
        return TriggerBuilder.newTrigger().forJob(doUpdateDataDicZxJob())
                .withIdentity("UpdateDataDicZxFndBasicInfoCyJob", "UpdateDataDicZxFndBasicInfoCyJob")
                .withSchedule(scheduleBuilder)
                .build();
    }
    @Bean
    public JobDetail doUpdateDataZxJob() {
        return JobBuilder.newJob(UpdateDataZxJob.class)
                .withIdentity("UpdateDataZxJob", "UpdateDataZxJob")
                .storeDurably().build();
    }
    @Bean
    public Trigger doUpdateDataUpdateDicZxJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateDataZxCron);
        return TriggerBuilder.newTrigger().forJob(doUpdateDataZxJob())
                .withIdentity("UpdateDataZxJob", "UpdateDataZxJob")
                .withSchedule(scheduleBuilder)
                .build();
    }
    @Bean
    public JobDetail doUpdateNetValueJob() {
        return JobBuilder.newJob(UpdateNetValueDataJob.class)
                .withIdentity("UpdateNetValueDataJob", "UpdateNetValueDataJob")
                .storeDurably().build();
    }
    @Bean
    public Trigger doUpdateNetValueJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateNetValueDataCron);
        return TriggerBuilder.newTrigger().forJob(doUpdateNetValueJob())
                .withIdentity("UpdateNetValueDataJob", "UpdateNetValueDataJob")
                .withSchedule(scheduleBuilder)
                .build();
    }
    @Bean
    public JobDetail doUpdateZhongxTotalAssetJob() {
        return JobBuilder.newJob(UpdateZhongxToatlAssetJob.class)
                .withIdentity("UpdateZhongxToatlAssetJob", "UpdateZhongxToatlAssetJob")
                .storeDurably().build();
    }
    @Bean
    public Trigger doUpdateZhongxTotalAssetJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateZhongxTotalAssetCron);
        return TriggerBuilder.newTrigger().forJob(doUpdateZhongxTotalAssetJob())
                .withIdentity("UpdateZhongxToatlAssetJob", "UpdateZhongxToatlAssetJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail doUpdateSWMgDataDailyJob() {
        return JobBuilder.newJob(UpdateSWMgDataDailyJob.class)
                .withIdentity("UpdateSWMgDataDailyJob", "UpdateSWMgDataDailyJob")
                .storeDurably().build();
    }
    @Bean
    public Trigger doUpdateSWMgDataDailyJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateSWMgDataDailyCron);
        return TriggerBuilder.newTrigger().forJob(doUpdateSWMgDataDailyJob())
                .withIdentity("UpdateSWMgDataDailyJob", "UpdateSWMgDataDailyJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    /**
     * 每天八点半更新通怡数据到临时表
     * @return
     */
    @Bean
    public JobDetail doUpdateTongyiJob() {
        return JobBuilder.newJob(UpdateTongyiJob.class)
                .withIdentity("UpdateTongyiJob", "UpdateTongyiJob")
                .storeDurably().build();
    }
    @Bean
    public Trigger doUpdateTongyiJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateTongyiCron);
        return TriggerBuilder.newTrigger().forJob(doUpdateTongyiJob())
                .withIdentity("UpdateTongyiJob", "UpdateTongyiJob")
                .withSchedule(scheduleBuilder)
                .build();
    }
    /**
     * 每天 点更新国金道富数据
     * @return
     */
    @Bean
    public JobDetail doUpdateGJDFJob() {
        return JobBuilder.newJob(UpdateGJDFJob.class)
                .withIdentity("UpdateGJDFJob", "UpdateGJDFJob")
                .storeDurably().build();
    }
    @Bean
    public Trigger doUpdategjdfJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(updateGJDFCron);
        return TriggerBuilder.newTrigger().forJob(doUpdateGJDFJob())
                .withIdentity("UpdateGJDFJob", "UpdateGJDFJob")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail doSyncZXDataJob() {
        return JobBuilder.newJob(SyncZXDataJob.class)
                .withIdentity("SyncZXDataJob", "SyncZXDataJob")
                .storeDurably().build();
    }

    @Bean
    public Trigger doSyncZXDataJobTrigger() {
        CronScheduleBuilder scheduleBuilder;
        scheduleBuilder = CronScheduleBuilder.cronSchedule(syncZXDataCron);
        return TriggerBuilder.newTrigger().forJob(doSyncZXDataJob())
                .withIdentity("SyncZXDataJob", "SyncZXDataJob")
                .withSchedule(scheduleBuilder)
                .build();
    }
}
