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 com.xxl.job.executor.utils.DateUtils;
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 = Executors.newFixedThreadPool(8);
    @XxlJob("kuaishouSuZao")
    public void execute() throws Exception {
        List<CtopOauthToken> tokens = tokenService.selectKuaiShouToken();
        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
        String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, 1);
        String startDate = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
        tokens.forEach(token -> executorService.submit(() -> kuaishouInterfaceService.getSuZaoList(token.getAccessToken(), token.getAccountId(), 1, startDate, endDate)));
        XxlJobHelper.log("快手素造数据同步完成");
    }


}
