package com.iformall.schedule;

import com.iformall.domain.po.WxMall;
import com.iformall.domain.po.WxPropertyContract;
import com.iformall.domain.po.WxRentContract;
import com.iformall.mapper.WxMallMapper;
import com.iformall.service.WxPropertyContractService;
import com.iformall.service.WxRentContractService;
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 ContractSchedule {

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

    @Autowired
    private WxRentContractService wxRentContractService;

    @Autowired
    private WxPropertyContractService wxPropertyContractService;

    @Autowired
    private WxMallMapper wxMallMapper;


    /**
     * 2小时执行一次
     */
    @Scheduled(cron = "0 0 0/2 * * ?")
    public void sendMsg() {
        logger.info("合同状态更新开始");

        List<WxMall> wxMalls = wxMallMapper.findList(null);
        for (WxMall wxMall : wxMalls) {
            String tenantId = wxMall.getTenantId();
            WxRentContract wxRentContract = new WxRentContract();
            wxRentContract.setTenantId(tenantId);
            logger.info("租赁合同状态更新开始");
            wxRentContractService.updateStatus(wxRentContract);
            logger.info("租赁合同状态更新结束");

            WxPropertyContract wxPropertyContract = new WxPropertyContract();
            wxPropertyContract.setTenantId(tenantId);
            logger.info("物业合同状态更新开始");
            wxPropertyContractService.updateStatus(wxPropertyContract);
            logger.info("物业合同状态更新结束");
        }
        logger.info("合同状态更新结束");

    }


}