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

import cn.com.ctop.common.module.service.IUserAllocationService;
import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouLandpagePackageService;
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.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
public class KuaishouLandpagesJob {
    @Autowired
    private IKuaishouLandpagePackageService landpagePackageService;
    @Autowired
    private IUserAllocationService userAllocationService;
    static ExecutorService executorService = Executors.newFixedThreadPool(3);

    /**
     * 定时更新账户关联落地页数据
     */
    @XxlJob("kuaishouLandpagesJob")
    public void execute() {
        //获取快手有效的账户
        List<Long> list = userAllocationService.getValidProjectIds(2);
        list.forEach(projectId -> executorService.submit(() -> landpagePackageService.synchronousData(projectId)));
        XxlJobHelper.log("快手落地页数据更新");
    }
}
