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.report.service.IKuaishouGroupExploreService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

@Component
public class KuaishouGroupExploreJob {
    @Autowired
    private ICtopOauthTokenService tokenService;
    @Autowired
    private IKuaishouGroupExploreService kuaishouGroupExploreService;
    static ExecutorService executorService = Executors.newFixedThreadPool(5);
    //TODO 待删除
    @XxlJob("kuaishouGroupExploreReportJob")
    public void execute() throws ParseException {
        List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
        tokens.forEach(token -> executorService.submit(() ->
                kuaishouGroupExploreService.getReportByAccount(token))
        );
        XxlJobHelper.log("快手物料数据同步完成");
    }
}
