This commit is contained in:
2025-10-17 10:11:04 +08:00
commit 9618d5cfa1
2012 changed files with 163764 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.jeelowcode</groupId>
<artifactId>jeelowcode-tool</artifactId>
<version>${jeelowcode.version}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>tool-spring-boot-starter-biz-dict</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>字典类型、数据</description>
<url>https://gitee.com/jeelowecode/JeeLowCode</url>
<dependencies>
<dependency>
<groupId>com.jeelowcode</groupId>
<artifactId>tool-common</artifactId>
</dependency>
<!-- Spring 核心 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- 业务组件 -->
<dependency>
<groupId>com.jeelowcode</groupId>
<artifactId>jeelowcode-service-system-api</artifactId> <!-- 需要使用它,进行 Token 的校验 -->
<version>${jeelowcode.version}</version>
</dependency>
<!-- 工具类相关 -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<!-- Test 测试相关 -->
<dependency>
<groupId>com.jeelowcode</groupId>
<artifactId>tool-spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,18 @@
package com.jeelowcode.tool.framework.dict.config;
import com.jeelowcode.tool.framework.dict.core.util.DictFrameworkUtils;
import com.jeelowcode.service.system.api.IApiDictDataApi;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
@AutoConfiguration
public class DictAutoConfiguration {
@Bean
@SuppressWarnings("InstantiationOfUtilityClass")
public DictFrameworkUtils dictUtils(IApiDictDataApi apiDictDataApi) {
DictFrameworkUtils.init(apiDictDataApi);
return new DictFrameworkUtils();
}
}

View File

@@ -0,0 +1,4 @@
/**
* 占位
*/
package com.jeelowcode.tool.framework.dict.core;

View File

@@ -0,0 +1,75 @@
package com.jeelowcode.tool.framework.dict.core.util;
import cn.hutool.core.util.ObjectUtil;
import com.jeelowcode.tool.framework.common.core.KeyValue;
import com.jeelowcode.tool.framework.common.util.cache.CacheUtils;
import com.jeelowcode.service.system.api.IApiDictDataApi;
import com.jeelowcode.service.system.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 IApiDictDataApi apiDictDataApi;
private static final DictDataRespDTO DICT_DATA_NULL = new DictDataRespDTO();
/**
* 针对 {@link #getDictDataLabel(String, String)} 的缓存
*/
private static final LoadingCache<KeyValue<String, String>, DictDataRespDTO> GET_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache(
Duration.ofMinutes(1L), // 过期时间 1 分钟
new CacheLoader<KeyValue<String, String>, DictDataRespDTO>() {
@Override
public DictDataRespDTO load(KeyValue<String, String> key) {
return ObjectUtil.defaultIfNull(apiDictDataApi.getDictData(key.getKey(), key.getValue()), DICT_DATA_NULL);
}
});
/**
* 针对 {@link #parseDictDataValue(String, String)} 的缓存
*/
private static final LoadingCache<KeyValue<String, String>, DictDataRespDTO> PARSE_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache(
Duration.ofMinutes(1L), // 过期时间 1 分钟
new CacheLoader<KeyValue<String, String>, DictDataRespDTO>() {
@Override
public DictDataRespDTO load(KeyValue<String, String> key) {
return ObjectUtil.defaultIfNull(apiDictDataApi.parseDictData(key.getKey(), key.getValue()), DICT_DATA_NULL);
}
});
public static void init(IApiDictDataApi apiDictDataApi) {
DictFrameworkUtils.apiDictDataApi = apiDictDataApi;
log.info("[init][初始化 DictFrameworkUtils 成功]");
}
@SneakyThrows
public static String getDictDataLabel(String dictType, Integer value) {
return GET_DICT_DATA_CACHE.get(new KeyValue<>(dictType, String.valueOf(value))).getLabel();
}
@SneakyThrows
public static String getDictDataLabel(String dictType, String value) {
return GET_DICT_DATA_CACHE.get(new KeyValue<>(dictType, value)).getLabel();
}
@SneakyThrows
public static String parseDictDataValue(String dictType, String label) {
return PARSE_DICT_DATA_CACHE.get(new KeyValue<>(dictType, label)).getValue();
}
}

View File

@@ -0,0 +1,6 @@
/**
* 字典数据模块,提供 {@link com.jeelowcode.tool.framework.dict.core.util.DictFrameworkUtils} 工具类
*
* 通过将字典缓存在内存中,保证性能
*/
package com.jeelowcode.tool.framework.dict;

View File

@@ -0,0 +1 @@
com.jeelowcode.tool.framework.dict.config.DictAutoConfiguration