package cn.hnthyy.thmz.common.scheduled;


import cn.hnthyy.thmz.service.thmz.DiscountService;
import cn.hnthyy.thmz.service.thmz.TokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * 定时任务类
 */
@Slf4j
//1.主要用于标记配置类，兼备Component的效果。
@Configuration
// 2.开启定时任务
@EnableScheduling
public class ScheduledService {
    @Autowired
    private TokenService tokenService;
    @Autowired
    private DiscountService discountService;

    /**
     * 每天凌晨零点5分运行一次
     */
    @Scheduled(cron = "5 0 0 * * *")
    public void scheduled() {
        //刷新营销缓存
        discountService.getCacheMap();
    }

    /**
     * 每20分钟执行一次
     */
    @Scheduled(cron = "0 0/20 * * * ?")
    public void refreshTokenCache() {
        tokenService.refreshTokenCache();
    }


}
