mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-13 07:33:42 +08:00
1.如果别名为空,解析字段所属实体表名作为默认前缀,避免同名列歧义
2.字段转换时引用qualifiedColumn,避免@TableField/@TableId 自定义列名、全局命名策略和关键字转义被忽略 3.字典翻译时新增convertToString,根据类型返回对应的String值,防止抛出 NullPointerException、科学计数法、尾随零等其他问题。
This commit is contained in:
parent
4500a0b9b6
commit
63ff298d49
@ -25,8 +25,6 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
|
||||
public static final String COLON = ":";
|
||||
|
||||
public static final String DOT = ".";
|
||||
|
||||
private static final AntPathMatcher ANT_PATH_MATCHER = new AntPathMatcher();
|
||||
|
||||
@Deprecated
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package org.dromara.common.mybatis.core.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
@ -73,11 +75,16 @@ public final class LambdaJoinQueryBuilder<T> {
|
||||
return this;
|
||||
}
|
||||
for (SFunction<E, ?> column : columns) {
|
||||
String columnUnder = StringUtils.toUnderScoreCase(LambdaUtils.getName(column));
|
||||
if (StringUtils.isNotBlank(alias)) {
|
||||
columnUnder = alias + StringUtils.DOT + columnUnder;
|
||||
// 无别名时,解析字段所属实体表名作为默认前缀,避免同名列歧义
|
||||
String effectiveAlias = alias;
|
||||
if (StringUtils.isBlank(effectiveAlias)) {
|
||||
Class<?> entityClass = LambdaUtils.getEntityClass(column);
|
||||
TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
|
||||
if (tableInfo != null) {
|
||||
effectiveAlias = tableInfo.getTableName();
|
||||
}
|
||||
}
|
||||
wrapper.groupBy(columnUnder);
|
||||
wrapper.groupBy(qualifiedColumn(effectiveAlias, column));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import org.dromara.common.translation.annotation.TranslationType;
|
||||
import org.dromara.common.translation.constant.TransConstant;
|
||||
import org.dromara.common.translation.core.TranslationInterface;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@ -33,7 +34,8 @@ public class DictTypeTranslationImpl implements TranslationInterface<String> {
|
||||
*/
|
||||
@Override
|
||||
public String translation(Object key, String other) {
|
||||
if (key.toString() instanceof String dictValue && StringUtils.isNotBlank(other)) {
|
||||
if (StringUtils.isNotBlank(other)) {
|
||||
String dictValue = convertToString(key);
|
||||
return dictService.getDictLabel(other, dictValue);
|
||||
}
|
||||
return null;
|
||||
@ -54,7 +56,8 @@ public class DictTypeTranslationImpl implements TranslationInterface<String> {
|
||||
Map<String, String> dictMap = dictService.getAllDictByDictType(other);
|
||||
Map<Object, String> result = new LinkedHashMap<>(keys.size());
|
||||
for (Object key : keys) {
|
||||
if (key.toString() instanceof String dictValue) {
|
||||
String dictValue = convertToString(key);
|
||||
if (dictValue != null) {
|
||||
result.put(key, StreamUtils.join(
|
||||
StreamUtils.filter(Arrays.asList(dictValue.split(",")), StringUtils::isNotBlank),
|
||||
value -> dictMap.get(value.trim())
|
||||
@ -63,4 +66,28 @@ public class DictTypeTranslationImpl implements TranslationInterface<String> {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 类型转换为String
|
||||
* @param key 转换对象
|
||||
* @return string值
|
||||
*/
|
||||
private String convertToString(Object key) {
|
||||
if (key instanceof String s) {
|
||||
return s;
|
||||
} else if (key == null) {
|
||||
return null;
|
||||
} else if (key instanceof BigDecimal bd) {
|
||||
// 规范化数值
|
||||
return bd.stripTrailingZeros().toPlainString();
|
||||
} else if (key instanceof Integer || key instanceof Long || key instanceof Short || key instanceof Byte) {
|
||||
return key.toString();
|
||||
} else if (key instanceof Double || key instanceof Float) {
|
||||
// 浮点也用 BigDecimal 规范化
|
||||
return new BigDecimal(key.toString()).stripTrailingZeros().toPlainString();
|
||||
} else {
|
||||
// 其他类型按需处理,或干脆返回 null
|
||||
return key.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user