All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zznote.basecommon.common.util.DictUtils Maven / Gradle / Ivy

The newest version!
package com.zznote.basecommon.common.util;

import cn.hutool.core.util.ObjectUtil;
import com.zznote.basecommon.common.constant.Constants;
import com.zznote.basecommon.common.util.cache.RedisUtils;
import com.zznote.basecommon.entity.system.TDictData;
import lombok.RequiredArgsConstructor;

import java.util.Collection;
import java.util.List;

/**
 * 字典工具类
 *
 * @author ruoyi
 */
@RequiredArgsConstructor
public class DictUtils {
    /**
     * 设置字典缓存
     *
     * @param key       参数键
     * @param dictDatas 字典数据列表
     */
    public static void setDictCache(String key, List dictDatas) {
        RedisUtils.setCacheList(getCacheKey(key), dictDatas);
    }

    /**
     * 获取字典缓存
     *
     * @param key 参数键
     * @return dictDatas 字典数据列表
     */
    public static List getDictCache(String key) {
        List dictDatas = RedisUtils.getCacheList(getCacheKey(key));
        if (ObjectUtil.isNotNull(dictDatas)) {
            return dictDatas;
        }
        return null;
    }

    /**
     * 删除指定字典缓存
     *
     * @param key 字典键
     */
    public static void removeDictCache(String key) {
        RedisUtils.deleteObject(getCacheKey(key));
    }

    /**
     * 清空字典缓存
     */
    public static void clearDictCache() {
        Collection keys = RedisUtils.keys(Constants.SYS_DICT_KEY + "*");
        RedisUtils.deleteObject(keys);
    }

    /**
     * 设置cache key
     *
     * @param configKey 参数键
     * @return 缓存键key
     */
    public static String getCacheKey(String configKey) {
        return Constants.SYS_DICT_KEY + configKey;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy