mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
cf-framework:dict移到starter-excel、升级easyexcel版本
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
package com.cf.imes.framework.dict.config;
|
||||
|
||||
import com.cf.imes.framework.dict.core.util.DictFrameworkUtils;
|
||||
import com.cf.imes.module.system.api.dict.DictDataApi;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@AutoConfiguration
|
||||
public class ChenfengDictAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("InstantiationOfUtilityClass")
|
||||
public DictFrameworkUtils dictUtils(DictDataApi dictDataApi) {
|
||||
DictFrameworkUtils.init(dictDataApi);
|
||||
return new DictFrameworkUtils();
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.cf.imes.framework.dict.config;
|
||||
|
||||
import com.cf.imes.module.system.api.dict.DictDataApi;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* 字典用到 Feign 的配置项
|
||||
*
|
||||
* @author 晨丰科技
|
||||
*/
|
||||
@AutoConfiguration
|
||||
@EnableFeignClients(clients = DictDataApi.class) // 主要是引入相关的 API 服务
|
||||
public class ChenfengDictRpcAutoConfiguration {
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 占位
|
||||
*/
|
||||
package com.cf.imes.framework.dict.core;
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.cf.imes.framework.dict.core.util;
|
||||
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.cf.imes.framework.common.util.cache.CacheUtils;
|
||||
import com.cf.imes.module.system.api.dict.DictDataApi;
|
||||
import com.cf.imes.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 DictDataApi dictDataApi;
|
||||
|
||||
private static final DictDataRespDTO DICT_DATA_NULL = new DictDataRespDTO();
|
||||
|
||||
/**
|
||||
* 针对 {@link #getDictDataLabel(String, String)} 的缓存
|
||||
*/
|
||||
private static final LoadingCache<Pair<String, String>, DictDataRespDTO> GET_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache(
|
||||
Duration.ofMinutes(10L), // 过期时间 1 分钟
|
||||
new CacheLoader<>() {
|
||||
|
||||
@Override
|
||||
public DictDataRespDTO load(Pair<String, String> key) {
|
||||
return ObjectUtil.defaultIfNull(dictDataApi.getDictData(key.getKey(), key.getValue()).getCheckedData(),
|
||||
DICT_DATA_NULL);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* 针对 {@link #parseDictDataValue(String, String)} 的缓存
|
||||
*/
|
||||
private static final LoadingCache<Pair<String, String>, DictDataRespDTO> PARSE_DICT_DATA_CACHE = CacheUtils.buildAsyncReloadingCache(
|
||||
Duration.ofMinutes(10L), // 过期时间 1 分钟
|
||||
new CacheLoader<>() {
|
||||
|
||||
@Override
|
||||
public DictDataRespDTO load(Pair<String, String> key) {
|
||||
return ObjectUtil.defaultIfNull(dictDataApi.parseDictData(key.getKey(), key.getValue()).getCheckedData(),
|
||||
DICT_DATA_NULL);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
public static void init(DictDataApi dictDataApi) {
|
||||
DictFrameworkUtils.dictDataApi = dictDataApi;
|
||||
log.info("[init][初始化 DictFrameworkUtils 成功]");
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String getDictDataLabel(String dictType, Integer value) {
|
||||
return GET_DICT_DATA_CACHE.get(new Pair<>(dictType, String.valueOf(value))).getLabel();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String getDictDataLabel(String dictType, String value) {
|
||||
return GET_DICT_DATA_CACHE.get(new Pair<>(dictType, value)).getLabel();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String parseDictDataValue(String dictType, String label) {
|
||||
return PARSE_DICT_DATA_CACHE.get(new Pair<>(dictType, label)).getValue();
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 字典数据模块,提供 {@link com.cf.imes.framework.dict.core.util.DictFrameworkUtils} 工具类
|
||||
*
|
||||
* 通过将字典缓存在内存中,保证性能
|
||||
*/
|
||||
package com.cf.imes.framework.dict;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
com.cf.imes.framework.dict.config.ChenfengDictRpcAutoConfiguration
|
||||
com.cf.imes.framework.dict.config.ChenfengDictAutoConfiguration
|
||||
Reference in New Issue
Block a user