mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
1、新增组织、用户、角色、短信日志、短信模版、token管理easyexcel导出国际化,i18n文件整理;2、新增字典cache支持多语言;
This commit is contained in:
+28
@@ -9,8 +9,11 @@ import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* 字典工具类
|
||||
@@ -54,6 +57,21 @@ public class DictFrameworkUtils {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* 针对 {@link #getDictI18nDataLabel(String, String)} 的缓存
|
||||
*/
|
||||
private static final LoadingCache<Triple<String, String, String>, DictDataRespDTO> GET_DICT_DATA_CACHE_I18n = CacheUtils.buildAsyncReloadingCache(
|
||||
Duration.ofMinutes(10L), // 过期时间 1 分钟
|
||||
new CacheLoader<>() {
|
||||
|
||||
@Override
|
||||
public DictDataRespDTO load(Triple<String, String, String> key) {
|
||||
return ObjectUtil.defaultIfNull(dictDataApi.getDictI18nData(key.getLeft(), key.getMiddle(), key.getRight()).getCheckedData(),
|
||||
DICT_DATA_NULL);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
public static void init(DictDataApi dictDataApi) {
|
||||
DictFrameworkUtils.dictDataApi = dictDataApi;
|
||||
log.info("[init][初始化 DictFrameworkUtils 成功]");
|
||||
@@ -69,6 +87,16 @@ public class DictFrameworkUtils {
|
||||
return GET_DICT_DATA_CACHE.get(new Pair<>(dictType, value)).getLabel();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String getDictI18nDataLabel(String dictType, String value) {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
if(locale == null || Locale.CHINESE.equals(locale)) {
|
||||
return GET_DICT_DATA_CACHE.get(new Pair<>(dictType, value)).getLabel();
|
||||
} else {
|
||||
return GET_DICT_DATA_CACHE_I18n.get(Triple.of(dictType, value, locale.getLanguage())).getLabel();
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String parseDictDataValue(String dictType, String label) {
|
||||
return PARSE_DICT_DATA_CACHE.get(new Pair<>(dictType, label)).getValue();
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class DictConvert implements Converter<Object> {
|
||||
// 使用字典格式化
|
||||
String type = getType(contentProperty);
|
||||
String value = String.valueOf(object);
|
||||
String label = DictFrameworkUtils.getDictDataLabel(type, value);
|
||||
String label = DictFrameworkUtils.getDictI18nDataLabel(type, value);
|
||||
if (label == null) {
|
||||
log.error("[convertToExcelData][type({}) 转换不了 label({})]", type, value);
|
||||
return new WriteCellData<>("");
|
||||
|
||||
Reference in New Issue
Block a user