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

import cn.superdesk.uniorder.openapi.service.qchjc.task.accounting.QchjcSupplierStatementDubboConsumerService;
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:11
 */
@Component
@Slf4j
public class SupplierAccountingTask {
    @Resource
    private QchjcSupplierStatementDubboConsumerService qchjcSupplierStatementDubboConsumerService;

    private final ExecutorService executorService = Executors.newSingleThreadExecutor();

    @XxlJob("supplierAccountingSaveTask")
    public void doSave() {
        String jobParam = XxlJobHelper.getJobParam();

        log.info("供应商对账单入库任务开始，jobParam:{}", jobParam);

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

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