mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 09:08:24 +08:00
fixed: 子表过滤应该在join 不应该在where; close #I7F03L
This commit is contained in:
parent
51df4b93e6
commit
6f2d8113c1
@ -30,7 +30,8 @@ import java.util.Map;
|
||||
|
||||
public class CPI {
|
||||
|
||||
private CPI() {}
|
||||
private CPI() {
|
||||
}
|
||||
|
||||
public static Object[] getValueArray(QueryWrapper queryWrapper) {
|
||||
return queryWrapper.getValueArray();
|
||||
@ -97,6 +98,15 @@ public class CPI {
|
||||
return join.getQueryTable();
|
||||
}
|
||||
|
||||
public static QueryCondition getJoinQueryCondition(Join join) {
|
||||
return join.on;
|
||||
}
|
||||
|
||||
public static void setJoinQueryCondition(Join join, QueryCondition queryCondition) {
|
||||
join.on = queryCondition;
|
||||
}
|
||||
|
||||
|
||||
public static List<QueryTable> getJoinTables(QueryWrapper queryWrapper) {
|
||||
return queryWrapper.getJoinTables();
|
||||
}
|
||||
|
||||
@ -632,7 +632,6 @@ public class TableInfo {
|
||||
}
|
||||
|
||||
private static final String APPEND_CONDITIONS_FLAG = "appendConditions";
|
||||
private static final String APPEND_JOIN_FLAG = "appendJoins";
|
||||
|
||||
public void appendConditions(Object entity, QueryWrapper queryWrapper) {
|
||||
|
||||
@ -699,23 +698,24 @@ public class TableInfo {
|
||||
|
||||
|
||||
//join
|
||||
if (!Boolean.TRUE.equals(CPI.getContext(queryWrapper, APPEND_JOIN_FLAG))) {
|
||||
List<Join> joins = CPI.getJoins(queryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(joins)) {
|
||||
for (Join join : joins) {
|
||||
QueryTable joinQueryTable = CPI.getJoinQueryTable(join);
|
||||
if (joinQueryTable instanceof SelectQueryTable) {
|
||||
QueryWrapper childQuery = ((SelectQueryTable) joinQueryTable).getQueryWrapper();
|
||||
doAppendConditions(entity, childQuery);
|
||||
} else {
|
||||
String nameWithSchema = joinQueryTable.getNameWithSchema();
|
||||
if (StringUtil.isNotBlank(nameWithSchema)) {
|
||||
TableInfo tableInfo = TableInfoFactory.ofTableName(nameWithSchema);
|
||||
if (tableInfo != null) {
|
||||
CPI.putContext(queryWrapper, APPEND_CONDITIONS_FLAG, Boolean.FALSE);
|
||||
CPI.putContext(queryWrapper, APPEND_JOIN_FLAG, Boolean.TRUE);
|
||||
tableInfo.appendConditions(entity, queryWrapper);
|
||||
}
|
||||
List<Join> joins = CPI.getJoins(queryWrapper);
|
||||
if (CollectionUtil.isNotEmpty(joins)) {
|
||||
for (Join join : joins) {
|
||||
QueryTable joinQueryTable = CPI.getJoinQueryTable(join);
|
||||
if (joinQueryTable instanceof SelectQueryTable) {
|
||||
QueryWrapper childQuery = ((SelectQueryTable) joinQueryTable).getQueryWrapper();
|
||||
doAppendConditions(entity, childQuery);
|
||||
} else {
|
||||
|
||||
String nameWithSchema = joinQueryTable.getNameWithSchema();
|
||||
if (StringUtil.isNotBlank(nameWithSchema)) {
|
||||
TableInfo tableInfo = TableInfoFactory.ofTableName(nameWithSchema);
|
||||
if (tableInfo != null) {
|
||||
QueryCondition joinQueryCondition = CPI.getJoinQueryCondition(join);
|
||||
QueryWrapper newWrapper = QueryWrapper.create()
|
||||
.where(joinQueryCondition);
|
||||
tableInfo.appendConditions(entity, newWrapper);
|
||||
CPI.setJoinQueryCondition(join, CPI.getWhereQueryCondition(newWrapper));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user