mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-23 23:09:47 +08:00
update 优化 转换模块代码 删除无用的 common-dict 依赖
This commit is contained in:
@ -25,8 +25,8 @@ public @interface Translation {
|
||||
String type();
|
||||
|
||||
/**
|
||||
* 通用Key 如果为空则取被标注的字段值 例如: 字典type(sys_user_sex)
|
||||
* 其他条件 例如: 字典type(sys_user_sex)
|
||||
*/
|
||||
String key() default "";
|
||||
String other() default "";
|
||||
|
||||
}
|
||||
|
@ -8,15 +8,18 @@ package com.ruoyi.common.translation.constant;
|
||||
public interface TransConstant {
|
||||
|
||||
/**
|
||||
* 用户名翻译
|
||||
* 用户id转账号
|
||||
*/
|
||||
String USER_ID_TO_NAME = "userIdToName";
|
||||
|
||||
/**
|
||||
* 字典值翻译
|
||||
* 字典type转label
|
||||
*/
|
||||
String DICT_TYPE_TO_LABEL = "dictTypeToLabel";
|
||||
|
||||
/**
|
||||
* ossId转url
|
||||
*/
|
||||
String OSS_ID_TO_URL = "ossIdToUrl";
|
||||
|
||||
}
|
||||
|
@ -13,5 +13,5 @@ public interface TranslationInterface {
|
||||
* @param key 需要被翻译的键
|
||||
* @return 返回键对应的值
|
||||
*/
|
||||
String translation(Object key);
|
||||
String translation(Object key, String other);
|
||||
}
|
||||
|
@ -38,13 +38,13 @@ public class TranslationHandler extends JsonSerializer<Object> implements Contex
|
||||
try {
|
||||
TranslationInterface trans = TRANSLATION_MAPPER.get(translation.type());
|
||||
if (ObjectUtil.isNotNull(trans)) {
|
||||
String result = trans.translation(StringUtils.isBlank(translation.key()) ? value : translation.key());
|
||||
String result = trans.translation(value, translation.other());
|
||||
gen.writeString(StringUtils.isNotBlank(result) ? result : value.toString());
|
||||
} else {
|
||||
gen.writeString(value.toString());
|
||||
}
|
||||
} catch (BeansException e) {
|
||||
log.error("字典数据未查到, 采用默认处理 => {}", e.getMessage());
|
||||
log.error("数据未查到, 采用默认处理 => {}", e.getMessage());
|
||||
gen.writeString(value.toString());
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
package com.ruoyi.common.translation.core.impl;
|
||||
|
||||
import com.ruoyi.common.translation.annotation.TranslationType;
|
||||
import com.ruoyi.common.translation.constant.TransConstant;
|
||||
import com.ruoyi.common.translation.core.TranslationInterface;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 翻译接口 (实现类需标注 {@link com.ruoyi.common.translation.annotation.TranslationType} 注解标明翻译类型)
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Component
|
||||
@TranslationType(type = TransConstant.DICT_TYPE_TO_LABEL)
|
||||
public class DictTranslationImpl implements TranslationInterface {
|
||||
|
||||
/**
|
||||
* 翻译
|
||||
*
|
||||
* @param key 需要被翻译的键
|
||||
* @return 返回键对应的值
|
||||
*/
|
||||
public String translation(Object key) {
|
||||
if (key instanceof String dictType) {
|
||||
return "dict";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.ruoyi.common.translation.core.impl;
|
||||
|
||||
import com.ruoyi.common.core.service.DictService;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.translation.annotation.TranslationType;
|
||||
import com.ruoyi.common.translation.constant.TransConstant;
|
||||
import com.ruoyi.common.translation.core.TranslationInterface;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 字典翻译实现
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
@TranslationType(type = TransConstant.DICT_TYPE_TO_LABEL)
|
||||
public class DictTypeTranslationImpl implements TranslationInterface {
|
||||
|
||||
private final DictService dictService;
|
||||
|
||||
public String translation(Object key, String other) {
|
||||
if (key instanceof String dictValue && StringUtils.isNotBlank(other)) {
|
||||
return dictService.getDictLabel(other, dictValue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ import com.ruoyi.common.translation.core.TranslationInterface;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 翻译接口 (实现类需标注 {@link com.ruoyi.common.translation.annotation.TranslationType} 注解标明翻译类型)
|
||||
* 用户名翻译实现
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@ -14,13 +14,8 @@ import org.springframework.stereotype.Component;
|
||||
@TranslationType(type = TransConstant.USER_ID_TO_NAME)
|
||||
public class UserNameTranslationImpl implements TranslationInterface {
|
||||
|
||||
/**
|
||||
* 翻译
|
||||
*
|
||||
* @param key 需要被翻译的键
|
||||
* @return 返回键对应的值
|
||||
*/
|
||||
public String translation(Object key) {
|
||||
public String translation(Object key, String other) {
|
||||
// todo 待实现
|
||||
if (key instanceof Long id) {
|
||||
return "admin";
|
||||
}
|
||||
|
Reference in New Issue
Block a user