fixed and close #I6X4U8

This commit is contained in:
开源海哥 2023-04-21 12:55:18 +08:00
parent 9265fa7755
commit 3af6c82c67
3 changed files with 43 additions and 14 deletions

View File

@ -54,6 +54,10 @@ public class Brackets extends QueryCondition {
return checkEffective() ? WrapperUtil.getValues(childCondition) : null;
}
public QueryCondition getChildCondition(){
return childCondition;
}
@Override
public String toSql(List<QueryTable> queryTables, IDialect dialect) {
StringBuilder sql = new StringBuilder();

View File

@ -38,22 +38,34 @@ class WrapperUtil {
List<QueryWrapper> list = null;
while (condition != null) {
if (condition.checkEffective()) {
Object value = condition.getValue();
if (value instanceof QueryWrapper) {
if (list == null) {
list = new ArrayList<>();
if (condition instanceof Brackets) {
List<QueryWrapper> childQueryWrapper = getChildSelect(((Brackets) condition).getChildCondition());
if (!childQueryWrapper.isEmpty()) {
if (list == null) {
list = new ArrayList<>();
}
list.addAll(childQueryWrapper);
}
list.add((QueryWrapper) value);
list.addAll(((QueryWrapper) value).getChildSelect());
} else if (value != null && value.getClass().isArray()) {
for (int i = 0; i < Array.getLength(value); i++) {
Object arrayValue = Array.get(value, i);
if (arrayValue instanceof QueryWrapper) {
if (list == null) {
list = new ArrayList<>();
}
// not Brackets
else {
Object value = condition.getValue();
if (value instanceof QueryWrapper) {
if (list == null) {
list = new ArrayList<>();
}
list.add((QueryWrapper) value);
list.addAll(((QueryWrapper) value).getChildSelect());
} else if (value != null && value.getClass().isArray()) {
for (int i = 0; i < Array.getLength(value); i++) {
Object arrayValue = Array.get(value, i);
if (arrayValue instanceof QueryWrapper) {
if (list == null) {
list = new ArrayList<>();
}
list.add((QueryWrapper) arrayValue);
list.addAll(((QueryWrapper) arrayValue).getChildSelect());
}
list.add((QueryWrapper) arrayValue);
list.addAll(((QueryWrapper) arrayValue).getChildSelect());
}
}
}

View File

@ -64,6 +64,19 @@ public class EntityTestStarter {
// Page<Account> paginate = accountMapper.paginate(1,10,queryWrapper);
// System.out.println(paginate);
// QueryWrapper query = QueryWrapper.create()
// .where(ACCOUNT.ID.in(
// select(ACCOUNT.ID).from(ACCOUNT)
// .where(ACCOUNT.ID.eq(1))
// ).and("1 = 1")
// );
//
// List<Account> accounts = accountMapper.selectListByQuery(query);
// System.out.println(accounts);
// List<Account> accounts = new ArrayList<>();
// for (int i = 0; i < 10; i++) {
// Account account = new Account();