package com.reptileclient.jlifeapp.schedule;


import com.reptileclient.jlifeapp.service.DyLaikeService;
import com.reptileclient.jlifeapp.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
public class DouyinLaikeTask {

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


    @Autowired
    private DyLaikeService dyLaikeService;

    private static String runDate;

    //一天一次
    public void startJob() {
        try {
            if (LocalDateTime.now().getHour() == 8 && StringUtils.isNotEmpty(runDate) && runDate.equals(DateUtils.getCurrentDay()))
                return;
            runDate = DateUtils.getCurrentDay();

            log.info("开始获取抖音来客门店评价信息");
            dyLaikeService.getReviewData();
            log.info("结束获取抖音来客门店评价信息");

            log.info("开始获取抖音来客门店违规三率信息");
            dyLaikeService.getThreeRate();
            log.info("结束获取抖音来客门店违规三率信息");
        } catch (Exception ex) {
            log.error("获取抖来客数据错误{}", ex);
        }
    }

    @Scheduled(cron = "0 30 8 * * ?")
    public void runTask() {
        log.info("开始获取抖音来客门店评价信息");
        dyLaikeService.getReviewData();
        log.info("结束获取抖音来客门店评价信息");
    }

    @Scheduled(cron = "0 10 9 ? * WED")
    public void queryThreeRate() {
        log.info("开始获取抖音来客门店违规三率信息");
        dyLaikeService.getThreeRate();
        log.info("结束获取抖音来客门店违规三率信息");
    }
}
