package cn.com.ctop.job.kuaishou.handler;

import cn.com.ctop.common.module.utils.HttpUtils;
import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouAdvertiserStrategyService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
@Slf4j
public class KuaishouAccountAutoCreativeJob {

    @Value("${xxl-job.requestUrl}")
    private String jobUrl;

    @Autowired
    private IAiKuaishouAdvertiserStrategyService strategyService;


    /**
     * 自动投放账户_素材清洗
     */
    @XxlJob("kuaishouAccountAutoVideos")
    public void kuaishouAccountAutoVideos() {
        List<Long> accountIds = strategyService.getKuaishouAccountAutoStrategy();
        if (null == accountIds || accountIds.isEmpty()) {
            return;
        }
        log.info("自动投放账户_开始清洗素材");
        accountIds.forEach(accountId -> {
            String url = jobUrl + "/jeecg-boot/auto/aiKuaishouAccountAutoVideo/insertAutoVideo?accountId=" + accountId;
            HttpUtils.httpGet(url, null, null);
        });
    }

    /**
     * 创建自定义上新广告创意 、频率 20分钟/次
     */

    @XxlJob("autoCreateCustomUpNewCreative")
    public void createCustomUpNewCreative() {
        List<Long> ids = strategyService.getKuaishouAccountAutoStrategyIds();
        if (null == ids || ids.isEmpty()) {
            return;
        }
        ids.forEach(id -> {
            String url = jobUrl + "/jeecg-boot/auto/create/createCustomUpNewCreative?id=" + id;
            HttpUtils.httpGet(url, null, null);
        });
    }

    /**
     * 创建自定义非上新广告创意 、频率 60分钟/次
     */
    @XxlJob("autoCreateCustomCreative")
    public void createCustomCreative() {
        List<Long> ids = strategyService.getKuaishouAccountAutoStrategyIds();
        if (null == ids || ids.isEmpty()) {
            return;
        }
        ids.forEach(id -> {
            String url = jobUrl + "/jeecg-boot/auto/create/createCustomCreative?id=" + id;
            HttpUtils.httpGet(url, null, null);
        });
    }

    /**
     * 创建程序化广告创意 频率 60分钟/次
     */
    @XxlJob("autoCreateProgramCreative")
    public void createProgramCreative() {
        List<Long> ids = strategyService.getKuaishouAccountAutoStrategyIds();
        if (null == ids || ids.isEmpty()) {
            return;
        }
        ids.forEach(id -> {
            String url = jobUrl + "/jeecg-boot/auto/create/createProgramCreative?id=" + id;
            HttpUtils.httpGet(url, null, null);
        });
    }

    /**
     * 每日补充创建创意 、频率 每天22点05分钟执行1次
     */
    @XxlJob("aotoSupplementCreatives")
    public void aotoSupplementCreatives() {
        List<Long> ids = strategyService.getKuaishouAccountAutoStrategyIds();
        if (null == ids || ids.isEmpty()) {
            return;
        }
        ids.forEach(id -> {
            String url = jobUrl + "/jeecg-boot/auto/create/supplementTodayCreatives?id=" + id;
            HttpUtils.httpGet(url, null, null);
        });
    }

}
