package com.reptileclient.jlifeapp.schedule;


import com.reptileclient.jlifeapp.service.HMClueSyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Async
@Slf4j
@Component
public class HMClueSyncTask {


    @Autowired
    private HMClueSyncService hmClueSyncService;
    @Value("${spring.profiles.active}")
    private String env;

    @Scheduled(cron = "0 0 0,2,4,6,8,10,12,14,16,18,20,22 * * ?")
//    @PostConstruct //启动先执行一次
    public void runTask() {
        log.info("开始同步盒马线索信息");
        if ("pro".equals(env)) {
            hmClueSyncService.syncClue();
        } else {
            log.info("非生产环境，不进行同步！");
        }
        log.info("结束同步盒马线索信息");
    }

    public void startJob() {
        if (LocalDateTime.now().getHour() % 2 != 0) return;
        log.info("开始同步盒马线索信息");
        hmClueSyncService.syncClue();
        log.info("结束同步盒马线索信息");
    }
}
