mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
简化代码
This commit is contained in:
parent
39942b28ce
commit
fde21a04dd
@ -36,15 +36,15 @@ public final class JSqlParserHelper {
|
||||
SelectExpressionItem selectExpressionItem = (SelectExpressionItem) item;
|
||||
if (null == selectExpressionItem.getAlias()) {
|
||||
if (selectExpressionItem.getExpression() instanceof Column) {
|
||||
col = StringUtils.getTargetColumn(((Column) selectExpressionItem.getExpression()).getColumnName());
|
||||
col = ((Column) selectExpressionItem.getExpression()).getColumnName();
|
||||
} else {
|
||||
col = StringUtils.getTargetColumn(selectExpressionItem.getExpression().toString());
|
||||
col = selectExpressionItem.getExpression().toString();
|
||||
}
|
||||
} else {
|
||||
col = StringUtils.getTargetColumn(selectExpressionItem.getAlias().getName());
|
||||
col = selectExpressionItem.getAlias().getName();
|
||||
}
|
||||
if (StringUtils.isNotBlank(col)) {
|
||||
columConsumer.accept(col);
|
||||
columConsumer.accept(StringUtils.getTargetColumn(col));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,7 @@ import lombok.Getter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
@ -371,30 +369,19 @@ public abstract class JoinAbstractLambdaWrapper<T, Children extends JoinAbstract
|
||||
/**
|
||||
* 检验表是否已连接
|
||||
*/
|
||||
public boolean checkJoinTable(Class clazz) {
|
||||
TableInfo info = TableHelper.get(clazz);
|
||||
Asserts.hasTable(info, clazz);
|
||||
String tableName = info.getTableName();
|
||||
|
||||
for (Children wrapper : onWrappers) {
|
||||
if (StringUtils.isBlank(wrapper.from.getStringValue())) {
|
||||
if (this.subLogicSql && this.logicDelType == LogicDelTypeEnum.ON) {
|
||||
TableInfo tableInfo = TableHelper.get(wrapper.getJoinClass());
|
||||
if (tableInfo != null && tableName.equals(tableInfo.getTableName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (wrapper.getTableName().equals(tableName)) {
|
||||
return true;
|
||||
}
|
||||
public boolean checkJoinTable(Class<?> clazz) {
|
||||
return onWrappers.stream().anyMatch(wrapper -> {
|
||||
if (Objects.equals(wrapper.getJoinClass(), clazz)) {
|
||||
return true;
|
||||
} else {
|
||||
if (wrapper.from.getStringValue().contains(Constant.JOIN + StringPool.SPACE + tableName)) {
|
||||
return true;
|
||||
}
|
||||
TableInfo info = TableHelper.get(clazz);
|
||||
Asserts.hasTable(info, clazz);
|
||||
String tableName = info.getTableName();
|
||||
return Optional.ofNullable(wrapper.from.getStringValue())
|
||||
.map(w -> w.contains(Constant.JOIN + StringPool.SPACE + tableName + StringPool.SPACE))
|
||||
.orElse(false);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,6 +130,11 @@ class LambdaWrapperTest {
|
||||
.orderByDesc(UserDO::getId);
|
||||
List<UserDTO> list = userMapper.selectJoinList(UserDTO.class, wrapper);
|
||||
|
||||
assert wrapper.checkJoinTable(AddressDO.class);
|
||||
assert wrapper.checkJoinTable(AreaDO.class);
|
||||
assert !wrapper.checkJoinTable(UserDO.class);
|
||||
assert !wrapper.checkJoinTable(UserDto.class);
|
||||
|
||||
assert list.get(0).getAddressList() != null && list.get(0).getAddressList().get(0).getId() != null;
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user