package com.xxl.job.executor.jobhandler;

import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.executor.common.entity.CtopOauthToken;
import com.xxl.job.executor.common.service.ICtopOauthTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

/**
 * 快手广告组物料数据
 */
@Component
public class KuaishouCampaignJob {
    @Autowired
    private ICtopOauthTokenService tokenService;
    @Autowired
    private IKuaishouInterfaceService kuaishouInterfaceService;
    static ExecutorService executorService = Executors.newFixedThreadPool(5);
    @XxlJob("kuaishouCampaignJob")
    public void execute() {
        List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
        tokens.forEach(token -> executorService.submit(() -> kuaishouInterfaceService.getCampaignList(token, null, null)));
        XxlJobHelper.log("快手物料数据同步完成");
    }
}
