| File was renamed from blade-auth/src/main/java/org/springblade/system/cache/DictBizCache.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.DictBizEnum; |
| | | import org.springblade.core.cache.utils.CacheUtil; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | import org.springblade.core.tool.utils.StringPool; |
| | | import org.springblade.system.entity.DictBiz; |
| | | import org.springblade.system.enums.DictBizEnum; |
| | | import org.springblade.system.service.IDictBizService; |
| | | |
| | | import java.util.List; |
| | |
| | | private static final String DICT_VALUE = "dictBiz:value"; |
| | | private static final String DICT_LIST = "dictBiz:list"; |
| | | |
| | | private static IDictBizService dictClient; |
| | | private static final IDictBizService dictService; |
| | | |
| | | private static IDictBizService getDictClient() { |
| | | if (dictClient == null) { |
| | | dictClient = SpringUtil.getBean(IDictBizService.class); |
| | | } |
| | | return dictClient; |
| | | static { |
| | | dictService = SpringUtil.getBean(IDictBizService.class); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static DictBiz getById(Long id) { |
| | | String keyPrefix = DICT_ID.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON); |
| | | return CacheUtil.get(DICT_CACHE, keyPrefix, id, () -> { |
| | | DictBiz result = getDictClient().getById(id); |
| | | return result; |
| | | }); |
| | | return CacheUtil.get(DICT_CACHE, keyPrefix, id, () -> dictService.getById(id)); |
| | | } |
| | | |
| | | /** |
| | |
| | | return getValue(code.getName(), dictKey); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取字典值 |
| | | * |
| | |
| | | */ |
| | | public static String getValue(String code, Integer dictKey) { |
| | | String keyPrefix = DICT_VALUE.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON); |
| | | return CacheUtil.get(DICT_CACHE, keyPrefix + code + StringPool.COLON, String.valueOf(dictKey), () -> { |
| | | String result = getDictClient().getValue(code, String.valueOf(dictKey)); |
| | | return result; |
| | | }); |
| | | return CacheUtil.get(DICT_CACHE, keyPrefix + code + StringPool.COLON, String.valueOf(dictKey), () -> dictService.getValue(code, String.valueOf(dictKey))); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static String getValue(String code, String dictKey) { |
| | | String keyPrefix = DICT_VALUE.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON); |
| | | return CacheUtil.get(DICT_CACHE, keyPrefix + code + StringPool.COLON, dictKey, () -> { |
| | | String result = getDictClient().getValue(code, dictKey); |
| | | return result; |
| | | }); |
| | | return CacheUtil.get(DICT_CACHE, keyPrefix + code + StringPool.COLON, dictKey, () -> dictService.getValue(code, dictKey)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static List<DictBiz> getList(String code) { |
| | | String keyPrefix = DICT_LIST.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON); |
| | | return CacheUtil.get(DICT_CACHE, keyPrefix, code, () -> { |
| | | List<DictBiz> result = getDictClient().getList(code); |
| | | return result; |
| | | }); |
| | | return CacheUtil.get(DICT_CACHE, keyPrefix, code, () -> dictService.getList(code)); |
| | | } |
| | | |
| | | } |