mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 17:48:25 +08:00
fixed: left join关联查询on有第二个条件赋值错误 close #I6YT2R
This commit is contained in:
parent
a13540b83d
commit
5d1d556b1c
@ -65,7 +65,9 @@ public class CPI {
|
|||||||
|
|
||||||
public static void setSelectColumnsIfNecessary(QueryWrapper queryWrapper, List<QueryColumn> selectColumns) {
|
public static void setSelectColumnsIfNecessary(QueryWrapper queryWrapper, List<QueryColumn> selectColumns) {
|
||||||
if (CollectionUtil.isEmpty(queryWrapper.getSelectColumns())
|
if (CollectionUtil.isEmpty(queryWrapper.getSelectColumns())
|
||||||
&& CollectionUtil.isNotEmpty(selectColumns)) {
|
&& CollectionUtil.isNotEmpty(selectColumns)
|
||||||
|
&& CollectionUtil.isEmpty(CPI.getJoinTables(queryWrapper))
|
||||||
|
) {
|
||||||
queryWrapper.setSelectColumns(selectColumns);
|
queryWrapper.setSelectColumns(selectColumns);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,6 +65,9 @@ public class Join implements Serializable {
|
|||||||
this.on = condition;
|
this.on = condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QueryCondition getOnCondition(){
|
||||||
|
return on;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean checkEffective() {
|
public boolean checkEffective() {
|
||||||
return effective;
|
return effective;
|
||||||
|
|||||||
@ -348,25 +348,47 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
|
|||||||
* 在构建 sql 的时候,需要保证 where 在 having 的前面
|
* 在构建 sql 的时候,需要保证 where 在 having 的前面
|
||||||
*/
|
*/
|
||||||
Object[] getValueArray() {
|
Object[] getValueArray() {
|
||||||
|
List<Object> joinValues = null;
|
||||||
|
List<Join> joins = getJoins();
|
||||||
|
if (CollectionUtil.isNotEmpty(joins)) {
|
||||||
|
for (Join join : joins) {
|
||||||
|
QueryCondition onCondition = join.getOnCondition();
|
||||||
|
Object[] values = WrapperUtil.getValues(onCondition);
|
||||||
|
if (values.length > 0) {
|
||||||
|
if (joinValues == null) {
|
||||||
|
joinValues = new ArrayList<>();
|
||||||
|
}
|
||||||
|
joinValues.addAll(Arrays.asList(values));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Object[] whereValues = WrapperUtil.getValues(whereQueryCondition);
|
Object[] whereValues = WrapperUtil.getValues(whereQueryCondition);
|
||||||
Object[] havingValues = WrapperUtil.getValues(havingQueryCondition);
|
Object[] havingValues = WrapperUtil.getValues(havingQueryCondition);
|
||||||
|
|
||||||
Object[] values = ArrayUtil.concat(whereValues, havingValues);
|
Object[] values = ArrayUtil.concat(whereValues, havingValues);
|
||||||
|
|
||||||
if (CollectionUtil.isNotEmpty(unions)) {
|
if (CollectionUtil.isNotEmpty(unions)) {
|
||||||
for (UnionWrapper union : unions) {
|
for (UnionWrapper union : unions) {
|
||||||
QueryWrapper queryWrapper = union.getQueryWrapper();
|
QueryWrapper queryWrapper = union.getQueryWrapper();
|
||||||
values = ArrayUtil.concat(values, queryWrapper.getValueArray());
|
values = ArrayUtil.concat(values, queryWrapper.getValueArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return values;
|
|
||||||
|
if (joinValues != null) {
|
||||||
|
return ArrayUtil.concat(joinValues.toArray(), values);
|
||||||
|
} else {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<QueryWrapper> getChildSelect() {
|
List<QueryWrapper> getChildSelect() {
|
||||||
|
|
||||||
List<QueryWrapper> whereChildQuery= WrapperUtil.getChildSelect(whereQueryCondition);
|
List<QueryWrapper> whereChildQuery = WrapperUtil.getChildSelect(whereQueryCondition);
|
||||||
List<QueryWrapper> havingChildQuery = WrapperUtil.getChildSelect(havingQueryCondition);
|
List<QueryWrapper> havingChildQuery = WrapperUtil.getChildSelect(havingQueryCondition);
|
||||||
|
|
||||||
if (whereChildQuery.isEmpty() && havingChildQuery.isEmpty()){
|
if (whereChildQuery.isEmpty() && havingChildQuery.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -232,7 +232,7 @@ public class TableInfoFactory {
|
|||||||
largeColumns.add(columnName);
|
largeColumns.add(columnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (column == null || (!column.isLarge() && !column.isLogicDelete())) {
|
if (column == null || !column.isLarge()) {
|
||||||
defaultColumns.add(columnName);
|
defaultColumns.add(columnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import javax.sql.DataSource;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.mybatisflex.test.table.Tables.ACCOUNT;
|
import static com.mybatisflex.test.table.Tables.ACCOUNT;
|
||||||
|
import static com.mybatisflex.test.table.Tables.ARTICLE;
|
||||||
|
|
||||||
public class EntityTestStarter {
|
public class EntityTestStarter {
|
||||||
|
|
||||||
@ -52,12 +53,21 @@ public class EntityTestStarter {
|
|||||||
|
|
||||||
AccountMapper accountMapper = bootstrap.getMapper(AccountMapper.class);
|
AccountMapper accountMapper = bootstrap.getMapper(AccountMapper.class);
|
||||||
|
|
||||||
|
// QueryWrapper wrapper = QueryWrapper.create().select().from(ACCOUNT)
|
||||||
|
// .and(ACCOUNT.ID.ge(100).and(ACCOUNT.ID.ge(200)))
|
||||||
|
// .and(ACCOUNT.ID.ge(100).and(ACCOUNT.ID.ge(200)))
|
||||||
|
// .groupBy(ACCOUNT.ID);
|
||||||
|
//
|
||||||
|
// List<Account> accounts = accountMapper.selectListByQuery(wrapper);
|
||||||
|
|
||||||
|
|
||||||
QueryWrapper wrapper = QueryWrapper.create().select().from(ACCOUNT)
|
QueryWrapper wrapper = QueryWrapper.create().select().from(ACCOUNT)
|
||||||
.and(ACCOUNT.ID.ge(100).and(ACCOUNT.ID.ge(200)))
|
.leftJoin(ARTICLE).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID).and(ACCOUNT.ID.ge(100)))
|
||||||
.and(ACCOUNT.ID.ge(100).and(ACCOUNT.ID.ge(200)))
|
.and(ACCOUNT.ID.ge(100));
|
||||||
.groupBy(ACCOUNT.ID);
|
|
||||||
|
|
||||||
List<Account> accounts = accountMapper.selectListByQuery(wrapper);
|
List<Account> accounts = accountMapper.selectListByQuery(wrapper);
|
||||||
|
System.out.println(accounts);
|
||||||
|
|
||||||
|
|
||||||
// QueryWrapper queryWrapper = new QueryWrapper();
|
// QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
// queryWrapper.where(ACCOUNT.ID.in(
|
// queryWrapper.where(ACCOUNT.ID.in(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user