package com.iformall.schedule;

import com.iformall.domain.po.WxMall;
import com.iformall.domain.vo.WxBillAll;
import com.iformall.mapper.WxMallMapper;
import com.iformall.service.WxBillAllService;
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;

/**
 * @author gongbiao
 */
@Component
public class BillStatusSchedule {

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

    @Autowired
    private WxBillAllService wxBillAllService;

    @Autowired
    private WxMallMapper wxMallMapper;

    /**
     * 每天1点执行
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void updateBillStatus() {
        logger.info("账单状态更新开始");

        List<WxMall> wxMalls = wxMallMapper.findList(null);
        for (WxMall wxMall : wxMalls) {
            String tenantId = wxMall.getTenantId();
            WxBillAll wxBillAll = new WxBillAll();
            wxBillAll.setTenantId(tenantId);
            wxBillAllService.updateBillStatus(wxBillAll);
        }

        logger.info("账单状态更新结束");
    }


}