package org.ts.ddcs.Job;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component
@Configuration
@Data
public class XxlJobConfig {

    @Value("${run-config.job.xxl.job.admin.addresses}")
    private String adminAddresses;

    @Value("${run-config.job.xxl.job.executor.appname}")
    private String appName;

    @Value("${run-config.job.xxl.job.executor.ip}")
    private String ip;

    @Value("${run-config.job.xxl.job.executor.port}")
    private int port;

    @Value("${run-config.job.xxl.job.accessToken}")
    private String accessToken;

    @Value("${run-config.job.xxl.job.executor.logpath}")
    private String logPath;

    @Value("${run-config.job.xxl.job.executor.logretentiondays}")
    private int logRetentionDays;


    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appName);
        xxlJobSpringExecutor.setIp(ip);
        xxlJobSpringExecutor.setPort(port);
        xxlJobSpringExecutor.setAccessToken(accessToken);
        xxlJobSpringExecutor.setLogPath(logPath);
        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
        return xxlJobSpringExecutor;
    }
}
