package com.ho.xxljob.handlers;

import com.ho.common.tools.constant.RedisKeyConstant;
import com.ho.common.tools.util.RedisCommon;
import com.ho.xxljob.util.TimeConvertUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author fancl
 * @desc: 时间生成处理器
 * @date 2022/10/19
 */
@Service
@Slf4j
public class TimeGenerateService {

    @Autowired
    RedisCommon redisUtil;

    //按分钟的时间间隔
    public void buildTimeMinutes() {
        Date date = new Date();
        //建立5分钟间隔数据
        List<String> fiveMinutesList = new ArrayList<>(300);
        List<String> OneMinutesList = new ArrayList<>(1440);
        List<String> sixtyMinutesList = new ArrayList<>(24);
        List<String> thirtyMinutesList = new ArrayList<>(48);
        fiveMinutesList = TimeConvertUtil.minute(date, 5);
        OneMinutesList = TimeConvertUtil.minute(date, 1);
        thirtyMinutesList = TimeConvertUtil.minute(date,30);
        sixtyMinutesList = TimeConvertUtil.minute2(date, 60);
        redisUtil.set(RedisKeyConstant.FIVE_MINUTE_INTERVAL, fiveMinutesList);
        redisUtil.set(RedisKeyConstant.ONE_MINUTE_INTERVAL, OneMinutesList);
        redisUtil.set(RedisKeyConstant.SIXTY_MINUTE_INTERVAL,sixtyMinutesList);
        redisUtil.set(RedisKeyConstant.THIRTY_MINUTE_INTERVAL,thirtyMinutesList);
    }

    //每月每天的数据  yyyy-MM-dd
    public void buildTimeDays() {
        Date date = new Date();
        List<String> currentMonthList = new ArrayList<>(TimeConvertUtil.getCurrentMonthLastDay());
        currentMonthList = TimeConvertUtil.day(date, 1);
        redisUtil.set(RedisKeyConstant.ONE_DAY_INTERVAL,currentMonthList);
    }

    //每年每月数据 yyyy-MM
    public void buildYearMonth(){
        //每年每月
        Date dateMonth = new Date();
        List<String> currentYearMonthList = new ArrayList<>(20);
        currentYearMonthList = TimeConvertUtil.month(dateMonth, 1);
        redisUtil.set(RedisKeyConstant.MONTH_INTERVAL,currentYearMonthList);
    }
}
