‘liusuyi’
2023-09-21 c6a05cc862a98abd7d16560e7ac2ab9bf4e12feb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.ruoyi.common.utils;
 
import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.spring.SpringUtils;
 
import java.util.Map;
 
 
/**
 * @Description: 配置工具类
 * @ClassName: ConfigUtils
 * @Author: 刘苏义
 * @Date: 2023年08月23日16:12:09
 * @Version: 1.0
 **/
public class ConfigUtils {
    /**
     * 根据配置key获取配置value值
     *
     * @return configValue 配置value值
     */
    public static String getConfigValue(String key) {
        String configValue = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
        if (StringUtils.isNotNull(configValue)) {
            return configValue;
        }
        return null;
    }
 
    /**
     * 获取所有配置信息
     *
     * @return configMap 配置信息map
     */
    public static Map<String, Object> getConfigMap() {
        Map<String, Object> configMap = SpringUtils.getBean(RedisCache.class).getMapKey(CacheConstants.SYS_CONFIG_KEY);
        if (StringUtils.isNotNull(configMap)) {
            return configMap;
        }
        return null;
    }
 
    /**
     * 设置cache key
     *
     * @param configKey 参数键
     * @return 缓存键key
     */
    public static String getCacheKey(String configKey) {
        return CacheConstants.SYS_CONFIG_KEY + configKey;
    }
 
}