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

import cn.com.ctop.common.module.entity.CtopOauthToken;
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
import cn.com.ctop.common.module.utils.CtopAdConstant;
import cn.com.ctop.toutiao.modules.material.service.IByteDanceCreativeService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.jeecg.common.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
public class BytedanceSameDayCreativeLoadJob {
    @Autowired
    private ICtopOauthTokenService tokenService;
    static ExecutorService executorService = Executors.newFixedThreadPool(6);
    @Autowired
    private IByteDanceCreativeService byteDanceCreativeService;

    /**
     * 头条当日实时创意数据
     * @throws Exception
     */
    @XxlJob("bytedanceSameDayCreative")
    public void execute() throws Exception {
        List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
        String getDateStr = DateUtils.formatDate(new Date());
        tokens.forEach(token -> executorService.submit(() -> byteDanceCreativeService.getAdvertiserCreative(token, null,getDateStr)));
    }
}
