package com.xjrsoft.module.job;

import com.xjrsoft.common.utils.DateUtils;
import com.xjrsoft.module.holiday.service.IHolidayDateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

@Component
@Slf4j
public class HolidayTask {

    @Autowired
    private IHolidayDateService holidayDateService;

    /**
     * 定时拉取节假日数据
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void RefreshHoliday() {
        System.out.printf("定时拉取节假日数据：%s", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        holidayDateService.initHoliday(calendar.get(Calendar.YEAR));
    }
}
