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 ApplyNumCache {

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


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

}
