fixed: left join关联查询on有第二个条件赋值错误 close #I6YT2R

This commit is contained in:
开源海哥 2023-04-25 17:50:30 +08:00
parent a13540b83d
commit 5d1d556b1c
5 changed files with 45 additions and 8 deletions

View File

@ -65,7 +65,9 @@ public class CPI {
public static void setSelectColumnsIfNecessary(QueryWrapper queryWrapper, List<QueryColumn> selectColumns) {
if (CollectionUtil.isEmpty(queryWrapper.getSelectColumns())
&& CollectionUtil.isNotEmpty(selectColumns)) {
&& CollectionUtil.isNotEmpty(selectColumns)
&& CollectionUtil.isEmpty(CPI.getJoinTables(queryWrapper))
) {
queryWrapper.setSelectColumns(selectColumns);
}
}

View File

@ -65,6 +65,9 @@ public class Join implements Serializable {
this.on = condition;
}
QueryCondition getOnCondition(){
return on;
}
public boolean checkEffective() {
return effective;

View File

@ -348,25 +348,47 @@ public class QueryWrapper extends BaseQueryWrapper<QueryWrapper> {
* 在构建 sql 的时候需要保证 where having 的前面
*/
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[] havingValues = WrapperUtil.getValues(havingQueryCondition);
Object[] values = ArrayUtil.concat(whereValues, havingValues);
if (CollectionUtil.isNotEmpty(unions)) {
for (UnionWrapper union : unions) {
QueryWrapper queryWrapper = union.getQueryWrapper();
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> whereChildQuery= WrapperUtil.getChildSelect(whereQueryCondition);
List<QueryWrapper> whereChildQuery = WrapperUtil.getChildSelect(whereQueryCondition);
List<QueryWrapper> havingChildQuery = WrapperUtil.getChildSelect(havingQueryCondition);
if (whereChildQuery.isEmpty() && havingChildQuery.isEmpty()){
if (whereChildQuery.isEmpty() && havingChildQuery.isEmpty()) {
return Collections.emptyList();
}

View File

@ -232,7 +232,7 @@ public class TableInfoFactory {
largeColumns.add(columnName);
}
if (column == null || (!column.isLarge() && !column.isLogicDelete())) {
if (column == null || !column.isLarge()) {
defaultColumns.add(columnName);
}

View File

@ -27,6 +27,7 @@ import javax.sql.DataSource;
import java.util.List;
import static com.mybatisflex.test.table.Tables.ACCOUNT;
import static com.mybatisflex.test.table.Tables.ARTICLE;
public class EntityTestStarter {
@ -52,12 +53,21 @@ public class EntityTestStarter {
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)
.and(ACCOUNT.ID.ge(100).and(ACCOUNT.ID.ge(200)))
.and(ACCOUNT.ID.ge(100).and(ACCOUNT.ID.ge(200)))
.groupBy(ACCOUNT.ID);
.leftJoin(ARTICLE).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID).and(ACCOUNT.ID.ge(100)))
.and(ACCOUNT.ID.ge(100));
List<Account> accounts = accountMapper.selectListByQuery(wrapper);
System.out.println(accounts);
// QueryWrapper queryWrapper = new QueryWrapper();
// queryWrapper.where(ACCOUNT.ID.in(