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

import cn.com.ctop.common.module.service.IProjectService;
import cn.com.ctop.toutiao.modules.agent.service.AgentManagementService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.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;

/**
 头条结算单
 */
@Slf4j
@Component
public class AgentManagementJob {
    @Autowired
    AgentManagementService agentManagementService;
    @Autowired
    private IProjectService projectService;

    static ExecutorService executorService = Executors.newFixedThreadPool(3);

    @XxlJob("agentManagementJob")
    public void execute() throws Exception {
        List<Long> ids = projectService.getProjectIdsByMediaId("1");

        String today = DateUtils.date2Str();
        //昨天
        String yesterday = DateUtils.getLastDay(today, 1);
        String yesterday3 = DateUtils.getLastDay(today, 3);

        for (Long id : ids) {
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    agentManagementService.insertAccountTransactionDayByProjectId(id,yesterday3,yesterday);
                }
            });
        }
        XxlJobHelper.log("同步头条结算单完成");
    }

}
