package com.ruoyi.cache;

import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.spring.SpringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class VarietyNumCache {

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
    private static final String VARIETY_NUM_KEY = "VARIETY_NUM_KEY:";


    public static String getVarietyNumKey() {
        String currentDate = dateFormat.format(new Date());
        RedisCache bean = SpringUtils.getBean(RedisCache.class);
        bean.setCacheObject(VARIETY_NUM_KEY + currentDate,
                bean.getCacheObject(VARIETY_NUM_KEY + currentDate) == null
                        ? 1 :  (Integer)(bean.getCacheObject(VARIETY_NUM_KEY + currentDate)) + 1);
        return currentDate + String.format("%03d", (Integer)(bean.getCacheObject(VARIETY_NUM_KEY + currentDate)));
    }

}
