package cn.superdesk.uniorder.openapi.scheduler.job;

import cn.superdesk.uniorder.openapi.service.qchjc.task.accounting.QchjcCutomerStatementDubboConsumerService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author xc
 * @description 采购单位对账单入库
 * @date 2022/4/7 19:05
 */
@Component
@Slf4j
public class CustomerAccountingTask {
    @Resource
    private QchjcCutomerStatementDubboConsumerService qchjcCutomerStatementDubboConsumerService;

    private final ExecutorService executorService = Executors.newSingleThreadExecutor();

    @XxlJob("customerAccountingSaveTask")
    public void doSave(){
        String jobParam = XxlJobHelper.getJobParam();
        log.info("集采采购单位对账单入库 开始 jobParam:{}",jobParam);

        log.info("集采采购单位对账单入库任务 ========== submit start");
        //List<QchjcCustomerStatementVo> list = qchjcCutomerStatementDubboConsumerService.getTodoList();
        List<Long> list = qchjcCutomerStatementDubboConsumerService.getTodoIdList();
        log.info("集采采购单位对账单入库任务 ========== todoList.size() : {}",list.size());
        if (CollectionUtils.isNotEmpty(list)) {
            for (Long id : list) {
                executorService.execute(() ->
                        qchjcCutomerStatementDubboConsumerService.doSave(id));
            }

        }
        log.info("集采采购单位对账单入库任务 ========== submit end");
    }


}
