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 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.List;

@Component
public class BwSettleTask {
    private static final Logger logger = LoggerFactory.getLogger(BwSettleTask.class);

    @Autowired
    CustomerEntryService customerEntryService;
    @Scheduled(cron = "0 43 23 * * ?") //每天0点13分执行
    public void settle() {
        logger.info("执行结算任务 BwSettleTask ");
        List<Record> records = Db.find(" select id from crm_customer_entry where status = 'a' and  bw_settle_flag = '0' and partner_id in ('03','04') and project_num = '1' ");
        for (Record record : records) {
            String id = record.getStr("id");
            try {
                customerEntryService.initBwSettle(id);
            }catch (Exception e){
                logger.error("BwSettleTask 执行异常，error :{}  entryId :{} " ,e.getMessage(), id);
            }
        }
    }
}
