RuoYi
2024-05-29 c08da88542e5b4838c376a166b4c22922cd1c09a
src/main/java/com/ruoyi/common/utils/DictUtils.java
@@ -2,7 +2,8 @@
import java.util.Collection;
import java.util.List;
import com.ruoyi.common.constant.Constants;
import com.alibaba.fastjson2.JSONArray;
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.redis.RedisCache;
import com.ruoyi.project.system.domain.SysDictData;
@@ -38,11 +39,10 @@
     */
    public static List<SysDictData> getDictCache(String key)
    {
        Object cacheObj = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
        if (StringUtils.isNotNull(cacheObj))
        JSONArray arrayCache = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
        if (StringUtils.isNotNull(arrayCache))
        {
            List<SysDictData> dictDatas = StringUtils.cast(cacheObj);
            return dictDatas;
            return arrayCache.toList(SysDictData.class);
        }
        return null;
    }
@@ -56,6 +56,10 @@
     */
    public static String getDictLabel(String dictType, String dictValue)
    {
        if (StringUtils.isEmpty(dictValue))
        {
            return StringUtils.EMPTY;
        }
        return getDictLabel(dictType, dictValue, SEPARATOR);
    }
@@ -68,6 +72,10 @@
     */
    public static String getDictValue(String dictType, String dictLabel)
    {
        if (StringUtils.isEmpty(dictLabel))
        {
            return StringUtils.EMPTY;
        }
        return getDictValue(dictType, dictLabel, SEPARATOR);
    }
@@ -84,27 +92,30 @@
        StringBuilder propertyString = new StringBuilder();
        List<SysDictData> datas = getDictCache(dictType);
        if (StringUtils.containsAny(separator, dictValue) && StringUtils.isNotEmpty(datas))
        if (StringUtils.isNotEmpty(datas))
        {
            for (SysDictData dict : datas)
            if (StringUtils.containsAny(separator, dictValue))
            {
                for (String value : dictValue.split(separator))
                for (SysDictData dict : datas)
                {
                    if (value.equals(dict.getDictValue()))
                    for (String value : dictValue.split(separator))
                    {
                        propertyString.append(dict.getDictLabel() + separator);
                        break;
                        if (value.equals(dict.getDictValue()))
                        {
                            propertyString.append(dict.getDictLabel()).append(separator);
                            break;
                        }
                    }
                }
            }
        }
        else
        {
            for (SysDictData dict : datas)
            else
            {
                if (dictValue.equals(dict.getDictValue()))
                for (SysDictData dict : datas)
                {
                    return dict.getDictLabel();
                    if (dictValue.equals(dict.getDictValue()))
                    {
                        return dict.getDictLabel();
                    }
                }
            }
        }
@@ -132,7 +143,7 @@
                {
                    if (label.equals(dict.getDictLabel()))
                    {
                        propertyString.append(dict.getDictValue() + separator);
                        propertyString.append(dict.getDictValue()).append(separator);
                        break;
                    }
                }
@@ -152,11 +163,21 @@
    }
    /**
     * 删除指定字典缓存
     *
     * @param key 字典键
     */
    public static void removeDictCache(String key)
    {
        SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key));
    }
    /**
     * 清空字典缓存
     */
    public static void clearDictCache()
    {
        Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(Constants.SYS_DICT_KEY + "*");
        Collection<String> keys = SpringUtils.getBean(RedisCache.class).keys(CacheConstants.SYS_DICT_KEY + "*");
        SpringUtils.getBean(RedisCache.class).deleteObject(keys);
    }
@@ -168,6 +189,6 @@
     */
    public static String getCacheKey(String configKey)
    {
        return Constants.SYS_DICT_KEY + configKey;
        return CacheConstants.SYS_DICT_KEY + configKey;
    }
}