package top.baogutang.admin.schedule;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.baogutang.admin.services.IScriptService;

import javax.annotation.Resource;

/**
 * @description: 脚本schedule
 * @author: nikooh
 * @date: 2023/10/12 : 15:30
 */
@Slf4j
@Component
@RefreshScope
public class ScriptSchedule {


    @Value("${baogutang.script.switch:false}")
    private Boolean scriptExecSwitch;
    @Resource
    private IScriptService scriptService;

    /**
     * 每天11:50执行京东抢购茅台脚本
     */
    @Scheduled(cron = "0 50 11 * * ?")
    public void maoTaiScript() {
        if (!Boolean.TRUE.equals(scriptExecSwitch)) {
            log.warn(">>>>>>>>>>scriptExecSwitch closed!<<<<<<<<<<");
            return;
        }
        log.info(">>>>>>>>>>schedule start exec maoTai script<<<<<<<<<<<");
        scriptService.execPython("/usr/local/scripts/10-13MaoTai/main.py");
        log.info(">>>>>>>>>>schedule exec maoTai script end<<<<<<<<<<");
    }
}
