package com.qianwen.smartman.common.cache; import java.util.List; import com.qianwen.smartman.common.constant.ExtCacheConstant; import com.qianwen.smartman.common.enums.DictEnum; import com.qianwen.core.cache.utils.CacheUtil; import com.qianwen.core.tool.utils.SpringUtil; import com.qianwen.smartman.modules.system.entity.Dict; import com.qianwen.smartman.modules.system.service.IDictService; /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/common/cache/DictCache.class */ public class DictCache { private static final String DICT_ID = "dict:id:"; private static final String DICT_KEY = "dict:key:"; private static final String DICT_VALUE = "dict:value:"; private static final String DICT_LIST = "dict:list:"; private static final IDictService dictService = (IDictService) SpringUtil.getBean(IDictService.class); public static Dict getById(Long id) { return (Dict) CacheUtil.get("blade:dict", DICT_ID, id, () -> { return (Dict) dictService.getById(id); }, ExtCacheConstant.TENANT_MODE); } public static String getKey(DictEnum code, String dictValue) { return getKey(code.getName(), dictValue); } public static String getKey(String code, String dictValue) { return (String) CacheUtil.get("blade:dict", DICT_KEY + code + ":", dictValue, () -> { List list = getList(code); return (String) list.stream().filter(dict -> { return dict.getDictValue().equalsIgnoreCase(dictValue); }).map((v0) -> { return v0.getDictKey(); }).findFirst().orElse(""); }, ExtCacheConstant.TENANT_MODE); } public static String getValue(DictEnum code, Integer dictKey) { return getValue(code.getName(), dictKey); } public static String getValue(String code, Integer dictKey) { return (String) CacheUtil.get("blade:dict", DICT_VALUE + code + ":", String.valueOf(dictKey), () -> { return dictService.getValue(code, String.valueOf(dictKey)); }, ExtCacheConstant.TENANT_MODE); } public static String getValue(DictEnum code, String dictKey) { return getValue(code.getName(), dictKey); } public static String getValue(String code, String dictKey) { return CacheUtil.get("blade:dict", DICT_VALUE + code + ":", dictKey, () -> { return dictService.getValue(code, dictKey); }, ExtCacheConstant.TENANT_MODE); } public static List getList(String code) { return CacheUtil.get("blade:dict", DICT_LIST, code, () -> { return dictService.getList(code); }, ExtCacheConstant.TENANT_MODE); } }