package com.sifang.modules.task;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.customer.Service.CustomerEntryService;
import com.sifang.modules.customer.Service.OperatingLeaseService;
import com.sifang.modules.sunshine.SystemSetting.dao.ProjectSettingDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class BatchAdmitTask {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    CustomerEntryService customerService;

    @Autowired
    ProjectSettingDao projectDao;

    @Autowired
    OperatingLeaseService operatingLeaseService;

    //批量提交预审
    @Scheduled(cron = "0 0/5 * * * ?")//五分钟执行一次
    public void submitPreAuditInBulk(){
        logger.info("submitPreAuditInBulk 批量提交预审");
        List<Record> records = Db.find(" SELECT a.id FROM `crm_customer_entry` a WHERE a.`credit` IN ('0','1') AND a.`authorization` = '3' AND a.`status` = '0' and a.is_history != '1'  ");
        logger.info(" 获取待预审的电站id size:{}",records.size());
        List<String> list = new ArrayList<>();
        for (Record record : records) {
            list.add(record.getStr("id"));
        }
        long begin = System.currentTimeMillis();
        customerService.batchAdmitForTask(list);
        long end = System.currentTimeMillis();
        logger.info("submitPreAuditInBulk 批量提交预审 定时任务结束，共耗时：[" + (end-begin) / 1000 + "]秒");
    }
}
