package com.fuint.module.schedule;

import com.fuint.common.enums.PayStatusEnum;
import com.fuint.common.service.CommissionLogService;
import com.fuint.common.service.GrowService;
import com.fuint.common.service.OrderService;
import com.fuint.common.util.DateUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.repository.model.MtOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * 定时任务
 *
 * Created by FSQ
 * CopyRight https://www.fuint.cn
 */
@EnableScheduling
@Component("GrowJob")
public class GrowJob {

    private Logger logger = LoggerFactory.getLogger(GrowJob.class);

    /**
     * 系统环境变量
     * */
    @Autowired
    private Environment environment;

    @Autowired
    private GrowService growService;

    @Scheduled(cron = "${grow.job.time}")
    @Transactional(rollbackFor = Exception.class)
    public void dealGrow() throws BusinessCheckException {
        String theSwitch = environment.getProperty("grow.job.switch");
         if (theSwitch != null && theSwitch.equals("1")) {
             logger.info("GrowJobStart!!!");
             growService.clearAdvNum();
             logger.info("GrowJobEnd!!!");
        }
    }
}
