mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-04-12 13:33:16 +08:00
update 优化 翻译模块 增加逻辑注释和相关警告日志
This commit is contained in:
@@ -4,6 +4,8 @@ import cn.hutool.core.convert.Convert;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.translation.annotation.TranslationType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -21,6 +23,8 @@ import java.util.function.Function;
|
||||
*/
|
||||
public interface TranslationInterface<T> {
|
||||
|
||||
Logger log = LoggerFactory.getLogger(TranslationInterface.class);
|
||||
|
||||
/**
|
||||
* 按翻译键执行转换。
|
||||
*
|
||||
@@ -38,6 +42,9 @@ public interface TranslationInterface<T> {
|
||||
* @return 翻译结果映射
|
||||
*/
|
||||
default Map<Object, T> translationBatch(Set<Object> keys, String other) {
|
||||
TranslationType annotation = this.getClass().getAnnotation(TranslationType.class);
|
||||
String type = annotation != null ? annotation.type() : this.getClass().getSimpleName();
|
||||
log.warn("翻译类型 [{}] 未覆盖 translationBatch 方法,已退化为逐条查询,建议实现批量查询以提升性能", type);
|
||||
Map<Object, T> result = new LinkedHashMap<>(keys.size());
|
||||
for (Object key : keys) {
|
||||
result.put(key, translation(key, other));
|
||||
|
||||
@@ -88,7 +88,7 @@ public class TranslationJsonFieldProcessor implements JsonFieldProcessor {
|
||||
}
|
||||
Object sourceValue = resolveSourceValue(fieldContext, translation);
|
||||
if (sourceValue == null) {
|
||||
return null;
|
||||
return value;
|
||||
}
|
||||
TranslationBatchKey batchKey = new TranslationBatchKey(translation.type(), translation.other());
|
||||
Map<TranslationBatchKey, Map<Object, Object>> results = context.getAttribute(ATTR_RESULTS);
|
||||
|
||||
Reference in New Issue
Block a user