diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/cache/CacheUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/cache/CacheUtils.java
index 8c9c7f6ca..7f7318487 100644
--- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/cache/CacheUtils.java
+++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/cache/CacheUtils.java
@@ -19,7 +19,7 @@ public class CacheUtils {
// 只阻塞当前数据加载线程,其他线程返回旧值
.refreshAfterWrite(duration)
// 通过 asyncReloading 实现全异步加载,包括 refreshAfterWrite 被阻塞的加载线程
- .build(CacheLoader.asyncReloading(loader, Executors.newSingleThreadExecutor()));
+ .build(CacheLoader.asyncReloading(loader, Executors.newCachedThreadPool())); // TODO 芋艿:可能要思考下,未来要不要做成可配置
}
}
diff --git a/yudao-framework/yudao-spring-boot-starter-biz-dict/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-dict/pom.xml
index b1ee580f4..f99d727ba 100644
--- a/yudao-framework/yudao-spring-boot-starter-biz-dict/pom.xml
+++ b/yudao-framework/yudao-spring-boot-starter-biz-dict/pom.xml
@@ -26,5 +26,25 @@
org.springframework.boot
spring-boot-starter
+
+
+
+ cn.iocoder.cloud
+ yudao-spring-boot-starter-rpc
+ true
+
+
+
+
+ cn.iocoder.cloud
+ yudao-module-system-api
+ ${revision}
+
+
+
+
+ com.google.guava
+ guava
+
diff --git a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictAutoConfiguration.java
index 1828585c0..01f7aba78 100644
--- a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictAutoConfiguration.java
+++ b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictAutoConfiguration.java
@@ -1,7 +1,7 @@
package cn.iocoder.yudao.framework.dict.config;
-import cn.iocoder.yudao.framework.dict.core.service.DictDataFrameworkService;
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
+import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -10,8 +10,8 @@ public class YudaoDictAutoConfiguration {
@Bean
@SuppressWarnings("InstantiationOfUtilityClass")
- public DictFrameworkUtils dictUtils(DictDataFrameworkService service) {
- DictFrameworkUtils.init(service);
+ public DictFrameworkUtils dictUtils(DictDataApi dictDataApi) {
+ DictFrameworkUtils.init(dictDataApi);
return new DictFrameworkUtils();
}
diff --git a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictRpcAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictRpcAutoConfiguration.java
new file mode 100644
index 000000000..83602e818
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/config/YudaoDictRpcAutoConfiguration.java
@@ -0,0 +1,15 @@
+package cn.iocoder.yudao.framework.dict.config;
+
+import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 字典用到 Feign 的配置项
+ *
+ * @author 芋道源码
+ */
+@Configuration(proxyBeanMethods = false)
+@EnableFeignClients(clients = DictDataApi.class) // 主要是引入相关的 API 服务
+public class YudaoDictRpcAutoConfiguration {
+}
diff --git a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/dto/DictDataRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/dto/DictDataRespDTO.java
deleted file mode 100644
index 150ee751e..000000000
--- a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/dto/DictDataRespDTO.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package cn.iocoder.yudao.framework.dict.core.dto;
-
-import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
-import lombok.Data;
-
-/**
- * 字典数据 Response DTO
- *
- * @author 芋道源码
- */
-@Data
-public class DictDataRespDTO {
-
- /**
- * 字典标签
- */
- private String label;
- /**
- * 字典值
- */
- private String value;
- /**
- * 字典类型
- */
- private String dictType;
- /**
- * 状态
- *
- * 枚举 {@link CommonStatusEnum}
- */
- private Integer status;
-
-}
diff --git a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/package-info.java b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/package-info.java
new file mode 100644
index 000000000..7ba720a9d
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * 占位
+ */
+package cn.iocoder.yudao.framework.dict.core;
diff --git a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/service/DictDataFrameworkService.java b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/service/DictDataFrameworkService.java
deleted file mode 100644
index 870f63a55..000000000
--- a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/service/DictDataFrameworkService.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package cn.iocoder.yudao.framework.dict.core.service;
-
-import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO;
-
-import java.util.List;
-
-public interface DictDataFrameworkService {
-
- /**
- * 获得指定的字典数据,从缓存中
- *
- * @param type 字典类型
- * @param value 字典数据值
- * @return 字典数据
- */
- DictDataRespDTO getDictDataFromCache(String type, String value);
-
- /**
- * 解析获得指定的字典数据,从缓存中
- *
- * @param type 字典类型
- * @param label 字典数据标签
- * @return 字典数据
- */
- DictDataRespDTO parseDictDataFromCache(String type, String label);
-
-}
diff --git a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/util/DictFrameworkUtils.java b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/util/DictFrameworkUtils.java
index 976f81c79..0ea5a7608 100644
--- a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/util/DictFrameworkUtils.java
+++ b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/java/cn/iocoder/yudao/framework/dict/core/util/DictFrameworkUtils.java
@@ -1,28 +1,75 @@
package cn.iocoder.yudao.framework.dict.core.util;
-import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO;
-import cn.iocoder.yudao.framework.dict.core.service.DictDataFrameworkService;
+import cn.hutool.core.util.ObjectUtil;
+import cn.iocoder.yudao.framework.common.core.KeyValue;
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
+import cn.iocoder.yudao.framework.common.util.cache.CacheUtils;
+import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
+import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
+import java.time.Duration;
+
/**
* 字典工具类
+ *
+ * @author 芋道源码
*/
@Slf4j
public class DictFrameworkUtils {
- private static DictDataFrameworkService service;
+ private static DictDataApi dictDataApi;
- public static void init(DictDataFrameworkService service) {
- DictFrameworkUtils.service = service;
+ private static final DictDataRespDTO DICT_DATA_NULL = new DictDataRespDTO();
+
+ /**
+ * 针对 {@link #getDictDataLabel(String, String)} 的缓存
+ */
+ private static final LoadingCache, DictDataRespDTO> getDictDataCache = CacheUtils.buildAsyncReloadingCache(
+ Duration.ofMinutes(1L), // 过期时间 1 分钟
+ new CacheLoader, DictDataRespDTO>() {
+
+ @Override
+ public DictDataRespDTO load(KeyValue key) {
+ CommonResult getDictDataResult = dictDataApi.getDictData(key.getKey(), key.getValue());
+ getDictDataResult.checkError();
+ return ObjectUtil.defaultIfNull(getDictDataResult.getData(), DICT_DATA_NULL);
+ }
+
+ });
+
+ /**
+ * 针对 {@link #parseDictDataValue(String, String)} 的缓存
+ */
+ private static final LoadingCache, DictDataRespDTO> parseDictDataCache = CacheUtils.buildAsyncReloadingCache(
+ Duration.ofMinutes(1L), // 过期时间 1 分钟
+ new CacheLoader, DictDataRespDTO>() {
+
+ @Override
+ public DictDataRespDTO load(KeyValue key) {
+ CommonResult parseDictDataResult = dictDataApi.parseDictData(key.getKey(), key.getValue());
+ parseDictDataResult.checkError();
+ return ObjectUtil.defaultIfNull(parseDictDataResult.getData(), DICT_DATA_NULL);
+ }
+
+ });
+
+ public static void init(DictDataApi dictDataApi) {
+ DictFrameworkUtils.dictDataApi = dictDataApi;
log.info("[init][初始化 DictFrameworkUtils 成功]");
}
- public static DictDataRespDTO getDictDataFromCache(String type, String value) {
- return service.getDictDataFromCache(type, value);
+ @SneakyThrows
+ public static String getDictDataLabel(String dictType, String value) {
+ return getDictDataCache.get(new KeyValue<>(dictType, value)).getLabel();
}
- public static DictDataRespDTO parseDictDataFromCache(String type, String label) {
- return service.parseDictDataFromCache(type, label);
+ @SneakyThrows
+ public static String parseDictDataValue(String dictType, String label) {
+ return parseDictDataCache.get(new KeyValue<>(dictType, label)).getValue();
}
}
diff --git a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/resources/META-INF/spring.factories b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/resources/META-INF/spring.factories
index 3986b1c2b..39cfcffe0 100644
--- a/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/resources/META-INF/spring.factories
+++ b/yudao-framework/yudao-spring-boot-starter-biz-dict/src/main/resources/META-INF/spring.factories
@@ -1,2 +1,3 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+ cn.iocoder.yudao.framework.dict.config.YudaoDictRpcAutoConfiguration,\
cn.iocoder.yudao.framework.dict.config.YudaoDictAutoConfiguration
diff --git a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/convert/DictConvert.java b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/convert/DictConvert.java
index beed26f94..7698cf4a6 100644
--- a/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/convert/DictConvert.java
+++ b/yudao-framework/yudao-spring-boot-starter-excel/src/main/java/cn/iocoder/yudao/framework/excel/core/convert/DictConvert.java
@@ -1,7 +1,6 @@
package cn.iocoder.yudao.framework.excel.core.convert;
import cn.hutool.core.convert.Convert;
-import cn.iocoder.yudao.framework.dict.core.dto.DictDataRespDTO;
import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import com.alibaba.excel.converters.Converter;
@@ -12,7 +11,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
import lombok.extern.slf4j.Slf4j;
/**
- * Excel {@link DictDataRespDTO} 数据字典转换器
+ * Excel 数据字典转换器
*
* @author 芋道源码
*/
@@ -35,14 +34,14 @@ public class DictConvert implements Converter