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

import cn.com.ctop.common.module.entity.CtopOauthToken;
import cn.com.ctop.common.module.service.ICtopOauthTokenService;
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
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 KuaishouSuZaoLoadJob {
    @Autowired
    private ICtopOauthTokenService tokenService;
    @Autowired
    private IKuaishouInterfaceService kuaishouInterfaceService;
    static ExecutorService executorService = null;

    @XxlJob("kuaishouSuZao")
    public ReturnT<String> execute(String param) throws Exception {
        List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
        executorService = Executors.newFixedThreadPool(8);
        tokens.forEach(token -> executorService.submit(() -> kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1)));
        XxlJobLogger.log("快手素造数据同步完成");
        return ReturnT.SUCCESS;
    }
}
