| File was renamed from blade-auth/src/main/java/org/springblade/system/cache/DictCache.java |
| | |
| | | * this software without specific prior written permission. |
| | | * Author: Chill 庄骞 (smallchill@163.com) |
| | | */ |
| | | package org.springblade.system.cache; |
| | | package org.springblade.common.cache; |
| | | |
| | | import org.springblade.common.enums.DictEnum; |
| | | import org.springblade.core.cache.utils.CacheUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | import org.springblade.core.tool.utils.StringPool; |
| | | import org.springblade.system.entity.Dict; |
| | | import org.springblade.system.enums.DictEnum; |
| | | import org.springblade.system.service.IDictService; |
| | | |
| | | import java.util.List; |
| | |
| | | |
| | | private static final Boolean TENANT_MODE = Boolean.FALSE; |
| | | |
| | | private static IDictService dictClient; |
| | | private static final IDictService dictService; |
| | | |
| | | private static IDictService getDictClient() { |
| | | if (dictClient == null) { |
| | | dictClient = SpringUtil.getBean(IDictService.class); |
| | | } |
| | | return dictClient; |
| | | static { |
| | | dictService = SpringUtil.getBean(IDictService.class); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return Dict |
| | | */ |
| | | public static Dict getById(Long id) { |
| | | return CacheUtil.get(DICT_CACHE, DICT_ID, id, () -> { |
| | | Dict result = getDictClient().getById(id); |
| | | return result; |
| | | }, TENANT_MODE); |
| | | return CacheUtil.get(DICT_CACHE, DICT_ID, id, () -> dictService.getById(id), TENANT_MODE); |
| | | } |
| | | |
| | | /** |
| | |
| | | return getValue(code.getName(), dictKey); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取字典值 |
| | | * |
| | |
| | | * @return String |
| | | */ |
| | | public static String getValue(String code, Integer dictKey) { |
| | | return CacheUtil.get(DICT_CACHE, DICT_VALUE + code + StringPool.COLON, String.valueOf(dictKey), () -> { |
| | | String result = getDictClient().getValue(code, String.valueOf(dictKey)); |
| | | return result; |
| | | }, TENANT_MODE); |
| | | return CacheUtil.get(DICT_CACHE, DICT_VALUE + code + StringPool.COLON, String.valueOf(dictKey), () -> dictService.getValue(code, String.valueOf(dictKey)), TENANT_MODE); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return String |
| | | */ |
| | | public static String getValue(String code, String dictKey) { |
| | | return CacheUtil.get(DICT_CACHE, DICT_VALUE + code + StringPool.COLON, dictKey, () -> { |
| | | String result = getDictClient().getValue(code, dictKey); |
| | | return result; |
| | | }, TENANT_MODE); |
| | | return CacheUtil.get(DICT_CACHE, DICT_VALUE + code + StringPool.COLON, dictKey, () -> dictService.getValue(code, dictKey), TENANT_MODE); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return List<Dict> |
| | | */ |
| | | public static List<Dict> getList(String code) { |
| | | return CacheUtil.get(DICT_CACHE, DICT_LIST, code, () -> { |
| | | List<Dict> result = getDictClient().getList(code); |
| | | return result; |
| | | }, TENANT_MODE); |
| | | return CacheUtil.get(DICT_CACHE, DICT_LIST, code, () -> dictService.getList(code), TENANT_MODE); |
| | | } |
| | | |
| | | } |